Skip to content

Commit

Permalink
Use the more specialized lookup functions.
Browse files Browse the repository at this point in the history
#5637

RELNOTES: None.
PiperOrigin-RevId: 211476817
  • Loading branch information
laurentlb authored and Copybara-Service committed Sep 4, 2018
1 parent b919a1d commit c3e5851
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public Object call(Object[] args, FuncallExpression ast, Environment env)
BuildLangTypedAttributeValuesMap attributeValues =
new BuildLangTypedAttributeValuesMap((Map<String, Object>) args[0]);
try {
PackageContext pkgContext = (PackageContext) env.lookup(PackageFactory.PKG_CONTEXT);
PackageContext pkgContext = (PackageContext) env.dynamicLookup(PackageFactory.PKG_CONTEXT);
if (pkgContext == null) {
throw new EvalException(ast.getLocation(),
"Cannot instantiate a rule when loading a .bzl file. Rules can only be called from "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ public Object call(Object[] arguments, FuncallExpression ast, Environment env)
*/
public static PackageContext getContext(Environment env, Location location)
throws EvalException {
PackageContext value = (PackageContext) env.lookup(PKG_CONTEXT);
PackageContext value = (PackageContext) env.dynamicLookup(PKG_CONTEXT);
if (value == null) {
// if PKG_CONTEXT is missing, we're not called from a BUILD file. This happens if someone
// uses native.some_func() in the wrong place.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
"Failed to evaluate resolved file " + key.getPath()));
}
}
Object resolved = resolvedEnvironment.lookup("resolved");
Object resolved = resolvedEnvironment.moduleLookup("resolved");
if (resolved == null) {
throw new ResolvedFileFunctionException(
new BuildFileContainsErrorsException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ private static void possiblyExport(Statement statement, Label extensionLabel,
AssignmentStatement assignmentStatement = (AssignmentStatement) statement;
ImmutableSet<Identifier> boundIdentifiers = assignmentStatement.getLValue().boundIdentifiers();
for (Identifier ident : boundIdentifiers) {
Object lookup = extensionEnv.lookup(ident.getName());
Object lookup = extensionEnv.moduleLookup(ident.getName());
if (lookup instanceof SkylarkExportable) {
try {
SkylarkExportable exportable = (SkylarkExportable) lookup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ public Object dynamicLookup(String varname) {
* <p>TODO(laurentlb): Remove this method. Callers should know where the value is defined and use
* the corresponding method (e.g. localLookup or moduleLookup).
*/
public Object lookup(String varname) {
Object lookup(String varname) {
// Lexical frame takes precedence, then globals, then dynamics.
Object lexicalValue = lexicalFrame.get(varname);
if (lexicalValue != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public int hashCode() {
private static final String BAZEL_INFO_KEY = "$bazel";

private static BazelInfo getInfo(Environment env) {
Object info = env.lookup(BAZEL_INFO_KEY);
Object info = env.moduleLookup(BAZEL_INFO_KEY);
if (info != null) {
return (BazelInfo) info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public void testListFramesShadowedBinding() throws Exception {
Scope.newBuilder()
.setName("global")
.addBinding(getValueProto("c", 3))
.addBinding(getValueProto("fn", env.lookup("fn"))))
.addBinding(getValueProto("fn", env.moduleLookup("fn"))))
.build());

assertFramesEqualIgnoringValueIdentifiers(
Expand All @@ -458,7 +458,7 @@ public void testListFramesShadowedBinding() throws Exception {
.setName("global")
.addBinding(getValueProto("a", 1))
.addBinding(getValueProto("c", 3))
.addBinding(getValueProto("fn", env.lookup("fn"))))
.addBinding(getValueProto("fn", env.moduleLookup("fn"))))
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testParseBuildFileOK() throws Exception {
//
// input1.BUILD contains:
// x = [1,2,'foo',4] + [1,2, "%s%d" % ('foo', 1)]
assertThat(env.lookup("x"))
assertThat(env.moduleLookup("x"))
.isEqualTo(SkylarkList.createImmutable(Tuple.of(1, 2, "foo", 4, 1, 2, "foo1")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ public void testFrozen() throws Exception {
.setEventHandler(Environment.FAIL_FAST_HANDLER)
.build();
env.update("x", 1);
assertThat(env.lookup("x")).isEqualTo(1);
assertThat(env.moduleLookup("x")).isEqualTo(1);
env.update("y", 2);
assertThat(env.lookup("y")).isEqualTo(2);
assertThat(env.lookup("x")).isEqualTo(1);
assertThat(env.moduleLookup("y")).isEqualTo(2);
assertThat(env.moduleLookup("x")).isEqualTo(1);
env.update("x", 3);
assertThat(env.lookup("x")).isEqualTo(3);
assertThat(env.moduleLookup("x")).isEqualTo(3);
}
try {
// This update to an existing variable should fail because the environment was frozen.
Expand All @@ -205,7 +205,7 @@ public void testBuiltinsCanBeShadowed() throws Exception {
newEnvironmentWithSkylarkOptions("--incompatible_static_name_resolution=true")
.setup("special_var", 42);
BuildFileAST.eval(env, "special_var = 41");
assertThat(env.lookup("special_var")).isEqualTo(41);
assertThat(env.moduleLookup("special_var")).isEqualTo(41);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public EvaluationTestCase update(String varname, Object value) throws Exception
}

public Object lookup(String varname) throws Exception {
return env.lookup(varname);
return env.moduleLookup(varname);
}

public Object eval(String... input) throws Exception {
Expand Down

0 comments on commit c3e5851

Please sign in to comment.