-
Notifications
You must be signed in to change notification settings - Fork 45
Auto install Cocoapods when Podfile.lock not exist #723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
7ebdf6c
282c55c
48e9e60
6a4ae3a
50230bc
b874485
d3ceb61
88ead38
56a1f07
3ea40cb
bea61aa
5422e98
35a1e94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,7 +311,7 @@ var flagsMap = map[string]components.Flag{ | |
| WorkingDirs: components.NewStringFlag(WorkingDirs, "A comma-separated(,) list of relative working directories, to determine the audit targets locations. If flag isn't provided, a recursive scan is triggered from the root directory of the project."), | ||
| OutputDir: components.NewStringFlag(OutputDir, "Target directory to save partial results to.", components.SetHiddenStrFlag()), | ||
| UploadRepoPath: components.NewStringFlag(UploadRepoPath, "Artifactory repository name or path to upload the cyclonedx file to. If no name or path are provided, a local generic repository will be created which will automatically be indexed by Xray.", components.WithStrDefaultValue("import-cdx-scan-results")), | ||
| SkipAutoInstall: components.NewBoolFlag(SkipAutoInstall, "Set to true to skip auto-install of dependencies in un-built modules. Currently supported for Yarn and NPM only.", components.SetHiddenBoolFlag()), | ||
| SkipAutoInstall: components.NewBoolFlag(SkipAutoInstall, "Set to true to skip auto-install of dependencies in un-built modules. Currently supported only for some package managers.", components.SetHiddenBoolFlag()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. “Some package managers” is vague for troubleshooting. Even for a hidden flag, naming Yarn, npm, and CocoaPods (or “including CocoaPods”) may be more useful . |
||
| AllowPartialResults: components.NewBoolFlag(AllowPartialResults, "Set to true to allow partial results and continuance of the scan in case of certain errors.", components.SetHiddenBoolFlag()), | ||
| ExclusionsAudit: components.NewStringFlag( | ||
| Exclusions, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,13 @@ package cocoapods | |
|
|
||
| import ( | ||
| "fmt" | ||
| "golang.org/x/exp/slices" | ||
| "os" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
|
|
||
| "golang.org/x/exp/slices" | ||
|
|
||
| "github.com/jfrog/gofrog/datastructures" | ||
| "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" | ||
| "github.com/jfrog/jfrog-cli-security/sca/bom/buildinfo/technologies" | ||
|
|
@@ -22,6 +23,9 @@ import ( | |
| // dependencies. | ||
| const ( | ||
| VersionForMainModule = "0.0.0" | ||
|
|
||
| descriptorFileName = "Podfile" | ||
| lockFileName = "Podfile.lock" | ||
| ) | ||
|
|
||
| var ( | ||
|
|
@@ -34,7 +38,7 @@ func GetTechDependencyLocation(directDependencyName, directDependencyVersion str | |
| var podPositions []*sarif.Location | ||
| for _, descriptorPath := range descriptorPaths { | ||
| descriptorPath = filepath.Clean(descriptorPath) | ||
| if !strings.HasSuffix(descriptorPath, "Podfile") { | ||
| if !strings.HasSuffix(descriptorPath, descriptorFileName) { | ||
| log.Logger.Warn("Cannot support other files besides Podfile: %s", descriptorPath) | ||
| continue | ||
| } | ||
|
|
@@ -92,7 +96,7 @@ func parsePodLine(line, directDependencyName, directDependencyVersion, descripto | |
| func FixTechDependency(dependencyName, dependencyVersion, fixVersion string, descriptorPaths ...string) error { | ||
| for _, descriptorPath := range descriptorPaths { | ||
| descriptorPath = filepath.Clean(descriptorPath) | ||
| if !strings.HasSuffix(descriptorPath, "Podfile") { | ||
| if !strings.HasSuffix(descriptorPath, descriptorFileName) { | ||
| log.Logger.Warn("Cannot support other files besides Podfile: %s", descriptorPath) | ||
| continue | ||
| } | ||
|
|
@@ -180,11 +184,11 @@ func extractPodsSection(filePath string) (string, error) { | |
| } | ||
|
|
||
| func GetDependenciesData(currentDir string) (string, error) { | ||
| _, err := os.Stat(filepath.Join(currentDir, "Podfile.lock")) | ||
| _, err := os.Stat(filepath.Join(currentDir, lockFileName)) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| result, err := extractPodsSection(filepath.Join(currentDir, "Podfile.lock")) | ||
| result, err := extractPodsSection(filepath.Join(currentDir, lockFileName)) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
@@ -199,11 +203,21 @@ func BuildDependencyTree(params technologies.BuildInfoBomGeneratorParams) (depen | |
|
|
||
| packageName := filepath.Base(currentDir) | ||
| packageInfo := fmt.Sprintf("%s:%s", packageName, VersionForMainModule) | ||
| _, _, err = getPodVersionAndExecPath() | ||
| _, podExecPath, err := getPodVersionAndExecPath() | ||
| if err != nil { | ||
| err = fmt.Errorf("failed while retrieving pod path: %s", err.Error()) | ||
| return | ||
| } | ||
| // Check if lock file exists, if not run 'pod install' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| lockFilePath := filepath.Join(currentDir, lockFileName) | ||
| if _, err := os.Stat(lockFilePath); os.IsNotExist(err) { | ||
| if params.SkipAutoInstall { | ||
| return nil, nil, fmt.Errorf("the Podfile.lock file was not found and skip auto install is enabled") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can write "skip-auto-install" to be aligned with the real flag name. |
||
| } | ||
| if _, err = runPodCmd(podExecPath, currentDir, []string{"install"}); err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Auto pod install writes into the project (Pods/, Podfile.lock). Worth a one-line note in the PR description or docs so users expect workspace mutation (similar to npm/yarn auto-install). |
||
| return nil, nil, fmt.Errorf("failed to run 'pod install': %w", err) | ||
| } | ||
| } | ||
| // Calculate pod dependencies | ||
| data, err := GetDependenciesData(currentDir) | ||
| if err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| platform :ios, '9.0' | ||
|
|
||
| target 'Test' do | ||
| use_frameworks! | ||
| pod 'GoogleSignIn', '~> 6.2.4' | ||
| pod 'AppAuth', '~> 1.7.5' | ||
| pod 'nanopb', '~> 0.3.0' | ||
|
|
||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant "return"