aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/bazel
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-07-17 01:06:11 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-17 01:08:23 -0700
commitde22ab0582760dc95f33e217e82a7b822378f625 (patch)
tree87f8b63f24522d99e2aa7630c5053c94253c7ca3 /src/main/java/com/google/devtools/build/lib/bazel
parente39991acbeb5c5cacbb61de004be77436be3664e (diff)
External repositories: disallow use of unexported repository rules
Treat repository rules the same way as build rules: they may only be used, if exported by a Skylark file. It has never been intended to create external repositories by anonymous rules, and, in fact, for properly recording resolved information, it is necessary that all repository rules used can be referred to by an accessible name. Change-Id: Ib9259d58be66b033721a6f591656c45889f49931 PiperOrigin-RevId: 204872735
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/bazel')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryModule.java20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryModule.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryModule.java
index 1a4ec433d3..cf72e63f7e 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryModule.java
@@ -36,12 +36,9 @@ import com.google.devtools.build.lib.packages.WorkspaceFactoryHelper;
import com.google.devtools.build.lib.skylarkbuildapi.repository.RepositoryModuleApi;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.syntax.BaseFunction;
-import com.google.devtools.build.lib.syntax.DotExpression;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.Expression;
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.FunctionSignature;
-import com.google.devtools.build.lib.syntax.Identifier;
import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.syntax.SkylarkList;
import java.util.Map;
@@ -124,22 +121,13 @@ public class SkylarkRepositoryModule implements RepositoryModuleApi {
Object[] args, FuncallExpression ast, com.google.devtools.build.lib.syntax.Environment env)
throws EvalException, InterruptedException {
String ruleClassName = null;
- Expression function = ast.getFunction();
- // If the function ever got exported (the common case), we take the name
- // it was exprted to. Only in the not intended case of calling an unexported
- // repository function through an exported macro, we fall back, for lack of
- // alternatives, to the name in the local context.
- // TODO(b/111199163): we probably should disallow the use of non-exported
- // repository rules anyway.
+ // If the function ever got exported, we take the name it was exported to.
if (isExported()) {
ruleClassName = exportedName;
- } else if (function instanceof Identifier) {
- ruleClassName = ((Identifier) function).getName();
- } else if (function instanceof DotExpression) {
- ruleClassName = ((DotExpression) function).getField().getName();
} else {
- // TODO: Remove the wrong assumption that a "function name" always exists and is relevant
- throw new IllegalStateException("Function is not an identifier or method call");
+ throw new EvalException(ast.getLocation(),
+ "Use of unexported repository rule; this repository rule class has not been exported"
+ + "by a Skylark file");
}
try {
RuleClass ruleClass = builder.build(ruleClassName, ruleClassName);