diff --git a/Gopkg.lock b/Gopkg.lock index 72eb74bc..592fbc24 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -92,7 +92,7 @@ [[projects]] branch = "master" - digest = "1:c5ac1b062ba1470ca0901d2272624bd59d42042f15e92c8d0b15b5711a123d64" + digest = "1:241f153676f6090e307e6858d11d71f1d61d48bdf666718db1f116e325e7d3ba" name = "github.com/bitrise-tools/go-xcode" packages = [ "certificateutil", @@ -106,7 +106,7 @@ "xcodeproj", ] pruneopts = "UT" - revision = "8e44ecb550c0cadef602edda92e5c10476dd5daa" + revision = "b3f7172f910693d60973a07b61db757aca81f778" [[projects]] branch = "master" diff --git a/codesigndocuitests/iostestrunner.go b/codesigndocuitests/iostestrunner.go index 3236d08c..7a756db1 100644 --- a/codesigndocuitests/iostestrunner.go +++ b/codesigndocuitests/iostestrunner.go @@ -9,6 +9,7 @@ import ( "github.com/bitrise-io/go-utils/pathutil" "github.com/bitrise-tools/go-xcode/plistutil" "github.com/bitrise-tools/go-xcode/profileutil" + "github.com/bitrise-tools/go-xcode/utility" ) // IOSTestRunner ... @@ -21,7 +22,7 @@ type IOSTestRunner struct { // NewIOSTestRunners is the *-Runner.app which is generated with the xcodebuild build-for-testing command func NewIOSTestRunners(path string) ([]*IOSTestRunner, error) { - runnerPattern := filepath.Join(path, "*-Runner.app") + runnerPattern := filepath.Join(utility.EscapeGlobPath(path), "*-Runner.app") possibleTestRunnerPths, err := filepath.Glob(runnerPattern) if err != nil { return nil, err diff --git a/vendor/github.com/bitrise-tools/go-xcode/profileutil/util.go b/vendor/github.com/bitrise-tools/go-xcode/profileutil/util.go index e29bda85..c5a4f3b5 100644 --- a/vendor/github.com/bitrise-tools/go-xcode/profileutil/util.go +++ b/vendor/github.com/bitrise-tools/go-xcode/profileutil/util.go @@ -5,6 +5,7 @@ import ( "github.com/bitrise-io/go-utils/fileutil" "github.com/bitrise-io/go-utils/pathutil" + "github.com/bitrise-tools/go-xcode/utility" "github.com/fullsailor/pkcs7" ) @@ -46,7 +47,7 @@ func InstalledProvisioningProfiles(profileType ProfileType) ([]*pkcs7.PKCS7, err return nil, err } - pattern := filepath.Join(absProvProfileDirPath, "*"+ext) + pattern := filepath.Join(utility.EscapeGlobPath(absProvProfileDirPath), "*"+ext) pths, err := filepath.Glob(pattern) if err != nil { return nil, err diff --git a/vendor/github.com/bitrise-tools/go-xcode/utility/glob.go b/vendor/github.com/bitrise-tools/go-xcode/utility/glob.go new file mode 100644 index 00000000..1333c6f4 --- /dev/null +++ b/vendor/github.com/bitrise-tools/go-xcode/utility/glob.go @@ -0,0 +1,13 @@ +package utility + +// EscapeGlobPath escapes a partial path, determined at runtime, used as a parameter for filepath.Glob +func EscapeGlobPath(path string) string { + var escaped string + for _, ch := range path { + if ch == '[' || ch == ']' || ch == '-' || ch == '*' || ch == '?' || ch == '\\' { + escaped += "\\" + } + escaped += string(ch) + } + return escaped +} diff --git a/vendor/github.com/bitrise-tools/go-xcode/xcarchive/ios.go b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/ios.go index 7d2faafd..b83eb55d 100644 --- a/vendor/github.com/bitrise-tools/go-xcode/xcarchive/ios.go +++ b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/ios.go @@ -109,7 +109,7 @@ func NewIosWatchApplication(path string) (IosWatchApplication, error) { } extensions := []IosExtension{} - pattern := filepath.Join(path, "PlugIns/*.appex") + pattern := filepath.Join(utility.EscapeGlobPath(path), "PlugIns/*.appex") pths, err := filepath.Glob(pattern) if err != nil { return IosWatchApplication{}, fmt.Errorf("failed to search for watch application's extensions using pattern: %s, error: %s", pattern, err) @@ -145,7 +145,7 @@ func NewIosApplication(path string) (IosApplication, error) { var watchApp *IosWatchApplication { - pattern := filepath.Join(path, "Watch/*.app") + pattern := filepath.Join(utility.EscapeGlobPath(path), "Watch/*.app") pths, err := filepath.Glob(pattern) if err != nil { return IosApplication{}, err @@ -162,7 +162,7 @@ func NewIosApplication(path string) (IosApplication, error) { extensions := []IosExtension{} { - pattern := filepath.Join(path, "PlugIns/*.appex") + pattern := filepath.Join(utility.EscapeGlobPath(path), "PlugIns/*.appex") pths, err := filepath.Glob(pattern) if err != nil { return IosApplication{}, fmt.Errorf("failed to search for watch application's extensions using pattern: %s, error: %s", pattern, err) @@ -210,17 +210,19 @@ func NewIosArchive(path string) (IosArchive, error) { application := IosApplication{} { - pattern := filepath.Join(path, "Products/Applications/*.app") - pths, err := filepath.Glob(pattern) - if err != nil { - return IosArchive{}, err - } - appPath := "" - if len(pths) > 0 { - appPath = pths[0] + if appRelativePathToProducts, found := applicationFromPlist(infoPlist); found { + appPath = filepath.Join(path, "Products", appRelativePathToProducts) } else { - return IosArchive{}, fmt.Errorf("failed to find main app, using pattern: %s", pattern) + var err error + if appPath, err = applicationFromArchive(path); err != nil { + return IosArchive{}, err + } + } + if exist, err := pathutil.IsPathExists(appPath); err != nil { + return IosArchive{}, fmt.Errorf("failed to check if app exists, path: %s, error: %s", appPath, err) + } else if !exist { + return IosArchive{}, fmt.Errorf("application not found on path: %s, error: %s", appPath, err) } app, err := NewIosApplication(appPath) @@ -237,6 +239,25 @@ func NewIosArchive(path string) (IosArchive, error) { }, nil } +func applicationFromPlist(InfoPlist plistutil.PlistData) (string, bool) { + if properties, found := InfoPlist.GetMapStringInterface("ApplicationProperties"); found { + return properties.GetString("ApplicationPath") + } + return "", false +} + +func applicationFromArchive(path string) (string, error) { + pattern := filepath.Join(utility.EscapeGlobPath(path), "Products/Applications/*.app") + pths, err := filepath.Glob(pattern) + if err != nil { + return "", err + } + if len(pths) == 0 { + return "", fmt.Errorf("failed to find main app, using pattern: %s", pattern) + } + return pths[0], nil +} + // IsXcodeManaged ... func (archive IosArchive) IsXcodeManaged() bool { return archive.Application.ProvisioningProfile.IsXcodeManaged() @@ -244,8 +265,7 @@ func (archive IosArchive) IsXcodeManaged() bool { // SigningIdentity ... func (archive IosArchive) SigningIdentity() string { - properties, found := archive.InfoPlist.GetMapStringInterface("ApplicationProperties") - if found { + if properties, found := archive.InfoPlist.GetMapStringInterface("ApplicationProperties"); found { identity, _ := properties.GetString("SigningIdentity") return identity } diff --git a/vendor/github.com/bitrise-tools/go-xcode/xcarchive/macos.go b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/macos.go index 7907149a..234daf39 100644 --- a/vendor/github.com/bitrise-tools/go-xcode/xcarchive/macos.go +++ b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/macos.go @@ -109,7 +109,7 @@ func NewMacosApplication(path string) (MacosApplication, error) { extensions := []MacosExtension{} { - pattern := filepath.Join(path, "Contents/PlugIns/*.appex") + pattern := filepath.Join(utility.EscapeGlobPath(path), "Contents/PlugIns/*.appex") pths, err := filepath.Glob(pattern) if err != nil { return MacosApplication{}, fmt.Errorf("failed to search for watch application's extensions using pattern: %s, error: %s", pattern, err) @@ -156,7 +156,7 @@ func NewMacosArchive(path string) (MacosArchive, error) { application := MacosApplication{} { - pattern := filepath.Join(path, "Products/Applications/*.app") + pattern := filepath.Join(utility.EscapeGlobPath(path), "Products/Applications/*.app") pths, err := filepath.Glob(pattern) if err != nil { return MacosArchive{}, err