diff options
author | 2017-05-03 22:13:44 +0200 | |
---|---|---|
committer | 2017-05-04 13:13:49 +0200 | |
commit | cc21998c299b4d1f97df37b961552ff8168da17f (patch) | |
tree | 85a5a1845a1802842e5bf127d3b07f34c36eb52d /tools/osx/xcode_configure.bzl | |
parent | 655c07b87161030f73f8e2103aebcf8277051582 (diff) |
Rollforward #2 of: Basic open-source crosstool to support targeting apple platform types.
RELNOTES: None.
PiperOrigin-RevId: 154993630
Diffstat (limited to 'tools/osx/xcode_configure.bzl')
-rw-r--r-- | tools/osx/xcode_configure.bzl | 101 |
1 files changed, 69 insertions, 32 deletions
diff --git a/tools/osx/xcode_configure.bzl b/tools/osx/xcode_configure.bzl index 82833c07bf..7326e602a4 100644 --- a/tools/osx/xcode_configure.bzl +++ b/tools/osx/xcode_configure.bzl @@ -89,22 +89,30 @@ def _xcode_version_output(repository_ctx, name, version, aliases, developer_dir) 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(["env", "-i", "xcrun", "xcodebuild", "-version"], 30) - # "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 print warning should be emitted here. - if (xcodebuild_result.return_code != 0): - 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" +def run_xcode_locator(repository_ctx, xcode_locator_src_label): + """Generates xcode-locator from source and runs it. + + Builds xcode-locator in the current repository directory. + Returns the standard output of running xcode-locator with -v, which will + return information about locally installed Xcode toolchains and the versions + they are associated with. - xcodeloc_src_path = str(repository_ctx.path(Label(repository_ctx.attr.xcode_locator))) + This should only be invoked on a darwin OS, as xcode-locator cannot be built + otherwise. + + Args: + repository_ctx: The repository context. + xcode_locator_src_label: The label of the source file for xcode-locator. + Returns: + 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 instead None 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(["env", "-i", "xcrun", "clang", "-fobjc-arc", "-framework", "CoreServices", "-framework", "Foundation", "-o", "xcode-locator-bin", xcodeloc_src_path], 30) @@ -116,8 +124,7 @@ def _darwin_build_file(repository_ctx): code=xcrun_result.return_code, err=xcrun_result.stderr, out=xcrun_result.stdout) - print(error_msg) - return VERSION_CONFIG_STUB + "\n# Error: " + error_msg.replace("\n", " ") + "\n" + return (None, error_msg.replace("\n", " ")) xcode_locator_result = repository_ctx.execute(["./xcode-locator-bin", "-v"], 30) if (xcode_locator_result.return_code != 0): @@ -127,28 +134,58 @@ def _darwin_build_file(repository_ctx): code=xcode_locator_result.return_code, err=xcode_locator_result.stderr, out=xcode_locator_result.stdout) - print(error_msg) + return (None, error_msg.replace("\n", " ")) + xcode_toolchains = [] + # xcode_dump is comprised of newlines with different installed xcode versions, + # each line of the form <version>:<comma_separated_aliases>:<developer_dir>. + xcode_dump = xcode_locator_result.stdout + for xcodeversion in xcode_dump.split("\n"): + if ":" in xcodeversion: + infosplit = xcodeversion.split(":") + toolchain = struct( + version = infosplit[0], + aliases = infosplit[1].split(","), + developer_dir = infosplit[2] + ) + xcode_toolchains.append(toolchain) + return (xcode_toolchains, None) + + +def _darwin_build_file(repository_ctx): + """Evaluates local system state to create xcode_config and xcode_version targets.""" + xcodebuild_result = repository_ctx.execute(["env", "-i", "xcrun", "xcodebuild", "-version"], 30) + # "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 print warning should be emitted here. + if (xcodebuild_result.return_code != 0): + 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" + (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 = [] buildcontents = "" - # xcode_dump is comprised of newlines with different installed xcode versions, - # each line of the form <version>:<comma_separated_aliases>:<developer_dir>. - xcode_dump = xcode_locator_result.stdout - for xcodeversion in xcode_dump.split("\n"): - if ":" in xcodeversion: - infosplit = xcodeversion.split(":") - version = infosplit[0] - aliases = infosplit[1].split(",") - developer_dir = infosplit[2] - target_name = "version%s" % version.replace(".", "_") - buildcontents += _xcode_version_output(repository_ctx, target_name, version, aliases, developer_dir) - target_names.append("':%s'" % target_name) - if (version == default_xcode_version or default_xcode_version in aliases): - default_xcode_target = target_name + for toolchain in toolchains: + version = toolchain.version + aliases = toolchain.aliases + developer_dir = toolchain.developer_dir + target_name = "version%s" % version.replace(".", "_") + buildcontents += _xcode_version_output(repository_ctx, target_name, version, aliases, developer_dir) + target_names.append("':%s'" % target_name) + if (version == default_xcode_version or default_xcode_version in aliases): + default_xcode_target = target_name buildcontents += "xcode_config(name = 'host_xcodes'," if target_names: buildcontents += "\n versions = [%s]," % ", ".join(target_names) |