Skip to content

Commit

Permalink
Remote repositories: add the infrastructure for extending the marker …
Browse files Browse the repository at this point in the history
…file

This add a markerData map to the RepositoryFunction#fetch function so RepositoryFunction-s
can declare extraneous data to add to the marker file. The RepositoryFunction#verifyMarkerData
is called to verify those data in order to know if the repository is up to date
and need re-fetching.

Design doc: https://bazel.build/designs/2016/10/18/repository-invalidation.html [step 2]

--
Change-Id: I9083fb72a0142f418a7296f889cd3eaf32e92498
Reviewed-on: https://cr.bazel.build/7973
PiperOrigin-RevId: 144728497
MOS_MIGRATED_REVID=144728497
  • Loading branch information
damienmg authored and vladmos committed Jan 17, 2017
1 parent 29263e2 commit 2963387
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.IOException;
import java.util.Map;

/**
* Clones a Git repository.
Expand All @@ -38,8 +39,8 @@ public boolean isLocal(Rule rule) {
}

@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws InterruptedException, RepositoryFunctionException {
createDirectory(outputDirectory, rule);
GitCloner.clone(rule, outputDirectory, env.getListener(), clientEnvironment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyValue;

import java.io.IOException;
import java.util.Map;

/**
* Downloads a file over HTTP.
Expand Down Expand Up @@ -58,9 +58,9 @@ protected void createDirectory(Path path)
}

@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
throws RepositoryFunctionException, InterruptedException {
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws RepositoryFunctionException, InterruptedException {
// The output directory is always under output_base/external (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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyValue;

import java.io.IOException;
import java.util.Map;

/**
* Implementation of maven_jar.
Expand Down Expand Up @@ -91,9 +91,9 @@ private static MavenServerValue getServer(Rule rule, Environment env)
}

@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
throws RepositoryFunctionException, InterruptedException {
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws RepositoryFunctionException, InterruptedException {
MavenServerValue serverValue = getServer(rule, env);
if (env.valuesMissing()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.google.devtools.build.skyframe.SkyFunctionException;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyValue;

import java.util.Map;
import javax.annotation.Nullable;

/**
Expand All @@ -40,9 +40,9 @@ public boolean isLocal(Rule rule) {

@Nullable
@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
throws SkyFunctionException, InterruptedException {
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws SkyFunctionException, InterruptedException {
throw new RepositoryFunctionException(new EvalException(
rule.getLocation(),
"maven_server rule '" + rule.getName() + "' does not represent an actual repository"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyValue;
import java.util.Map;

/**
* Clones a Git repository, creates a WORKSPACE file, and adds a BUILD file for it.
*/
public class NewGitRepositoryFunction extends GitRepositoryFunction {
@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws InterruptedException, RepositoryFunctionException {
NewRepositoryBuildFileHandler buildFileHandler =
new NewRepositoryBuildFileHandler(directories.getWorkspace());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyValue;

import java.io.IOException;
import java.util.Map;
import javax.annotation.Nullable;

/**
Expand All @@ -43,9 +43,9 @@ public NewHttpArchiveFunction(HttpDownloader httpDownloader) {

@Nullable
@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
throws RepositoryFunctionException, InterruptedException {
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws RepositoryFunctionException, InterruptedException {
NewRepositoryBuildFileHandler buildFileHandler =
new NewRepositoryBuildFileHandler(directories.getWorkspace());
if (!buildFileHandler.prepareBuildFile(rule, env)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.IOException;
import java.util.Map;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -69,8 +70,8 @@ static EvalException restart() {

@Nullable
@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws RepositoryFunctionException, InterruptedException {
BaseFunction function = rule.getRuleClassObject().getConfiguredTargetFunction();
try (Mutability mutability = Mutability.create("skylark repository")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public boolean isLocal(Rule rule) {
}

@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws InterruptedException, RepositoryFunctionException {
prepareLocalRepositorySymlinkTree(rule, outputDirectory);
WorkspaceAttributeMapper attributes = WorkspaceAttributeMapper.of(rule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public boolean isLocal(Rule rule) {
}

@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws SkyFunctionException, InterruptedException {

prepareLocalRepositorySymlinkTree(rule, outputDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.IOException;
import java.util.Map;

/**
* Access a repository on the local filesystem.
Expand All @@ -36,8 +37,8 @@ public boolean isLocal(Rule rule) {
}

@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws InterruptedException, RepositoryFunctionException {
PathFragment pathFragment = RepositoryFunction.getTargetPath(rule, directories.getWorkspace());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.IOException;
import java.util.Map;

/**
* Create a repository from a directory on the local filesystem.
Expand All @@ -43,8 +44,8 @@ public boolean isLocal(Rule rule) {
}

@Override
public SkyValue fetch(
Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env)
public SkyValue fetch(Rule rule, Path outputDirectory, BlazeDirectories directories,
Environment env, Map<String, String> markerData)
throws SkyFunctionException, InterruptedException {

NewRepositoryBuildFileHandler buildFileHandler =
Expand Down
Loading

0 comments on commit 2963387

Please sign in to comment.