Skip to content

Commit

Permalink
Automated rollback of commit d03dcfb.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Breaks in edge cases where xcodes are not or incorrectly installed.

*** Original change description ***

Make Xcode setup more resilient

Previously if you tried to build a project from a entirely clean bazel
state, and ctrl-c'd while bazel was fetching the local_config_xcode
information, you would end up in a state where the
local_config_xcode/BUILD file contained error information, which made
the Apple crosstool unusable until you did a `clean --expunge`. Now the
Xcode setup calls `fail()` in those cases, which makes bazel re-run it
again the next time you try to build.

It is still possible to reproduce if you ctrl-c while the `xcodebuild
-version` command that determines if you have Xcode installed at all
runs. Because we want to support users who don't have Xcode installed on
macOS, we cannot fail in that case.

Fixes #6056

Closes #7519.

PiperOrigin-RevId: 236161124
  • Loading branch information
keith authored and copybara-github committed Feb 28, 2019
1 parent 4187acf commit c6c9b58
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 158 deletions.
4 changes: 3 additions & 1 deletion tools/cpp/osx_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def configure_osx_toolchain(repository_ctx, overriden_tools):
])

xcode_toolchains = []
xcode_toolchains = run_xcode_locator(
(xcode_toolchains, xcodeloc_err) = run_xcode_locator(
repository_ctx,
paths["@bazel_tools//tools/osx:xcode_locator.m"],
)
Expand Down Expand Up @@ -133,6 +133,8 @@ def configure_osx_toolchain(repository_ctx, overriden_tools):
escaped_cxx_include_directories = []
for path in escaped_include_paths:
escaped_cxx_include_directories.append((" \"%s\"," % path))
if xcodeloc_err:
escaped_cxx_include_directories.append("# Error: " + xcodeloc_err + "\n")
repository_ctx.template(
"cc_toolchain_config.bzl",
paths["@bazel_tools//tools/osx/crosstool:cc_toolchain_config.bzl.tpl"],
Expand Down
144 changes: 0 additions & 144 deletions tools/cpp/osx_cc_configure.bzl.orig

This file was deleted.

32 changes: 19 additions & 13 deletions tools/osx/xcode_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ 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(
Expand All @@ -64,8 +65,6 @@ def _xcode_version_output(repository_ctx, name, version, aliases, developer_dir)
err = xcodebuild_result.stderr,
out = xcodebuild_result.stdout,
)
print(error_msg)
fail(error_msg)
ios_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "iphoneos")
tvos_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "appletvos")
macos_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "macosx")
Expand All @@ -83,6 +82,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

VERSION_CONFIG_STUB = "xcode_config(name = 'host_xcodes')"
Expand All @@ -102,10 +104,13 @@ def run_xcode_locator(repository_ctx, xcode_locator_src_label):
repository_ctx: The repository context.
xcode_locator_src_label: The label of the source file for xcode-locator.
Returns:
A list representing installed xcode toolchain information. Each
element of the list is a struct containing information for one installed
toolchain. This is an empty list if there was an error building or
running xcode-locator.
A 2-tuple containing:
output: A list representing installed xcode toolchain information. Each
element of the list is a struct containing information for one installed
toolchain. This is an empty list if there was an error building or
running xcode-locator.
err: An error string describing the error that occurred when attempting
to build and run xcode-locator, or None if the run was successful.
"""
xcodeloc_src_path = str(repository_ctx.path(xcode_locator_src_label))
xcrun_result = repository_ctx.execute([
Expand Down Expand Up @@ -137,8 +142,7 @@ def run_xcode_locator(repository_ctx, xcode_locator_src_label):
err = xcrun_result.stderr,
out = xcrun_result.stdout,
)
print(error_msg)
fail(error_msg)
return ([], error_msg.replace("\n", " "))

xcode_locator_result = repository_ctx.execute(["./xcode-locator-bin", "-v"], 30)
if (xcode_locator_result.return_code != 0):
Expand All @@ -149,9 +153,8 @@ def run_xcode_locator(repository_ctx, xcode_locator_src_label):
code = xcode_locator_result.return_code,
err = xcode_locator_result.stderr,
out = xcode_locator_result.stdout,
).replace("\n", " ")
print(error_msg)
fail(error_msg)
)
return ([], error_msg.replace("\n", " "))
xcode_toolchains = []

# xcode_dump is comprised of newlines with different installed xcode versions,
Expand All @@ -166,7 +169,7 @@ def run_xcode_locator(repository_ctx, xcode_locator_src_label):
developer_dir = infosplit[2],
)
xcode_toolchains.append(toolchain)
return xcode_toolchains
return (xcode_toolchains, None)

def _darwin_build_file(repository_ctx):
"""Evaluates local system state to create xcode_config and xcode_version targets."""
Expand All @@ -186,11 +189,14 @@ def _darwin_build_file(repository_ctx):
)
return VERSION_CONFIG_STUB + "\n# Error: " + error_msg.replace("\n", " ") + "\n"

toolchains = run_xcode_locator(
(toolchains, xcodeloc_err) = run_xcode_locator(
repository_ctx,
Label(repository_ctx.attr.xcode_locator),
)

if xcodeloc_err:
return VERSION_CONFIG_STUB + "\n# Error: " + xcodeloc_err + "\n"

default_xcode_version = _search_string(xcodebuild_result.stdout, "Xcode ", "\n")
default_xcode_target = ""
target_names = []
Expand Down

1 comment on commit c6c9b58

@keith
Copy link
Member Author

@keith keith commented on c6c9b58 Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI #7592

Please sign in to comment.