diff options
author | dannark <dannark@google.com> | 2018-06-11 12:53:25 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-11 12:54:49 -0700 |
commit | 8c666d999699f788d4ff286a4a30c9dab0beb5b0 (patch) | |
tree | ed0261194796cfd91e5d9fcc1e1caf29e2f358b6 /src/main/java/com/google/devtools/build/lib/packages | |
parent | abeb8515ced94f94e80a0196bd5e8330fefba938 (diff) |
Only remove 'repo_mapping' from kwargs if experimental_enable_repo_mapping is set. Repository rules should throw an attribute not found error if repo_mapping is used but the flag isn't set, otherwise it silently fails.
RELNOTES: None
PiperOrigin-RevId: 200097695
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java index 26b84c669e..5c5c222296 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java @@ -513,7 +513,11 @@ public class WorkspaceFactory { RuleClass bindRuleClass = ruleFactory.getRuleClass("bind"); Rule rule = WorkspaceFactoryHelper.createAndAddRepositoryRule( - builder, ruleClass, bindRuleClass, getFinalKwargs(kwargs), ast); + builder, + ruleClass, + bindRuleClass, + getFinalKwargs(kwargs, env.getSemantics()), + ast); if (!isLegalWorkspaceName(rule.getName())) { throw new EvalException( ast.getLocation(), rule + "'s name field must be a legal workspace name"); @@ -528,12 +532,17 @@ public class WorkspaceFactory { }; } - private static Map<String, Object> getFinalKwargs(Map<String, Object> kwargs) { - // 'repo_mapping' is not an explicit attribute of any rule and so it would - // result in a rule error if propagated to the rule factory. - return kwargs.entrySet().stream() - .filter(x -> !x.getKey().equals("repo_mapping")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + private static Map<String, Object> getFinalKwargs( + Map<String, Object> kwargs, + SkylarkSemantics semantics) { + if (semantics.experimentalEnableRepoMapping()) { + // 'repo_mapping' is not an explicit attribute of any rule and so it would + // result in a rule error if propagated to the rule factory. + return kwargs.entrySet().stream() + .filter(x -> !x.getKey().equals("repo_mapping")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + return kwargs; } private static ImmutableMap<String, BaseFunction> createWorkspaceFunctions( |