-
Notifications
You must be signed in to change notification settings - Fork 46
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
e504e79
a8400b0
634ead7
ea5047d
27dde4c
741586c
75a99e3
53cb522
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 |
|---|---|---|
|
|
@@ -2,12 +2,14 @@ package cocoapods | |
|
|
||
| import ( | ||
| "fmt" | ||
| "golang.org/x/exp/slices" | ||
| "os" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
|
|
||
| "golang.org/x/exp/slices" | ||
|
|
||
| biutils "github.com/jfrog/build-info-go/utils" | ||
| "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 +24,9 @@ import ( | |
| // dependencies. | ||
| const ( | ||
| VersionForMainModule = "0.0.0" | ||
|
|
||
| descriptorFileName = "Podfile" | ||
| lockFileName = "Podfile.lock" | ||
| ) | ||
|
|
||
| var ( | ||
|
|
@@ -34,7 +39,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 +97,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 +185,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)) | ||
|
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. Is this necessary? we called it and checked the existence of the lock file prior to the call to GetDependenciesData |
||
| 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 +204,24 @@ func BuildDependencyTree(params technologies.BuildInfoBomGeneratorParams) (depen | |
|
|
||
| packageName := filepath.Base(currentDir) | ||
| packageInfo := fmt.Sprintf("%s:%s", packageName, VersionForMainModule) | ||
| _, _, err = getPodVersionAndExecPath() | ||
| _, podExecPath, err := getPodVersionAndExecPath() | ||
|
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. This is used only inside the 'if' and if !SkipAutoInstall |
||
| 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' | ||
|
attiasas marked this conversation as resolved.
|
||
| lockFilePath := filepath.Join(currentDir, lockFileName) | ||
| if _, err := os.Stat(lockFilePath); os.IsNotExist(err) { | ||
|
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. Error variable shadowing — permission errors silently swallowed |
||
| if params.SkipAutoInstall { | ||
|
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. No unit tests for the new auto-install / SkipAutoInstall code paths. Yarn and NuGet both test SkipAutoInstall at the unit level; at minimum, add a test asserting ErrProjectNotInstalled is returned |
||
| return nil, nil, &biutils.ErrProjectNotInstalled{UninstalledDir: currentDir} | ||
| } | ||
| log.Debug("Running 'pod install' command to install dependencies...") | ||
| if _, err = runPodCmd(podExecPath, currentDir, []string{"install"}); err != nil { | ||
|
attiasas marked this conversation as resolved.
|
||
| return nil, nil, fmt.Errorf("failed to run 'pod install': %w", err) | ||
| } | ||
| } else if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to check if lock file exists: %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.
TestXrayAuditCocoapodsNoLockFile will fail noisily on Linux CI without CocoaPods — add a pod binary availability skip guard.