From 19979e619ccbb8257a6d696553e1b00fafccb504 Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Fri, 15 Sep 2023 01:42:54 -0700 Subject: [PATCH] Update unknown Xcode version error message and provide an environment variable to force re-evaluation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As of c747ae7aab077227099409f2f0774b485d42eaa4, you need to run `bazel sync --configure` instead of `bazel shutdown`, to force re-finding of Xcode versions. Certain setups have a hard time running that new command, versus previously only having to cause Bazel to restart. To accommodate that, I’ve also added the `XCODE_VERSION` variable to `environ` (to match a similar use defined here: https://github.com/bazelbuild/apple_support/commit/ddf25c260162b01ec639739aad41ad6008343d22), which allows those setups to force the re-evaluation by using `--repo_env`. And since the `default` attribute is influenced by `DEVELOPER_DIR`, I've included that in `environ` as well. Closes #19512. PiperOrigin-RevId: 565610471 Change-Id: Ideca7165308ce53fdf1ce22b31eeb7a9e681dedc --- .../build/lib/rules/apple/XcodeConfig.java | 20 +++++++++---------- tools/osx/xcode_configure.bzl | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java index c2f74a152082c6..7ade7cf08bdfef 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java @@ -388,11 +388,11 @@ private static Map.Entry resolveXcodeFromLoc } else if (specifiedVersionFromRemote != null) { ruleContext.ruleWarning( String.format( - "--xcode_version=%1$s specified, but it is not available locally. Your build" - + " will fail if any actions require a local Xcode. If you believe you have" - + " '%1$s' installed, try running \"blaze shutdown\", and then re-run your" - + " command. localy available versions: [%2$s]. remotely available" - + " versions: [%3$s]", + "--xcode_version=%1$s specified, but it is not available locally. Your build will" + + " fail if any actions require a local Xcode. If you believe you have '%1$s'" + + " installed, try running \"blaze sync --configure\", and then re-run your" + + " command. localy available versions: [%2$s]. remotely available versions:" + + " [%3$s]", versionOverrideFlag, printableXcodeVersions(localVersions.getAvailableVersions()), printableXcodeVersions(remoteVersions.getAvailableVersions()))); @@ -403,7 +403,7 @@ private static Map.Entry resolveXcodeFromLoc "--xcode_version=%1$s specified, but '%1$s' is not an available Xcode version." + " localy available versions: [%2$s]. remotely available versions:" + " [%3$s]. If you believe you have '%1$s' installed, try running \"blaze" - + " shutdown\", and then re-run your command.", + + " sync --configure\", and then re-run your command.", versionOverrideFlag, printableXcodeVersions(localVersions.getAvailableVersions()), printableXcodeVersions(remoteVersions.getAvailableVersions()))); @@ -457,10 +457,10 @@ private static Map.Entry resolveXcodeFromLoc checkState(defaultVersion != null); return Maps.immutableEntry(defaultVersion, Availability.BOTH); } else { // Use the local default. - ruleContext.ruleWarning( - "You passed --experimental_prefer_mutual_xcode=false, which prevents Bazel from" - + " selecting an Xcode version that optimizes your performance. Please consider" - + " using --experimental_prefer_mutual_xcode=true."); + ruleContext.ruleWarning( + "You passed --experimental_prefer_mutual_xcode=false, which prevents Bazel from" + + " selecting an Xcode version that optimizes your performance. Please consider" + + " using --experimental_prefer_mutual_xcode=true."); return Maps.immutableEntry(localVersions.getDefaultVersion(), Availability.LOCAL); } } diff --git a/tools/osx/xcode_configure.bzl b/tools/osx/xcode_configure.bzl index 79efd1241c8b1a..a4a712a3417df4 100644 --- a/tools/osx/xcode_configure.bzl +++ b/tools/osx/xcode_configure.bzl @@ -295,6 +295,10 @@ def _impl(repository_ctx): repository_ctx.file("BUILD", build_contents) xcode_autoconf = repository_rule( + environ = [ + "DEVELOPER_DIR", + "XCODE_VERSION", + ], implementation = _impl, configure = True, attrs = {