diff options
author | 2016-03-31 17:56:32 +0000 | |
---|---|---|
committer | 2016-03-31 20:28:50 +0000 | |
commit | 04e3e37cefa2fbc8e64e6f1d109267680e345b24 (patch) | |
tree | 0bf45c890417dedd68ed150027e5941c2f361134 /src/main/java/com/google/devtools/build/lib | |
parent | 2eaff2e6c44d0b6a7017e6cb45334eac82dee7fb (diff) |
Remove the directories field from RepositoryFunction.
This is problematic for coming up with a less stateful BlazeModule API, which
- in turn - is a requirement for running multiple commands in the same server.
--
MOS_MIGRATED_REVID=118696892
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
14 files changed, 125 insertions, 147 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java index 6d7c4f8886..0524b78aeb 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java @@ -17,7 +17,6 @@ package com.google.devtools.build.lib.bazel; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.analysis.BlazeDirectories; -import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.bazel.commands.FetchCommand; @@ -60,7 +59,6 @@ import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.skyframe.SkyFunctions; import com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker; import com.google.devtools.build.lib.util.AbruptExitException; -import com.google.devtools.build.lib.util.Clock; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -69,7 +67,6 @@ import com.google.devtools.build.skyframe.SkyValue; import com.google.devtools.common.options.OptionsProvider; import java.util.Map.Entry; -import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nullable; @@ -103,16 +100,6 @@ public class BazelRepositoryModule extends BlazeModule { .build(); } - @Override - public void blazeStartup(OptionsProvider startupOptions, - BlazeVersionInfo versionInfo, UUID instanceId, BlazeDirectories directories, - Clock clock) { - for (RepositoryFunction handler : repositoryHandlers.values()) { - handler.setDirectories(directories); - } - skylarkRepositoryFunction.setDirectories(directories); - } - /** * A dirtiness checker that always dirties {@link RepositoryDirectoryValue}s so that if they were * produced in a {@code --nofetch} build, they are re-created no subsequent {@code --fetch} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitRepositoryFunction.java index 4bb282eb97..5bcdbd4cb7 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitRepositoryFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.bazel.repository; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.bazel.rules.workspace.GitRepositoryRule; import com.google.devtools.build.lib.packages.Rule; @@ -38,8 +39,9 @@ public class GitRepositoryFunction extends RepositoryFunction { } @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws SkyFunctionException { + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws SkyFunctionException { createDirectory(outputDirectory, rule); GitCloner.clone(rule, outputDirectory, env.getListener()); return RepositoryDirectoryValue.create(outputDirectory); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpArchiveFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpArchiveFunction.java index 8761558931..e86c23b586 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpArchiveFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpArchiveFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.bazel.repository; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader; import com.google.devtools.build.lib.bazel.rules.workspace.HttpArchiveRule; @@ -49,8 +50,9 @@ public class HttpArchiveFunction extends RepositoryFunction { } @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws RepositoryFunctionException, InterruptedException { + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws RepositoryFunctionException, InterruptedException { // The output directory is always under .external-repository (to stay out of the way of // artifacts from this repository) and uses the rule's name to avoid conflicts with other // remote repository rules. For example, suppose you had the following WORKSPACE file: diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java index 30c2704f3d..f3dbb06a0b 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunction.java @@ -14,12 +14,12 @@ package com.google.devtools.build.lib.bazel.repository; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader; import com.google.devtools.build.lib.bazel.rules.workspace.MavenJarRule; @@ -106,25 +106,26 @@ public class MavenJarFunction extends HttpArchiveFunction { } @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws RepositoryFunctionException, InterruptedException { + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws RepositoryFunctionException, InterruptedException { AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule); MavenServerValue serverValue = getServer(rule, env); if (env.valuesMissing()) { return null; } - MavenDownloader downloader = createMavenDownloader(mapper, serverValue); - return createOutputTree(downloader, env); + MavenDownloader downloader = createMavenDownloader(directories, mapper, serverValue); + return createOutputTree(downloader); } - @VisibleForTesting - MavenDownloader createMavenDownloader(AttributeMap mapper, MavenServerValue serverValue) { + private MavenDownloader createMavenDownloader( + BlazeDirectories directories, AttributeMap mapper, MavenServerValue serverValue) { String name = mapper.getName(); - Path outputDirectory = getExternalRepositoryDirectory().getRelative(name); + Path outputDirectory = getExternalRepositoryDirectory(directories).getRelative(name); return new MavenDownloader(name, mapper, outputDirectory, serverValue); } - SkyValue createOutputTree(MavenDownloader downloader, Environment env) + private SkyValue createOutputTree(MavenDownloader downloader) throws RepositoryFunctionException, InterruptedException { Path outputDirectory = downloader.getOutputDirectory(); createDirectory(outputDirectory); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerRepositoryFunction.java index 4ddf40e4f5..8ac84376bd 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerRepositoryFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.bazel.repository; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.bazel.rules.workspace.MavenServerRule; import com.google.devtools.build.lib.packages.Rule; @@ -39,8 +40,9 @@ public class MavenServerRepositoryFunction extends RepositoryFunction { @Nullable @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws SkyFunctionException, InterruptedException { + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws SkyFunctionException, InterruptedException { throw new RepositoryFunctionException(new EvalException( rule.getLocation(), "maven_server rule '" + rule.getName() + "' does not represent an actual repository"), diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/NewGitRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/NewGitRepositoryFunction.java index 2b89ce3a5d..96f2b2bd78 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/NewGitRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/NewGitRepositoryFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.bazel.repository; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.rules.repository.NewRepositoryBuildFileHandler; import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue; @@ -27,11 +28,11 @@ import com.google.devtools.build.skyframe.SkyValue; */ public class NewGitRepositoryFunction extends GitRepositoryFunction { @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws SkyFunctionException { - + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws SkyFunctionException { NewRepositoryBuildFileHandler buildFileHandler = - new NewRepositoryBuildFileHandler(getWorkspace()); + new NewRepositoryBuildFileHandler(directories.getWorkspace()); if (!buildFileHandler.prepareBuildFile(rule, env)) { return null; } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/NewHttpArchiveFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/NewHttpArchiveFunction.java index ecdbb5c165..815e41d9a2 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/NewHttpArchiveFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/NewHttpArchiveFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.bazel.repository; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader; import com.google.devtools.build.lib.packages.AggregatingAttributeMapper; import com.google.devtools.build.lib.packages.Rule; @@ -38,11 +39,11 @@ public class NewHttpArchiveFunction extends HttpArchiveFunction { @Nullable @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws RepositoryFunctionException, InterruptedException { - + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws RepositoryFunctionException, InterruptedException { NewRepositoryBuildFileHandler buildFileHandler = - new NewRepositoryBuildFileHandler(getWorkspace()); + new NewRepositoryBuildFileHandler(directories.getWorkspace()); if (!buildFileHandler.prepareBuildFile(rule, env)) { return null; } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryFunction.java index 5f76bce594..3c84a073e7 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryFunction.java @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.bazel.repository.skylark; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.Rule; @@ -78,8 +79,9 @@ public class SkylarkRepositoryFunction extends RepositoryFunction { @Nullable @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws SkyFunctionException, InterruptedException { + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws SkyFunctionException, InterruptedException { BaseFunction function = rule.getRuleClassObject().getConfiguredTargetFunction(); try (Mutability mutability = Mutability.create("skylark repository")) { com.google.devtools.build.lib.syntax.Environment buildEnv = diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java index 7b3a7686ab..2dbb030384 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.bazel.rules.android; import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.AndroidNdkCrosstools; import com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.AndroidNdkCrosstools.NdkCrosstoolsException; @@ -74,10 +75,11 @@ public class AndroidNdkRepositoryFunction extends RepositoryFunction { } @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws SkyFunctionException { + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws SkyFunctionException { prepareLocalRepositorySymlinkTree(rule, outputDirectory); - PathFragment pathFragment = getTargetPath(rule, getWorkspace()); + PathFragment pathFragment = getTargetPath(rule, directories.getWorkspace()); Path ndkSymlinkTreeDirectory = outputDirectory.getRelative("ndk"); try { ndkSymlinkTreeDirectory.createDirectory(); @@ -85,8 +87,8 @@ public class AndroidNdkRepositoryFunction extends RepositoryFunction { throw new RepositoryFunctionException(e, Transience.TRANSIENT); } - if (!symlinkLocalRepositoryContents( - ndkSymlinkTreeDirectory, getOutputBase().getFileSystem().getPath(pathFragment))) { + if (!symlinkLocalRepositoryContents(ndkSymlinkTreeDirectory, + directories.getOutputBase().getFileSystem().getPath(pathFragment))) { return null; } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java index c5711ff7c0..c729dd14dd 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.bazel.rules.android; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper; @@ -39,13 +40,14 @@ public class AndroidSdkRepositoryFunction extends RepositoryFunction { } @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws SkyFunctionException { + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws SkyFunctionException { prepareLocalRepositorySymlinkTree(rule, outputDirectory); - PathFragment pathFragment = getTargetPath(rule, getWorkspace()); + PathFragment pathFragment = getTargetPath(rule, directories.getWorkspace()); if (!symlinkLocalRepositoryContents( - outputDirectory, getOutputBase().getFileSystem().getPath(pathFragment))) { + outputDirectory, directories.getOutputBase().getFileSystem().getPath(pathFragment))) { return null; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java index f706daa559..130e163996 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.repository; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.packages.AggregatingAttributeMapper; import com.google.devtools.build.lib.packages.Rule; @@ -38,8 +39,9 @@ public class LocalRepositoryFunction extends RepositoryFunction { } @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws SkyFunctionException { + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws SkyFunctionException { AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule); PathFragment pathFragment = new PathFragment(mapper.get("path", Type.STRING)); try { diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java index e5537c4a65..38bde19cb9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.repository; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.vfs.Path; @@ -33,21 +34,22 @@ public class NewLocalRepositoryFunction extends RepositoryFunction { } @Override - public SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws SkyFunctionException { + public SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws SkyFunctionException { NewRepositoryBuildFileHandler buildFileHandler = - new NewRepositoryBuildFileHandler(getWorkspace()); + new NewRepositoryBuildFileHandler(directories.getWorkspace()); if (!buildFileHandler.prepareBuildFile(rule, env)) { return null; } prepareLocalRepositorySymlinkTree(rule, outputDirectory); - PathFragment pathFragment = getTargetPath(rule, getWorkspace()); + PathFragment pathFragment = getTargetPath(rule, directories.getWorkspace()); // Link x/y/z to /some/path/to/y/z. if (!symlinkLocalRepositoryContents( - outputDirectory, getOutputBase().getFileSystem().getPath(pathFragment))) { + outputDirectory, directories.getOutputBase().getFileSystem().getPath(pathFragment))) { return null; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java index 8c66b96469..622d030e9d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java @@ -20,9 +20,11 @@ import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.Rule; +import com.google.devtools.build.lib.packages.RuleSerializer; import com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException; import com.google.devtools.build.lib.skyframe.FileValue; import com.google.devtools.build.lib.syntax.EvalException; +import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.skyframe.SkyFunction; @@ -32,6 +34,7 @@ import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; import java.io.IOException; +import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nullable; @@ -42,7 +45,7 @@ import javax.annotation.Nullable; * <p>Each repository in the WORKSPACE file is represented by a {@link SkyValue} that is computed * by this function. */ -public class RepositoryDelegatorFunction implements SkyFunction { +public final class RepositoryDelegatorFunction implements SkyFunction { // A special repository delegate used to handle Skylark remote repositories if present. public static final String SKYLARK_DELEGATE_NAME = "$skylark"; @@ -108,7 +111,7 @@ public class RepositoryDelegatorFunction implements SkyFunction { // not depend on non-local data, so it does not make much sense to try to catch from across // server instances. setupRepositoryRoot(repoRoot); - return handler.fetch(rule, repoRoot, env); + return handler.fetch(rule, repoRoot, directories, env); } // We check the repository root for existence here, but we can't depend on the FileValue, @@ -119,7 +122,9 @@ public class RepositoryDelegatorFunction implements SkyFunction { if (ruleSpecificData == null) { return null; } - boolean markerUpToDate = handler.isFilesystemUpToDate(rule, ruleSpecificData); + byte[] ruleKey = computeRuleKey(rule, ruleSpecificData); + Path markerPath = getMarkerPath(directories, rule); + boolean markerUpToDate = isFilesystemUpToDate(markerPath, ruleKey); if (markerUpToDate && repoRoot.exists()) { // Now that we know that it exists, we can declare a Skyframe dependency on the repository // root. @@ -134,7 +139,7 @@ public class RepositoryDelegatorFunction implements SkyFunction { if (isFetch.get()) { // Fetching enabled, go ahead. setupRepositoryRoot(repoRoot); - SkyValue result = handler.fetch(rule, repoRoot, env); + SkyValue result = handler.fetch(rule, repoRoot, directories, env); if (env.valuesMissing()) { return null; } @@ -143,7 +148,7 @@ public class RepositoryDelegatorFunction implements SkyFunction { // and writing the marker file because if they aren't computed, it would cause a Skyframe // restart thus calling the possibly very slow (networking, decompression...) fetch() // operation again. So we write the marker file here immediately. - handler.writeMarkerFile(rule, ruleSpecificData); + writeMarkerFile(markerPath, ruleKey); return result; } @@ -171,6 +176,54 @@ public class RepositoryDelegatorFunction implements SkyFunction { return RepositoryDirectoryValue.fetchingDelayed(repoRootValue.realRootedPath().asPath()); } + private final byte[] computeRuleKey(Rule rule, byte[] ruleSpecificData) { + return new Fingerprint() + .addBytes(RuleSerializer.serializeRule(rule).build().toByteArray()) + .addBytes(ruleSpecificData) + .digestAndReset(); + } + + /** + * Checks if the state of the repository in the file system is consistent with the rule in the + * WORKSPACE file. + * + * <p>Deletes the marker file if not so that no matter what happens after, the state of the file + * system stays consistent. + */ + private final boolean isFilesystemUpToDate(Path markerPath, byte[] ruleKey) + throws RepositoryFunctionException { + try { + if (!markerPath.exists()) { + return false; + } + + byte[] content = FileSystemUtils.readContent(markerPath); + boolean result = Arrays.equals(ruleKey, content); + if (!result) { + // So that we are in a consistent state if something happens while fetching the repository + markerPath.delete(); + } + + return result; + } catch (IOException e) { + throw new RepositoryFunctionException(e, Transience.TRANSIENT); + } + } + + private final void writeMarkerFile(Path markerPath, byte[] ruleKey) + throws RepositoryFunctionException { + try { + FileSystemUtils.writeContent(markerPath, ruleKey); + } catch (IOException e) { + throw new RepositoryFunctionException(e, Transience.TRANSIENT); + } + } + + private static Path getMarkerPath(BlazeDirectories directories, Rule rule) { + return RepositoryFunction.getExternalRepositoryDirectory(directories) + .getChild("@" + rule.getName() + ".marker"); + } + @Override public String extractTag(SkyKey skyKey) { return null; diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java index b7edfeee04..1fd1b5fccc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java @@ -27,7 +27,6 @@ import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException; import com.google.devtools.build.lib.packages.NoSuchPackageException; import com.google.devtools.build.lib.packages.Package; import com.google.devtools.build.lib.packages.Rule; -import com.google.devtools.build.lib.packages.RuleSerializer; import com.google.devtools.build.lib.skyframe.FileSymlinkException; import com.google.devtools.build.lib.skyframe.FileValue; import com.google.devtools.build.lib.skyframe.InconsistentFilesystemException; @@ -35,7 +34,6 @@ import com.google.devtools.build.lib.skyframe.PackageLookupValue; import com.google.devtools.build.lib.skyframe.WorkspaceFileValue; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.Type; -import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; @@ -50,7 +48,6 @@ import com.google.devtools.build.skyframe.SkyValue; import java.io.IOException; import java.nio.charset.Charset; -import java.util.Arrays; import javax.annotation.Nullable; @@ -122,15 +119,6 @@ public abstract class RepositoryFunction { } } - private BlazeDirectories directories; - - private byte[] computeRuleKey(Rule rule, byte[] ruleSpecificData) { - return new Fingerprint() - .addBytes(RuleSerializer.serializeRule(rule).build().toByteArray()) - .addBytes(ruleSpecificData) - .digestAndReset(); - } - /** * Fetch the remote repository represented by the given rule. * @@ -151,8 +139,9 @@ public abstract class RepositoryFunction { */ @ThreadSafe @Nullable - public abstract SkyValue fetch(Rule rule, Path outputDirectory, Environment env) - throws SkyFunctionException, InterruptedException; + public abstract SkyValue fetch( + Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env) + throws SkyFunctionException, InterruptedException; /** * Whether fetching is done using local operations only. @@ -170,51 +159,8 @@ public abstract class RepositoryFunction { * to keep it working somehow) */ protected byte[] getRuleSpecificMarkerData(Rule rule, Environment env) - throws RepositoryFunctionException { - return new byte[] {}; - } - - private Path getMarkerPath(Rule rule) { - return getExternalRepositoryDirectory().getChild("@" + rule.getName() + ".marker"); - } - - /** - * Checks if the state of the repository in the file system is consistent with the rule in the - * WORKSPACE file. - * - * <p>Deletes the marker file if not so that no matter what happens after, the state of the file - * system stays consistent. - */ - boolean isFilesystemUpToDate(Rule rule, byte[] ruleSpecificData) - throws RepositoryFunctionException { - try { - Path markerPath = getMarkerPath(rule); - if (!markerPath.exists()) { - return false; - } - - boolean result = Arrays.equals( - computeRuleKey(rule, ruleSpecificData), - FileSystemUtils.readContent(markerPath)); - if (!result) { - // So that we are in a consistent state if something happens while fetching the repository - markerPath.delete(); - } - - return result; - - } catch (IOException e) { - throw new RepositoryFunctionException(e, Transience.TRANSIENT); - } - } - - void writeMarkerFile(Rule rule, byte[] ruleSpecificData) throws RepositoryFunctionException { - try { - FileSystemUtils.writeContent(getMarkerPath(rule), computeRuleKey(rule, ruleSpecificData)); - } catch (IOException e) { - throw new RepositoryFunctionException(e, Transience.TRANSIENT); - } + return new byte[] {}; } protected Path prepareLocalRepositorySymlinkTree(Rule rule, Path repositoryDirectory) @@ -255,8 +201,7 @@ public abstract class RepositoryFunction { } @VisibleForTesting - protected static PathFragment getTargetPath(Rule rule, Path workspace) - throws RepositoryFunctionException { + protected static PathFragment getTargetPath(Rule rule, Path workspace) { AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule); String path = mapper.get("path", Type.STRING); PathFragment pathFragment = new PathFragment(path); @@ -351,7 +296,7 @@ public abstract class RepositoryFunction { @Nullable public static Rule getRule( String ruleName, @Nullable String ruleClassName, Environment env) - throws RepositoryFunctionException { + throws RepositoryFunctionException { try { return getRule(RepositoryName.create("@" + ruleName), ruleClassName, env); } catch (LabelSyntaxException e) { @@ -369,7 +314,7 @@ public abstract class RepositoryFunction { @Nullable public static Rule getRule( RepositoryName repositoryName, @Nullable String ruleClassName, Environment env) - throws RepositoryFunctionException { + throws RepositoryFunctionException { Rule rule = getRule(repositoryName.strippedName(), env); Preconditions.checkState( rule == null || ruleClassName == null || rule.getRuleClass().equals(ruleClassName), @@ -398,17 +343,6 @@ public abstract class RepositoryFunction { return value; } - /** - * Sets up output path information. - */ - public void setDirectories(BlazeDirectories directories) { - this.directories = directories; - } - - protected Path getExternalRepositoryDirectory() { - return RepositoryFunction.getExternalRepositoryDirectory(directories); - } - public static Path getExternalRepositoryDirectory(BlazeDirectories directories) { return directories .getOutputBase() @@ -416,21 +350,6 @@ public abstract class RepositoryFunction { } /** - * Gets the base directory repositories should be stored in locally. - */ - protected Path getOutputBase() { - return directories.getOutputBase(); - } - - /** - * Gets the directory the WORKSPACE file for the build is in. - */ - protected Path getWorkspace() { - return directories.getWorkspace(); - } - - - /** * Returns the RuleDefinition class for this type of repository. */ public abstract Class<? extends RuleDefinition> getRuleDefinition(); |