Skip to content

Commit

Permalink
Automated g4 rollback of commit d5ee3b5.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

The go rules have tons of transitive dependencies that are not declared in their "local" WORKSPACE files, so this broke lots of projects on ci.bazel.build

I'll fix up the go rules, update all of _their_ reverse-dep projects, and resubmit.

*** Original change description ***

Repositories can only be accessed in projects that define them in their WORKSPACE file

This is prep for #1943 - hierarchical workspace loading.

RELNOTES[INC]: Remote repositories must define any remote repositories they
themselves use (e.g., if @x//:foo depends on @y//:bar, @y must be defined
in @x's WORKSPACE file).

PiperOrigin-RevId: 154321845
  • Loading branch information
kchodorow authored and vladmos committed Apr 26, 2017
1 parent 496d3de commit f91c008
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 251 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.LinkedListMultimap;
Expand Down Expand Up @@ -51,7 +50,6 @@
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.build.lib.analysis.config.PatchTransition;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
Expand All @@ -71,8 +69,6 @@
import com.google.devtools.build.lib.packages.SkylarkProviderIdentifier;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.packages.TargetUtils;
import com.google.devtools.build.lib.rules.repository.RepositoryVisibilityFunction;
import com.google.devtools.build.lib.rules.repository.RepositoryVisibilityFunction.RepositoryVisibilityValue;
import com.google.devtools.build.lib.skyframe.AspectFunction.AspectCreationException;
import com.google.devtools.build.lib.skyframe.AspectValue.AspectKey;
import com.google.devtools.build.lib.skyframe.SkyframeExecutor.BuildViewProvider;
Expand All @@ -95,7 +91,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Semaphore;
Expand Down Expand Up @@ -341,35 +336,6 @@ static OrderedSetMultimap<Attribute, ConfiguredTarget> computeDependencies(
throw new DependencyEvaluationException(e);
}

RepositoryName ctgRepository = ctgValue.getLabel().getPackageIdentifier().getRepository();
ImmutableSet.Builder<SkyKey> pairsToCheck = ImmutableSet.builder();
for (Dependency dep : depValueNames.values()) {
RepositoryName depRepository = dep.getLabel().getPackageIdentifier().getRepository();
if (ctgRepository.equals(depRepository) || depRepository.isMain()) {
continue;
}
pairsToCheck.add(RepositoryVisibilityFunction.key(ctgRepository, depRepository));
}
Map<SkyKey, SkyValue> pairs = env.getValues(pairsToCheck.build());
if (env.valuesMissing()) {
return null;
}
boolean hadError = false;
for (Entry<SkyKey, SkyValue> entry : pairs.entrySet()) {
if (!((RepositoryVisibilityValue) entry.getValue()).ok()) {
RepositoryVisibilityFunction.Key key =
(RepositoryVisibilityFunction.Key) entry.getKey().argument();
String message = ctgValue.getLabel() + " has a dependency on "
+ key.child() + " but does not define " + key.child() + " in its WORKSPACE";
env.getListener().handle(Event.error(message));
hadError = true;
}
}
if (hadError) {
throw new DependencyEvaluationException(
new ConfiguredValueCreationException("Missing external repository definitions"));
}

// Trim each dep's configuration so it only includes the fragments needed by its transitive
// closure (only dynamic configurations support this).
if (useDynamicConfigurations(ctgValue.getConfiguration())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ public final class SkyFunctions {
SkyFunctionName.create("ACTION_TEMPLATE_EXPANSION");
public static final SkyFunctionName LOCAL_REPOSITORY_LOOKUP =
SkyFunctionName.create("LOCAL_REPOSITORY_LOOKUP");
public static final SkyFunctionName REPOSITORY_DEPENDENCY =
SkyFunctionName.create("REPOSITORY_DEPENDENCY");

public static Predicate<SkyKey> isSkyFunction(final SkyFunctionName functionName) {
return new Predicate<SkyKey>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
import com.google.devtools.build.lib.pkgcache.TestFilter;
import com.google.devtools.build.lib.pkgcache.TransitivePackageLoader;
import com.google.devtools.build.lib.profiler.AutoProfiler;
import com.google.devtools.build.lib.rules.repository.RepositoryVisibilityFunction;
import com.google.devtools.build.lib.skyframe.AspectValue.AspectValueKey;
import com.google.devtools.build.lib.skyframe.DirtinessCheckerUtils.FileDirtinessChecker;
import com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction;
Expand Down Expand Up @@ -447,7 +446,6 @@ private ImmutableMap<SkyFunctionName, SkyFunction> skyFunctions(
SkyFunctions.ACTION_TEMPLATE_EXPANSION,
new ActionTemplateExpansionFunction(removeActionsAfterEvaluation));
map.put(SkyFunctions.LOCAL_REPOSITORY_LOOKUP, new LocalRepositoryLookupFunction());
map.put(SkyFunctions.REPOSITORY_DEPENDENCY, new RepositoryVisibilityFunction());
map.putAll(extraSkyFunctions);
return map.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ public void testCcLibraryExternalIncludesNotWarned() throws Exception {
new ModifiedFileSet.Builder().modify(PathFragment.create("WORKSPACE")).build(),
rootDirectory);
FileSystemUtils.createDirectoryAndParents(scratch.resolve("/foo/bar"));
scratch.file("/foo/WORKSPACE",
"workspace(name = 'pkg')",
"local_repository(name = 'bazel_tools', path = '/whatever')");
scratch.file("/foo/WORKSPACE", "workspace(name = 'pkg')");
scratch.file(
"/foo/bar/BUILD",
"cc_library(name = 'lib',",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ public void outputDirectoryForProtoCompileAction_externalRepos() throws Exceptio
scratch.file(
"x/BUILD", "cc_proto_library(name = 'foo_cc_proto', deps = ['@bla//foo:bar_proto'])");

scratch.file("/bla/WORKSPACE",
"local_repository(name = 'com_google_protobuf', path = '/whatever')",
"local_repository(name = 'com_google_protobuf_cc', path = '/whatever')");
scratch.file("/bla/WORKSPACE");
// Create the rule '@bla//foo:bar_proto'.
scratch.file(
"/bla/foo/BUILD",
Expand Down
5 changes: 1 addition & 4 deletions src/test/shell/bazel/external_correctness_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,12 @@ function test_refs_btwn_repos() {
REMOTE1=$TEST_TMPDIR/remote1
REMOTE2=$TEST_TMPDIR/remote2
mkdir -p $REMOTE1 $REMOTE2
touch $REMOTE1/WORKSPACE
touch $REMOTE1/WORKSPACE $REMOTE2/WORKSPACE
cat > $REMOTE1/input <<EOF
1.0
EOF
cat > $REMOTE1/BUILD <<EOF
exports_files(['input'])
EOF
cat > $REMOTE2/WORKSPACE <<EOF
local_repository(name = "remote1", path = "/whatever")
EOF
cat > $REMOTE2/BUILD <<EOF
genrule(
Expand Down
76 changes: 0 additions & 76 deletions src/test/shell/bazel/workspace_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ EOF
touch foo/baz
cat > bar/WORKSPACE <<EOF
workspace(name = "bar")
# Needs to be defined, since @foo is referenced from the genrule.
local_repository(name = "foo", path = "/whatever")
EOF
cat > bar/BUILD <<EOF
genrule(
Expand Down Expand Up @@ -246,77 +243,4 @@ EOF
assert_contains "override" bazel-genfiles/external/o/gen.out
}

function test_direct_deps() {
REPO1="$PWD/repo1"
REPO2="$PWD/repo2"
mkdir -p "$REPO1" "$REPO2"

# repo1 has dependencies on the main repo and repo2.
cat > "$REPO1/WORKSPACE" <<EOF
workspace(name = "repo1")
local_repository(name = "repo2", path = "/whatever")
# Definition of main_repo purposely omitted to make build fail.
EOF
cat > "$REPO1/BUILD" << EOF
genrule(
name = "bar",
srcs = ["@repo2//:baz", "@main_repo//:qux"],
outs = ["bar.out"],
cmd = "echo \$(SRCS) > \$@",
visibility = ["//visibility:public"],
)
EOF

# repo2 has no dependencies.
touch "$REPO2/WORKSPACE"
cat > "$REPO2/BUILD" << EOF
genrule(
name = "baz",
outs = ["baz.out"],
cmd = "echo 'baz' > \$@",
visibility = ["//visibility:public"],
)
EOF

# The main repo has dependencies on repo1.
cat > WORKSPACE << EOF
workspace(name = "main_repo")
local_repository(name = "repo1", path = "$REPO1")
# TODO: move this to repo1/WORKSPACE once hierarchical workspaces work.
local_repository(name = "repo2", path = "$REPO2")
EOF
cat > BUILD <<EOF
exports_files(["qux"])
genrule(
name = "foo",
srcs = ["@repo1//:bar"],
outs = ["foo.out"],
cmd = "echo 'hi' > \$@",
)
EOF
touch qux

bazel build //:foo &> $TEST_log && fail "Expected missing main_repo"
expect_log "@repo1//:bar has a dependency on @main_repo but does not define @main_repo in its WORKSPACE"

cat > "$REPO1/WORKSPACE" <<EOF
workspace(name = "repo1")
local_repository(name = "main_repo", path = "/whatever")
# Definition of repo2 purposely omitted to make build fail.
EOF
bazel build //:foo &> $TEST_log && fail "Expected missing repo2"
expect_log "@repo1//:bar has a dependency on @repo2 but does not define @repo2 in its WORKSPACE"

cat > "$REPO1/WORKSPACE" <<EOF
workspace(name = "repo1")
local_repository(name = "main_repo", path = "/whatever")
local_repository(name = "repo2", path = "/whatever")
EOF
bazel build //:foo &> $TEST_log || fail "Expected success"
}

run_suite "workspace tests"

0 comments on commit f91c008

Please sign in to comment.