diff options
author | Kristina Chodorow <kchodorow@google.com> | 2016-06-30 14:26:11 +0000 |
---|---|---|
committer | Lukacs Berki <lberki@google.com> | 2016-07-01 07:08:28 +0000 |
commit | dd7bd50ad1f6cdddea218c704c933239e31ce7bf (patch) | |
tree | 9b410f58d334cf57d8a00270c17df4178dcc6870 | |
parent | 6b6ff76945c80fb8b11b71d402b5146c85b86859 (diff) |
Make repository name warning less noisy
This way it won't print if the repo maintainer doesn't set the repo name.
--
MOS_MIGRATED_REVID=126300205
4 files changed, 29 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index 3f9172b993..01a2c15dd3 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -270,7 +270,7 @@ public class BazelRuleClassProvider { .addBuildInfoFactory(new ObjcBuildInfoFactory()) .setConfigurationCollectionFactory(new BazelConfigurationCollection()) .setPrelude("//tools/build_rules:prelude_bazel") - .setRunfilesPrefix("__main__") + .setRunfilesPrefix(Label.DEFAULT_REPOSITORY_DIRECTORY) .setToolsRepository(TOOLS_REPOSITORY) .setPrerequisiteValidator(new BazelPrerequisiteValidator()) .setSkylarkAccessibleTopLevels(SKYLARK_BUILT_IN_JAVA_OBJECTS) diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java index 19f346f48b..9ca11b6e07 100644 --- a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java +++ b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java @@ -52,6 +52,7 @@ import java.io.Serializable; public final class Label implements Comparable<Label>, Serializable, SkylarkPrintableValue { public static final PathFragment EXTERNAL_PACKAGE_NAME = new PathFragment("external"); public static final PathFragment EXTERNAL_PACKAGE_FILE_NAME = new PathFragment("WORKSPACE"); + public static final String DEFAULT_REPOSITORY_DIRECTORY = "__main__"; /** * Package names that aren't made relative to the current repository because they mean special diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java index 9b40f7c342..19af038d62 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.repository; +import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.events.Event; @@ -34,6 +35,7 @@ import javax.annotation.Nullable; * Creates a local or remote repository and checks its WORKSPACE file. */ public class RepositoryLoaderFunction implements SkyFunction { + @Nullable @Override public SkyValue compute(SkyKey skyKey, Environment env) @@ -65,7 +67,9 @@ public class RepositoryLoaderFunction implements SkyFunction { throw new IllegalStateException(e); } - if (!workspaceName.isDefault() && !nameFromRule.equals(workspaceName)) { + if (!workspaceName.isDefault() + && !workspaceName.strippedName().equals(Label.DEFAULT_REPOSITORY_DIRECTORY) + && !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 the " diff --git a/src/test/shell/bazel/local_repository_test.sh b/src/test/shell/bazel/local_repository_test.sh index d078cadba3..41b5319f6b 100755 --- a/src/test/shell/bazel/local_repository_test.sh +++ b/src/test/shell/bazel/local_repository_test.sh @@ -504,6 +504,28 @@ EOF expect_log "//external:my_repo" } +function test_warning() { + local bar=$TEST_TMPDIR/bar + rm -rf "$bar" + mkdir -p "$bar" + touch "$bar/WORKSPACE" "$bar/BUILD" + cat > WORKSPACE <<EOF +local_repository( + name = "bar", + path = "$bar", +) +EOF + touch BUILD + bazel build @bar//... &> $TEST_log || fail "Build failed" + expect_not_log "Workspace name in .* does not match the name given in the repository's definition (@bar); this will cause a build error in future versions." + + cat > "$bar/WORKSPACE" <<EOF +workspace(name = "foo") +EOF + bazel build @bar//... &> $TEST_log || fail "Build failed" + expect_log "Workspace name in .* does not match the name given in the repository's definition (@bar); this will cause a build error in future versions." +} + function test_override_workspace_file() { local bar=$TEST_TMPDIR/bar mkdir -p "$bar" |