diff options
Diffstat (limited to 'src/main/java/com')
33 files changed, 211 insertions, 153 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BlazeDirectories.java b/src/main/java/com/google/devtools/build/lib/analysis/BlazeDirectories.java index 6fa762df89..374c9e684c 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BlazeDirectories.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BlazeDirectories.java @@ -18,7 +18,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import com.google.common.hash.HashCode; import com.google.common.hash.Hashing; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.Root; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.util.Preconditions; @@ -50,11 +49,6 @@ import javax.annotation.Nullable; @Immutable public final class BlazeDirectories { - // Output directory name, relative to the execRoot. - // TODO(bazel-team): (2011) make this private? - public static final String RELATIVE_OUTPUT_PATH = StringCanonicalizer.intern( - Constants.PRODUCT_NAME + "-out"); - // Include directory name, relative to execRoot/blaze-out/configuration. public static final String RELATIVE_INCLUDE_DIR = StringCanonicalizer.intern("include"); @VisibleForTesting @@ -72,7 +66,7 @@ public final class BlazeDirectories { private final Path localOutputPath; public BlazeDirectories(Path installBase, Path outputBase, Path workspace, - boolean deepExecRoot, @Nullable String installMD5) { + boolean deepExecRoot, @Nullable String installMD5, String productName) { this.installBase = installBase; this.workspace = workspace; this.outputBase = outputBase; @@ -88,11 +82,13 @@ public final class BlazeDirectories { } else { this.execRoot = execRootBase.getChild(workspace.getBaseName()); } - this.outputPath = execRoot.getRelative(RELATIVE_OUTPUT_PATH); + String relativeOutputPath = getRelativeOutputPath(productName); + this.outputPath = execRoot.getRelative(relativeOutputPath); Preconditions.checkState(useDefaultExecRootName || outputPath.asFragment().equals( - outputPathFromOutputBase(outputBase.asFragment(), workspace.asFragment(), deepExecRoot))); + outputPathFromOutputBase(outputBase.asFragment(), workspace.asFragment(), deepExecRoot, + productName))); - this.localOutputPath = outputBase.getRelative(BlazeDirectories.RELATIVE_OUTPUT_PATH); + this.localOutputPath = outputBase.getRelative(relativeOutputPath); } private static HashCode checkMD5(HashCode hash) { @@ -102,8 +98,8 @@ public final class BlazeDirectories { } @VisibleForTesting - public BlazeDirectories(Path installBase, Path outputBase, Path workspace) { - this(installBase, outputBase, workspace, false, null); + public BlazeDirectories(Path installBase, Path outputBase, Path workspace, String productName) { + this(installBase, outputBase, workspace, false, null, productName); } /** @@ -165,13 +161,13 @@ public final class BlazeDirectories { * @return the outputPath as a path fragment, given the outputBase. */ public static PathFragment outputPathFromOutputBase( - PathFragment outputBase, PathFragment workspace, boolean deepExecRoot) { + PathFragment outputBase, PathFragment workspace, boolean deepExecRoot, String productName) { PathFragment execRoot = deepExecRoot ? outputBase.getChild("execroot") : outputBase; if (workspace.equals(PathFragment.EMPTY_FRAGMENT)) { return execRoot; } - return execRoot.getRelative(workspace.getBaseName() + "/" + RELATIVE_OUTPUT_PATH); + return execRoot.getRelative(workspace.getBaseName() + "/" + getRelativeOutputPath(productName)); } /** @@ -213,4 +209,13 @@ public final class BlazeDirectories { public HashCode getInstallMD5() { return installMD5; } + + /** + * Returns the output directory name, relative to the execRoot. + * TODO(bazel-team): (2011) make this private? + */ + public static String getRelativeOutputPath(String productName) { + return StringCanonicalizer.intern(productName + "-out"); + } + } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java index c0b5bfcfc9..d9172ec8ff 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java @@ -17,7 +17,6 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.pkgcache.PackageCacheOptions; @@ -66,7 +65,7 @@ public final class FetchCommand implements BlazeCommand { if (options.getResidue().isEmpty()) { env.getReporter().handle(Event.error(String.format( "missing fetch expression. Type '%s help fetch' for syntax and help", - Constants.PRODUCT_NAME))); + env.getRuntime().getProductName()))); return ExitCode.COMMAND_LINE_ERROR; } diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java index 9effa36c06..f5f67c275d 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildRequest.java @@ -20,7 +20,6 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Sets; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BuildView; import com.google.devtools.build.lib.analysis.OutputGroupProvider; import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; @@ -86,7 +85,7 @@ public class BuildRequest implements OptionsClassProvider { defaultValue = "null", category = "verbosity", converter = OptionsUtils.PathFragmentConverter.class, - help = "Causes " + Constants.PRODUCT_NAME + " to explain each executed step of the " + help = "Causes the build system to explain each executed step of the " + "build. The explanation is written to the specified log file.") public PathFragment explanationPath; @@ -249,7 +248,7 @@ public class BuildRequest implements OptionsClassProvider { defaultValue = "false", category = "undocumented", help = "If set, tell the output service (if any) to track when files in the output " - + "tree have been modified externally (not by " + Constants.PRODUCT_NAME + "). " + + "tree have been modified externally (not by the build system). " + "This should improve incremental build speed when an appropriate output service " + "is enabled.") public boolean finalizeActions; @@ -263,8 +262,8 @@ public class BuildRequest implements OptionsClassProvider { ) public List<String> aspects; - public String getSymlinkPrefix() { - return symlinkPrefix == null ? Constants.PRODUCT_NAME + "-" : symlinkPrefix; + public String getSymlinkPrefix(String productName) { + return symlinkPrefix == null ? productName + "-" : symlinkPrefix; } } diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildResultPrinter.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildResultPrinter.java index 00aba284a5..8ef4a38ec9 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildResultPrinter.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildResultPrinter.java @@ -130,6 +130,7 @@ class BuildResultPrinter { // (ie, preprocessed and assembler files). OutputGroupProvider topLevelProvider = target.getProvider(OutputGroupProvider.class); + String productName = env.getRuntime().getProductName(); if (topLevelProvider != null) { for (Artifact temp : topLevelProvider.getOutputGroup(OutputGroupProvider.TEMP_FILES)) { if (temp.getPath().exists()) { @@ -137,7 +138,8 @@ class BuildResultPrinter { + OutputDirectoryLinksUtils.getPrettyPath(temp.getPath(), env.getWorkspaceName(), env.getWorkspace(), - request.getBuildOptions().getSymlinkPrefix())); + request.getBuildOptions().getSymlinkPrefix(productName), + productName)); } } } @@ -152,9 +154,10 @@ class BuildResultPrinter { } private String formatArtifactForShowResults(Artifact artifact, BuildRequest request) { + String productName = env.getRuntime().getProductName(); return " " + OutputDirectoryLinksUtils.getPrettyPath(artifact.getPath(), env.getWorkspaceName(), env.getWorkspace(), - request.getBuildOptions().getSymlinkPrefix()); + request.getBuildOptions().getSymlinkPrefix(productName), productName); } /** diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java index f741fe6a99..9724a35904 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java @@ -25,7 +25,6 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; import com.google.common.collect.Ordering; import com.google.common.collect.Table; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.ActionCacheChecker; import com.google.devtools.build.lib.actions.ActionContextConsumer; @@ -340,7 +339,7 @@ public class ExecutionTool { ImmutableMap<PathFragment, Path> packageRoots) throws BuildFailedException, InterruptedException, TestExecException, AbruptExitException { Stopwatch timer = Stopwatch.createStarted(); - prepare(packageRoots, configurations); + prepare(packageRoots); ActionGraph actionGraph = analysisResult.getActionGraph(); @@ -360,10 +359,11 @@ public class ExecutionTool { BuildConfiguration targetConfiguration = targetConfigurations.size() == 1 ? targetConfigurations.get(0) : null; if (targetConfigurations.size() == 1) { + String productName = runtime.getProductName(); OutputDirectoryLinksUtils.createOutputDirectoryLinks( env.getWorkspaceName(), env.getWorkspace(), getExecRoot(), env.getOutputPath(), getReporter(), targetConfiguration, - request.getBuildOptions().getSymlinkPrefix()); + request.getBuildOptions().getSymlinkPrefix(productName), productName); } ActionCache actionCache = getActionCache(); @@ -496,8 +496,8 @@ public class ExecutionTool { } } - private void prepare(ImmutableMap<PathFragment, Path> packageRoots, - BuildConfigurationCollection configurations) throws ExecutorInitException { + private void prepare(ImmutableMap<PathFragment, Path> packageRoots) + throws ExecutorInitException { // Prepare for build. Profiler.instance().markPhase(ProfilePhase.PREPARE); @@ -505,7 +505,7 @@ public class ExecutionTool { createActionLogDirectory(); // Plant the symlink forest. - plantSymlinkForest(packageRoots, configurations); + plantSymlinkForest(packageRoots); } private void createToolsSymlinks() throws ExecutorInitException { @@ -516,12 +516,12 @@ public class ExecutionTool { } } - private void plantSymlinkForest(ImmutableMap<PathFragment, Path> packageRoots, - BuildConfigurationCollection configurations) throws ExecutorInitException { + private void plantSymlinkForest(ImmutableMap<PathFragment, Path> packageRoots) + throws ExecutorInitException { try { FileSystemUtils.deleteTreesBelowNotPrefixed(getExecRoot(), - new String[] { ".", "_", Constants.PRODUCT_NAME + "-"}); - FileSystemUtils.plantLinkForest(packageRoots, getExecRoot()); + new String[] { ".", "_", runtime.getProductName() + "-"}); + FileSystemUtils.plantLinkForest(packageRoots, getExecRoot(), runtime.getProductName()); } catch (IOException e) { throw new ExecutorInitException("Source forest creation failed", e); } diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java b/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java index afa4356157..2698861520 100644 --- a/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java +++ b/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.buildtool; import com.google.common.base.Joiner; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; @@ -33,15 +32,17 @@ import javax.annotation.Nullable; * Static utilities for managing output directory symlinks. */ public class OutputDirectoryLinksUtils { - public static final String OUTPUT_SYMLINK_NAME = Constants.PRODUCT_NAME + "-out"; - // Used in getPrettyPath() method below. private static final String[] LINKS = { "bin", "genfiles", "includes" }; private static final String NO_CREATE_SYMLINKS_PREFIX = "/"; - private static String execRootSymlink(String workspaceName) { - return Constants.PRODUCT_NAME + "-" + workspaceName; + public static final String getOutputSymlinkName(String productName) { + return productName + "-out"; + } + + private static String execRootSymlink(String productName, String workspaceName) { + return productName + "-" + workspaceName; } /** * Attempts to create convenience symlinks in the workspaceDirectory and in @@ -51,7 +52,8 @@ public class OutputDirectoryLinksUtils { */ public static void createOutputDirectoryLinks(String workspaceName, Path workspace, Path execRoot, Path outputPath, - EventHandler eventHandler, @Nullable BuildConfiguration targetConfig, String symlinkPrefix) { + EventHandler eventHandler, @Nullable BuildConfiguration targetConfig, + String symlinkPrefix, String productName) { if (NO_CREATE_SYMLINKS_PREFIX.equals(symlinkPrefix)) { return; } @@ -60,10 +62,10 @@ public class OutputDirectoryLinksUtils { // Make the two non-specific links from the workspace to the output area, // and the configuration-specific links in both the workspace and the execution root dirs. // NB! Keep in sync with removeOutputDirectoryLinks below. - createLink(workspace, OUTPUT_SYMLINK_NAME, outputPath, failures); + createLink(workspace, getOutputSymlinkName(productName), outputPath, failures); // Points to execroot - createLink(workspace, execRootSymlink(workspaceName), execRoot, failures); + createLink(workspace, execRootSymlink(productName, workspaceName), execRoot, failures); if (targetConfig != null) { createLink(workspace, symlinkPrefix + "bin", @@ -90,7 +92,7 @@ public class OutputDirectoryLinksUtils { * before, the pretty path may be incorrect if the symlinks end up pointing somewhere new. */ public static PathFragment getPrettyPath(Path file, String workspaceName, - Path workspaceDirectory, String symlinkPrefix) { + Path workspaceDirectory, String symlinkPrefix, String productName) { for (String link : LINKS) { PathFragment result = relativize(file, workspaceDirectory, symlinkPrefix + link); if (result != null) { @@ -98,12 +100,13 @@ public class OutputDirectoryLinksUtils { } } - PathFragment result = relativize(file, workspaceDirectory, execRootSymlink(workspaceName)); + PathFragment result = relativize(file, workspaceDirectory, + execRootSymlink(productName, workspaceName)); if (result != null) { return result; } - result = relativize(file, workspaceDirectory, OUTPUT_SYMLINK_NAME); + result = relativize(file, workspaceDirectory, getOutputSymlinkName(productName)); if (result != null) { return result; } @@ -137,16 +140,17 @@ public class OutputDirectoryLinksUtils { * @param workspace the runtime's workspace * @param eventHandler the error eventHandler * @param symlinkPrefix the symlink prefix which should be removed + * @param productName the product name */ public static void removeOutputDirectoryLinks(String workspaceName, Path workspace, - EventHandler eventHandler, String symlinkPrefix) { + EventHandler eventHandler, String symlinkPrefix, String productName) { if (NO_CREATE_SYMLINKS_PREFIX.equals(symlinkPrefix)) { return; } List<String> failures = new ArrayList<>(); - removeLink(workspace, OUTPUT_SYMLINK_NAME, failures); - removeLink(workspace, execRootSymlink(workspaceName), failures); + removeLink(workspace, getOutputSymlinkName(productName), failures); + removeLink(workspace, execRootSymlink(productName, workspaceName), failures); removeLink(workspace, symlinkPrefix + "bin", failures); removeLink(workspace, symlinkPrefix + "testlogs", failures); removeLink(workspace, symlinkPrefix + "genfiles", failures); 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 93a8c8ce60..578a763831 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 @@ -42,7 +42,8 @@ final class RemoteActionContextProvider extends ActionContextProvider { buildRequest.getOptions(RemoteOptions.class), verboseFailures, actionCache, - workExecutor)); + workExecutor, + env.getRuntime().getProductName())); this.strategies = strategiesBuilder.build(); } diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnStrategy.java index 1b93d5679d..7184f79dfd 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnStrategy.java @@ -66,9 +66,10 @@ final class RemoteSpawnStrategy implements SpawnActionContext { RemoteOptions options, boolean verboseFailures, RemoteActionCache actionCache, - RemoteWorkExecutor workExecutor) { + RemoteWorkExecutor workExecutor, + String productName) { this.execRoot = execRoot; - this.standaloneStrategy = new StandaloneSpawnStrategy(execRoot, verboseFailures); + this.standaloneStrategy = new StandaloneSpawnStrategy(execRoot, verboseFailures, productName); this.remoteActionCache = actionCache; this.remoteWorkExecutor = workExecutor; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleHostInfo.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleHostInfo.java index 0253fe3355..dd0023a23c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleHostInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleHostInfo.java @@ -50,15 +50,17 @@ public class AppleHostInfo { * @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 UserExecException 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 */ public static String getSdkRoot(Path execRoot, String developerDir, - String sdkVersion, String appleSdkPlatform) throws UserExecException { + String sdkVersion, String appleSdkPlatform, String productName) throws UserExecException { try { CacheManager cacheManager = - new CacheManager(execRoot.getRelative(BlazeDirectories.RELATIVE_OUTPUT_PATH), + new CacheManager(execRoot.getRelative( + BlazeDirectories.getRelativeOutputPath(productName)), XCRUN_CACHE_FILENAME); String sdkString = appleSdkPlatform.toLowerCase() + sdkVersion; @@ -101,7 +103,7 @@ public class AppleHostInfo { throw new UserExecException(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. @@ -110,15 +112,16 @@ public class AppleHostInfo { * * @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 UserExecException 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 */ - public static String getDeveloperDir(Path execRoot, DottedVersion version) + public static String getDeveloperDir(Path execRoot, DottedVersion version, String productName) throws UserExecException { try { CacheManager cacheManager = - new CacheManager(execRoot.getRelative(BlazeDirectories.RELATIVE_OUTPUT_PATH), + new CacheManager(execRoot.getRelative(BlazeDirectories.getRelativeOutputPath(productName)), XCODE_LOCATOR_CACHE_FILENAME); String cacheResult = cacheManager.getValue(version.toString()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java index 545619e4dc..747ea822e0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java @@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.Root; import com.google.devtools.build.lib.analysis.AnalysisEnvironment; @@ -257,7 +256,8 @@ public class FdoSupport { Root fdoRoot = (fdoProfile == null) ? null - : Root.asDerivedRoot(execRoot, execRoot.getRelative(Constants.PRODUCT_NAME + "-fdo")); + : Root.asDerivedRoot(execRoot, execRoot.getRelative( + PrecomputedValue.PRODUCT_NAME.get(env) + "-fdo")); PathFragment fdoRootExecPath = fdoProfile == null ? null @@ -282,7 +282,8 @@ public class FdoSupport { } FdoZipContents fdoZipContents = extractFdoZip( - fdoMode, lipoMode, execRoot, fdoProfile, fdoRootExecPath); + fdoMode, lipoMode, execRoot, fdoProfile, fdoRootExecPath, + PrecomputedValue.PRODUCT_NAME.get(env)); return new FdoSupport( fdoMode, lipoMode, fdoRoot, fdoRootExecPath, fdoInstrument, fdoProfile, fdoZipContents); } @@ -308,7 +309,7 @@ public class FdoSupport { * @throws FdoException if the FDO ZIP contains a file of unknown type */ private static FdoZipContents extractFdoZip(FdoMode fdoMode, LipoMode lipoMode, Path execRoot, - Path fdoProfile, PathFragment fdoRootExecPath) + Path fdoProfile, PathFragment fdoRootExecPath, String productName) throws IOException, FdoException { // The execRoot != null case is only there for testing. We cannot provide a real ZIP file in // tests because ZipFileSystem does not work with a ZIP on an in-memory file system. @@ -333,7 +334,7 @@ public class FdoSupport { execRoot.getRelative(getLLVMProfilePath(fdoProfile, fdoRootExecPath)), fdoProfile); } else { Path zipFilePath = new ZipFileSystem(fdoProfile).getRootDirectory(); - String outputSymlinkName = Constants.PRODUCT_NAME + "-out"; + String outputSymlinkName = productName + "-out"; if (!zipFilePath.getRelative(outputSymlinkName).isDirectory()) { throw new ZipException( "FDO zip files must be zipped directly above '" diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java index 3e17b47a38..8094094e52 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java @@ -27,7 +27,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.ListMultimap; import com.google.common.io.Flushables; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Reporter; @@ -198,7 +197,7 @@ public class BlazeCommandDispatcher { Path workspace = env.getWorkspace(); // TODO(kchodorow): Remove this once spaces are supported. if (workspace.getPathString().contains(" ")) { - outErr.printErrLn(Constants.PRODUCT_NAME + " does not currently work properly from paths " + outErr.printErrLn(runtime.getProductName() + " does not currently work properly from paths " + "containing spaces (" + workspace + ")."); return ExitCode.LOCAL_ENVIRONMENTAL_ERROR; } @@ -286,7 +285,7 @@ public class BlazeCommandDispatcher { BlazeCommand command = runtime.getCommandMap().get(commandName); if (command == null) { outErr.printErrLn(String.format( - "Command '%s' not found. Try '%s help'.", commandName, Constants.PRODUCT_NAME)); + "Command '%s' not found. Try '%s help'.", commandName, runtime.getProductName())); return ExitCode.COMMAND_LINE_ERROR.getNumericExitCode(); } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandUtils.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandUtils.java index 3ba6e22ef9..f7bcd1d224 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandUtils.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandUtils.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.runtime; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.util.ResourceFileLoader; import com.google.devtools.common.options.OptionsBase; @@ -106,12 +105,14 @@ public class BlazeCommandUtils { * descriptions, passed to {@link OptionsParser#describeOptions}. * @param helpVerbosity a tri-state verbosity option selecting between just * names, names and syntax, and full description. + * @param productName the product name */ public static final String expandHelpTopic(String topic, String help, Class<? extends BlazeCommand> commandClass, Collection<Class<? extends OptionsBase>> options, Map<String, String> categoryDescriptions, - OptionsParser.HelpVerbosity helpVerbosity) { + OptionsParser.HelpVerbosity helpVerbosity, + String productName) { OptionsParser parser = OptionsParser.newOptionsParser(options); String template; @@ -134,9 +135,9 @@ public class BlazeCommandUtils { String optionStr = parser .describeOptions(categoryDescriptions, helpVerbosity) - .replace("%{product}", Constants.PRODUCT_NAME); + .replace("%{product}", productName); return template - .replace("%{product}", Constants.PRODUCT_NAME) + .replace("%{product}", productName) .replace("%{command}", topic) .replace("%{options}", optionStr) .trim() @@ -159,7 +160,8 @@ public class BlazeCommandUtils { Map<String, String> categoryDescriptions, OptionsParser.HelpVerbosity verbosity, Iterable<BlazeModule> blazeModules, - ConfiguredRuleClassProvider ruleClassProvider) { + ConfiguredRuleClassProvider ruleClassProvider, + String productName) { Command commandAnnotation = commandClass.getAnnotation(Command.class); return BlazeCommandUtils.expandHelpTopic( commandAnnotation.name(), @@ -167,6 +169,7 @@ public class BlazeCommandUtils { commandClass, BlazeCommandUtils.getOptions(commandClass, blazeModules, ruleClassProvider), categoryDescriptions, - verbosity); + verbosity, + productName); } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java index c03192c3b7..1b9d821301 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java @@ -302,7 +302,8 @@ public final class BlazeRuntime { preprocessorFactorySupplier, skyFunctions.build(), precomputedValues.build(), - customDirtinessCheckers.build()); + customDirtinessCheckers.build(), + getProductName()); this.workspace = new BlazeWorkspace( this, directories, skyframeExecutor, eventBusExceptionHandler, workspaceStatusActionFactory, binTools); @@ -379,7 +380,7 @@ public final class BlazeRuntime { } if (profiledTasks != ProfiledTaskKinds.NONE) { Profiler.instance().start(profiledTasks, out, - Constants.PRODUCT_NAME + " profile for " + env.getOutputBase() + " at " + new Date() + getProductName() + " profile for " + env.getOutputBase() + " at " + new Date() + ", build ID: " + buildID, recordFullProfilerData, clock, execStartTimeNanos); return true; @@ -1006,7 +1007,7 @@ public final class BlazeRuntime { } PathFragment outputPathFragment = BlazeDirectories.outputPathFromOutputBase( - outputBase, workspaceDirectory, startupOptions.deepExecRoot); + outputBase, workspaceDirectory, startupOptions.deepExecRoot, Constants.PRODUCT_NAME); FileSystem fs = null; for (BlazeModule module : blazeModules) { FileSystem moduleFs = module.getFileSystem(options, outputPathFragment); @@ -1038,7 +1039,8 @@ public final class BlazeRuntime { BlazeDirectories directories = new BlazeDirectories(installBasePath, outputBasePath, workspaceDirectoryPath, - startupOptions.deepExecRoot, startupOptions.installMD5); + startupOptions.deepExecRoot, startupOptions.installMD5, + Constants.PRODUCT_NAME); Clock clock = BlazeClock.instance(); @@ -1152,6 +1154,10 @@ public final class BlazeRuntime { new VersionCommand()); } + public String getProductName() { + return Constants.PRODUCT_NAME; + } + /** * A builder for {@link BlazeRuntime} objects. The only required fields are the {@link * BlazeDirectories}, and the {@link RuleClassProvider} (except for testing). All other fields @@ -1298,8 +1304,8 @@ public final class BlazeRuntime { * parameters. */ public Builder setDirectories(Path installBase, Path outputBase, - Path workspace) { - this.directories = new BlazeDirectories(installBase, outputBase, workspace); + Path workspace, String productName) { + this.directories = new BlazeDirectories(installBase, outputBase, workspace, productName); return this; } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java b/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java index a5d3e106f6..d81a8b7c00 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BugReport.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.runtime; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.util.ExitCode; import com.google.devtools.build.lib.util.LoggingUtil; @@ -72,7 +71,7 @@ public abstract class BugReport { private static void logCrash(Throwable throwable, String... args) { BugReport.sendBugReport(throwable, Arrays.asList(args)); BugReport.printBug(OutErr.SYSTEM_OUT_ERR, throwable); - System.err.println(Constants.PRODUCT_NAME + " crash in async thread:"); + System.err.println(runtime.getProductName() + " crash in async thread:"); throwable.printStackTrace(); } @@ -106,9 +105,9 @@ public abstract class BugReport { } catch (Throwable t) { System.err.println( "An crash occurred while " - + Constants.PRODUCT_NAME + + runtime.getProductName() + " was trying to handle a crash! Please file a bug against " - + Constants.PRODUCT_NAME + + runtime.getProductName() + " and include the information below."); System.err.println("Original uncaught exception:"); @@ -132,7 +131,7 @@ public abstract class BugReport { PrintStream err = new PrintStream(outErr.getErrorStream()); e.printStackTrace(err); err.flush(); - LOG.log(Level.SEVERE, Constants.PRODUCT_NAME + " crashed", e); + LOG.log(Level.SEVERE, runtime.getProductName() + " crashed", e); } /** @@ -144,7 +143,7 @@ public abstract class BugReport { public static void printBug(OutErr outErr, Throwable e) { if (e instanceof OutOfMemoryError) { outErr.printErr( - e.getMessage() + "\n\n" + Constants.PRODUCT_NAME + " ran out of memory and crashed.\n"); + e.getMessage() + "\n\n" + runtime.getProductName() + " ran out of memory and crashed.\n"); } else { printThrowableTo(outErr, e); } @@ -175,7 +174,7 @@ public abstract class BugReport { private static void logException(Throwable exception, List<String> args, String... values) { // The preamble is used in the crash watcher, so don't change it // unless you know what you're doing. - String preamble = Constants.PRODUCT_NAME + String preamble = runtime.getProductName() + (exception instanceof OutOfMemoryError ? " OOMError: " : " crashed with args: "); LoggingUtil.logToRemote(Level.SEVERE, preamble + Joiner.on(' ').join(args), exception, diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java index 1080c4594b..923f89473e 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java @@ -105,8 +105,8 @@ public final class CleanCommand implements BlazeCommand { env.getReporter().handle(Event.info(null/*location*/, cleanBanner)); try { - String symlinkPrefix = - options.getOptions(BuildRequest.BuildRequestOptions.class).getSymlinkPrefix(); + String symlinkPrefix = options.getOptions(BuildRequest.BuildRequestOptions.class) + .getSymlinkPrefix(env.getRuntime().getProductName()); actuallyClean(env, env.getOutputBase(), cleanOptions, symlinkPrefix); return ExitCode.SUCCESS; } catch (IOException e) { @@ -174,7 +174,8 @@ public final class CleanCommand implements BlazeCommand { } // remove convenience links OutputDirectoryLinksUtils.removeOutputDirectoryLinks( - env.getWorkspaceName(), env.getWorkspace(), env.getReporter(), symlinkPrefix); + env.getWorkspaceName(), env.getWorkspace(), env.getReporter(), symlinkPrefix, + env.getRuntime().getProductName()); // shutdown on expunge cleans if (cleanOptions.expunge || cleanOptions.expunge_async) { throw new ShutdownBlazeServerException(0, ShutdownMethod.EXPUNGE); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java index b18714e695..03adf0570a 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java @@ -135,7 +135,8 @@ public class DumpCommand implements BlazeCommand { getClass().getAnnotation(Command.class).name(), getClass().getAnnotation(Command.class).help(), getClass(), - optionList, categories, OptionsParser.HelpVerbosity.LONG)); + optionList, categories, OptionsParser.HelpVerbosity.LONG, + runtime.getProductName())); return ExitCode.ANALYSIS_FAILURE; } PrintStream out = new PrintStream(env.getReporter().getOutErr().getOutputStream()); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/HelpCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/HelpCommand.java index 08ef73eae8..8e11e08cde 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/HelpCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/HelpCommand.java @@ -17,7 +17,6 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.docgen.BlazeRuleHelpPrinter; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.analysis.NoBuildEvent; @@ -88,7 +87,7 @@ public final class HelpCommand implements BlazeCommand { */ private ImmutableMap<String, String> getOptionCategories(BlazeRuntime runtime) { ImmutableMap.Builder<String, String> optionCategoriesBuilder = ImmutableMap.builder(); - String name = Constants.PRODUCT_NAME; + String name = runtime.getProductName(); optionCategoriesBuilder .put("checking", String.format( "Checking options, which control %s's error checking and/or warnings", name)) @@ -141,7 +140,7 @@ public final class HelpCommand implements BlazeCommand { OutErr outErr = env.getReporter().getOutErr(); Options helpOptions = options.getOptions(Options.class); if (options.getResidue().isEmpty()) { - emitBlazeVersionInfo(outErr); + emitBlazeVersionInfo(outErr, runtime.getProductName()); emitGenericHelp(runtime, outErr); return ExitCode.SUCCESS; } @@ -151,12 +150,12 @@ public final class HelpCommand implements BlazeCommand { } String helpSubject = options.getResidue().get(0); if (helpSubject.equals("startup_options")) { - emitBlazeVersionInfo(outErr); + emitBlazeVersionInfo(outErr, runtime.getProductName()); emitStartupOptions(outErr, helpOptions.helpVerbosity, runtime, getOptionCategories(runtime)); return ExitCode.SUCCESS; } else if (helpSubject.equals("target-syntax")) { - emitBlazeVersionInfo(outErr); - emitTargetSyntaxHelp(outErr, getOptionCategories(runtime)); + emitBlazeVersionInfo(outErr, runtime.getProductName()); + emitTargetSyntaxHelp(outErr, getOptionCategories(runtime), runtime.getProductName()); return ExitCode.SUCCESS; } else if (helpSubject.equals("info-keys")) { emitInfoKeysHelp(env, outErr); @@ -180,19 +179,20 @@ public final class HelpCommand implements BlazeCommand { return ExitCode.COMMAND_LINE_ERROR; } } - emitBlazeVersionInfo(outErr); + emitBlazeVersionInfo(outErr, runtime.getProductName()); outErr.printOut(BlazeCommandUtils.getUsage( command.getClass(), getOptionCategories(runtime), helpOptions.helpVerbosity, runtime.getBlazeModules(), - runtime.getRuleClassProvider())); + runtime.getRuleClassProvider(), + runtime.getProductName())); return ExitCode.SUCCESS; } - private void emitBlazeVersionInfo(OutErr outErr) { + private void emitBlazeVersionInfo(OutErr outErr, String productName) { String releaseInfo = BlazeVersionInfo.instance().getReleaseName(); - String line = String.format("[%s %s]", Constants.PRODUCT_NAME, releaseInfo); + String line = String.format("[%s %s]", productName, releaseInfo); outErr.printOut(String.format("%80s\n", line)); } @@ -205,7 +205,8 @@ public final class HelpCommand implements BlazeCommand { getClass(), BlazeCommandUtils.getStartupOptions(runtime.getBlazeModules()), optionCategories, - helpVerbosity)); + helpVerbosity, + runtime.getProductName())); } private void emitCompletionHelp(BlazeRuntime runtime, OutErr outErr) { @@ -218,7 +219,7 @@ public final class HelpCommand implements BlazeCommand { outErr.printOutLn("BAZEL_COMMAND_LIST=\"" + SPACE_JOINER.join(commands) + "\""); outErr.printOutLn("BAZEL_INFO_KEYS=\""); - for (String name : InfoCommand.getHardwiredInfoItemNames(Constants.PRODUCT_NAME)) { + for (String name : InfoCommand.getHardwiredInfoItemNames(runtime.getProductName())) { outErr.printOutLn(name); } outErr.printOutLn("\""); @@ -244,13 +245,15 @@ public final class HelpCommand implements BlazeCommand { } } - private void emitTargetSyntaxHelp(OutErr outErr, ImmutableMap<String, String> optionCategories) { + private void emitTargetSyntaxHelp(OutErr outErr, ImmutableMap<String, String> optionCategories, + String productName) { outErr.printOut(BlazeCommandUtils.expandHelpTopic("target-syntax", "resource:target-syntax.txt", getClass(), ImmutableList.<Class<? extends OptionsBase>>of(), optionCategories, - OptionsParser.HelpVerbosity.MEDIUM)); + OptionsParser.HelpVerbosity.MEDIUM, + productName)); } private void emitInfoKeysHelp(CommandEnvironment env, OutErr outErr) { @@ -263,7 +266,7 @@ public final class HelpCommand implements BlazeCommand { private void emitGenericHelp(BlazeRuntime runtime, OutErr outErr) { outErr.printOut(String.format("Usage: %s <command> <options> ...\n\n", - Constants.PRODUCT_NAME)); + runtime.getProductName())); outErr.printOut("Available commands:\n"); @@ -279,20 +282,20 @@ public final class HelpCommand implements BlazeCommand { } String shortDescription = annotation.shortDescription(). - replace("%{product}", Constants.PRODUCT_NAME); + replace("%{product}", runtime.getProductName()); outErr.printOut(String.format(" %-19s %s\n", name, shortDescription)); } outErr.printOut("\n"); outErr.printOut("Getting more help:\n"); - outErr.printOut(String.format(" %s help <command>\n", Constants.PRODUCT_NAME)); + outErr.printOut(String.format(" %s help <command>\n", runtime.getProductName())); outErr.printOut(" Prints help and options for <command>.\n"); - outErr.printOut(String.format(" %s help startup_options\n", Constants.PRODUCT_NAME)); + outErr.printOut(String.format(" %s help startup_options\n", runtime.getProductName())); outErr.printOut(String.format(" Options for the JVM hosting %s.\n", - Constants.PRODUCT_NAME)); - outErr.printOut(String.format(" %s help target-syntax\n", Constants.PRODUCT_NAME)); + runtime.getProductName())); + outErr.printOut(String.format(" %s help target-syntax\n", runtime.getProductName())); outErr.printOut(" Explains the syntax for specifying targets.\n"); - outErr.printOut(String.format(" %s help info-keys\n", Constants.PRODUCT_NAME)); + outErr.printOut(String.format(" %s help info-keys\n", runtime.getProductName())); outErr.printOut(" Displays a list of keys used by the info command.\n"); } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java index a2badf3c31..7ba1e2daaf 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java @@ -17,7 +17,6 @@ import com.google.common.base.Supplier; import com.google.common.base.Verify; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.NoBuildEvent; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; @@ -198,7 +197,7 @@ public class InfoCommand implements BlazeCommand { List<InfoItem> hardwiredInfoItems = ImmutableList.<InfoItem>of( new InfoItem.WorkspaceInfoItem(), new InfoItem.InstallBaseInfoItem(), - new InfoItem.OutputBaseInfoItem(), + new InfoItem.OutputBaseInfoItem(productName), new InfoItem.ExecutionRootInfoItem(), new InfoItem.OutputPathInfoItem(), new InfoItem.BlazeBinInfoItem(productName), @@ -242,7 +241,7 @@ public class InfoCommand implements BlazeCommand { result.put(item.getName(), item); } } - result.putAll(getHardwiredInfoItemMap(commandOptions, Constants.PRODUCT_NAME)); + result.putAll(getHardwiredInfoItemMap(commandOptions, env.getRuntime().getProductName())); return result; } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java index 923f29ce0c..8237317cfb 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java @@ -20,7 +20,6 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Supplier; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.packages.Attribute; @@ -149,9 +148,9 @@ public abstract class InfoItem { * Info item for the output_base directory. */ public static final class OutputBaseInfoItem extends InfoItem { - public OutputBaseInfoItem() { + public OutputBaseInfoItem(String productName) { super("output_base", - "A directory for shared " + Constants.PRODUCT_NAME + "A directory for shared " + productName + " state as well as tool and strategy specific subdirectories.", false); } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java index cf857fd810..9af780e5eb 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java @@ -19,7 +19,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.NoBuildEvent; import com.google.devtools.build.lib.collect.CompactHashSet; import com.google.devtools.build.lib.events.Event; @@ -118,7 +117,7 @@ public final class QueryCommand implements BlazeCommand { } else { env.getReporter().handle(Event.error(String.format( "missing query expression. Type '%s help query' for syntax and help", - Constants.PRODUCT_NAME))); + runtime.getProductName()))); return ExitCode.COMMAND_LINE_ERROR; } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java index be47fc1a7d..729bace0ef 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java @@ -233,6 +233,7 @@ public class RunCommand implements BlazeCommand { } } + String productName = env.getRuntime().getProductName(); // // We now have a unique executable ready to be run. // @@ -242,7 +243,8 @@ public class RunCommand implements BlazeCommand { PathFragment prettyExecutablePath = OutputDirectoryLinksUtils.getPrettyPath(executablePath, env.getWorkspaceName(), env.getWorkspace(), - options.getOptions(BuildRequestOptions.class).getSymlinkPrefix()); + options.getOptions(BuildRequestOptions.class).getSymlinkPrefix(productName), + productName); List<String> cmdLine = new ArrayList<>(); if (runOptions.scriptPath == null) { PathFragment processWrapperPath = diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java index 385a14d30b..5c025102c2 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java @@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.io.Files; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionInput; import com.google.devtools.build.lib.actions.ActionInputHelper; @@ -81,6 +80,7 @@ public class LinuxSandboxedStrategy implements SpawnActionContext { private final List<String> sandboxAddPath; private final UUID uuid = UUID.randomUUID(); private final AtomicInteger execCounter = new AtomicInteger(); + private final String productName; public LinuxSandboxedStrategy( Map<String, String> clientEnv, @@ -89,7 +89,8 @@ public class LinuxSandboxedStrategy implements SpawnActionContext { boolean verboseFailures, boolean sandboxDebug, List<String> sandboxAddPath, - boolean unblockNetwork) { + boolean unblockNetwork, + String productName) { this.clientEnv = ImmutableMap.copyOf(clientEnv); this.blazeDirs = blazeDirs; this.execRoot = blazeDirs.getExecRoot(); @@ -98,7 +99,9 @@ public class LinuxSandboxedStrategy implements SpawnActionContext { this.sandboxDebug = sandboxDebug; this.sandboxAddPath = sandboxAddPath; this.unblockNetwork = unblockNetwork; - this.standaloneStrategy = new StandaloneSpawnStrategy(blazeDirs.getExecRoot(), verboseFailures); + this.standaloneStrategy = new StandaloneSpawnStrategy( + blazeDirs.getExecRoot(), verboseFailures, productName); + this.productName = productName; } /** @@ -132,7 +135,7 @@ public class LinuxSandboxedStrategy implements SpawnActionContext { // Each invocation of "exec" gets its own sandbox. Path sandboxPath = - execRoot.getRelative(Constants.PRODUCT_NAME + "-sandbox").getRelative(execId); + execRoot.getRelative(productName + "-sandbox").getRelative(execId); ImmutableMap<Path, Path> mounts; try { 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 2cfe3ddedf..a1f6134ff0 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 @@ -55,7 +55,8 @@ public class SandboxActionContextProvider extends ActionContextProvider { verboseFailures, sandboxDebug, sandboxAddPath, - unblockNetwork)); + unblockNetwork, + env.getRuntime().getProductName())); } this.strategies = strategies.build(); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java index a6a110cc51..0717561c47 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java @@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.ActionCacheChecker.Token; import com.google.devtools.build.lib.actions.ActionExecutionContext; @@ -425,9 +424,8 @@ public class ActionExecutionFunction implements SkyFunction, CompletionReceiver // and also report the issue. String errorMessage = action.prettyPrint() - + " discovered unexpected inputs. This indicates a mismatch between " - + Constants.PRODUCT_NAME - + " and the action's compiler. Please report this issue. The "; + + " discovered unexpected inputs. This indicates a mismatch between the build" + + " system and the action's compiler. Please report this issue. The "; if (metadataFoundDuringActionExecution.size() > 10) { errorMessage += "first ten "; } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java index 8d20b9ea97..3fe34d4288 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java @@ -101,6 +101,9 @@ public final class PrecomputedValue implements SkyValue { public static final Precomputed<BlazeDirectories> BLAZE_DIRECTORIES = new Precomputed<>(SkyKey.create(SkyFunctions.PRECOMPUTED, "blaze_directories")); + public static final Precomputed<String> PRODUCT_NAME = + new Precomputed<>(SkyKey.create(SkyFunctions.PRECOMPUTED, "product_name")); + static final Precomputed<ImmutableMap<ActionAnalysisMetadata, ConflictException>> BAD_ACTIONS = new Precomputed<>(SkyKey.create(SkyFunctions.PRECOMPUTED, "bad_actions")); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java index 6f6b48c459..ace63f8173 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java @@ -113,7 +113,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor { ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions, ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues, Iterable<SkyValueDirtinessChecker> customDirtinessCheckers, - PathFragment blacklistedPackagePrefixesFile) { + PathFragment blacklistedPackagePrefixesFile, + String productName) { super( evaluatorSupplier, pkgFactory, @@ -126,7 +127,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor { extraSkyFunctions, extraPrecomputedValues, false, - blacklistedPackagePrefixesFile); + blacklistedPackagePrefixesFile, + productName); this.diffAwarenessManager = new DiffAwarenessManager(diffAwarenessFactories); this.customDirtinessCheckers = customDirtinessCheckers; } @@ -142,7 +144,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor { Preprocessor.Factory.Supplier preprocessorFactorySupplier, ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions, ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues, - Iterable<SkyValueDirtinessChecker> customDirtinessCheckers) { + Iterable<SkyValueDirtinessChecker> customDirtinessCheckers, + String productName) { return create( pkgFactory, directories, @@ -155,7 +158,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor { extraSkyFunctions, extraPrecomputedValues, customDirtinessCheckers, - /*blacklistedPackagePrefixesFile=*/ PathFragment.EMPTY_FRAGMENT); + /*blacklistedPackagePrefixesFile=*/ PathFragment.EMPTY_FRAGMENT, + productName); } private static SequencedSkyframeExecutor create( @@ -170,7 +174,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor { ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions, ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues, Iterable<SkyValueDirtinessChecker> customDirtinessCheckers, - PathFragment blacklistedPackagePrefixesFile) { + PathFragment blacklistedPackagePrefixesFile, + String productName) { SequencedSkyframeExecutor skyframeExecutor = new SequencedSkyframeExecutor( InMemoryMemoizingEvaluator.SUPPLIER, @@ -185,7 +190,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor { extraSkyFunctions, extraPrecomputedValues, customDirtinessCheckers, - blacklistedPackagePrefixesFile); + blacklistedPackagePrefixesFile, + productName); skyframeExecutor.init(); return skyframeExecutor; } @@ -196,7 +202,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor { WorkspaceStatusAction.Factory workspaceStatusActionFactory, ImmutableList<BuildInfoFactory> buildInfoFactories, Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories, - PathFragment blacklistedPackagePrefixesFile) { + PathFragment blacklistedPackagePrefixesFile, + String productName) { return create( pkgFactory, directories, @@ -209,7 +216,8 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor { ImmutableMap.<SkyFunctionName, SkyFunction>of(), ImmutableList.<PrecomputedValue.Injected>of(), ImmutableList.<SkyValueDirtinessChecker>of(), - blacklistedPackagePrefixesFile); + blacklistedPackagePrefixesFile, + productName); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java index 3dbeb2ed09..6ae70ff3ed 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutorFactory.java @@ -43,7 +43,8 @@ public class SequencedSkyframeExecutorFactory implements SkyframeExecutorFactory Preprocessor.Factory.Supplier preprocessorFactorySupplier, ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions, ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues, - Iterable<SkyValueDirtinessChecker> customDirtinessCheckers) { + Iterable<SkyValueDirtinessChecker> customDirtinessCheckers, + String productName) { return SequencedSkyframeExecutor.create( pkgFactory, directories, @@ -55,6 +56,7 @@ public class SequencedSkyframeExecutorFactory implements SkyframeExecutorFactory preprocessorFactorySupplier, extraSkyFunctions, extraPrecomputedValues, - customDirtinessCheckers); + customDirtinessCheckers, + productName); } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java index d118eafbaf..c542e24335 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java @@ -258,6 +258,8 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { private final ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions; private final ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues; + private final String productName; + protected SkyframeIncrementalBuildMonitor incrementalBuildMonitor = new SkyframeIncrementalBuildMonitor(); @@ -281,7 +283,8 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions, ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues, boolean errorOnExternalFiles, - PathFragment blacklistedPackagePrefixesFile) { + PathFragment blacklistedPackagePrefixesFile, + String productName) { // Strictly speaking, these arguments are not required for initialization, but all current // callsites have them at hand, so we might as well set them during construction. this.evaluatorSupplier = evaluatorSupplier; @@ -312,6 +315,7 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { this.artifactFactory.set(skyframeBuildView.getArtifactFactory()); this.externalFilesHelper = new ExternalFilesHelper( pkgLocator, this.errorOnExternalFiles, directories); + this.productName = productName; } private ImmutableMap<SkyFunctionName, SkyFunction> skyFunctions( @@ -648,6 +652,7 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { protected void maybeInjectPrecomputedValuesForAnalysis() { if (needToInjectPrecomputedValuesForAnalysis) { PrecomputedValue.BLAZE_DIRECTORIES.set(injectable(), directories); + PrecomputedValue.PRODUCT_NAME.set(injectable(), productName); injectBuildInfoFactories(); injectExtraPrecomputedValues(); needToInjectPrecomputedValuesForAnalysis = false; diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutorFactory.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutorFactory.java index 8e3cea4d2e..9a92aea216 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutorFactory.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutorFactory.java @@ -47,6 +47,7 @@ public interface SkyframeExecutorFactory { * @param extraSkyFunctions * @param extraPrecomputedValues * @param customDirtinessCheckers + * @param productName * @return an instance of the SkyframeExecutor * @throws AbruptExitException if the executor cannot be created */ @@ -61,6 +62,7 @@ public interface SkyframeExecutorFactory { Preprocessor.Factory.Supplier preprocessorFactorySupplier, ImmutableMap<SkyFunctionName, SkyFunction> extraSkyFunctions, ImmutableList<PrecomputedValue.Injected> extraPrecomputedValues, - Iterable<SkyValueDirtinessChecker> customDirtinessCheckers) + Iterable<SkyValueDirtinessChecker> customDirtinessCheckers, + String productName) throws AbruptExitException; } 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 4982624988..92690c2655 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 @@ -81,7 +81,10 @@ public class StandaloneActionContextProvider extends ActionContextProvider { // could potentially be used and a spawnActionContext doesn't specify which one it wants, the // last one from strategies list will be used strategiesBuilder.add( - new StandaloneSpawnStrategy(env.getExecRoot(), verboseFailures), + new StandaloneSpawnStrategy( + env.getExecRoot(), + verboseFailures, + env.getRuntime().getProductName()), new DummyIncludeScanningContext(), new SpawnLinkStrategy(), new SpawnGccStrategy(), diff --git a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategy.java index 6f009af507..fa04143b32 100644 --- a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategy.java @@ -48,12 +48,14 @@ public class StandaloneSpawnStrategy implements SpawnActionContext { private final boolean verboseFailures; private final Path processWrapper; private final Path execRoot; + private final String productName; - public StandaloneSpawnStrategy(Path execRoot, boolean verboseFailures) { + public StandaloneSpawnStrategy(Path execRoot, boolean verboseFailures, String productName) { this.verboseFailures = verboseFailures; this.execRoot = execRoot; this.processWrapper = execRoot.getRelative( "_bin/process-wrapper" + OsUtils.executableExtension()); + this.productName = productName; } /** @@ -144,14 +146,14 @@ public class StandaloneSpawnStrategy implements SpawnActionContext { /** * Adds to the given environment all variables that are dependent on system state of the host * machine. - * + * * <p> Admittedly, hermeticity is "best effort" in such cases; these environment values * should be as tied to configuration parameters as possible. - * + * * <p>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. - * + * * @return the new environment, comprised of the old environment plus any new variables * @throws UserExecException if any variables dependent on system state could not be * resolved @@ -186,7 +188,8 @@ public class StandaloneSpawnStrategy implements SpawnActionContext { throw new UserExecException( "Cannot locate xcode developer directory on non-darwin operating system"); } - return AppleHostInfo.getDeveloperDir(execRoot, DottedVersion.fromString(xcodeVersion)); + return AppleHostInfo.getDeveloperDir(execRoot, DottedVersion.fromString(xcodeVersion), + productName); } private String getSdkRootEnv(String developerDir, @@ -194,7 +197,8 @@ public class StandaloneSpawnStrategy implements SpawnActionContext { if (OS.getCurrent() != OS.DARWIN) { throw new UserExecException("Cannot locate iOS SDK on non-darwin operating system"); } - return AppleHostInfo.getSdkRoot(execRoot, developerDir, iosSdkVersion, appleSdkPlatform); + return AppleHostInfo.getSdkRoot(execRoot, developerDir, iosSdkVersion, appleSdkPlatform, + productName); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/util/IncludeScanningUtil.java b/src/main/java/com/google/devtools/build/lib/util/IncludeScanningUtil.java index 37557ab2c7..753e50fe48 100644 --- a/src/main/java/com/google/devtools/build/lib/util/IncludeScanningUtil.java +++ b/src/main/java/com/google/devtools/build/lib/util/IncludeScanningUtil.java @@ -14,7 +14,6 @@ package com.google.devtools.build.lib.util; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.vfs.PathFragment; /** @@ -25,16 +24,19 @@ public class IncludeScanningUtil { } private static final String INCLUDES_SUFFIX = ".includes"; - public static final PathFragment GREPPED_INCLUDES = - new PathFragment(Constants.PRODUCT_NAME + "-out/_grepped_includes"); + + public static PathFragment getGreppedIncludes(String productName) { + return new PathFragment(productName + "-out/_grepped_includes"); + } /** * Returns the exec-root relative output path for grepped includes. * * @param srcExecPath the exec-root relative path of the source file. */ - public static PathFragment getExecRootRelativeOutputPath(PathFragment srcExecPath) { - return GREPPED_INCLUDES.getRelative(getRootRelativeOutputPath(srcExecPath)); + public static PathFragment getExecRootRelativeOutputPath(PathFragment srcExecPath, + String productName) { + return getGreppedIncludes(productName).getRelative(getRootRelativeOutputPath(srcExecPath)); } /** diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java index 9ef39736b6..0facfefde1 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java @@ -22,7 +22,6 @@ import com.google.common.collect.Sets; import com.google.common.io.ByteSink; import com.google.common.io.ByteSource; import com.google.common.io.ByteStreams; -import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.concurrent.ThreadSafety.ConditionallyThreadSafe; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.util.Preconditions; @@ -683,7 +682,8 @@ public class FileSystemUtils { * files. Symlink are made at the highest dir possible, linking files directly * only when needed with nested packages. */ - public static void plantLinkForest(ImmutableMap<PathFragment, Path> packageRootMap, Path linkRoot) + public static void plantLinkForest(ImmutableMap<PathFragment, Path> packageRootMap, + Path linkRoot, String productName) throws IOException { Path emptyPackagePath = null; @@ -782,7 +782,7 @@ public class FileSystemUtils { for (Path target : emptyPackagePath.getDirectoryEntries()) { String baseName = target.getBaseName(); // Create any links that don't exist yet and don't start with bazel-. - if (!baseName.startsWith(Constants.PRODUCT_NAME + "-") + if (!baseName.startsWith(productName + "-") && !linkRoot.getRelative(baseName).exists()) { linkRoot.getRelative(baseName).createSymbolicLink(target); } @@ -935,7 +935,7 @@ public class FileSystemUtils { public static Iterable<String> readLines(Path inputFile, Charset charset) throws IOException { return asByteSource(inputFile).asCharSource(charset).readLines(); } - + /** * Returns the entirety of the specified file and returns it as a byte array. * |