aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Chris Parsons <cparsons@google.com>2017-02-17 00:09:48 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2017-02-17 14:53:48 +0000
commitb3aa6ce3be689c91a6cbfae0f4b1ebff4a942872 (patch)
treee1f6a83fc104b654332b1c21e7b89231622f2f1b
parentedeb6d0ba47a52ddd9fc421f1ab577f4eafdc2b5 (diff)
Improve xcode-configure error messaging, and use "env -i" to clear environment for various processes
-- PiperOrigin-RevId: 147780864 MOS_MIGRATED_REVID=147780864
-rwxr-xr-xsrc/test/shell/bazel/apple/bazel_apple_test.sh6
-rw-r--r--tools/osx/xcode_configure.bzl54
2 files changed, 39 insertions, 21 deletions
diff --git a/src/test/shell/bazel/apple/bazel_apple_test.sh b/src/test/shell/bazel/apple/bazel_apple_test.sh
index 94c4822524..6a54e9824b 100755
--- a/src/test/shell/bazel/apple/bazel_apple_test.sh
+++ b/src/test/shell/bazel/apple/bazel_apple_test.sh
@@ -541,11 +541,11 @@ EOF
}
function test_host_xcodes() {
- XCODE_VERSION=$(xcodebuild -version | grep "Xcode" \
+ XCODE_VERSION=$(env -i xcodebuild -version | grep "Xcode" \
| sed -E "s/Xcode (([0-9]|.)+).*/\1/")
- IOS_SDK=$(xcodebuild -version -sdk | grep iphoneos \
+ IOS_SDK=$(env -i xcodebuild -version -sdk | grep iphoneos \
| sed -E "s/.*\(iphoneos(([0-9]|.)+)\).*/\1/")
- MACOSX_SDK=$(xcodebuild -version -sdk | grep macosx \
+ MACOSX_SDK=$(env -i xcodebuild -version -sdk | grep macosx \
| sed -E "s/.*\(macosx(([0-9]|.)+)\).*/\1/" | head -n 1)
# Unfortunately xcodebuild -version doesn't always pad with trailing .0, so,
diff --git a/tools/osx/xcode_configure.bzl b/tools/osx/xcode_configure.bzl
index 96bccdd881..16e4688adc 100644
--- a/tools/osx/xcode_configure.bzl
+++ b/tools/osx/xcode_configure.bzl
@@ -50,14 +50,18 @@ def _xcode_version_output(repository_ctx, name, version, aliases, developer_dir)
"""Returns a string containing an xcode_version build target."""
build_contents = ""
decorated_aliases = []
+ error_msg = ""
for alias in aliases:
decorated_aliases.append("'%s'" % alias)
- xcodebuild_result = repository_ctx.execute(["xcodebuild", "-version", "-sdk"], 5, {"DEVELOPER_DIR": developer_dir})
+ xcodebuild_result = repository_ctx.execute(["xcodebuild", "-version", "-sdk"], 5,
+ {"DEVELOPER_DIR": developer_dir})
if (xcodebuild_result.return_code != 0):
- print(
- "Invoking xcodebuild failed, return code {code}, stderr: {err}".format(
+ error_msg = (
+ "Invoking xcodebuild failed, " +
+ "return code {code}, stderr: {err}, stdout: {out}").format(
code=xcodebuild_result.return_code,
- err=xcodebuild_result.stderr))
+ err=xcodebuild_result.stderr,
+ out=xcodebuild_result.stdout)
ios_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "iphoneos")
tvos_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "appletvos")
macosx_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "macosx")
@@ -75,6 +79,9 @@ def _xcode_version_output(repository_ctx, name, version, aliases, developer_dir)
if watchos_sdk_version:
build_contents += "\n default_watchos_sdk_version = '%s'," % watchos_sdk_version
build_contents += "\n)\n"
+ if error_msg:
+ build_contents += "\n# Error: " + error_msg.replace("\n", " ") + "\n"
+ print(error_msg)
return build_contents
@@ -83,33 +90,44 @@ VERSION_CONFIG_STUB = "xcode_config(name = 'host_xcodes')"
def _darwin_build_file(repository_ctx):
"""Evaluates local system state to create xcode_config and xcode_version targets."""
- xcodebuild_result = repository_ctx.execute(["xcodebuild", "-version"])
+ xcodebuild_result = repository_ctx.execute(["env", "-i", "xcodebuild", "-version"])
# "xcodebuild -version" failing may be indicative of no versions of xcode
# installed, which is an acceptable machine configuration to have for using
- # bazel. Thus no warning should be emitted here.
+ # bazel. Thus no print warning should be emitted here.
if (xcodebuild_result.return_code != 0):
- return VERSION_CONFIG_STUB
+ error_msg = (
+ "Running xcodebuild -version failed, " +
+ "return code {code}, stderr: {err}, stdout: {out}").format(
+ code=xcodebuild_result.return_code,
+ err=xcodebuild_result.stderr,
+ out=xcodebuild_result.stdout)
+ return VERSION_CONFIG_STUB + "\n# Error: " + error_msg.replace("\n", " ") + "\n"
xcodeloc_src_path = str(repository_ctx.path(Label(repository_ctx.attr.xcode_locator)))
- xcrun_result = repository_ctx.execute(["xcrun", "clang", "-fobjc-arc", "-framework",
+ xcrun_result = repository_ctx.execute(["env", "-i", "xcrun", "clang", "-fobjc-arc", "-framework",
"CoreServices", "-framework", "Foundation", "-o",
- "xcode-locator-bin", xcodeloc_src_path],
- 5, {"SDKROOT": "", "IPHONEOS_DEPLOYMENT_TARGET": ""})
+ "xcode-locator-bin", xcodeloc_src_path], 5)
if (xcrun_result.return_code != 0):
- print(
- "Generating xcode-locator-bin failed, return code {code}, stderr: {err}".format(
+ error_msg = (
+ "Generating xcode-locator-bin failed, " +
+ "return code {code}, stderr: {err}, stdout: {out}").format(
code=xcrun_result.return_code,
- err=xcrun_result.stderr))
- return VERSION_CONFIG_STUB
+ err=xcrun_result.stderr,
+ out=xcrun_result.stdout)
+ print(error_msg)
+ return VERSION_CONFIG_STUB + "\n# Error: " + error_msg.replace("\n", " ") + "\n"
xcode_locator_result = repository_ctx.execute(["./xcode-locator-bin", "-v"])
if (xcode_locator_result.return_code != 0):
- print(
- "Invoking xcode-locator failed, return code {code}, stderr: {err}".format(
+ error_msg = (
+ "Invoking xcode-locator failed, " +
+ "return code {code}, stderr: {err}, stdout: {out}").format(
code=xcode_locator_result.return_code,
- err=xcode_locator_result.stderr))
- return VERSION_CONFIG_STUB
+ err=xcode_locator_result.stderr,
+ out=xcode_locator_result.stdout)
+ print(error_msg)
+ return VERSION_CONFIG_STUB + "\n# Error: " + error_msg.replace("\n", " ") + "\n"
default_xcode_version = _search_string(xcodebuild_result.stdout, "Xcode ", "\n")
default_xcode_target = ""