aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
diff options
context:
space:
mode:
authorGravatar Francois-Rene Rideau <tunes@google.com>2015-09-04 19:13:47 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-09-08 09:02:28 +0000
commit5a94e59f02833f9142bad9203acd72626b089535 (patch)
treeddfe00a54a701eff0f74af6e84e5b8cefcef1c93 /src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
parentab1711b026f8a4915ee2ef2556b2a7dbff18fa63 (diff)
Refactor Skylark Environment-s
Make Environment-s freezable: Introduce a class Mutability as a revokable capability to mutate objects in an Environment. For now, only Environment-s carry this capability. Make sure that every Mutability is revoked in the same function that creates it, so no Environment is left open for modification after being created and exported; exceptions for tests, the shell and initialization contexts. Unify Environment, SkylarkEnvironment and EvaluationContext into Environment. Have a notion of Frame for the bindings + parent + mutability. Replace the updateAndPropagate mechanism by a dynamicFrame. Simplify ValidationEnvironment, that is now always deduced from the Environment. -- MOS_MIGRATED_REVID=102363438
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
index 2b339046e0..fe44617e02 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
@@ -20,6 +20,9 @@ import com.google.devtools.build.lib.packages.CachingPackageLocator;
import com.google.devtools.build.lib.packages.RuleClassProvider;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.syntax.BuildFileAST;
+import com.google.devtools.build.lib.syntax.Mutability;
+import com.google.devtools.build.lib.syntax.Runtime;
+import com.google.devtools.build.lib.syntax.ValidationEnvironment;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.RootedPath;
@@ -113,26 +116,33 @@ public class ASTFileLookupFunction implements SkyFunction {
if (lookupResult == null) {
return null;
}
-
- BuildFileAST ast = null;
if (!lookupResult.lookupSuccessful()) {
return ASTFileLookupValue.noFile();
- } else {
- Path path = lookupResult.rootedPath().asPath();
- // Skylark files end with bzl.
- boolean parseAsSkylark = astFilePathFragment.getPathString().endsWith(".bzl");
- try {
- ast = parseAsSkylark
- ? BuildFileAST.parseSkylarkFile(path, env.getListener(),
- packageManager, ruleClassProvider.getSkylarkValidationEnvironment().clone())
- : BuildFileAST.parseBuildFile(path, env.getListener(),
- packageManager, false);
- } catch (IOException e) {
+ }
+ BuildFileAST ast = null;
+ Path path = lookupResult.rootedPath().asPath();
+ // Skylark files end with bzl.
+ boolean parseAsSkylark = astFilePathFragment.getPathString().endsWith(".bzl");
+ try {
+ if (parseAsSkylark) {
+ try (Mutability mutability = Mutability.create("validate")) {
+ ast = BuildFileAST.parseSkylarkFile(path, env.getListener(),
+ packageManager, new ValidationEnvironment(
+ ruleClassProvider.createSkylarkRuleClassEnvironment(
+ mutability,
+ env.getListener(),
+ // the two below don't matter for extracting the ValidationEnvironment:
+ /*astFileContentHashCode=*/null,
+ /*importMap=*/null)
+ .setupDynamic(Runtime.PKG_NAME, Runtime.NONE)));
+ }
+ } else {
+ ast = BuildFileAST.parseBuildFile(path, env.getListener(), packageManager, false);
+ }
+ } catch (IOException e) {
throw new ASTLookupFunctionException(new ErrorReadingSkylarkExtensionException(
e.getMessage()), Transience.TRANSIENT);
- }
}
-
return ASTFileLookupValue.withFile(ast);
}