diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java index a225672b61c..e2ea4f19c1c 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java @@ -14,27 +14,19 @@ package com.google.devtools.build.lib.rules.repository; -import com.google.devtools.build.lib.cmdline.LabelSyntaxException; 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.skyframe.ExternalPackageFunction; -import com.google.devtools.build.lib.skyframe.PackageValue; import com.google.devtools.build.lib.skyframe.RepositoryValue; -import com.google.devtools.build.lib.vfs.Path; -import com.google.devtools.build.lib.vfs.PathFragment; -import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionException; +import com.google.devtools.build.skyframe.SkyFunctionException.Transience; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; - +import java.io.IOException; import javax.annotation.Nullable; -/** - * Creates a local or remote repository and checks its WORKSPACE file. - */ +/** Creates a local or remote repository. */ public class RepositoryLoaderFunction implements SkyFunction { + @Nullable @Override public SkyValue compute(SkyKey skyKey, Environment env) @@ -48,32 +40,10 @@ public SkyValue compute(SkyKey skyKey, Environment env) if (repository == null) { return null; } - - SkyKey workspaceKey = ExternalPackageFunction.key( - RootedPath.toRootedPath(repository.getPath(), new PathFragment("WORKSPACE"))); - PackageValue workspacePackage = (PackageValue) env.getValue(workspaceKey); - if (workspacePackage == null) { - return null; + if (!repository.repositoryExists()) { + return RepositoryValue.notFound(nameFromRule); } - - RepositoryName workspaceName; - try { - String workspaceNameStr = workspacePackage.getPackage().getWorkspaceName(); - workspaceName = workspaceNameStr.isEmpty() - ? RepositoryName.create("") : RepositoryName.create("@" + workspaceNameStr); - } catch (LabelSyntaxException e) { - throw new IllegalStateException(e); - } - - if (!workspaceName.isDefault() && !nameFromRule.equals(workspaceName)) { - Path workspacePath = repository.getPath().getRelative("WORKSPACE"); - env.getListener().handle(Event.warn(Location.fromFile(workspacePath), - "Workspace name in " + workspacePath + " (" + workspaceName + ") does not match name " - + " given in the repository's definition (" + nameFromRule + "), this will cause " - + " a build error in future versions.")); - } - - return new RepositoryValue(nameFromRule, repository); + return RepositoryValue.success(nameFromRule, repository); } @Nullable @@ -81,4 +51,13 @@ public SkyValue compute(SkyKey skyKey, Environment env) public String extractTag(SkyKey skyKey) { return null; } + + /** An exception thrown by RepositoryLoaderFunction */ + public static class RepositoryLoaderFunctionException extends SkyFunctionException { + + /** Error reading or writing to the filesystem. */ + public RepositoryLoaderFunctionException(IOException cause, Transience transience) { + super(cause, transience); + } + } } diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java index 850ec88ad8f..08229a24b3d 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java @@ -16,7 +16,6 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.common.base.Ascii; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -32,10 +31,10 @@ import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.WorkspaceFileValue; import com.google.devtools.build.lib.packages.WorkspaceFileValue.WorkspaceFileKey; -import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions; import com.google.devtools.build.lib.rules.repository.ManagedDirectoriesKnowledgeImpl; import com.google.devtools.build.lib.rules.repository.ManagedDirectoriesKnowledgeImpl.ManagedDirectoriesListener; import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils; +import com.google.devtools.build.lib.syntax.StarlarkSemantics; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; @@ -47,15 +46,9 @@ 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.List; import java.util.Objects; import java.util.Set; import javax.annotation.Nullable; -import net.starlark.java.eval.StarlarkSemantics; -import net.starlark.java.syntax.ParserInput; -import net.starlark.java.syntax.StarlarkFile; -import net.starlark.java.syntax.Statement; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Test; @@ -279,7 +272,7 @@ public void testManagedDirectories() throws Exception { "managed_directories attribute should not contain multiple (or duplicate)" + " repository mappings for the same directory ('a/b')."); assertManagedDirectoriesParsingError( - "{'@repo1': [], '@repo1': [] }", "dictionary expression has duplicate key: \"@repo1\""); + "{'@repo1': [], '@repo1': [] }", "Duplicated key \"@repo1\" when creating dictionary"); assertManagedDirectoriesParsingError( "{'@repo1': ['a/b'], '@repo2': ['a/b/c/..'] }", "managed_directories attribute should not contain multiple (or duplicate)" @@ -481,9 +474,7 @@ public void testDoNotSymlinkInExecroot() throws Exception { try { StarlarkSemantics semanticsWithNinjaActions = - StarlarkSemantics.builder() - .setBool(BuildLanguageOptions.EXPERIMENTAL_NINJA_ACTIONS, true) - .build(); + StarlarkSemantics.builderWithDefaults().experimentalNinjaActions(true).build(); PrecomputedValue.STARLARK_SEMANTICS.set(injectable, semanticsWithNinjaActions); assertThat( @@ -597,124 +588,4 @@ public void reset() { repositoryNames = null; } } - - // tests of splitChunks, an internal helper function - - @Test - public void testChunksNoLoad() { - assertThat(split(parse("foo_bar = 1"))).isEqualTo("[(assignment)]"); - } - - @Test - public void testChunksOneLoadAtTop() { - assertThat( - split( - parse( - "load('//:foo.bzl', 'bar')", // - "foo_bar = 1"))) - .isEqualTo("[(load assignment)]"); - } - - @Test - public void testChunksOneLoad() { - assertThat( - split( - parse( - "foo_bar = 1", - // - "load('//:foo.bzl', 'bar')"))) - .isEqualTo("[(assignment)][(load)]"); - } - - @Test - public void testChunksTwoSuccessiveLoads() { - assertThat( - split( - parse( - "foo_bar = 1", - // - "load('//:foo.bzl', 'bar')", - "load('//:bar.bzl', 'foo')"))) - .isEqualTo("[(assignment)][(load load)]"); - } - - @Test - public void testChunksTwoSucessiveLoadsWithNonLoadStatement() { - assertThat( - split( - parse( - "foo_bar = 1", - // - "load('//:foo.bzl', 'bar')", - "load('//:bar.bzl', 'foo')", - "local_repository(name = 'foobar', path = '/bar/foo')"))) - .isEqualTo("[(assignment)][(load load expression)]"); - } - - @Test - public void testChunksThreeLoadsThreeSegments() { - assertThat( - split( - parse( - "foo_bar = 1", - // - "load('//:foo.bzl', 'bar')", - "load('//:bar.bzl', 'foo')", - "local_repository(name = 'foobar', path = '/bar/foo')", - // - "load('@foobar//:baz.bzl', 'bleh')"))) - .isEqualTo("[(assignment)][(load load expression)][(load)]"); - } - - @Test - public void testChunksThreeLoadsThreeSegmentsWithContent() { - assertThat( - split( - parse( - "foo_bar = 1", - // - "load('//:foo.bzl', 'bar')", - "load('//:bar.bzl', 'foo')", - "local_repository(name = 'foobar', path = '/bar/foo')", - // - "load('@foobar//:baz.bzl', 'bleh')", - "bleh()"))) - .isEqualTo("[(assignment)][(load load expression)][(load expression)]"); - } - - @Test - public void testChunksMaySpanFiles() { - assertThat( - split( - parse( - "x = 1", // - "load('m', 'y')"), - parse( - "z = 1", // - "load('m', 'y2')"))) - .isEqualTo("[(assignment)][(load)(assignment)][(load)]"); - } - - // Returns a string that indicates the breakdown of statements into chunks. - private static String split(StarlarkFile... files) { - StringBuilder buf = new StringBuilder(); - for (List chunk : WorkspaceFileFunction.splitChunks(Arrays.asList(files))) { - buf.append('['); - for (StarlarkFile partialFile : chunk) { - buf.append('('); - String sep = ""; - for (Statement stmt : partialFile.getStatements()) { - buf.append(sep).append(Ascii.toLowerCase(stmt.kind().toString())); - sep = " "; - } - buf.append(')'); - } - buf.append(']'); - } - return buf.toString(); - } - - private static StarlarkFile parse(String... lines) { - return StarlarkFile.parse(ParserInput.fromLines(lines)); - } }