diff options
author | Han-Wen Nienhuys <hanwen@google.com> | 2016-01-28 12:35:13 +0000 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2016-01-28 15:30:33 +0000 |
commit | de435f4bd1a46f2a0f28d42f302f0eb05517ca9c (patch) | |
tree | 666594b618237c1fd6cce3fe81bc60243e5f0f3d /src | |
parent | c63b90f8828cf5c5c17d028d2e1a41371bf11c24 (diff) |
Rename native.rule and native.rules to {existing_rule,existing_rules}
This is to avoid confusion between rule(), which declares a new build
rules, and native.rule(), which can only be used in macros to inspect
the BUILD file processed so far.
native.{rule,rules} is maintained and marked deprecated to smooth the
transition for early adopters.
--
MOS_MIGRATED_REVID=113250194
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java | 61 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java | 7 |
2 files changed, 57 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java index ad73b169c9..dd80289ca5 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkNativeModule.java @@ -95,13 +95,12 @@ public class SkylarkNativeModule { } }; + @Deprecated @SkylarkSignature( name = "rule", objectType = SkylarkNativeModule.class, returnType = Object.class, - doc = - "Returns a dictionary representing the attributes of a previously defined rule, " - + "or None if the rule does not exist.", + doc = "Deprecated. Use existing_rule instead.", mandatoryPositionals = { @Param(name = "name", type = String.class, doc = "The name of the rule.") }, @@ -122,12 +121,58 @@ public class SkylarkNativeModule { } }; + @SkylarkSignature( + name = "existing_rule", + objectType = SkylarkNativeModule.class, + returnType = Object.class, + doc = + "Returns a dictionary representing the attributes of a previously defined rule, " + + "or None if the rule does not exist.", + mandatoryPositionals = { + @Param(name = "name", type = String.class, doc = "The name of the rule.") + }, + useAst = true, + useEnvironment = true + ) + private static final BuiltinFunction existingRule = + new BuiltinFunction("existing_rule") { + public Object invoke(String name, FuncallExpression ast, Environment env) + throws EvalException, InterruptedException { + env.checkLoadingPhase("native.existing_rule", ast.getLocation()); + Map<String, Object> rule = PackageFactory.callGetRuleFunction(name, ast, env); + if (rule != null) { + return rule; + } + + return Runtime.NONE; + } + }; + + @Deprecated + @SkylarkSignature( + name = "rules", + objectType = SkylarkNativeModule.class, + returnType = Map.class, + doc = "Deprecated. Use existing_rules instead.", + mandatoryPositionals = {}, + useAst = true, + useEnvironment = true + ) + private static final BuiltinFunction getRules = + new BuiltinFunction("rules") { + public Map<?, ?> invoke(FuncallExpression ast, Environment env) + throws EvalException, InterruptedException { + env.checkLoadingPhase("native.rules", ast.getLocation()); + return PackageFactory.callGetRulesFunction(ast, env); + } + }; + /* If necessary, we could allow filtering by tag (anytag, alltags), name (regexp?), kind ? For now, we ignore this, since users can implement it in Skylark. */ @SkylarkSignature( - name = "rules", + name = "existing_rules", objectType = SkylarkNativeModule.class, returnType = Map.class, doc = @@ -138,11 +183,11 @@ public class SkylarkNativeModule { useAst = true, useEnvironment = true ) - private static final BuiltinFunction getRules = - new BuiltinFunction("rules") { - public Map invoke(FuncallExpression ast, Environment env) + private static final BuiltinFunction existingRules = + new BuiltinFunction("existing_rules") { + public Map<?, ?> invoke(FuncallExpression ast, Environment env) throws EvalException, InterruptedException { - env.checkLoadingPhase("native.rules", ast.getLocation()); + env.checkLoadingPhase("native.existing_rules", ast.getLocation()); return PackageFactory.callGetRulesFunction(ast, env); } }; diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java index 240b5878b1..2fb7db04af 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java @@ -356,7 +356,8 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { @Test public void testGetRuleSelect() throws Exception { scratch.file("test/skylark/BUILD"); - scratch.file("test/skylark/rulestr.bzl", "def rule_dict(name):", " return native.rule(name)"); + scratch.file( + "test/skylark/rulestr.bzl", "def rule_dict(name):", " return native.existing_rule(name)"); scratch.file( "test/getrule/BUILD", @@ -376,9 +377,9 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { scratch.file( "test/skylark/rulestr.bzl", "def rule_dict(name):", - " return native.rule(name)", + " return native.existing_rule(name)", "def rules_dict():", - " return native.rules()", + " return native.existing_rules()", "def nop(ctx):", " pass", "nop_rule = rule(attrs = {'x': attr.label()}, implementation = nop)", |