Skip to content

Commit f20e966

Browse files
committed
cmd/gomobile: filter out xcrun warnings to get path
Currently some installations of Xcode and Command Line Tools cause warnings about missing extensions which break parsing of paths returned from `xcrun` that `gomobile` depends on resulting in errors like this: ``` cgo: C compiler "2022-09-07" not found: exec: "2022-09-07": executable file not found in $PATH ``` This is caused by these warnings returned on `stdout` by `xcrun`: ``` > xcrun --find clang 2022-09-07 14:50:13.907 xcodebuild[69942:386823822] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore 2022-09-07 14:50:13.908 xcodebuild[69942:386823822] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore 2022-09-07 14:50:14.041 xcodebuild[69942:386823822] XType: com.apple.fonts is not accessible. 2022-09-07 14:50:14.041 xcodebuild[69942:386823822] XType: XTFontStaticRegistry is enabled. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang ``` Resulting in `gomobile` interpreting the date `2022-09-07` as Clang compiler. Resolves: golang/go#53316 Signed-off-by: Jakub Sokołowski <[email protected]>
1 parent aaac322 commit f20e966

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cmd/gomobile/env.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,16 @@ func ndkRoot(targets ...targetInfo) (string, error) {
431431
return ndkRoot, nil
432432
}
433433

434+
// Necessary to filter out warnings about missing extensions.
435+
func getAbsolutePath(output []byte) (path string) {
436+
for _, line := range strings.Split(string(output), "\n") {
437+
if strings.HasPrefix(line, "/") {
438+
return line
439+
}
440+
}
441+
return ""
442+
}
443+
434444
func envClang(sdkName string) (clang, cflags string, err error) {
435445
if buildN {
436446
return sdkName + "-clang", "-isysroot " + sdkName, nil
@@ -440,14 +450,14 @@ func envClang(sdkName string) (clang, cflags string, err error) {
440450
if err != nil {
441451
return "", "", fmt.Errorf("xcrun --find: %v\n%s", err, out)
442452
}
443-
clang = strings.TrimSpace(string(out))
453+
clang = getAbsolutePath(out)
444454

445455
cmd = exec.Command("xcrun", "--sdk", sdkName, "--show-sdk-path")
446456
out, err = cmd.CombinedOutput()
447457
if err != nil {
448458
return "", "", fmt.Errorf("xcrun --show-sdk-path: %v\n%s", err, out)
449459
}
450-
sdk := strings.TrimSpace(string(out))
460+
sdk := getAbsolutePath(out)
451461
return clang, "-isysroot " + sdk, nil
452462
}
453463

0 commit comments

Comments
 (0)