From 27b8cc3f4a06e781a92cf2087476af5d51c06b1b Mon Sep 17 00:00:00 2001 From: Sergio Campama Date: Tue, 6 Mar 2018 07:54:50 -0800 Subject: Replace instances of XCode with Xcode which is the proper casing for the name. Closes #4640. PiperOrigin-RevId: 188022228 --- site/docs/install-os-x.md | 4 +- .../lib/exec/apple/XCodeLocalEnvProvider.java | 244 ------------------- .../lib/exec/apple/XcodeLocalEnvProvider.java | 261 +++++++++++++++++++++ .../lib/remote/RemoteActionContextProvider.java | 4 +- .../build/lib/rules/objc/ObjcRuleClasses.java | 43 ++-- .../lib/sandbox/AbstractSandboxSpawnRunner.java | 2 +- .../lib/sandbox/DarwinSandboxedSpawnRunner.java | 4 +- .../ProcessWrapperSandboxedSpawnRunner.java | 4 +- .../lib/sandbox/SandboxActionContextProvider.java | 4 +- .../StandaloneActionContextProvider.java | 4 +- .../lib/worker/WorkerActionContextProvider.java | 4 +- .../lib/exec/apple/XCodeLocalEnvProviderTest.java | 52 ---- .../lib/exec/apple/XcodeLocalEnvProviderTest.java | 51 ++++ 13 files changed, 349 insertions(+), 332 deletions(-) delete mode 100644 src/main/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProvider.java create mode 100644 src/main/java/com/google/devtools/build/lib/exec/apple/XcodeLocalEnvProvider.java delete mode 100644 src/test/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProviderTest.java create mode 100644 src/test/java/com/google/devtools/build/lib/exec/apple/XcodeLocalEnvProviderTest.java diff --git a/site/docs/install-os-x.md b/site/docs/install-os-x.md index ee4cfab864..b1750a7615 100644 --- a/site/docs/install-os-x.md +++ b/site/docs/install-os-x.md @@ -60,7 +60,7 @@ The binary installers are on Bazel's [GitHub releases page](https://github.com/b The installer contains the Bazel binary and the required JDK. Some additional libraries must also be installed for Bazel to work. -### 1. Install XCode command line tools +### 1. Install Xcode command line tools Xcode can be downloaded from the [Apple Developer Site](https://developer.apple.com/xcode/downloads/) (this link redirects to @@ -69,7 +69,7 @@ their App Store). For `objc_*` and `ios_*` rule support, you must have Xcode 6.1 or later with iOS SDK 8.1 installed on your system. -Once XCode is installed, you can agree to the license agreement for all users with +Once Xcode is installed, you can agree to the license agreement for all users with the following command: ``` diff --git a/src/main/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProvider.java b/src/main/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProvider.java deleted file mode 100644 index 553fef0039..0000000000 --- a/src/main/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProvider.java +++ /dev/null @@ -1,244 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.exec.apple; - -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.google.devtools.build.lib.analysis.BlazeDirectories; -import com.google.devtools.build.lib.exec.local.LocalEnvProvider; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.rules.apple.DottedVersion; -import com.google.devtools.build.lib.shell.AbnormalTerminationException; -import com.google.devtools.build.lib.shell.Command; -import com.google.devtools.build.lib.shell.CommandException; -import com.google.devtools.build.lib.shell.CommandResult; -import com.google.devtools.build.lib.shell.TerminationStatus; -import com.google.devtools.build.lib.util.OS; -import com.google.devtools.build.lib.vfs.Path; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Map; - -/** - * Adds to the given environment all variables that are dependent on system state of the host - * machine. - * - *

Admittedly, hermeticity is "best effort" in such cases; these environment values should be - * as tied to configuration parameters as possible. - * - *

For example, underlying iOS toolchains require that SDKROOT resolve to an absolute system - * path, but, when selecting which SDK to resolve, the version number comes from build - * configuration. - */ -public final class XCodeLocalEnvProvider implements LocalEnvProvider { - private static final String XCRUN_CACHE_FILENAME = "__xcruncache"; - private static final String XCODE_LOCATOR_CACHE_FILENAME = "__xcodelocatorcache"; - - private final String productName; - private final Map clientEnv; - - /** - * Creates a new {@link XCodeLocalEnvProvider}. - * - * @param clientEnv a map of the current Bazel command's environment - */ - public XCodeLocalEnvProvider(String productName, Map clientEnv) { - this.productName = productName; - this.clientEnv = clientEnv; - } - - @Override - public Map rewriteLocalEnv( - Map env, Path execRoot, String fallbackTmpDir) - throws IOException { - boolean containsXcodeVersion = env.containsKey(AppleConfiguration.XCODE_VERSION_ENV_NAME); - boolean containsAppleSdkVersion = - env.containsKey(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME); - - ImmutableMap.Builder newEnvBuilder = ImmutableMap.builder(); - newEnvBuilder.putAll(Maps.filterKeys(env, k -> !k.equals("TMPDIR"))); - String p = clientEnv.get("TMPDIR"); - if (Strings.isNullOrEmpty(p)) { - // Do not use `fallbackTmpDir`, use `/tmp` instead. This way if the user didn't export TMPDIR - // in their environment, Bazel will still set a TMPDIR that's Posixy enough and plays well - // with heavily path-length-limited scenarios, such as the socket creation scenario that - // motivated https://github.com/bazelbuild/bazel/issues/4376. - p = "/tmp"; - } - newEnvBuilder.put("TMPDIR", p); - - if (!containsXcodeVersion && !containsAppleSdkVersion) { - return newEnvBuilder.build(); - } - - // Empty developer dir indicates to use the system default. - // TODO(bazel-team): Bazel's view of the xcode version and developer dir should be explicitly - // set for build hermeticity. - String developerDir = ""; - if (containsXcodeVersion) { - String version = env.get(AppleConfiguration.XCODE_VERSION_ENV_NAME); - developerDir = getDeveloperDir(execRoot, DottedVersion.fromString(version), productName); - newEnvBuilder.put("DEVELOPER_DIR", developerDir); - } - if (containsAppleSdkVersion) { - // The Apple platform is needed to select the appropriate SDK. - if (!env.containsKey(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME)) { - throw new IOException("Could not resolve apple platform for determining SDK"); - } - String iosSdkVersion = env.get(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME); - String appleSdkPlatform = env.get(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME); - newEnvBuilder.put( - "SDKROOT", - getSdkRoot(execRoot, developerDir, iosSdkVersion, appleSdkPlatform, productName)); - } - - return newEnvBuilder.build(); - } - - /** - * Returns the absolute root path of the target Apple SDK on the host system for a given - * version of xcode (as defined by the given {@code developerDir}). This may spawn a - * process and use the {@code /usr/bin/xcrun} binary to locate the target SDK. This uses a local - * cache file under {@code bazel-out}, and will only spawn a new {@code xcrun} process in the case - * of a cache miss. - * - * @param execRoot the execution root path, used to locate the cache file - * @param developerDir the value of {@code DEVELOPER_DIR} for the target version of xcode - * @param sdkVersion the sdk version, for example, "9.1" - * @param appleSdkPlatform the sdk platform, for example, "iPhoneOS" - * @param productName the product name - * @throws IOException if there is an issue with obtaining the root from the spawned - * process, either because the SDK platform/version pair doesn't exist, or there was an - * unexpected issue finding or running the tool - */ - private static String getSdkRoot(Path execRoot, String developerDir, - String sdkVersion, String appleSdkPlatform, String productName) throws IOException { - if (OS.getCurrent() != OS.DARWIN) { - throw new IOException("Cannot locate iOS SDK on non-darwin operating system"); - } - try { - CacheManager cacheManager = - new CacheManager(execRoot.getRelative( - BlazeDirectories.getRelativeOutputPath(productName)), - XCRUN_CACHE_FILENAME); - - String sdkString = appleSdkPlatform.toLowerCase() + sdkVersion; - String cacheResult = cacheManager.getValue(developerDir, sdkString); - if (cacheResult != null) { - return cacheResult; - } else { - Map env = Strings.isNullOrEmpty(developerDir) - ? ImmutableMap.of() : ImmutableMap.of("DEVELOPER_DIR", developerDir); - CommandResult xcrunResult = - new Command( - new String[] {"/usr/bin/xcrun", "--sdk", sdkString, "--show-sdk-path"}, env, null) - .execute(); - - // calling xcrun via Command returns a value with a newline on the end. - String sdkRoot = new String(xcrunResult.getStdout(), StandardCharsets.UTF_8).trim(); - - cacheManager.writeEntry(ImmutableList.of(developerDir, sdkString), sdkRoot); - return sdkRoot; - } - } catch (AbnormalTerminationException e) { - TerminationStatus terminationStatus = e.getResult().getTerminationStatus(); - - if (terminationStatus.exited()) { - throw new IOException( - String.format("xcrun failed with code %s.\n" - + "This most likely indicates that SDK version [%s] for platform [%s] is " - + "unsupported for the target version of xcode.\n" - + "%s\n" - + "Stderr: %s", - terminationStatus.getExitCode(), - sdkVersion, appleSdkPlatform, - terminationStatus.toString(), - new String(e.getResult().getStderr(), StandardCharsets.UTF_8))); - } - String message = String.format("xcrun failed.\n%s\n%s", - e.getResult().getTerminationStatus(), - new String(e.getResult().getStderr(), StandardCharsets.UTF_8)); - throw new IOException(message, e); - } catch (CommandException e) { - throw new IOException(e); - } - } - - /** - * Returns the absolute root path of the xcode developer directory on the host system for - * the given xcode version. This may spawn a process and use the {@code xcode-locator} binary. - * This uses a local cache file under {@code bazel-out}, and will only spawn a new process in the - * case of a cache miss. - * - * @param execRoot the execution root path, used to locate the cache file - * @param version the xcode version number to look up - * @param productName the product name - * @throws IOException if there is an issue with obtaining the path from the spawned - * process, either because there is no installed xcode with the given version, or - * there was an unexpected issue finding or running the tool - */ - private static String getDeveloperDir(Path execRoot, DottedVersion version, String productName) - throws IOException { - if (OS.getCurrent() != OS.DARWIN) { - throw new IOException( - "Cannot locate xcode developer directory on non-darwin operating system"); - } - try { - CacheManager cacheManager = - new CacheManager( - execRoot.getRelative(BlazeDirectories.getRelativeOutputPath(productName)), - XCODE_LOCATOR_CACHE_FILENAME); - - String cacheResult = cacheManager.getValue(version.toString()); - if (cacheResult != null) { - return cacheResult; - } else { - CommandResult xcodeLocatorResult = new Command( - new String[] { - execRoot.getRelative("_bin/xcode-locator").getPathString(), version.toString()}) - .execute(); - - String developerDir = - new String(xcodeLocatorResult.getStdout(), StandardCharsets.UTF_8).trim(); - - cacheManager.writeEntry(ImmutableList.of(version.toString()), developerDir); - return developerDir; - } - } catch (AbnormalTerminationException e) { - TerminationStatus terminationStatus = e.getResult().getTerminationStatus(); - - String message; - if (e.getResult().getTerminationStatus().exited()) { - message = String.format("xcode-locator failed with code %s.\n" - + "This most likely indicates that xcode version %s is not available on the host " - + "machine.\n" - + "%s\n" - + "stderr: %s", - terminationStatus.getExitCode(), - version, - terminationStatus.toString(), - new String(e.getResult().getStderr(), StandardCharsets.UTF_8)); - } else { - message = String.format("xcode-locator failed. %s\nstderr: %s", - e.getResult().getTerminationStatus(), - new String(e.getResult().getStderr(), StandardCharsets.UTF_8)); - } - throw new IOException(message, e); - } catch (CommandException e) { - throw new IOException(e); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/exec/apple/XcodeLocalEnvProvider.java b/src/main/java/com/google/devtools/build/lib/exec/apple/XcodeLocalEnvProvider.java new file mode 100644 index 0000000000..55a2ba5ddc --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/exec/apple/XcodeLocalEnvProvider.java @@ -0,0 +1,261 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.exec.apple; + +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import com.google.devtools.build.lib.analysis.BlazeDirectories; +import com.google.devtools.build.lib.exec.local.LocalEnvProvider; +import com.google.devtools.build.lib.rules.apple.AppleConfiguration; +import com.google.devtools.build.lib.rules.apple.DottedVersion; +import com.google.devtools.build.lib.shell.AbnormalTerminationException; +import com.google.devtools.build.lib.shell.Command; +import com.google.devtools.build.lib.shell.CommandException; +import com.google.devtools.build.lib.shell.CommandResult; +import com.google.devtools.build.lib.shell.TerminationStatus; +import com.google.devtools.build.lib.util.OS; +import com.google.devtools.build.lib.vfs.Path; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Map; + +/** + * Adds to the given environment all variables that are dependent on system state of the host + * machine. + * + *

Admittedly, hermeticity is "best effort" in such cases; these environment values should be as + * tied to configuration parameters as possible. + * + *

For example, underlying iOS toolchains require that SDKROOT resolve to an absolute system + * path, but, when selecting which SDK to resolve, the version number comes from build + * configuration. + */ +public final class XcodeLocalEnvProvider implements LocalEnvProvider { + private static final String XCRUN_CACHE_FILENAME = "__xcruncache"; + private static final String XCODE_LOCATOR_CACHE_FILENAME = "__xcodelocatorcache"; + + private final String productName; + private final Map clientEnv; + + /** + * Creates a new {@link XcodeLocalEnvProvider}. + * + * @param clientEnv a map of the current Bazel command's environment + */ + public XcodeLocalEnvProvider(String productName, Map clientEnv) { + this.productName = productName; + this.clientEnv = clientEnv; + } + + @Override + public Map rewriteLocalEnv( + Map env, Path execRoot, String fallbackTmpDir) throws IOException { + boolean containsXcodeVersion = env.containsKey(AppleConfiguration.XCODE_VERSION_ENV_NAME); + boolean containsAppleSdkVersion = + env.containsKey(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME); + + ImmutableMap.Builder newEnvBuilder = ImmutableMap.builder(); + newEnvBuilder.putAll(Maps.filterKeys(env, k -> !k.equals("TMPDIR"))); + String p = clientEnv.get("TMPDIR"); + if (Strings.isNullOrEmpty(p)) { + // Do not use `fallbackTmpDir`, use `/tmp` instead. This way if the user didn't export TMPDIR + // in their environment, Bazel will still set a TMPDIR that's Posixy enough and plays well + // with heavily path-length-limited scenarios, such as the socket creation scenario that + // motivated https://github.com/bazelbuild/bazel/issues/4376. + p = "/tmp"; + } + newEnvBuilder.put("TMPDIR", p); + + if (!containsXcodeVersion && !containsAppleSdkVersion) { + return newEnvBuilder.build(); + } + + // Empty developer dir indicates to use the system default. + // TODO(bazel-team): Bazel's view of the xcode version and developer dir should be explicitly + // set for build hermeticity. + String developerDir = ""; + if (containsXcodeVersion) { + String version = env.get(AppleConfiguration.XCODE_VERSION_ENV_NAME); + developerDir = getDeveloperDir(execRoot, DottedVersion.fromString(version), productName); + newEnvBuilder.put("DEVELOPER_DIR", developerDir); + } + if (containsAppleSdkVersion) { + // The Apple platform is needed to select the appropriate SDK. + if (!env.containsKey(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME)) { + throw new IOException("Could not resolve apple platform for determining SDK"); + } + String iosSdkVersion = env.get(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME); + String appleSdkPlatform = env.get(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME); + newEnvBuilder.put( + "SDKROOT", + getSdkRoot(execRoot, developerDir, iosSdkVersion, appleSdkPlatform, productName)); + } + + return newEnvBuilder.build(); + } + + /** + * Returns the absolute root path of the target Apple SDK on the host system for a given version + * of xcode (as defined by the given {@code developerDir}). This may spawn a process and use the + * {@code /usr/bin/xcrun} binary to locate the target SDK. This uses a local cache file under + * {@code bazel-out}, and will only spawn a new {@code xcrun} process in the case of a cache miss. + * + * @param execRoot the execution root path, used to locate the cache file + * @param developerDir the value of {@code DEVELOPER_DIR} for the target version of xcode + * @param sdkVersion the sdk version, for example, "9.1" + * @param appleSdkPlatform the sdk platform, for example, "iPhoneOS" + * @param productName the product name + * @throws IOException if there is an issue with obtaining the root from the spawned process, + * either because the SDK platform/version pair doesn't exist, or there was an unexpected + * issue finding or running the tool + */ + private static String getSdkRoot( + Path execRoot, + String developerDir, + String sdkVersion, + String appleSdkPlatform, + String productName) + throws IOException { + if (OS.getCurrent() != OS.DARWIN) { + throw new IOException("Cannot locate iOS SDK on non-darwin operating system"); + } + try { + CacheManager cacheManager = + new CacheManager( + execRoot.getRelative(BlazeDirectories.getRelativeOutputPath(productName)), + XCRUN_CACHE_FILENAME); + + String sdkString = appleSdkPlatform.toLowerCase() + sdkVersion; + String cacheResult = cacheManager.getValue(developerDir, sdkString); + if (cacheResult != null) { + return cacheResult; + } else { + Map env = + Strings.isNullOrEmpty(developerDir) + ? ImmutableMap.of() + : ImmutableMap.of("DEVELOPER_DIR", developerDir); + CommandResult xcrunResult = + new Command( + new String[] {"/usr/bin/xcrun", "--sdk", sdkString, "--show-sdk-path"}, + env, + null) + .execute(); + + // calling xcrun via Command returns a value with a newline on the end. + String sdkRoot = new String(xcrunResult.getStdout(), StandardCharsets.UTF_8).trim(); + + cacheManager.writeEntry(ImmutableList.of(developerDir, sdkString), sdkRoot); + return sdkRoot; + } + } catch (AbnormalTerminationException e) { + TerminationStatus terminationStatus = e.getResult().getTerminationStatus(); + + if (terminationStatus.exited()) { + throw new IOException( + String.format( + "xcrun failed with code %s.\n" + + "This most likely indicates that SDK version [%s] for platform [%s] is " + + "unsupported for the target version of xcode.\n" + + "%s\n" + + "Stderr: %s", + terminationStatus.getExitCode(), + sdkVersion, + appleSdkPlatform, + terminationStatus.toString(), + new String(e.getResult().getStderr(), StandardCharsets.UTF_8))); + } + String message = + String.format( + "xcrun failed.\n%s\n%s", + e.getResult().getTerminationStatus(), + new String(e.getResult().getStderr(), StandardCharsets.UTF_8)); + throw new IOException(message, e); + } catch (CommandException e) { + throw new IOException(e); + } + } + + /** + * Returns the absolute root path of the xcode developer directory on the host system for the + * given xcode version. This may spawn a process and use the {@code xcode-locator} binary. This + * uses a local cache file under {@code bazel-out}, and will only spawn a new process in the case + * of a cache miss. + * + * @param execRoot the execution root path, used to locate the cache file + * @param version the xcode version number to look up + * @param productName the product name + * @throws IOException if there is an issue with obtaining the path from the spawned process, + * either because there is no installed xcode with the given version, or there was an + * unexpected issue finding or running the tool + */ + private static String getDeveloperDir(Path execRoot, DottedVersion version, String productName) + throws IOException { + if (OS.getCurrent() != OS.DARWIN) { + throw new IOException( + "Cannot locate xcode developer directory on non-darwin operating system"); + } + try { + CacheManager cacheManager = + new CacheManager( + execRoot.getRelative(BlazeDirectories.getRelativeOutputPath(productName)), + XCODE_LOCATOR_CACHE_FILENAME); + + String cacheResult = cacheManager.getValue(version.toString()); + if (cacheResult != null) { + return cacheResult; + } else { + CommandResult xcodeLocatorResult = + new Command( + new String[] { + execRoot.getRelative("_bin/xcode-locator").getPathString(), version.toString() + }) + .execute(); + + String developerDir = + new String(xcodeLocatorResult.getStdout(), StandardCharsets.UTF_8).trim(); + + cacheManager.writeEntry(ImmutableList.of(version.toString()), developerDir); + return developerDir; + } + } catch (AbnormalTerminationException e) { + TerminationStatus terminationStatus = e.getResult().getTerminationStatus(); + + String message; + if (e.getResult().getTerminationStatus().exited()) { + message = + String.format( + "xcode-locator failed with code %s.\n" + + "This most likely indicates that xcode version %s is not available on the " + + "host machine.\n" + + "%s\n" + + "stderr: %s", + terminationStatus.getExitCode(), + version, + terminationStatus.toString(), + new String(e.getResult().getStderr(), StandardCharsets.UTF_8)); + } else { + message = + String.format( + "xcode-locator failed. %s\nstderr: %s", + e.getResult().getTerminationStatus(), + new String(e.getResult().getStderr(), StandardCharsets.UTF_8)); + } + throw new IOException(message, e); + } catch (CommandException e) { + throw new IOException(e); + } + } +} diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java index 67acd0f93e..f3a2baec31 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionContextProvider.java @@ -21,7 +21,7 @@ import com.google.devtools.build.lib.actions.ResourceManager; import com.google.devtools.build.lib.exec.ActionContextProvider; import com.google.devtools.build.lib.exec.ExecutionOptions; import com.google.devtools.build.lib.exec.SpawnRunner; -import com.google.devtools.build.lib.exec.apple.XCodeLocalEnvProvider; +import com.google.devtools.build.lib.exec.apple.XcodeLocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalExecutionOptions; import com.google.devtools.build.lib.exec.local.LocalSpawnRunner; @@ -94,7 +94,7 @@ final class RemoteActionContextProvider extends ActionContextProvider { env.getOptions().getOptions(LocalExecutionOptions.class); LocalEnvProvider localEnvProvider = OS.getCurrent() == OS.DARWIN - ? new XCodeLocalEnvProvider(env.getRuntime().getProductName(), env.getClientEnv()) + ? new XcodeLocalEnvProvider(env.getRuntime().getProductName(), env.getClientEnv()) : (OS.getCurrent() == OS.WINDOWS ? new WindowsLocalEnvProvider(env.getClientEnv()) : new PosixLocalEnvProvider(env.getClientEnv())); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java index 2e5eee397a..4cb6fe3953 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java @@ -350,7 +350,7 @@ public class ObjcRuleClasses { * Files that are already compiled. */ static final FileTypeSet PRECOMPILED_SRCS_TYPE = FileTypeSet.of(OBJECT_FILE_SOURCES); - + static final FileTypeSet NON_ARC_SRCS_TYPE = FileTypeSet.of(FileType.of(".m", ".mm")); static final FileTypeSet PLIST_TYPE = FileTypeSet.of(FileType.of(".plist")); @@ -391,9 +391,10 @@ public class ObjcRuleClasses { Base.lproj), it will be placed under a directory of that name in the final bundle. This allows for localizable strings. */ - .add(attr("strings", LABEL_LIST) - .allowedFileTypes(STRINGS_TYPE) - .direct_compile_time_input()) + .add( + attr("strings", LABEL_LIST) + .allowedFileTypes(STRINGS_TYPE) + .direct_compile_time_input()) /* Files which are .xib resources, possibly localizable. @@ -403,9 +404,7 @@ public class ObjcRuleClasses { directory of that name in the final bundle. This allows for localizable UI. */ - .add(attr("xibs", LABEL_LIST) - .direct_compile_time_input() - .allowedFileTypes(XIB_TYPE)) + .add(attr("xibs", LABEL_LIST).direct_compile_time_input().allowedFileTypes(XIB_TYPE)) /* Files which are .storyboard resources, possibly localizable. @@ -415,8 +414,7 @@ public class ObjcRuleClasses { Base.lproj), it will be placed under a directory of that name in the final bundle. This allows for localizable UI. */ - .add(attr("storyboards", LABEL_LIST) - .allowedFileTypes(STORYBOARD_TYPE)) + .add(attr("storyboards", LABEL_LIST).allowedFileTypes(STORYBOARD_TYPE)) /* Files to include in the final application bundle. @@ -437,14 +435,15 @@ public class ObjcRuleClasses { the same structure passed to this argument, so ["res/foo.png"] will end up in Payload/foo.app/res/foo.png. -

Note that in the generated XCode project file, all files in the top directory of +

Note that in the generated Xcode project file, all files in the top directory of the specified files will be included in the Xcode-generated app bundle. So specifying ["res/foo.png"] will lead to the inclusion of all files in directory res. */ - .add(attr("structured_resources", LABEL_LIST) - .legacyAllowAnyFileType() - .direct_compile_time_input()) + .add( + attr("structured_resources", LABEL_LIST) + .legacyAllowAnyFileType() + .direct_compile_time_input()) /* Files that comprise the data models of the final linked binary. @@ -452,8 +451,7 @@ public class ObjcRuleClasses { is usually contained by another *.xcdatamodeld (note the added d) directory. */ - .add(attr("datamodels", LABEL_LIST).legacyAllowAnyFileType() - .direct_compile_time_input()) + .add(attr("datamodels", LABEL_LIST).legacyAllowAnyFileType().direct_compile_time_input()) /* Files that comprise the asset catalogs of the final linked binary. @@ -462,16 +460,19 @@ public class ObjcRuleClasses { linked with any binary that depends directly or indirectly on this target. */ - .add(attr("asset_catalogs", LABEL_LIST).legacyAllowAnyFileType() - .direct_compile_time_input()) + .add( + attr("asset_catalogs", LABEL_LIST) + .legacyAllowAnyFileType() + .direct_compile_time_input()) /* The list of bundle targets that this target requires to be included in the final bundle. */ - .add(attr("bundles", LABEL_LIST) - .direct_compile_time_input() - .allowedRuleClasses("objc_bundle", "objc_bundle_library") - .allowedFileTypes()) + .add( + attr("bundles", LABEL_LIST) + .direct_compile_time_input() + .allowedRuleClasses("objc_bundle", "objc_bundle_library") + .allowedFileTypes()) .build(); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/AbstractSandboxSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/AbstractSandboxSpawnRunner.java index b7263b863f..29c46b2e8d 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/AbstractSandboxSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/AbstractSandboxSpawnRunner.java @@ -248,7 +248,7 @@ abstract class AbstractSandboxSpawnRunner implements SpawnRunner { writablePaths, // As of 2018-01-09: // - every caller of `getWritableDirs` passes a LocalEnvProvider-processed environment as - // `env`, and in every case that's either PosixLocalEnvProvider or XCodeLocalEnvProvider, + // `env`, and in every case that's either PosixLocalEnvProvider or XcodeLocalEnvProvider, // therefore `env` surely has an entry for TMPDIR // - Bazel-on-Windows does not yet support sandboxing, so we don't need to add env[TMP] and // env[TEMP] as writable paths. diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java index 1c23623c57..6bf48fe22b 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java @@ -26,7 +26,7 @@ import com.google.devtools.build.lib.actions.Spawn; import com.google.devtools.build.lib.actions.SpawnActionContext; import com.google.devtools.build.lib.actions.SpawnResult; import com.google.devtools.build.lib.actions.Spawns; -import com.google.devtools.build.lib.exec.apple.XCodeLocalEnvProvider; +import com.google.devtools.build.lib.exec.apple.XcodeLocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalEnvProvider; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.runtime.ProcessWrapperUtil; @@ -151,7 +151,7 @@ final class DarwinSandboxedSpawnRunner extends AbstractSandboxSpawnRunner { this.alwaysWritableDirs = getAlwaysWritableDirs(cmdEnv.getRuntime().getFileSystem()); this.processWrapper = ProcessWrapperUtil.getProcessWrapper(cmdEnv); this.localEnvProvider = - new XCodeLocalEnvProvider(cmdEnv.getRuntime().getProductName(), cmdEnv.getClientEnv()); + new XcodeLocalEnvProvider(cmdEnv.getRuntime().getProductName(), cmdEnv.getClientEnv()); this.timeoutKillDelay = timeoutKillDelay; } diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java index 979878e8fd..dca292efca 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java @@ -17,7 +17,7 @@ package com.google.devtools.build.lib.sandbox; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.Spawn; import com.google.devtools.build.lib.actions.SpawnResult; -import com.google.devtools.build.lib.exec.apple.XCodeLocalEnvProvider; +import com.google.devtools.build.lib.exec.apple.XcodeLocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalEnvProvider; import com.google.devtools.build.lib.exec.local.PosixLocalEnvProvider; import com.google.devtools.build.lib.runtime.CommandEnvironment; @@ -88,7 +88,7 @@ final class ProcessWrapperSandboxedSpawnRunner extends AbstractSandboxSpawnRunne this.processWrapper = ProcessWrapperUtil.getProcessWrapper(cmdEnv); this.localEnvProvider = OS.getCurrent() == OS.DARWIN - ? new XCodeLocalEnvProvider(productName, cmdEnv.getClientEnv()) + ? new XcodeLocalEnvProvider(productName, cmdEnv.getClientEnv()) : new PosixLocalEnvProvider(cmdEnv.getClientEnv()); } diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextProvider.java index d125d7a4cd..cd36827512 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxActionContextProvider.java @@ -23,7 +23,7 @@ import com.google.devtools.build.lib.actions.SpawnResult; import com.google.devtools.build.lib.actions.Spawns; import com.google.devtools.build.lib.exec.ActionContextProvider; import com.google.devtools.build.lib.exec.SpawnRunner; -import com.google.devtools.build.lib.exec.apple.XCodeLocalEnvProvider; +import com.google.devtools.build.lib.exec.apple.XcodeLocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalExecutionOptions; import com.google.devtools.build.lib.exec.local.LocalSpawnRunner; @@ -100,7 +100,7 @@ final class SandboxActionContextProvider extends ActionContextProvider { env.getOptions().getOptions(LocalExecutionOptions.class); LocalEnvProvider localEnvProvider = OS.getCurrent() == OS.DARWIN - ? new XCodeLocalEnvProvider(env.getRuntime().getProductName(), env.getClientEnv()) + ? new XcodeLocalEnvProvider(env.getRuntime().getProductName(), env.getClientEnv()) : new PosixLocalEnvProvider(env.getClientEnv()); return new LocalSpawnRunner( diff --git a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextProvider.java index c3ee1883be..74cab934d1 100644 --- a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneActionContextProvider.java @@ -23,7 +23,7 @@ import com.google.devtools.build.lib.exec.FileWriteStrategy; import com.google.devtools.build.lib.exec.SpawnRunner; import com.google.devtools.build.lib.exec.StandaloneTestStrategy; import com.google.devtools.build.lib.exec.TestStrategy; -import com.google.devtools.build.lib.exec.apple.XCodeLocalEnvProvider; +import com.google.devtools.build.lib.exec.apple.XcodeLocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalExecutionOptions; import com.google.devtools.build.lib.exec.local.LocalSpawnRunner; @@ -72,7 +72,7 @@ public class StandaloneActionContextProvider extends ActionContextProvider { env.getOptions().getOptions(LocalExecutionOptions.class); LocalEnvProvider localEnvProvider = OS.getCurrent() == OS.DARWIN - ? new XCodeLocalEnvProvider(env.getRuntime().getProductName(), env.getClientEnv()) + ? new XcodeLocalEnvProvider(env.getRuntime().getProductName(), env.getClientEnv()) : (OS.getCurrent() == OS.WINDOWS ? new WindowsLocalEnvProvider(env.getClientEnv()) : new PosixLocalEnvProvider(env.getClientEnv())); diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java index f0b2070382..84b516a973 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerActionContextProvider.java @@ -20,7 +20,7 @@ import com.google.devtools.build.lib.actions.ResourceManager; import com.google.devtools.build.lib.analysis.test.TestActionContext; import com.google.devtools.build.lib.exec.ActionContextProvider; import com.google.devtools.build.lib.exec.SpawnRunner; -import com.google.devtools.build.lib.exec.apple.XCodeLocalEnvProvider; +import com.google.devtools.build.lib.exec.apple.XcodeLocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalEnvProvider; import com.google.devtools.build.lib.exec.local.LocalExecutionOptions; import com.google.devtools.build.lib.exec.local.LocalSpawnRunner; @@ -59,7 +59,7 @@ final class WorkerActionContextProvider extends ActionContextProvider { env.getOptions().getOptions(LocalExecutionOptions.class); LocalEnvProvider localEnvProvider = OS.getCurrent() == OS.DARWIN - ? new XCodeLocalEnvProvider(env.getRuntime().getProductName(), env.getClientEnv()) + ? new XcodeLocalEnvProvider(env.getRuntime().getProductName(), env.getClientEnv()) : (OS.getCurrent() == OS.WINDOWS ? new WindowsLocalEnvProvider(env.getClientEnv()) : new PosixLocalEnvProvider(env.getClientEnv())); diff --git a/src/test/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProviderTest.java b/src/test/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProviderTest.java deleted file mode 100644 index 1b8e3bb243..0000000000 --- a/src/test/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProviderTest.java +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2017 The Bazel Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.exec.apple; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; - -import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration; -import com.google.devtools.build.lib.util.OS; -import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.JavaIoFileSystem; -import java.io.IOException; -import org.junit.Test; - -/** - * Tests for {@link XCodeLocalEnvProvider}. - */ -public class XCodeLocalEnvProviderTest { - private final FileSystem fs = new JavaIoFileSystem(); - - @Test - public void testIOSEnvironmentOnNonDarwin() throws Exception { - if (OS.getCurrent() == OS.DARWIN) { - return; - } - try { - new XCodeLocalEnvProvider().rewriteLocalEnv( - ImmutableMap.of( - AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME, "8.4", - AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME, "iPhoneSimulator"), - fs.getPath("/tmp"), - "bazel"); - fail("action should fail due to being unable to resolve SDKROOT"); - } catch (IOException e) { - assertThat(e) - .hasMessageThat() - .contains("Cannot locate iOS SDK on non-darwin operating system"); - } - } -} diff --git a/src/test/java/com/google/devtools/build/lib/exec/apple/XcodeLocalEnvProviderTest.java b/src/test/java/com/google/devtools/build/lib/exec/apple/XcodeLocalEnvProviderTest.java new file mode 100644 index 0000000000..0bf1bb4beb --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/exec/apple/XcodeLocalEnvProviderTest.java @@ -0,0 +1,51 @@ +// Copyright 2017 The Bazel Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.exec.apple; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.fail; + +import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.rules.apple.AppleConfiguration; +import com.google.devtools.build.lib.util.OS; +import com.google.devtools.build.lib.vfs.FileSystem; +import com.google.devtools.build.lib.vfs.JavaIoFileSystem; +import java.io.IOException; +import org.junit.Test; + +/** Tests for {@link XcodeLocalEnvProvider}. */ +public class XcodeLocalEnvProviderTest { + private final FileSystem fs = new JavaIoFileSystem(); + + @Test + public void testIOSEnvironmentOnNonDarwin() throws Exception { + if (OS.getCurrent() == OS.DARWIN) { + return; + } + try { + new XcodeLocalEnvProvider() + .rewriteLocalEnv( + ImmutableMap.of( + AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME, "8.4", + AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME, "iPhoneSimulator"), + fs.getPath("/tmp"), + "bazel"); + fail("action should fail due to being unable to resolve SDKROOT"); + } catch (IOException e) { + assertThat(e) + .hasMessageThat() + .contains("Cannot locate iOS SDK on non-darwin operating system"); + } + } +} -- cgit v1.2.3