Rename StarlarkImportLookupFunction and friends
This renames "StarlarkImportLookup*" to "BzlLoad*", and also changes a number of uses of "import" to "load". This helps keep names to a more manageable length and is in line with modern Starlark terminology.
This is refactoring work toward adding a new kind of .bzl loading context, for Bazel-internal .bzl files.
Work toward #11437.
RELNOTES: None
PiperOrigin-RevId: 313240742
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java
index 43c7867..c9b6af9 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java
@@ -102,7 +102,7 @@
private final boolean hasNext;
private final ImmutableMap<String, Object> bindings;
private final ImmutableMap<String, Module> loadedModules;
- private final ImmutableMap<String, Integer> importToChunkMap;
+ private final ImmutableMap<String, Integer> loadToChunkMap;
private final ImmutableMap<RepositoryName, ImmutableMap<RepositoryName, RepositoryName>>
repositoryMapping;
// Mapping of the relative paths of the incrementally updated managed directories
@@ -118,8 +118,8 @@
* @param pkg Package built by agreggating all parts of the split WORKSPACE file up to this one.
* @param loadedModules modules loaded by load statements in chunks of the WORKSPACE file up to
* this one.
- * @param importToChunkMap Map of all load statements encountered so far to the chunk they
- * initially appeared in.
+ * @param loadToChunkMap Map of all load statements encountered so far to the chunk they initially
+ * appeared in.
* @param bindings List of top-level variable bindings from the all parts of the split WORKSPACE
* file up to this one. The key is the name of the bindings and the value is the actual
* object.
@@ -133,7 +133,7 @@
public WorkspaceFileValue(
Package pkg,
Map<String, Module> loadedModules,
- Map<String, Integer> importToChunkMap,
+ Map<String, Integer> loadToChunkMap,
Map<String, Object> bindings,
RootedPath path,
int idx,
@@ -146,7 +146,7 @@
this.hasNext = hasNext;
this.bindings = ImmutableMap.copyOf(bindings);
this.loadedModules = ImmutableMap.copyOf(loadedModules);
- this.importToChunkMap = ImmutableMap.copyOf(importToChunkMap);
+ this.loadToChunkMap = ImmutableMap.copyOf(loadToChunkMap);
this.repositoryMapping = pkg.getExternalPackageRepositoryMappings();
this.managedDirectories = managedDirectories;
this.doNotSymlinkInExecrootPaths = doNotSymlinkInExecrootPaths;
@@ -223,8 +223,8 @@
return loadedModules;
}
- public ImmutableMap<String, Integer> getImportToChunkMap() {
- return importToChunkMap;
+ public ImmutableMap<String, Integer> getLoadToChunkMap() {
+ return loadToChunkMap;
}
public ImmutableMap<RepositoryName, ImmutableMap<RepositoryName, RepositoryName>>
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
index 28b7ecb..ee6628a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
@@ -63,9 +63,9 @@
import com.google.devtools.build.lib.packages.Type.ConversionException;
import com.google.devtools.build.lib.profiler.memory.CurrentRuleTracker;
import com.google.devtools.build.lib.skyframe.AspectValueKey.AspectKey;
+import com.google.devtools.build.lib.skyframe.BzlLoadFunction.BzlLoadFailedException;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.ConfiguredTargetFunctionException;
import com.google.devtools.build.lib.skyframe.SkyframeExecutor.BuildViewProvider;
-import com.google.devtools.build.lib.skyframe.StarlarkImportLookupFunction.StarlarkImportFailedException;
import com.google.devtools.build.lib.util.OrderedSetMultimap;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
@@ -154,18 +154,17 @@
static StarlarkAspect loadStarlarkAspect(
Environment env, Label extensionLabel, String starlarkValueName)
throws AspectCreationException, InterruptedException {
- SkyKey importFileKey = StarlarkImportLookupValue.packageBzlKey(extensionLabel);
+ SkyKey importFileKey = BzlLoadValue.packageBzlKey(extensionLabel);
try {
- StarlarkImportLookupValue starlarkImportLookupValue =
- (StarlarkImportLookupValue)
- env.getValueOrThrow(importFileKey, StarlarkImportFailedException.class);
- if (starlarkImportLookupValue == null) {
+ BzlLoadValue bzlLoadValue =
+ (BzlLoadValue) env.getValueOrThrow(importFileKey, BzlLoadFailedException.class);
+ if (bzlLoadValue == null) {
Preconditions.checkState(
env.valuesMissing(), "no Starlark import value for %s", importFileKey);
return null;
}
- Object starlarkValue = starlarkImportLookupValue.getModule().getGlobal(starlarkValueName);
+ Object starlarkValue = bzlLoadValue.getModule().getGlobal(starlarkValueName);
if (starlarkValue == null) {
throw new ConversionException(
String.format(
@@ -177,7 +176,7 @@
"%s from %s is not an aspect", starlarkValueName, extensionLabel.toString()));
}
return (StarlarkAspect) starlarkValue;
- } catch (StarlarkImportFailedException | ConversionException e) {
+ } catch (BzlLoadFailedException | ConversionException e) {
env.getListener().handle(Event.error(e.getMessage()));
throw new AspectCreationException(e.getMessage(), extensionLabel);
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD
index ce4b33f..098c34b 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD
@@ -27,6 +27,7 @@
"BazelSkyframeExecutorConstants.java",
"BuildConfigurationFunction.java",
"BuildInfoCollectionFunction.java",
+ "BzlLoadFunction.java",
"CompletionFunction.java",
"ConfiguredTargetCycleReporter.java",
"ConfiguredTargetFunction.java",
@@ -72,7 +73,6 @@
"StarlarkAspectFactory.java",
"StarlarkBuiltinsFunction.java",
"StarlarkBuiltinsValue.java",
- "StarlarkImportLookupFunction.java",
"TargetCompletionValue.java",
"TargetCompletor.java",
"TargetPatternFunction.java",
@@ -127,8 +127,9 @@
":blacklisted_package_prefixes_value",
":build_configuration_value",
":build_info_collection_value",
- ":cached_starlark_import_lookup_value_and_deps",
- ":cached_starlark_import_lookup_value_and_deps_builder_factory",
+ ":bzl_load_value",
+ ":cached_bzl_load_value_and_deps",
+ ":cached_bzl_load_value_and_deps_builder_factory",
":client_environment_function",
":client_environment_value",
":collect_packages_under_directory_function",
@@ -198,7 +199,6 @@
":skyframe_incremental_build_monitor",
":skylark_module_cycle_reporter",
":starlark_file_dependency",
- ":starlark_import_lookup_value",
":state_informing_sky_function_environment",
":target_pattern_error_function",
":target_pattern_phase_value",
@@ -942,10 +942,10 @@
)
java_library(
- name = "cached_starlark_import_lookup_value_and_deps",
- srcs = ["CachedStarlarkImportLookupValueAndDeps.java"],
+ name = "cached_bzl_load_value_and_deps",
+ srcs = ["CachedBzlLoadValueAndDeps.java"],
deps = [
- ":starlark_import_lookup_value",
+ ":bzl_load_value",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//third_party:auto_value",
"//third_party:guava",
@@ -953,10 +953,10 @@
)
java_library(
- name = "cached_starlark_import_lookup_value_and_deps_builder_factory",
- srcs = ["CachedStarlarkImportLookupValueAndDepsBuilderFactory.java"],
+ name = "cached_bzl_load_value_and_deps_builder_factory",
+ srcs = ["CachedBzlLoadValueAndDepsBuilderFactory.java"],
deps = [
- ":cached_starlark_import_lookup_value_and_deps",
+ ":cached_bzl_load_value_and_deps",
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//third_party:guava",
],
@@ -2268,9 +2268,9 @@
srcs = ["StarlarkModuleCycleReporter.java"],
deps = [
":abstract_label_cycle_reporter",
+ ":bzl_load_value",
":repository_value",
":sky_functions",
- ":starlark_import_lookup_value",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/packages",
@@ -2292,8 +2292,8 @@
)
java_library(
- name = "starlark_import_lookup_value",
- srcs = ["StarlarkImportLookupValue.java"],
+ name = "bzl_load_value",
+ srcs = ["BzlLoadValue.java"],
deps = [
":sky_functions",
":starlark_file_dependency",
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java
similarity index 68%
rename from src/main/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupFunction.java
rename to src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java
index 16acbe7..c122bdb 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java
@@ -75,12 +75,11 @@
*
* <p>Given a {@link Label} referencing a .bzl file, attempts to locate the file and load it. The
* Label must be absolute, and must not reference the special {@code external} package. If loading
- * is successful, returns a {@link StarlarkImportLookupValue} that encapsulates the loaded {@link
- * Module} and its transitive digest and {@link StarlarkFileDependency} information. If loading is
- * unsuccessful, throws a {@link StarlarkImportLookupFunctionException} that encapsulates the cause
- * of the failure.
+ * is successful, returns a {@link BzlLoadValue} that encapsulates the loaded {@link Module} and its
+ * transitive digest and {@link StarlarkFileDependency} information. If loading is unsuccessful,
+ * throws a {@link BzlLoadFunctionException} that encapsulates the cause of the failure.
*/
-public class StarlarkImportLookupFunction implements SkyFunction {
+public class BzlLoadFunction implements SkyFunction {
// Creates the BazelStarlarkContext and populates the predeclared .bzl symbols.
private final RuleClassProvider ruleClassProvider;
@@ -92,7 +91,7 @@
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
- private StarlarkImportLookupFunction(
+ private BzlLoadFunction(
RuleClassProvider ruleClassProvider,
PackageFactory packageFactory,
ASTFileLookupValueManager astFileLookupValueManager,
@@ -103,31 +102,31 @@
this.selfInliningManager = selfInliningManager;
}
- public static StarlarkImportLookupFunction create(
+ public static BzlLoadFunction create(
RuleClassProvider ruleClassProvider,
PackageFactory packageFactory,
DigestHashFunction digestHashFunction,
Cache<Label, ASTFileLookupValue> astFileLookupValueCache) {
- return new StarlarkImportLookupFunction(
+ return new BzlLoadFunction(
ruleClassProvider,
packageFactory,
- // When we are not inlining StarlarkImportLookupValue nodes, there is no need to have
- // separate ASTFileLookupValue nodes for bzl files. Instead we inline them for a strict
- // memory win, at a small code complexity cost.
+ // When we are not inlining BzlLoadValue nodes, there is no need to have separate
+ // ASTFileLookupValue nodes for bzl files. Instead we inline them for a strict memory win,
+ // at a small code complexity cost.
//
// Detailed explanation:
// (1) The ASTFileLookupValue node for a bzl file is used only for the computation of
- // that file's StarlarkImportLookupValue node. So there's no concern about duplicate
- // work that would otherwise get deduped by Skyframe.
+ // that file's BzlLoadValue node. So there's no concern about duplicate work that would
+ // otherwise get deduped by Skyframe.
// (2) ASTFileLookupValue doesn't have an interesting equality relation, so we have no
// hope of getting any interesting change-pruning of ASTFileLookupValue nodes. If we
// had an interesting equality relation that was e.g. able to ignore benign
// whitespace, then there would be a hypothetical benefit to having separate
// ASTFileLookupValue nodes (e.g. on incremental builds we'd be able to not re-execute
// top-level code in bzl files if the file were reparsed to an equivalent AST).
- // (3) A ASTFileLookupValue node lets us avoid redoing work on a
- // StarlarkImportLookupFunction Skyframe restart, but we can also achieve that result
- // ourselves with a cache that persists between Skyframe restarts.
+ // (3) A ASTFileLookupValue node lets us avoid redoing work on a BzlLoadFunction Skyframe
+ // restart, but we can also achieve that result ourselves with a cache that persists between
+ // Skyframe restarts.
//
// Therefore, ASTFileLookupValue nodes are wasteful from two perspectives:
// (a) ASTFileLookupValue contains a StarlarkFile, and that business object is really
@@ -139,72 +138,69 @@
/*selfInliningManager=*/ null);
}
- public static StarlarkImportLookupFunction createForInliningSelfForPackageAndWorkspaceNodes(
+ public static BzlLoadFunction createForInliningSelfForPackageAndWorkspaceNodes(
RuleClassProvider ruleClassProvider,
PackageFactory packageFactory,
- int starlarkImportLookupValueCacheSize) {
- return new StarlarkImportLookupFunction(
+ int bzlLoadValueCacheSize) {
+ return new BzlLoadFunction(
ruleClassProvider,
packageFactory,
- // When we are inlining StarlarkImportLookupValue nodes, then we want to have explicit
- // ASTFileLookupValue nodes, since now (1) in the comment above doesn't hold. This way we
- // read and parse each needed bzl file at most once total globally, rather than once per
- // need (in the worst-case of a StarlarkImportLookupValue inlining cache miss). This is
- // important in the situation where a bzl file is loaded by a lot of other bzl files or
- // BUILD files.
+ // When we are inlining BzlLoadValue nodes, then we want to have explicit ASTFileLookupValue
+ // nodes, since now (1) in the comment above doesn't hold. This way we read and parse each
+ // needed bzl file at most once total globally, rather than once per need (in the worst-case
+ // of a BzlLoadValue inlining cache miss). This is important in the situation where a bzl
+ // file is loaded by a lot of other bzl files or BUILD files.
RegularSkyframeASTFileLookupValueManager.INSTANCE,
- new SelfInliningManager(starlarkImportLookupValueCacheSize));
+ new SelfInliningManager(bzlLoadValueCacheSize));
}
@Override
@Nullable
public SkyValue compute(SkyKey skyKey, Environment env)
throws SkyFunctionException, InterruptedException {
- StarlarkImportLookupValue.Key key = (StarlarkImportLookupValue.Key) skyKey.argument();
+ BzlLoadValue.Key key = (BzlLoadValue.Key) skyKey.argument();
try {
return computeInternal(key, env, /*inliningState=*/ null);
} catch (InconsistentFilesystemException e) {
- throw new StarlarkImportLookupFunctionException(e, Transience.PERSISTENT);
- } catch (StarlarkImportFailedException e) {
- throw new StarlarkImportLookupFunctionException(e);
+ throw new BzlLoadFunctionException(e, Transience.PERSISTENT);
+ } catch (BzlLoadFailedException e) {
+ throw new BzlLoadFunctionException(e);
}
}
@Nullable
- StarlarkImportLookupValue computeWithSelfInlineCallsForPackageAndWorkspaceNodes(
- StarlarkImportLookupValue.Key key,
+ BzlLoadValue computeWithSelfInlineCallsForPackageAndWorkspaceNodes(
+ BzlLoadValue.Key key,
Environment env,
- Map<StarlarkImportLookupValue.Key, CachedStarlarkImportLookupValueAndDeps>
- visitedDepsInToplevelLoad)
- throws InconsistentFilesystemException, StarlarkImportFailedException, InterruptedException {
+ Map<BzlLoadValue.Key, CachedBzlLoadValueAndDeps> visitedDepsInToplevelLoad)
+ throws InconsistentFilesystemException, BzlLoadFailedException, InterruptedException {
Preconditions.checkNotNull(selfInliningManager);
// See comments in computeWithSelfInlineCallsInternal for an explanation of the visitedNested
// and visitedDepsInToplevelLoad vars.
- CachedStarlarkImportLookupValueAndDeps cachedStarlarkImportLookupValueAndDeps =
+ CachedBzlLoadValueAndDeps cachedBzlLoadValueAndDeps =
computeWithSelfInlineCallsInternal(
key,
env,
// visitedNested must use insertion order to display the correct error.
/*visitedNested=*/ new LinkedHashSet<>(),
/*visitedDepsInToplevelLoad=*/ visitedDepsInToplevelLoad);
- if (cachedStarlarkImportLookupValueAndDeps == null) {
+ if (cachedBzlLoadValueAndDeps == null) {
return null;
}
- return cachedStarlarkImportLookupValueAndDeps.getValue();
+ return cachedBzlLoadValueAndDeps.getValue();
}
@Nullable
- private CachedStarlarkImportLookupValueAndDeps computeWithSelfInlineCallsInternal(
- StarlarkImportLookupValue.Key key,
+ private CachedBzlLoadValueAndDeps computeWithSelfInlineCallsInternal(
+ BzlLoadValue.Key key,
Environment env,
- Set<StarlarkImportLookupValue.Key> visitedNested,
- Map<StarlarkImportLookupValue.Key, CachedStarlarkImportLookupValueAndDeps>
- visitedDepsInToplevelLoad)
- throws InconsistentFilesystemException, StarlarkImportFailedException, InterruptedException {
- // Under StarlarkImportLookupFunction inlining, BUILD and WORKSPACE files are evaluated in
- // separate Skyframe threads, but all the .bzls transitively loaded by a single package occur in
- // one thread. All these threads share a global cache in selfInliningManager, so that once any
- // thread completes evaluation of a .bzl, it needn't be evaluated again (unless it's evicted).
+ Set<BzlLoadValue.Key> visitedNested,
+ Map<BzlLoadValue.Key, CachedBzlLoadValueAndDeps> visitedDepsInToplevelLoad)
+ throws InconsistentFilesystemException, BzlLoadFailedException, InterruptedException {
+ // Under BzlLoadFunction inlining, BUILD and WORKSPACE files are evaluated in separate Skyframe
+ // threads, but all the .bzls transitively loaded by a single package occur in one thread. All
+ // these threads share a global cache in selfInliningManager, so that once any thread completes
+ // evaluation of a .bzl, it needn't be evaluated again (unless it's evicted).
//
// If two threads race to evaluate the same .bzl, each one will see a different copy of it, and
// only one will end up in the global cache. This presents a hazard if the same BUILD or
@@ -223,18 +219,15 @@
// (We don't need to worry about Starlark values from different packages interacting since
// inlining is only used for the loading phase.)
//
- CachedStarlarkImportLookupValueAndDeps cachedStarlarkImportLookupValueAndDeps =
- visitedDepsInToplevelLoad.get(key);
- if (cachedStarlarkImportLookupValueAndDeps == null) {
- cachedStarlarkImportLookupValueAndDeps =
- selfInliningManager.starlarkImportLookupValueCache.getIfPresent(key);
- if (cachedStarlarkImportLookupValueAndDeps != null) {
- cachedStarlarkImportLookupValueAndDeps.traverse(
- env::registerDependencies, visitedDepsInToplevelLoad);
+ CachedBzlLoadValueAndDeps cachedBzlLoadValueAndDeps = visitedDepsInToplevelLoad.get(key);
+ if (cachedBzlLoadValueAndDeps == null) {
+ cachedBzlLoadValueAndDeps = selfInliningManager.bzlLoadValueCache.getIfPresent(key);
+ if (cachedBzlLoadValueAndDeps != null) {
+ cachedBzlLoadValueAndDeps.traverse(env::registerDependencies, visitedDepsInToplevelLoad);
}
}
- if (cachedStarlarkImportLookupValueAndDeps != null) {
- return cachedStarlarkImportLookupValueAndDeps;
+ if (cachedBzlLoadValueAndDeps != null) {
+ return cachedBzlLoadValueAndDeps;
}
// visitedNested is keyed on the SkyKey, not the label, because it's possible for distinct keys
@@ -243,17 +236,17 @@
// chunking information. It's unclear whether these particular cycles can arise in practice, but
// it doesn't hurt to be robust to future changes that may make that possible.
if (!visitedNested.add(key)) {
- ImmutableList<StarlarkImportLookupValue.Key> cycle =
+ ImmutableList<BzlLoadValue.Key> cycle =
CycleUtils.splitIntoPathAndChain(Predicates.equalTo(key), visitedNested).second;
- throw new StarlarkImportFailedException("Starlark import cycle: " + cycle);
+ throw new BzlLoadFailedException("Starlark load cycle: " + cycle);
}
- CachedStarlarkImportLookupValueAndDeps.Builder inlineCachedValueBuilder =
- selfInliningManager.cachedStarlarkImportLookupValueAndDepsBuilderFactory
- .newCachedStarlarkImportLookupValueAndDepsBuilder();
- // Use an instrumented Skyframe env to capture Skyframe deps in the
- // CachedStarlarkImportLookupValueAndDeps. This is transitive but doesn't include deps
- // underneath recursively loaded .bzls (the recursion uses the unwrapped original env).
+ CachedBzlLoadValueAndDeps.Builder inlineCachedValueBuilder =
+ selfInliningManager.cachedBzlLoadValueAndDepsBuilderFactory
+ .newCachedBzlLoadValueAndDepsBuilder();
+ // Use an instrumented Skyframe env to capture Skyframe deps in the CachedBzlLoadValueAndDeps.
+ // This is transitive but doesn't include deps underneath recursively loaded .bzls (the
+ // recursion uses the unwrapped original env).
Preconditions.checkState(
!(env instanceof RecordingSkyFunctionEnvironment),
"Found nested RecordingSkyFunctionEnvironment but it should have been stripped: %s",
@@ -264,23 +257,22 @@
inlineCachedValueBuilder::addDep,
inlineCachedValueBuilder::addDeps,
inlineCachedValueBuilder::noteException);
- StarlarkImportLookupValue value =
+ BzlLoadValue value =
computeInternal(
key,
recordingEnv,
new InliningState(visitedNested, inlineCachedValueBuilder, visitedDepsInToplevelLoad));
- // All imports traversed, this key can no longer be part of a cycle.
+ // All loads traversed, this key can no longer be part of a cycle.
Preconditions.checkState(visitedNested.remove(key), key);
if (value != null) {
inlineCachedValueBuilder.setValue(value);
inlineCachedValueBuilder.setKey(key);
- cachedStarlarkImportLookupValueAndDeps = inlineCachedValueBuilder.build();
- visitedDepsInToplevelLoad.put(key, cachedStarlarkImportLookupValueAndDeps);
- selfInliningManager.starlarkImportLookupValueCache.put(
- key, cachedStarlarkImportLookupValueAndDeps);
+ cachedBzlLoadValueAndDeps = inlineCachedValueBuilder.build();
+ visitedDepsInToplevelLoad.put(key, cachedBzlLoadValueAndDeps);
+ selfInliningManager.bzlLoadValueCache.put(key, cachedBzlLoadValueAndDeps);
}
- return cachedStarlarkImportLookupValueAndDeps;
+ return cachedBzlLoadValueAndDeps;
}
public void resetSelfInliningCache() {
@@ -289,7 +281,7 @@
private static ContainingPackageLookupValue getContainingPackageLookupValue(
Environment env, Label label)
- throws InconsistentFilesystemException, StarlarkImportFailedException, InterruptedException {
+ throws InconsistentFilesystemException, BzlLoadFailedException, InterruptedException {
PathFragment dir = Label.getContainingDirectory(label);
PackageIdentifier dirId =
PackageIdentifier.create(label.getPackageIdentifier().getRepository(), dir);
@@ -302,7 +294,7 @@
BuildFileNotFoundException.class,
InconsistentFilesystemException.class);
} catch (BuildFileNotFoundException e) {
- throw StarlarkImportFailedException.errorReadingFile(
+ throw BzlLoadFailedException.errorReadingFile(
label.toPathFragment(), new ErrorReadingStarlarkExtensionException(e));
}
if (containingPackageLookupValue == null) {
@@ -310,29 +302,26 @@
}
// Ensure the label doesn't cross package boundaries.
if (!containingPackageLookupValue.hasContainingPackage()) {
- throw StarlarkImportFailedException.noBuildFile(
+ throw BzlLoadFailedException.noBuildFile(
label, containingPackageLookupValue.getReasonForNoContainingPackage());
}
if (!containingPackageLookupValue
.getContainingPackageName()
.equals(label.getPackageIdentifier())) {
- throw StarlarkImportFailedException.labelCrossesPackageBoundary(
- label, containingPackageLookupValue);
+ throw BzlLoadFailedException.labelCrossesPackageBoundary(label, containingPackageLookupValue);
}
return containingPackageLookupValue;
}
private static class InliningState {
- private final Set<StarlarkImportLookupValue.Key> visitedNested;
- private final CachedStarlarkImportLookupValueAndDeps.Builder inlineCachedValueBuilder;
- private final Map<StarlarkImportLookupValue.Key, CachedStarlarkImportLookupValueAndDeps>
- visitedDepsInToplevelLoad;
+ private final Set<BzlLoadValue.Key> visitedNested;
+ private final CachedBzlLoadValueAndDeps.Builder inlineCachedValueBuilder;
+ private final Map<BzlLoadValue.Key, CachedBzlLoadValueAndDeps> visitedDepsInToplevelLoad;
private InliningState(
- Set<StarlarkImportLookupValue.Key> visitedNested,
- CachedStarlarkImportLookupValueAndDeps.Builder inlineCachedValueBuilder,
- Map<StarlarkImportLookupValue.Key, CachedStarlarkImportLookupValueAndDeps>
- visitedDepsInToplevelLoad) {
+ Set<BzlLoadValue.Key> visitedNested,
+ CachedBzlLoadValueAndDeps.Builder inlineCachedValueBuilder,
+ Map<BzlLoadValue.Key, CachedBzlLoadValueAndDeps> visitedDepsInToplevelLoad) {
this.visitedNested = visitedNested;
this.inlineCachedValueBuilder = inlineCachedValueBuilder;
this.visitedDepsInToplevelLoad = visitedDepsInToplevelLoad;
@@ -343,9 +332,9 @@
// exception. We are allowed to wrap the thrown exception and rethrow it for any calling functions
// to handle though.
@Nullable
- private StarlarkImportLookupValue computeInternal(
- StarlarkImportLookupValue.Key key, Environment env, @Nullable InliningState inliningState)
- throws InconsistentFilesystemException, StarlarkImportFailedException, InterruptedException {
+ private BzlLoadValue computeInternal(
+ BzlLoadValue.Key key, Environment env, @Nullable InliningState inliningState)
+ throws InconsistentFilesystemException, BzlLoadFailedException, InterruptedException {
Label label = key.getLabel();
PathFragment filePath = label.toPathFragment();
@@ -363,20 +352,18 @@
try {
astLookupValue = astFileLookupValueManager.getASTFileLookupValue(label, env);
} catch (ErrorReadingStarlarkExtensionException e) {
- throw StarlarkImportFailedException.errorReadingFile(filePath, e);
+ throw BzlLoadFailedException.errorReadingFile(filePath, e);
}
if (astLookupValue == null) {
return null;
}
- StarlarkImportLookupValue result = null;
+ BzlLoadValue result = null;
try {
result =
computeInternalWithAst(
key, filePath, starlarkSemantics, astLookupValue, env, inliningState);
- } catch (InconsistentFilesystemException
- | StarlarkImportFailedException
- | InterruptedException e) {
+ } catch (InconsistentFilesystemException | BzlLoadFailedException | InterruptedException e) {
astFileLookupValueManager.doneWithASTFileLookupValue(label);
throw e;
}
@@ -388,23 +375,23 @@
}
@Nullable
- private StarlarkImportLookupValue computeInternalWithAst(
- StarlarkImportLookupValue.Key key,
+ private BzlLoadValue computeInternalWithAst(
+ BzlLoadValue.Key key,
PathFragment filePath,
StarlarkSemantics starlarkSemantics,
ASTFileLookupValue astLookupValue,
Environment env,
@Nullable InliningState inliningState)
- throws InconsistentFilesystemException, StarlarkImportFailedException, InterruptedException {
+ throws InconsistentFilesystemException, BzlLoadFailedException, InterruptedException {
Label label = key.getLabel();
if (!astLookupValue.lookupSuccessful()) {
- // Starlark import files must exist.
- throw new StarlarkImportFailedException(astLookupValue.getError());
+ // Starlark code must exist.
+ throw new BzlLoadFailedException(astLookupValue.getError());
}
StarlarkFile file = astLookupValue.getAST();
if (!file.ok()) {
- throw StarlarkImportFailedException.skylarkErrors(filePath);
+ throw BzlLoadFailedException.skylarkErrors(filePath);
}
// Process the load statements in the file,
@@ -417,25 +404,25 @@
getLoadLabels(env.getListener(), file, label.getPackageIdentifier(), repoMapping);
if (loads == null) {
// malformed load statements
- throw StarlarkImportFailedException.skylarkErrors(filePath);
+ throw BzlLoadFailedException.skylarkErrors(filePath);
}
// Compute Skyframe key for each label in 'loads'.
- List<StarlarkImportLookupValue.Key> loadKeys = Lists.newArrayListWithExpectedSize(loads.size());
+ List<BzlLoadValue.Key> loadKeys = Lists.newArrayListWithExpectedSize(loads.size());
for (Pair<String, Label> load : loads) {
loadKeys.add(key.getKeyForLoad(load.second));
}
// Load .bzl modules in parallel.
- List<StarlarkImportLookupValue> starlarkImports =
+ List<BzlLoadValue> bzlLoads =
inliningState == null
- ? computeStarlarkImportsNoInlining(env, loadKeys, file.getStartLocation())
- : computeStarlarkImportsWithSelfInlining(env, loadKeys, label, inliningState);
- if (starlarkImports == null) {
+ ? computeBzlLoadsNoInlining(env, loadKeys, file.getStartLocation())
+ : computeBzlLoadsWithSelfInlining(env, loadKeys, label, inliningState);
+ if (bzlLoads == null) {
return null; // Skyframe deps unavailable
}
- // Process the loaded imports.
+ // Process the loaded modules.
//
// Compute a digest of the file itself plus the transitive hashes of the modules it directly
// loads. Loop iteration order matches the source order of load statements.
@@ -446,7 +433,7 @@
ImmutableList.builderWithExpectedSize(loads.size());
for (int i = 0; i < loads.size(); i++) {
String loadString = loads.get(i).first;
- StarlarkImportLookupValue v = starlarkImports.get(i);
+ BzlLoadValue v = bzlLoads.get(i);
loadedModules.put(loadString, v.getModule());
fileDependencies.add(v.getDependency());
fp.addBytes(v.getTransitiveDigest());
@@ -454,7 +441,7 @@
byte[] transitiveDigest = fp.digestAndReset();
// executeModule does not request values from the Environment. It may post events to the
- // Environment, but events do not matter when caching StarlarkImportLookupValues.
+ // Environment, but events do not matter when caching BzlLoadValues.
Module module =
executeModule(
file,
@@ -463,23 +450,22 @@
loadedModules,
starlarkSemantics,
env,
- /*inWorkspace=*/ key instanceof StarlarkImportLookupValue.WorkspaceBzlKey,
+ /*inWorkspace=*/ key instanceof BzlLoadValue.WorkspaceBzlKey,
repoMapping);
- StarlarkImportLookupValue result =
- new StarlarkImportLookupValue(
+ BzlLoadValue result =
+ new BzlLoadValue(
module, transitiveDigest, new StarlarkFileDependency(label, fileDependencies.build()));
return result;
}
private static ImmutableMap<RepositoryName, RepositoryName> getRepositoryMapping(
- StarlarkImportLookupValue.Key key, Environment env) throws InterruptedException {
+ BzlLoadValue.Key key, Environment env) throws InterruptedException {
Label enclosingFileLabel = key.getLabel();
ImmutableMap<RepositoryName, RepositoryName> repositoryMapping;
- if (key instanceof StarlarkImportLookupValue.WorkspaceBzlKey) {
+ if (key instanceof BzlLoadValue.WorkspaceBzlKey) {
// Still during workspace file evaluation
- StarlarkImportLookupValue.WorkspaceBzlKey workspaceBzlKey =
- (StarlarkImportLookupValue.WorkspaceBzlKey) key;
+ BzlLoadValue.WorkspaceBzlKey workspaceBzlKey = (BzlLoadValue.WorkspaceBzlKey) key;
if (workspaceBzlKey.getWorkspaceChunk() == 0) {
// There is no previous workspace chunk
repositoryMapping = ImmutableMap.of();
@@ -569,53 +555,48 @@
}
/**
- * Compute the StarlarkImportLookupValue for all given keys using vanilla Skyframe evaluation,
- * returning {@code null} if Skyframe deps were missing and have been requested.
+ * Compute the BzlLoadValue for all given keys using vanilla Skyframe evaluation, returning {@code
+ * null} if Skyframe deps were missing and have been requested.
*/
@Nullable
- private static List<StarlarkImportLookupValue> computeStarlarkImportsNoInlining(
- Environment env, List<StarlarkImportLookupValue.Key> keys, Location locationForErrors)
- throws StarlarkImportFailedException, InterruptedException {
- List<StarlarkImportLookupValue> starlarkImports =
- Lists.newArrayListWithExpectedSize(keys.size());
- Map<SkyKey, ValueOrException<StarlarkImportFailedException>> values =
- env.getValuesOrThrow(keys, StarlarkImportFailedException.class);
+ private static List<BzlLoadValue> computeBzlLoadsNoInlining(
+ Environment env, List<BzlLoadValue.Key> keys, Location locationForErrors)
+ throws BzlLoadFailedException, InterruptedException {
+ List<BzlLoadValue> bzlLoads = Lists.newArrayListWithExpectedSize(keys.size());
+ Map<SkyKey, ValueOrException<BzlLoadFailedException>> values =
+ env.getValuesOrThrow(keys, BzlLoadFailedException.class);
// Uses same order as load()s in the file. Order matters since we report the first error.
- for (StarlarkImportLookupValue.Key key : keys) {
+ for (BzlLoadValue.Key key : keys) {
try {
- starlarkImports.add((StarlarkImportLookupValue) values.get(key).get());
- } catch (StarlarkImportFailedException exn) {
- throw new StarlarkImportFailedException(
+ bzlLoads.add((BzlLoadValue) values.get(key).get());
+ } catch (BzlLoadFailedException exn) {
+ throw new BzlLoadFailedException(
"in " + locationForErrors.file() + ": " + exn.getMessage());
}
}
- return env.valuesMissing() ? null : starlarkImports;
+ return env.valuesMissing() ? null : bzlLoads;
}
/**
- * Compute the StarlarkImportLookupValue for all given keys by reusing this instance of the
- * StarlarkImportLookupFunction, bypassing traditional Skyframe evaluation, returning {@code null}
- * if Skyframe deps were missing and have been requested.
+ * Compute the BzlLoadValue for all given keys by reusing this instance of the BzlLoadFunction,
+ * bypassing traditional Skyframe evaluation, returning {@code null} if Skyframe deps were missing
+ * and have been requested.
*/
@Nullable
- private List<StarlarkImportLookupValue> computeStarlarkImportsWithSelfInlining(
- Environment env,
- List<StarlarkImportLookupValue.Key> keys,
- Label fileLabel,
- InliningState inliningState)
- throws InterruptedException, StarlarkImportFailedException, InconsistentFilesystemException {
+ private List<BzlLoadValue> computeBzlLoadsWithSelfInlining(
+ Environment env, List<BzlLoadValue.Key> keys, Label fileLabel, InliningState inliningState)
+ throws InterruptedException, BzlLoadFailedException, InconsistentFilesystemException {
Preconditions.checkState(
env instanceof RecordingSkyFunctionEnvironment,
- "Expected to be recording dep requests when inlining StarlarkImportLookupFunction: %s",
+ "Expected to be recording dep requests when inlining BzlLoadFunction: %s",
fileLabel);
Environment strippedEnv = ((RecordingSkyFunctionEnvironment) env).getDelegate();
- List<StarlarkImportLookupValue> starlarkImports =
- Lists.newArrayListWithExpectedSize(keys.size());
+ List<BzlLoadValue> bzlLoads = Lists.newArrayListWithExpectedSize(keys.size());
Exception deferredException = null;
boolean valuesMissing = false;
- // NOTE: Iterating over imports in the order listed in the file.
- for (StarlarkImportLookupValue.Key key : keys) {
- CachedStarlarkImportLookupValueAndDeps cachedValue;
+ // NOTE: Iterating over loads in the order listed in the file.
+ for (BzlLoadValue.Key key : keys) {
+ CachedBzlLoadValueAndDeps cachedValue;
try {
cachedValue =
computeWithSelfInlineCallsInternal(
@@ -623,33 +604,33 @@
strippedEnv,
inliningState.visitedNested,
inliningState.visitedDepsInToplevelLoad);
- } catch (StarlarkImportFailedException | InconsistentFilesystemException e) {
+ } catch (BzlLoadFailedException | InconsistentFilesystemException e) {
// For determinism's sake while inlining, preserve the first exception and continue to run
- // subsequently listed imports to completion/exception, loading all transitive deps anyway.
+ // subsequently listed loads to completion/exception, loading all transitive deps anyway.
deferredException = MoreObjects.firstNonNull(deferredException, e);
continue;
}
if (cachedValue == null) {
- Preconditions.checkState(env.valuesMissing(), "no starlark import value for %s", key);
+ Preconditions.checkState(env.valuesMissing(), "no starlark load value for %s", key);
// We continue making inline calls even if some requested values are missing, to maximize
// the number of dependent (non-inlined) SkyFunctions that are requested, thus avoiding a
// quadratic number of restarts.
valuesMissing = true;
} else {
- starlarkImports.add(cachedValue.getValue());
+ bzlLoads.add(cachedValue.getValue());
inliningState.inlineCachedValueBuilder.addTransitiveDeps(cachedValue);
}
}
if (deferredException != null) {
- Throwables.throwIfInstanceOf(deferredException, StarlarkImportFailedException.class);
+ Throwables.throwIfInstanceOf(deferredException, BzlLoadFailedException.class);
Throwables.throwIfInstanceOf(deferredException, InconsistentFilesystemException.class);
throw new IllegalStateException(
"caught a checked exception of unexpected type", deferredException);
}
- return valuesMissing ? null : starlarkImports;
+ return valuesMissing ? null : bzlLoads;
}
- /** Executes the .bzl file defining the module to be imported. */
+ /** Executes the .bzl file defining the module to be loaded. */
private Module executeModule(
StarlarkFile file,
Label label,
@@ -659,14 +640,14 @@
Environment env,
boolean inWorkspace,
ImmutableMap<RepositoryName, RepositoryName> repositoryMapping)
- throws StarlarkImportFailedException, InterruptedException {
+ throws BzlLoadFailedException, InterruptedException {
// set up .bzl predeclared environment
Map<String, Object> predeclared = new HashMap<>(ruleClassProvider.getEnvironment());
predeclared.put("native", packageFactory.getNativeModule(inWorkspace));
Module module = Module.withPredeclared(starlarkSemantics, predeclared);
module.setClientData(BazelModuleContext.create(label, transitiveDigest));
- try (Mutability mu = Mutability.create("importing", label)) {
+ try (Mutability mu = Mutability.create("loading", label)) {
StarlarkThread thread = new StarlarkThread(mu, starlarkSemantics);
thread.setLoader(loadedModules::get);
StoredEventHandler eventHandler = new StoredEventHandler();
@@ -679,7 +660,7 @@
env.getListener().post(post);
}
if (eventHandler.hasErrors()) {
- throw StarlarkImportFailedException.errors(label.toPathFragment());
+ throw BzlLoadFailedException.errors(label.toPathFragment());
}
return module;
}
@@ -721,41 +702,38 @@
return null;
}
- static final class StarlarkImportFailedException extends Exception
- implements SaneAnalysisException {
+ static final class BzlLoadFailedException extends Exception implements SaneAnalysisException {
private final Transience transience;
- private StarlarkImportFailedException(String errorMessage) {
+ private BzlLoadFailedException(String errorMessage) {
super(errorMessage);
this.transience = Transience.PERSISTENT;
}
- private StarlarkImportFailedException(
- String errorMessage, Exception cause, Transience transience) {
+ private BzlLoadFailedException(String errorMessage, Exception cause, Transience transience) {
super(errorMessage, cause);
this.transience = transience;
}
- static StarlarkImportFailedException errors(PathFragment file) {
- return new StarlarkImportFailedException(
- String.format("Extension file '%s' has errors", file));
+ static BzlLoadFailedException errors(PathFragment file) {
+ return new BzlLoadFailedException(String.format("Extension file '%s' has errors", file));
}
- static StarlarkImportFailedException errorReadingFile(
+ static BzlLoadFailedException errorReadingFile(
PathFragment file, ErrorReadingStarlarkExtensionException cause) {
- return new StarlarkImportFailedException(
+ return new BzlLoadFailedException(
String.format(
"Encountered error while reading extension file '%s': %s", file, cause.getMessage()),
cause,
cause.getTransience());
}
- static StarlarkImportFailedException noBuildFile(Label file, @Nullable String reason) {
+ static BzlLoadFailedException noBuildFile(Label file, @Nullable String reason) {
if (reason != null) {
- return new StarlarkImportFailedException(
+ return new BzlLoadFailedException(
String.format("Unable to find package for %s: %s.", file, reason));
}
- return new StarlarkImportFailedException(
+ return new BzlLoadFailedException(
String.format(
"Every .bzl file must have a corresponding package, but '%s' does not have one."
+ " Please create a BUILD file in the same or any parent directory. Note that"
@@ -763,9 +741,9 @@
file));
}
- static StarlarkImportFailedException labelCrossesPackageBoundary(
+ static BzlLoadFailedException labelCrossesPackageBoundary(
Label label, ContainingPackageLookupValue containingPackageLookupValue) {
- return new StarlarkImportFailedException(
+ return new BzlLoadFailedException(
ContainingPackageLookupValue.getErrorMessageForLabelCrossingPackageBoundary(
// We don't actually know the proper Root to pass in here (since we don't e.g. know
// the root of the bzl/BUILD file that is trying to load 'label'). Therefore we just
@@ -776,8 +754,8 @@
containingPackageLookupValue));
}
- static StarlarkImportFailedException skylarkErrors(PathFragment file) {
- return new StarlarkImportFailedException(String.format("Extension '%s' has errors", file));
+ static BzlLoadFailedException skylarkErrors(PathFragment file) {
+ return new BzlLoadFailedException(String.format("Extension '%s' has errors", file));
}
}
@@ -816,9 +794,8 @@
private final RuleClassProvider ruleClassProvider;
private final DigestHashFunction digestHashFunction;
// We keep a cache of ASTFileLookupValues that have been computed but whose corresponding
- // StarlarkImportLookupValue has not yet completed. This avoids repeating the ASTFileLookupValue
- // work in case of Skyframe restarts. (If we weren't inlining, Skyframe would cache this for
- // us.)
+ // BzlLoadValue has not yet completed. This avoids repeating the ASTFileLookupValue work in case
+ // of Skyframe restarts. (If we weren't inlining, Skyframe would cache this for us.)
private final Cache<Label, ASTFileLookupValue> astFileLookupValueCache;
private InliningAndCachingASTFileLookupValueManager(
@@ -854,45 +831,40 @@
}
private static class SelfInliningManager {
- private final int starlarkImportLookupValueCacheSize;
- private Cache<StarlarkImportLookupValue.Key, CachedStarlarkImportLookupValueAndDeps>
- starlarkImportLookupValueCache;
- private CachedStarlarkImportLookupValueAndDepsBuilderFactory
- cachedStarlarkImportLookupValueAndDepsBuilderFactory =
- new CachedStarlarkImportLookupValueAndDepsBuilderFactory();
+ private final int bzlLoadValueCacheSize;
+ private Cache<BzlLoadValue.Key, CachedBzlLoadValueAndDeps> bzlLoadValueCache;
+ private CachedBzlLoadValueAndDepsBuilderFactory cachedBzlLoadValueAndDepsBuilderFactory =
+ new CachedBzlLoadValueAndDepsBuilderFactory();
- private SelfInliningManager(int starlarkImportLookupValueCacheSize) {
- this.starlarkImportLookupValueCacheSize = starlarkImportLookupValueCacheSize;
+ private SelfInliningManager(int bzlLoadValueCacheSize) {
+ this.bzlLoadValueCacheSize = bzlLoadValueCacheSize;
}
private void reset() {
- if (starlarkImportLookupValueCache != null) {
+ if (bzlLoadValueCache != null) {
logger.atInfo().log(
- "Starlark inlining cache stats from earlier build: "
- + starlarkImportLookupValueCache.stats());
+ "Starlark inlining cache stats from earlier build: " + bzlLoadValueCache.stats());
}
- cachedStarlarkImportLookupValueAndDepsBuilderFactory =
- new CachedStarlarkImportLookupValueAndDepsBuilderFactory();
+ cachedBzlLoadValueAndDepsBuilderFactory = new CachedBzlLoadValueAndDepsBuilderFactory();
Preconditions.checkState(
- starlarkImportLookupValueCacheSize >= 0,
+ bzlLoadValueCacheSize >= 0,
"Expected positive Starlark cache size if caching. %s",
- starlarkImportLookupValueCacheSize);
- starlarkImportLookupValueCache =
+ bzlLoadValueCacheSize);
+ bzlLoadValueCache =
CacheBuilder.newBuilder()
.concurrencyLevel(BlazeInterners.concurrencyLevel())
- .maximumSize(starlarkImportLookupValueCacheSize)
+ .maximumSize(bzlLoadValueCacheSize)
.recordStats()
.build();
}
}
- private static final class StarlarkImportLookupFunctionException extends SkyFunctionException {
- private StarlarkImportLookupFunctionException(StarlarkImportFailedException cause) {
+ private static final class BzlLoadFunctionException extends SkyFunctionException {
+ private BzlLoadFunctionException(BzlLoadFailedException cause) {
super(cause, cause.transience);
}
- private StarlarkImportLookupFunctionException(InconsistentFilesystemException e,
- Transience transience) {
+ private BzlLoadFunctionException(InconsistentFilesystemException e, Transience transience) {
super(e, transience);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadValue.java
similarity index 92%
rename from src/main/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupValue.java
rename to src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadValue.java
index 498ec5c..7bcbc6d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadValue.java
@@ -28,11 +28,11 @@
import java.util.Objects;
/**
- * A value that represents a Starlark import lookup result. The lookup value corresponds to exactly
- * one Starlark file, identified by an absolute {@link Label} {@link SkyKey} argument. The Label
- * should not reference the special {@code external} package.
+ * A value that represents a Starlark load result. The lookup value corresponds to exactly one
+ * Starlark file, identified by an absolute {@link Label} {@link SkyKey} argument. The Label should
+ * not reference the special {@code external} package.
*/
-public class StarlarkImportLookupValue implements SkyValue {
+public class BzlLoadValue implements SkyValue {
private final Module module; // .bzl module
private final byte[] transitiveDigest; // of .bzl file and load dependencies
@@ -45,8 +45,7 @@
private final StarlarkFileDependency dependency;
@VisibleForTesting
- public StarlarkImportLookupValue(
- Module module, byte[] transitiveDigest, StarlarkFileDependency dependency) {
+ public BzlLoadValue(Module module, byte[] transitiveDigest, StarlarkFileDependency dependency) {
this.module = Preconditions.checkNotNull(module);
this.transitiveDigest = Preconditions.checkNotNull(transitiveDigest);
this.dependency = Preconditions.checkNotNull(dependency);
@@ -62,14 +61,14 @@
return transitiveDigest;
}
- /** Returns the immediate Starlark file dependency corresponding to this import lookup value. */
+ /** Returns the immediate Starlark file dependency corresponding to this load value. */
public StarlarkFileDependency getDependency() {
return dependency;
}
private static final Interner<Key> keyInterner = BlazeInterners.newWeakInterner();
- /** SkyKey for a Starlark import. */
+ /** SkyKey for a Starlark load. */
abstract static class Key implements SkyKey {
/** Returns the label of the .bzl file to be loaded. */
@@ -87,7 +86,7 @@
@Override
public SkyFunctionName functionName() {
- return SkyFunctions.STARLARK_IMPORTS_LOOKUP;
+ return SkyFunctions.BZL_LOAD;
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/CachedStarlarkImportLookupValueAndDeps.java b/src/main/java/com/google/devtools/build/lib/skyframe/CachedBzlLoadValueAndDeps.java
similarity index 70%
rename from src/main/java/com/google/devtools/build/lib/skyframe/CachedStarlarkImportLookupValueAndDeps.java
rename to src/main/java/com/google/devtools/build/lib/skyframe/CachedBzlLoadValueAndDeps.java
index afc1180..7c9b469 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/CachedStarlarkImportLookupValueAndDeps.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/CachedBzlLoadValueAndDeps.java
@@ -25,17 +25,17 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
-class CachedStarlarkImportLookupValueAndDeps {
- private final StarlarkImportLookupValue.Key key;
- private final StarlarkImportLookupValue value;
+class CachedBzlLoadValueAndDeps {
+ private final BzlLoadValue.Key key;
+ private final BzlLoadValue value;
private final ImmutableList<Iterable<SkyKey>> directDeps;
- private final ImmutableList<CachedStarlarkImportLookupValueAndDeps> transitiveDeps;
+ private final ImmutableList<CachedBzlLoadValueAndDeps> transitiveDeps;
- private CachedStarlarkImportLookupValueAndDeps(
- StarlarkImportLookupValue.Key key,
- StarlarkImportLookupValue value,
+ private CachedBzlLoadValueAndDeps(
+ BzlLoadValue.Key key,
+ BzlLoadValue value,
ImmutableList<Iterable<SkyKey>> directDeps,
- ImmutableList<CachedStarlarkImportLookupValueAndDeps> transitiveDeps) {
+ ImmutableList<CachedBzlLoadValueAndDeps> transitiveDeps) {
this.key = key;
this.value = value;
this.directDeps = directDeps;
@@ -44,12 +44,12 @@
void traverse(
DepGroupConsumer depGroupConsumer,
- Map<StarlarkImportLookupValue.Key, CachedStarlarkImportLookupValueAndDeps> visitedDeps)
+ Map<BzlLoadValue.Key, CachedBzlLoadValueAndDeps> visitedDeps)
throws InterruptedException {
for (Iterable<SkyKey> directDepGroup : directDeps) {
depGroupConsumer.accept(directDepGroup);
}
- for (CachedStarlarkImportLookupValueAndDeps indirectDeps : transitiveDeps) {
+ for (CachedBzlLoadValueAndDeps indirectDeps : transitiveDeps) {
if (!visitedDeps.containsKey(indirectDeps.key)) {
visitedDeps.put(indirectDeps.key, indirectDeps);
indirectDeps.traverse(depGroupConsumer, visitedDeps);
@@ -57,16 +57,16 @@
}
}
- StarlarkImportLookupValue getValue() {
+ BzlLoadValue getValue() {
return value;
}
@Override
public boolean equals(Object obj) {
- if (obj instanceof CachedStarlarkImportLookupValueAndDeps) {
+ if (obj instanceof CachedBzlLoadValueAndDeps) {
// With the interner, force there to be exactly one cached value per key at any given point
// in time.
- return this.key.equals(((CachedStarlarkImportLookupValueAndDeps) obj).key);
+ return this.key.equals(((CachedBzlLoadValueAndDeps) obj).key);
}
return false;
}
@@ -82,16 +82,16 @@
}
static class Builder {
- Builder(Interner<CachedStarlarkImportLookupValueAndDeps> interner) {
+ Builder(Interner<CachedBzlLoadValueAndDeps> interner) {
this.interner = interner;
}
- private final Interner<CachedStarlarkImportLookupValueAndDeps> interner;
+ private final Interner<CachedBzlLoadValueAndDeps> interner;
private final List<Iterable<SkyKey>> directDeps = new ArrayList<>();
- private final List<CachedStarlarkImportLookupValueAndDeps> transitiveDeps = new ArrayList<>();
+ private final List<CachedBzlLoadValueAndDeps> transitiveDeps = new ArrayList<>();
private final AtomicReference<Exception> exceptionSeen = new AtomicReference<>(null);
- private StarlarkImportLookupValue value;
- private StarlarkImportLookupValue.Key key;
+ private BzlLoadValue value;
+ private BzlLoadValue.Key key;
@CanIgnoreReturnValue
Builder addDep(SkyKey key) {
@@ -116,36 +116,36 @@
}
@CanIgnoreReturnValue
- Builder addTransitiveDeps(CachedStarlarkImportLookupValueAndDeps transitiveDeps) {
+ Builder addTransitiveDeps(CachedBzlLoadValueAndDeps transitiveDeps) {
this.transitiveDeps.add(transitiveDeps);
return this;
}
@CanIgnoreReturnValue
- Builder setValue(StarlarkImportLookupValue value) {
+ Builder setValue(BzlLoadValue value) {
this.value = value;
return this;
}
@CanIgnoreReturnValue
- Builder setKey(StarlarkImportLookupValue.Key key) {
+ Builder setKey(BzlLoadValue.Key key) {
this.key = key;
return this;
}
- CachedStarlarkImportLookupValueAndDeps build() {
- // We expect that we don't handle any exceptions in StarlarkLookupImportFunction directly.
+ CachedBzlLoadValueAndDeps build() {
+ // We expect that we don't handle any exceptions in BzlLoadFunction directly.
Preconditions.checkState(exceptionSeen.get() == null, "Caching a value in error?: %s", this);
Preconditions.checkNotNull(value, "Expected value to be set: %s", this);
Preconditions.checkNotNull(key, "Expected key to be set: %s", this);
return interner.intern(
- new CachedStarlarkImportLookupValueAndDeps(
+ new CachedBzlLoadValueAndDeps(
key, value, ImmutableList.copyOf(directDeps), ImmutableList.copyOf(transitiveDeps)));
}
@Override
public String toString() {
- return MoreObjects.toStringHelper(CachedStarlarkImportLookupValueAndDeps.Builder.class)
+ return MoreObjects.toStringHelper(CachedBzlLoadValueAndDeps.Builder.class)
.add("key", key)
.add("value", value)
.add("directDeps", directDeps)
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/CachedStarlarkImportLookupValueAndDepsBuilderFactory.java b/src/main/java/com/google/devtools/build/lib/skyframe/CachedBzlLoadValueAndDepsBuilderFactory.java
similarity index 64%
rename from src/main/java/com/google/devtools/build/lib/skyframe/CachedStarlarkImportLookupValueAndDepsBuilderFactory.java
rename to src/main/java/com/google/devtools/build/lib/skyframe/CachedBzlLoadValueAndDepsBuilderFactory.java
index 5272424..77fc055 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/CachedStarlarkImportLookupValueAndDepsBuilderFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/CachedBzlLoadValueAndDepsBuilderFactory.java
@@ -17,13 +17,11 @@
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
-/** Factory class for producing CachedStarlarkImportLookupValueAndDeps. */
-public class CachedStarlarkImportLookupValueAndDepsBuilderFactory {
- private final Interner<CachedStarlarkImportLookupValueAndDeps> interner =
- BlazeInterners.newWeakInterner();
+/** Factory class for producing CachedBzlLoadValueAndDeps. */
+public class CachedBzlLoadValueAndDepsBuilderFactory {
+ private final Interner<CachedBzlLoadValueAndDeps> interner = BlazeInterners.newWeakInterner();
- CachedStarlarkImportLookupValueAndDeps.Builder
- newCachedStarlarkImportLookupValueAndDepsBuilder() {
- return new CachedStarlarkImportLookupValueAndDeps.Builder(interner);
+ CachedBzlLoadValueAndDeps.Builder newCachedBzlLoadValueAndDepsBuilder() {
+ return new CachedBzlLoadValueAndDeps.Builder(interner);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
index 266be0c..6c81c51d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
@@ -53,8 +53,8 @@
import com.google.devtools.build.lib.profiler.SilentCloseable;
import com.google.devtools.build.lib.repository.ExternalPackageHelper;
import com.google.devtools.build.lib.rules.repository.WorkspaceFileHelper;
+import com.google.devtools.build.lib.skyframe.BzlLoadFunction.BzlLoadFailedException;
import com.google.devtools.build.lib.skyframe.GlobValue.InvalidGlobPatternException;
-import com.google.devtools.build.lib.skyframe.StarlarkImportLookupFunction.StarlarkImportFailedException;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.FileOptions;
import com.google.devtools.build.lib.syntax.Location;
@@ -106,7 +106,7 @@
private final ExternalPackageHelper externalPackageHelper;
// Not final only for testing.
- @Nullable private StarlarkImportLookupFunction starlarkImportLookupFunctionForInlining;
+ @Nullable private BzlLoadFunction bzlLoadFunctionForInlining;
private final ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile;
@@ -119,12 +119,12 @@
Cache<PackageIdentifier, LoadedPackageCacheEntry> packageFunctionCache,
Cache<PackageIdentifier, StarlarkFile> fileSyntaxCache,
AtomicInteger numPackagesLoaded,
- @Nullable StarlarkImportLookupFunction starlarkImportLookupFunctionForInlining,
+ @Nullable BzlLoadFunction bzlLoadFunctionForInlining,
@Nullable PackageProgressReceiver packageProgress,
ActionOnIOExceptionReadingBuildFile actionOnIOExceptionReadingBuildFile,
IncrementalityIntent incrementalityIntent,
ExternalPackageHelper externalPackageHelper) {
- this.starlarkImportLookupFunctionForInlining = starlarkImportLookupFunctionForInlining;
+ this.bzlLoadFunctionForInlining = bzlLoadFunctionForInlining;
// Can be null in tests.
this.preludeLabel = packageFactory == null
? null
@@ -149,7 +149,7 @@
Cache<PackageIdentifier, LoadedPackageCacheEntry> packageFunctionCache,
Cache<PackageIdentifier, StarlarkFile> fileSyntaxCache,
AtomicInteger numPackagesLoaded,
- @Nullable StarlarkImportLookupFunction starlarkImportLookupFunctionForInlining,
+ @Nullable BzlLoadFunction bzlLoadFunctionForInlining,
ExternalPackageHelper externalPackageHelper) {
this(
packageFactory,
@@ -158,16 +158,15 @@
packageFunctionCache,
fileSyntaxCache,
numPackagesLoaded,
- starlarkImportLookupFunctionForInlining,
+ bzlLoadFunctionForInlining,
/*packageProgress=*/ null,
ActionOnIOExceptionReadingBuildFile.UseOriginalIOException.INSTANCE,
IncrementalityIntent.INCREMENTAL,
externalPackageHelper);
}
- public void setStarlarkImportLookupFunctionForInliningForTesting(
- StarlarkImportLookupFunction starlarkImportLookupFunctionForInlining) {
- this.starlarkImportLookupFunctionForInlining = starlarkImportLookupFunctionForInlining;
+ public void setBzlLoadFunctionForInliningForTesting(BzlLoadFunction bzlLoadFunctionForInlining) {
+ this.bzlLoadFunctionForInlining = bzlLoadFunctionForInlining;
}
/**
@@ -319,8 +318,8 @@
workspaceKey,
IOException.class,
EvalException.class,
- StarlarkImportFailedException.class);
- } catch (IOException | EvalException | StarlarkImportFailedException e) {
+ BzlLoadFailedException.class);
+ } catch (IOException | EvalException | BzlLoadFailedException e) {
throw new PackageFunctionException(
new NoSuchPackageException(
LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER,
@@ -572,8 +571,8 @@
return buildFileValue;
}
- private static BuildFileContainsErrorsException makeStarlarkImportFailedException(
- PackageIdentifier packageId, StarlarkImportFailedException e) {
+ private static BuildFileContainsErrorsException makeBzlLoadFailedException(
+ PackageIdentifier packageId, BzlLoadFailedException e) {
Throwable rootCause = Throwables.getRootCause(e);
return (rootCause instanceof IOException)
? new BuildFileContainsErrorsException(packageId, e.getMessage(), (IOException) rootCause)
@@ -585,52 +584,51 @@
* null.
*/
@Nullable
- static StarlarkImportResult fetchImportsFromBuildFile(
+ static BzlLoadResult fetchLoadsFromBuildFile(
RootedPath buildFilePath,
PackageIdentifier packageId,
ImmutableMap<RepositoryName, RepositoryName> repoMapping,
StarlarkFile file,
int workspaceChunk,
Environment env,
- StarlarkImportLookupFunction starlarkImportLookupFunctionForInlining)
+ BzlLoadFunction bzlLoadFunctionForInlining)
throws NoSuchPackageException, InterruptedException {
Preconditions.checkArgument(!packageId.getRepository().isDefault());
// Parse the labels in the file's load statements.
List<Pair<String, Label>> loads =
- StarlarkImportLookupFunction.getLoadLabels(env.getListener(), file, packageId, repoMapping);
+ BzlLoadFunction.getLoadLabels(env.getListener(), file, packageId, repoMapping);
if (loads == null) {
throw new BuildFileContainsErrorsException(packageId, "malformed load statements");
}
// Compute Skyframe key for each label in 'loads'.
- List<StarlarkImportLookupValue.Key> keys = Lists.newArrayListWithExpectedSize(loads.size());
+ List<BzlLoadValue.Key> keys = Lists.newArrayListWithExpectedSize(loads.size());
boolean inWorkspace =
WorkspaceFileHelper.endsWithWorkspaceFileName(buildFilePath.getRootRelativePath());
for (Pair<String, Label> load : loads) {
Label bzlLabel = load.second;
if (inWorkspace) {
int originalChunk = getOriginalWorkspaceChunk(env, buildFilePath, workspaceChunk, bzlLabel);
- keys.add(StarlarkImportLookupValue.workspaceBzlKey(bzlLabel, originalChunk, buildFilePath));
+ keys.add(BzlLoadValue.workspaceBzlKey(bzlLabel, originalChunk, buildFilePath));
} else {
- keys.add(StarlarkImportLookupValue.packageBzlKey(bzlLabel));
+ keys.add(BzlLoadValue.packageBzlKey(bzlLabel));
}
}
// Load .bzl modules in parallel.
- List<StarlarkImportLookupValue> starlarkImports;
+ List<BzlLoadValue> bzlLoads;
try {
- starlarkImports =
- starlarkImportLookupFunctionForInlining == null
- ? computeStarlarkImportsNoInlining(env, keys)
- : computeStarlarkImportsWithInlining(
- env, keys, starlarkImportLookupFunctionForInlining);
- } catch (StarlarkImportFailedException e) {
- throw makeStarlarkImportFailedException(packageId, e);
+ bzlLoads =
+ bzlLoadFunctionForInlining == null
+ ? computeBzlLoadsNoInlining(env, keys)
+ : computeBzlLoadsWithInlining(env, keys, bzlLoadFunctionForInlining);
+ } catch (BzlLoadFailedException e) {
+ throw makeBzlLoadFailedException(packageId, e);
} catch (InconsistentFilesystemException e) {
throw new NoSuchPackageException(packageId, e.getMessage(), e);
}
- if (starlarkImports == null) {
+ if (bzlLoads == null) {
return null; // Skyframe deps unavailable
}
@@ -639,89 +637,83 @@
ImmutableList.Builder<StarlarkFileDependency> fileDependencies = ImmutableList.builder();
for (int i = 0; i < loads.size(); i++) {
String loadString = loads.get(i).first;
- StarlarkImportLookupValue v = starlarkImports.get(i);
+ BzlLoadValue v = bzlLoads.get(i);
loadedModules.put(loadString, v.getModule());
fileDependencies.add(v.getDependency());
}
- return new StarlarkImportResult(
- loadedModules, transitiveClosureOfLabels(fileDependencies.build()));
+ return new BzlLoadResult(loadedModules, transitiveClosureOfLabels(fileDependencies.build()));
}
/**
- * Compute the StarlarkImportLookupValue for all given keys using vanilla Skyframe evaluation,
- * returning {@code null} if Skyframe deps were missing and have been requested.
- */
- @Nullable
- private static List<StarlarkImportLookupValue> computeStarlarkImportsNoInlining(
- Environment env, List<StarlarkImportLookupValue.Key> keys)
- throws InterruptedException, StarlarkImportFailedException, InconsistentFilesystemException {
- List<StarlarkImportLookupValue> starlarkImports =
- Lists.newArrayListWithExpectedSize(keys.size());
- Map<SkyKey, ValueOrException2<StarlarkImportFailedException, InconsistentFilesystemException>>
- skylarkLookupResults =
- env.getValuesOrThrow(
- keys, StarlarkImportFailedException.class, InconsistentFilesystemException.class);
- for (StarlarkImportLookupValue.Key key : keys) {
- starlarkImports.add((StarlarkImportLookupValue) skylarkLookupResults.get(key).get());
- }
- return env.valuesMissing() ? null : starlarkImports;
- }
-
- /**
- * Compute the StarlarkImportLookupValue for all given keys by "inlining" the
- * StarlarkImportLookupFunction and bypassing traditional Skyframe evaluation, returning {@code
+ * Compute the BzlLoadValue for all given keys using vanilla Skyframe evaluation, returning {@code
* null} if Skyframe deps were missing and have been requested.
*/
@Nullable
- private static List<StarlarkImportLookupValue> computeStarlarkImportsWithInlining(
- Environment env,
- List<StarlarkImportLookupValue.Key> keys,
- StarlarkImportLookupFunction starlarkImportLookupFunctionForInlining)
- throws InterruptedException, StarlarkImportFailedException, InconsistentFilesystemException {
- List<StarlarkImportLookupValue> starlarkImports =
- Lists.newArrayListWithExpectedSize(keys.size());
+ private static List<BzlLoadValue> computeBzlLoadsNoInlining(
+ Environment env, List<BzlLoadValue.Key> keys)
+ throws InterruptedException, BzlLoadFailedException, InconsistentFilesystemException {
+ List<BzlLoadValue> bzlLoads = Lists.newArrayListWithExpectedSize(keys.size());
+ Map<SkyKey, ValueOrException2<BzlLoadFailedException, InconsistentFilesystemException>>
+ skylarkLookupResults =
+ env.getValuesOrThrow(
+ keys, BzlLoadFailedException.class, InconsistentFilesystemException.class);
+ for (BzlLoadValue.Key key : keys) {
+ bzlLoads.add((BzlLoadValue) skylarkLookupResults.get(key).get());
+ }
+ return env.valuesMissing() ? null : bzlLoads;
+ }
+
+ /**
+ * Compute the BzlLoadValue for all given keys by "inlining" the BzlLoadFunction and bypassing
+ * traditional Skyframe evaluation, returning {@code null} if Skyframe deps were missing and have
+ * been requested.
+ */
+ @Nullable
+ private static List<BzlLoadValue> computeBzlLoadsWithInlining(
+ Environment env, List<BzlLoadValue.Key> keys, BzlLoadFunction bzlLoadFunctionForInlining)
+ throws InterruptedException, BzlLoadFailedException, InconsistentFilesystemException {
+ List<BzlLoadValue> bzlLoads = Lists.newArrayListWithExpectedSize(keys.size());
Exception deferredException = null;
boolean valuesMissing = false;
- // Compute StarlarkImportLookupValue for each key, sharing this map as one big cache. This
- // ensures that each .bzl is loaded only once, regardless of diamond dependencies. (Multiple
- // loads of the same .bzl would screw up identity equality of some Starlark symbols.)
- Map<StarlarkImportLookupValue.Key, CachedStarlarkImportLookupValueAndDeps>
- visitedDepsInToplevelLoad = new HashMap<>();
- for (StarlarkImportLookupValue.Key key : keys) {
+ // Compute BzlLoadValue for each key, sharing this map as one big cache. This ensures that each
+ // .bzl is loaded only once, regardless of diamond dependencies. (Multiple loads of the same
+ // .bzl would screw up identity equality of some Starlark symbols -- see comments in
+ // BzlLoadFunction.)
+ Map<BzlLoadValue.Key, CachedBzlLoadValueAndDeps> visitedDepsInToplevelLoad = new HashMap<>();
+ for (BzlLoadValue.Key key : keys) {
SkyValue skyValue;
try {
// Will complete right away if it's already cached in visitedDepsInToplevelLoad.
skyValue =
- starlarkImportLookupFunctionForInlining
- .computeWithSelfInlineCallsForPackageAndWorkspaceNodes(
- key, env, visitedDepsInToplevelLoad);
- } catch (StarlarkImportFailedException | InconsistentFilesystemException e) {
+ bzlLoadFunctionForInlining.computeWithSelfInlineCallsForPackageAndWorkspaceNodes(
+ key, env, visitedDepsInToplevelLoad);
+ } catch (BzlLoadFailedException | InconsistentFilesystemException e) {
// For determinism's sake while inlining, preserve the first exception and continue to run
- // subsequently listed imports to completion/exception, loading all transitive deps anyway.
+ // subsequently listed loads to completion/exception, loading all transitive deps anyway.
deferredException = MoreObjects.firstNonNull(deferredException, e);
continue;
}
if (skyValue == null) {
- Preconditions.checkState(env.valuesMissing(), "no starlark import value for %s", key);
+ Preconditions.checkState(env.valuesMissing(), "no starlark load value for %s", key);
// We continue making inline calls even if some requested values are missing, to
// maximize the number of dependent (non-inlined) SkyFunctions that are requested, thus
// avoiding a quadratic number of restarts.
valuesMissing = true;
} else {
- starlarkImports.add((StarlarkImportLookupValue) skyValue);
+ bzlLoads.add((BzlLoadValue) skyValue);
}
}
if (deferredException != null) {
- Throwables.throwIfInstanceOf(deferredException, StarlarkImportFailedException.class);
+ Throwables.throwIfInstanceOf(deferredException, BzlLoadFailedException.class);
Throwables.throwIfInstanceOf(deferredException, InconsistentFilesystemException.class);
throw new IllegalStateException(
"caught a checked exception of unexpected type", deferredException);
}
- return valuesMissing ? null : starlarkImports;
+ return valuesMissing ? null : bzlLoads;
}
private static int getOriginalWorkspaceChunk(
- Environment env, RootedPath workspacePath, int workspaceChunk, Label importLabel)
+ Environment env, RootedPath workspacePath, int workspaceChunk, Label loadLabel)
throws InterruptedException {
if (workspaceChunk < 1) {
return workspaceChunk;
@@ -731,9 +723,9 @@
// for nullness
SkyKey workspaceFileKey = WorkspaceFileValue.key(workspacePath, workspaceChunk - 1);
WorkspaceFileValue workspaceFileValue = (WorkspaceFileValue) env.getValue(workspaceFileKey);
- ImmutableMap<String, Integer> importToChunkMap = workspaceFileValue.getImportToChunkMap();
- String importString = importLabel.toString();
- return importToChunkMap.getOrDefault(importString, workspaceChunk);
+ ImmutableMap<String, Integer> loadToChunkMap = workspaceFileValue.getLoadToChunkMap();
+ String loadString = loadLabel.toString();
+ return loadToChunkMap.getOrDefault(loadString, workspaceChunk);
}
private static ImmutableList<Label> transitiveClosureOfLabels(
@@ -1206,24 +1198,24 @@
file = StarlarkFile.parseWithPrelude(input, preludeStatements, options);
fileSyntaxCache.put(packageId, file);
}
- StarlarkImportResult importResult;
+ BzlLoadResult loadResult;
try {
- importResult =
- fetchImportsFromBuildFile(
+ loadResult =
+ fetchLoadsFromBuildFile(
buildFilePath,
packageId,
repositoryMapping,
file,
/* workspaceChunk = */ -1,
env,
- starlarkImportLookupFunctionForInlining);
+ bzlLoadFunctionForInlining);
} catch (NoSuchPackageException e) {
throw new PackageFunctionException(e, Transience.PERSISTENT);
} catch (InterruptedException e) {
fileSyntaxCache.invalidate(packageId);
throw e;
}
- if (importResult == null) {
+ if (loadResult == null) {
return null;
}
// From here on, either of the following must happen:
@@ -1244,8 +1236,8 @@
packageId,
buildFilePath,
file,
- importResult.loadedModules,
- importResult.fileDependencies,
+ loadResult.loadedModules,
+ loadResult.fileDependencies,
defaultVisibility,
starlarkSemantics,
globberWithSkyframeGlobDeps);
@@ -1310,12 +1302,12 @@
}
}
- /** A simple value class to store the result of the Starlark imports. */
- static final class StarlarkImportResult {
+ /** A simple value class to store the result of the Starlark loads. */
+ static final class BzlLoadResult {
final Map<String, Module> loadedModules;
final ImmutableList<Label> fileDependencies;
- private StarlarkImportResult(
+ private BzlLoadResult(
Map<String, Module> loadedModules, ImmutableList<Label> fileDependencies) {
this.loadedModules = loadedModules;
this.fileDependencies = fileDependencies;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java
index 7218385..8804524 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java
@@ -47,8 +47,7 @@
SkyFunctionName.createHermetic("AST_FILE_LOOKUP");
public static final SkyFunctionName STARLARK_BUILTINS =
SkyFunctionName.createHermetic("STARLARK_BUILTINS");
- public static final SkyFunctionName STARLARK_IMPORTS_LOOKUP =
- SkyFunctionName.createHermetic("STARLARK_IMPORTS_LOOKUP");
+ public static final SkyFunctionName BZL_LOAD = SkyFunctionName.createHermetic("BZL_LOAD");
public static final SkyFunctionName GLOB = SkyFunctionName.createHermetic("GLOB");
public static final SkyFunctionName PACKAGE = SkyFunctionName.createHermetic("PACKAGE");
static final SkyFunctionName PACKAGE_ERROR = SkyFunctionName.createHermetic("PACKAGE_ERROR");
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index a11b714..c16dffe 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -262,7 +262,7 @@
// Cache of partially constructed Package instances, stored between reruns of the PackageFunction
// (because of missing dependencies, within the same evaluate() run) to avoid loading the same
- // package twice (first time loading to find imported bzl files and declare Skyframe
+ // package twice (first time loading to find load()ed bzl files and declare Skyframe
// dependencies).
private final Cache<PackageIdentifier, LoadedPackageCacheEntry> packageFunctionCache =
newPkgFunctionCache();
@@ -270,9 +270,8 @@
private final Cache<PackageIdentifier, StarlarkFile> buildFileSyntaxCache =
newBuildFileSyntaxCache();
- // Cache of parsed bzl files, for use when we're inlining ASTFileLookupValue in
- // StarlarkImportLookupValue. See the comments in StarlarkLookupFunction for motivations and
- // details.
+ // Cache of parsed bzl files, for use when we're inlining ASTFileLookupFunction in
+ // BzlLoadFunction. See the comments in BzlLoadFunction for motivations and details.
private final Cache<Label, ASTFileLookupValue> astFileLookupValueCache =
CacheBuilder.newBuilder().build();
@@ -471,8 +470,8 @@
private ImmutableMap<SkyFunctionName, SkyFunction> skyFunctions(PackageFactory pkgFactory) {
ConfiguredRuleClassProvider ruleClassProvider =
(ConfiguredRuleClassProvider) pkgFactory.getRuleClassProvider();
- StarlarkImportLookupFunction starlarkImportLookupFunctionForInliningPackageAndWorkspaceNodes =
- getStarlarkImportLookupFunctionForInliningPackageAndWorkspaceNodes();
+ BzlLoadFunction bzlLoadFunctionForInliningPackageAndWorkspaceNodes =
+ getBzlLoadFunctionForInliningPackageAndWorkspaceNodes();
// TODO(janakr): use this semaphore to bound memory usage for SkyFunctions besides
// ConfiguredTargetFunction that may have a large temporary memory blow-up.
Semaphore cpuBoundSemaphore = new Semaphore(ResourceUsage.getAvailableProcessors());
@@ -503,9 +502,7 @@
SkyFunctions.AST_FILE_LOOKUP,
new ASTFileLookupFunction(ruleClassProvider, DigestHashFunction.getDefaultUnchecked()));
map.put(SkyFunctions.STARLARK_BUILTINS, new StarlarkBuiltinsFunction());
- map.put(
- SkyFunctions.STARLARK_IMPORTS_LOOKUP,
- newStarlarkImportLookupFunction(ruleClassProvider, pkgFactory));
+ map.put(SkyFunctions.BZL_LOAD, newBzlLoadFunction(ruleClassProvider, pkgFactory));
map.put(SkyFunctions.GLOB, newGlobFunction());
map.put(SkyFunctions.TARGET_PATTERN, new TargetPatternFunction());
map.put(SkyFunctions.PREPARE_DEPS_OF_PATTERNS, new PrepareDepsOfPatternsFunction());
@@ -541,7 +538,7 @@
packageFunctionCache,
buildFileSyntaxCache,
numPackagesLoaded,
- starlarkImportLookupFunctionForInliningPackageAndWorkspaceNodes,
+ bzlLoadFunctionForInliningPackageAndWorkspaceNodes,
packageProgress,
actionOnIOExceptionReadingBuildFile,
tracksStateForIncrementality()
@@ -586,7 +583,7 @@
ruleClassProvider,
pkgFactory,
directories,
- starlarkImportLookupFunctionForInliningPackageAndWorkspaceNodes));
+ bzlLoadFunctionForInliningPackageAndWorkspaceNodes));
map.put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction(externalPackageHelper));
map.put(
SkyFunctions.TARGET_COMPLETION,
@@ -657,14 +654,13 @@
}
@Nullable
- protected StarlarkImportLookupFunction
- getStarlarkImportLookupFunctionForInliningPackageAndWorkspaceNodes() {
+ protected BzlLoadFunction getBzlLoadFunctionForInliningPackageAndWorkspaceNodes() {
return null;
}
- protected SkyFunction newStarlarkImportLookupFunction(
+ protected SkyFunction newBzlLoadFunction(
RuleClassProvider ruleClassProvider, PackageFactory pkgFactory) {
- return StarlarkImportLookupFunction.create(
+ return BzlLoadFunction.create(
ruleClassProvider,
this.pkgFactory,
DigestHashFunction.getDefaultUnchecked(),
@@ -981,7 +977,7 @@
private static final ImmutableSet<SkyFunctionName> LOADING_TYPES =
ImmutableSet.of(
SkyFunctions.PACKAGE,
- SkyFunctions.STARLARK_IMPORTS_LOOKUP,
+ SkyFunctions.BZL_LOAD,
SkyFunctions.AST_FILE_LOOKUP,
SkyFunctions.GLOB);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsFunction.java
index 56bca62..4972250 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsFunction.java
@@ -27,7 +27,7 @@
import javax.annotation.Nullable;
// TODO(brandjon): Determine places where we need to teach Skyframe about this Skyfunction. Look for
-// special treatment of StarlarkImportLookupFunction or ASTFileLookupFunction in existing code.
+// special treatment of BzlLoadFunction or ASTFileLookupFunction in existing code.
// TODO(brandjon): Add support to StarlarkModuleCycleReporter to pretty-print cycles involving
// @builtins. Blocked on us actually loading files from @builtins.
@@ -37,8 +37,7 @@
* exported by {@code @builtins//:exports.bzl}.
*
* <p>This function has a trivial key, so there can only be one value in the build at a time. It has
- * a single dependency, on the result of evaluating the exports.bzl file to a {@link
- * StarlarkImportLookupValue}.
+ * a single dependency, on the result of evaluating the exports.bzl file to a {@link BzlLoadValue}.
*
* <p>See also the design doc:
* https://docs.google.com/document/d/1GW7UVo1s9X0cti9OMgT3ga5ozKYUWLPk9k8c4-34rC4/edit
@@ -64,12 +63,12 @@
throws StarlarkBuiltinsFunctionException, InterruptedException {
// skyKey is a singleton, unused.
- // TODO(brandjon): Replace by @builtins//:exports once StarlarkImportLookupFunction can resolve
- // the @builtins namespace.
+ // TODO(brandjon): Replace by @builtins//:exports once BzlLoadFunction can resolve the @builtins
+ // namespace.
SkyKey exportsKey =
- StarlarkImportLookupValue.packageBzlKey(
+ BzlLoadValue.packageBzlKey(
Label.parseAbsoluteUnchecked("//tools/builtins_staging:exports.bzl"));
- StarlarkImportLookupValue exportsValue = (StarlarkImportLookupValue) env.getValue(exportsKey);
+ BzlLoadValue exportsValue = (BzlLoadValue) env.getValue(exportsKey);
if (exportsValue == null) {
return null;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsValue.java
index e53db49..2cf1e44 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsValue.java
@@ -24,7 +24,7 @@
* pseudo-repository.
*
* <p>These are parsed from {@code @builtins//:exports.bzl}, but not validated until they're used by
- * {@link PackageFunction} and {@link StarlarkImportLookupFunction}.
+ * {@link PackageFunction} and {@link BzlLoadFunction}.
*/
public final class StarlarkBuiltinsValue implements SkyValue {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkModuleCycleReporter.java b/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkModuleCycleReporter.java
index 83c773d..1a53ebb 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkModuleCycleReporter.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/StarlarkModuleCycleReporter.java
@@ -33,7 +33,7 @@
public class StarlarkModuleCycleReporter implements CyclesReporter.SingleCycleReporter {
private static final Predicate<SkyKey> IS_STARLARK_MODULE_SKY_KEY =
- SkyFunctions.isSkyFunction(SkyFunctions.STARLARK_IMPORTS_LOOKUP);
+ SkyFunctions.isSkyFunction(SkyFunctions.BZL_LOAD);
private static final Predicate<SkyKey> IS_PACKAGE_SKY_KEY =
SkyFunctions.isSkyFunction(SkyFunctions.PACKAGE);
@@ -50,8 +50,8 @@
private static final Predicate<SkyKey> IS_REPOSITORY_DIRECTORY =
SkyFunctions.isSkyFunction(SkyFunctions.REPOSITORY_DIRECTORY);
- private static final Predicate<SkyKey> IS_STARLARK_IMPORTS_LOOKUP =
- SkyFunctions.isSkyFunction(SkyFunctions.STARLARK_IMPORTS_LOOKUP);
+ private static final Predicate<SkyKey> IS_BZL_LOAD =
+ SkyFunctions.isSkyFunction(SkyFunctions.BZL_LOAD);
private static final Predicate<SkyKey> IS_EXTERNAL_PACKAGE =
SkyFunctions.isSkyFunction(SkyFunctions.EXTERNAL_PACKAGE);
@@ -95,8 +95,8 @@
new Function<SkyKey, String>() {
@Override
public String apply(SkyKey input) {
- if (input.argument() instanceof StarlarkImportLookupValue.Key) {
- return ((StarlarkImportLookupValue.Key) input.argument()).getLabel().toString();
+ if (input.argument() instanceof BzlLoadValue.Key) {
+ return ((BzlLoadValue.Key) input.argument()).getLabel().toString();
} else if (input.argument() instanceof PackageIdentifier) {
return ((PackageIdentifier) input.argument()) + "/BUILD";
} else if (input.argument() instanceof WorkspaceFileValue.WorkspaceFileKey) {
@@ -158,11 +158,9 @@
StringBuilder message = new StringBuilder();
- if (Iterables.any(cycle, IS_STARLARK_IMPORTS_LOOKUP)) {
+ if (Iterables.any(cycle, IS_BZL_LOAD)) {
Label fileLabel =
- ((StarlarkImportLookupValue.Key)
- Iterables.getLast(Iterables.filter(cycle, IS_STARLARK_IMPORTS_LOOKUP)))
- .getLabel();
+ ((BzlLoadValue.Key) Iterables.getLast(Iterables.filter(cycle, IS_BZL_LOAD))).getLabel();
message.append("Failed to load Starlark extension '").append(fileLabel).append("'.\n");
}
@@ -193,11 +191,9 @@
// repositories were defined.
requestRepoDefinitions(eventHandler, repos);
return true;
- } else if (Iterables.any(cycle, IS_STARLARK_IMPORTS_LOOKUP)) {
+ } else if (Iterables.any(cycle, IS_BZL_LOAD)) {
Label fileLabel =
- ((StarlarkImportLookupValue.Key)
- Iterables.getLast(Iterables.filter(cycle, IS_STARLARK_IMPORTS_LOOKUP)))
- .getLabel();
+ ((BzlLoadValue.Key) Iterables.getLast(Iterables.filter(cycle, IS_BZL_LOAD))).getLabel();
eventHandler.handle(
Event.error(null, "Failed to load Starlark extension '" + fileLabel + "'.\n"));
return true;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java
index 0edfd38..4188a18 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java
@@ -26,7 +26,7 @@
import com.google.devtools.build.lib.packages.WorkspaceFactory;
import com.google.devtools.build.lib.packages.WorkspaceFileValue;
import com.google.devtools.build.lib.packages.WorkspaceFileValue.WorkspaceFileKey;
-import com.google.devtools.build.lib.skyframe.PackageFunction.StarlarkImportResult;
+import com.google.devtools.build.lib.skyframe.PackageFunction.BzlLoadResult;
import com.google.devtools.build.lib.syntax.Module;
import com.google.devtools.build.lib.syntax.Mutability;
import com.google.devtools.build.lib.syntax.StarlarkFile;
@@ -45,18 +45,18 @@
private final PackageFactory packageFactory;
private final BlazeDirectories directories;
private final RuleClassProvider ruleClassProvider;
- private final StarlarkImportLookupFunction starlarkImportLookupFunctionForInlining;
+ private final BzlLoadFunction bzlLoadFunctionForInlining;
private static final PackageIdentifier rootPackage = PackageIdentifier.createInMainRepo("");
public WorkspaceFileFunction(
RuleClassProvider ruleClassProvider,
PackageFactory packageFactory,
BlazeDirectories directories,
- StarlarkImportLookupFunction starlarkImportLookupFunctionForInlining) {
+ BzlLoadFunction bzlLoadFunctionForInlining) {
this.packageFactory = packageFactory;
this.directories = directories;
this.ruleClassProvider = ruleClassProvider;
- this.starlarkImportLookupFunctionForInlining = starlarkImportLookupFunctionForInlining;
+ this.bzlLoadFunctionForInlining = bzlLoadFunctionForInlining;
}
@Override
@@ -84,7 +84,7 @@
return new WorkspaceFileValue(
/* pkg = */ builder.build(),
/* loadedModules = */ ImmutableMap.<String, Module>of(),
- /* importToChunkMap = */ ImmutableMap.<String, Integer>of(),
+ /* loadToChunkMap = */ ImmutableMap.<String, Integer>of(),
/* bindings = */ ImmutableMap.<String, Object>of(),
workspaceFile,
/* idx = */ 0, // first fragment
@@ -123,19 +123,19 @@
prevValue.getPackage(), prevValue.getLoadedModules(), prevValue.getBindings());
}
StarlarkFile ast = workspaceASTValue.getASTs().get(key.getIndex());
- StarlarkImportResult importResult =
- PackageFunction.fetchImportsFromBuildFile(
+ BzlLoadResult loadResult =
+ PackageFunction.fetchLoadsFromBuildFile(
workspaceFile,
rootPackage,
/*repoMapping=*/ ImmutableMap.of(),
ast,
key.getIndex(),
env,
- starlarkImportLookupFunctionForInlining);
- if (importResult == null) {
+ bzlLoadFunctionForInlining);
+ if (loadResult == null) {
return null;
}
- parser.execute(ast, importResult.loadedModules, key);
+ parser.execute(ast, loadResult.loadedModules, key);
} catch (NoSuchPackageException e) {
throw new WorkspaceFileFunctionException(e, Transience.PERSISTENT);
} catch (NameConflictException e) {
@@ -146,7 +146,7 @@
return new WorkspaceFileValue(
builder.build(),
parser.getLoadedModules(),
- createImportToChunkMap(prevValue, parser, key),
+ createLoadToChunkMap(prevValue, parser, key),
parser.getVariableBindings(),
workspaceFile,
key.getIndex(),
@@ -159,10 +159,11 @@
}
/**
- * This returns a map from import statement to the chunk the
- * import statement originated from.
+ * This returns a map from load statement to the chunk the load statement originated from.
*
- * For example, if the WORKSPACE file looked like the following:
+ * <p>For example, if the WORKSPACE file looked like the following:
+ *
+ * <pre>
* load(":a.bzl", "a")
* x = 0
* load(":b.bzl", "b")
@@ -170,12 +171,13 @@
* load(":a.bzl", "a1")
* load(":c.bzl", "c")
* x = 2
+ * </pre>
*
- * Then the map for chunk 0 would be: {@code {":a.bzl" : 0}}
- * for chunk 1 would be: {@code {":a.bzl" : 0, ":b.bzl" : 1}}
- * for chunk 2 would be: {@code {":a.bzl" : 0, ":b.bzl" : 1, ":c.bzl" : 2}}
+ * Then the map for chunk 0 would be {@code {":a.bzl" : 0}}, for chunk 1 it'd be: {@code {":a.bzl"
+ * : 0, ":b.bzl" : 1}}, and for chunk 2 it'd be: {@code {":a.bzl" : 0, ":b.bzl" : 1, ":c.bzl" :
+ * 2}}
*/
- private ImmutableMap<String, Integer> createImportToChunkMap(
+ private static ImmutableMap<String, Integer> createLoadToChunkMap(
WorkspaceFileValue prevValue, WorkspaceFactory parser, WorkspaceFileKey key) {
ImmutableMap.Builder<String, Integer> builder = new ImmutableMap.Builder<String, Integer>();
if (prevValue == null) {
@@ -183,9 +185,9 @@
builder.put(loadString, key.getIndex());
}
} else {
- builder.putAll(prevValue.getImportToChunkMap());
+ builder.putAll(prevValue.getLoadToChunkMap());
for (String label : parser.getLoadedModules().keySet()) {
- if (!prevValue.getImportToChunkMap().containsKey(label)) {
+ if (!prevValue.getLoadToChunkMap().containsKey(label)) {
builder.put(label, key.getIndex());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java b/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java
index d8fd5d6..25e2735 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java
@@ -45,6 +45,7 @@
import com.google.devtools.build.lib.repository.ExternalPackageHelper;
import com.google.devtools.build.lib.skyframe.ASTFileLookupFunction;
import com.google.devtools.build.lib.skyframe.BlacklistedPackagePrefixesFunction;
+import com.google.devtools.build.lib.skyframe.BzlLoadFunction;
import com.google.devtools.build.lib.skyframe.ContainingPackageLookupFunction;
import com.google.devtools.build.lib.skyframe.ExternalFilesHelper;
import com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction;
@@ -66,7 +67,6 @@
import com.google.devtools.build.lib.skyframe.PrecomputedValue;
import com.google.devtools.build.lib.skyframe.RepositoryMappingFunction;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
-import com.google.devtools.build.lib.skyframe.StarlarkImportLookupFunction;
import com.google.devtools.build.lib.skyframe.WorkspaceASTFunction;
import com.google.devtools.build.lib.skyframe.WorkspaceFileFunction;
import com.google.devtools.build.lib.skyframe.WorkspaceNameFunction;
@@ -444,8 +444,8 @@
SkyFunctions.AST_FILE_LOOKUP,
new ASTFileLookupFunction(ruleClassProvider, digestHashFunction))
.put(
- SkyFunctions.STARLARK_IMPORTS_LOOKUP,
- StarlarkImportLookupFunction.create(
+ SkyFunctions.BZL_LOAD,
+ BzlLoadFunction.create(
ruleClassProvider,
pkgFactory,
digestHashFunction,
@@ -455,10 +455,7 @@
.put(
WorkspaceFileValue.WORKSPACE_FILE,
new WorkspaceFileFunction(
- ruleClassProvider,
- pkgFactory,
- directories,
- /*starlarkImportLookupFunctionForInlining=*/ null))
+ ruleClassProvider, pkgFactory, directories, /*bzlLoadFunctionForInlining=*/ null))
.put(SkyFunctions.EXTERNAL_PACKAGE, new ExternalPackageFunction(getExternalPackageHelper()))
.put(SkyFunctions.REPOSITORY_MAPPING, new RepositoryMappingFunction())
.put(
@@ -470,7 +467,7 @@
packageFunctionCache,
astCache,
/*numPackagesLoaded=*/ new AtomicInteger(0),
- /*starlarkImportLookupFunctionForInlining=*/ null,
+ /*bzlLoadFunctionForInlining=*/ null,
/*packageProgress=*/ null,
getActionOnIOExceptionReadingBuildFile(),
// Tell PackageFunction to optimize for our use-case of no incrementality.
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
index 0c3c3bf..edaf815 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java
@@ -55,7 +55,7 @@
return flow;
}
- // Hack for StarlarkImportLookupFunction's "export" semantics.
+ // Hack for BzlLoadFunction's "export" semantics.
// We enable it only for statements outside any function (isToplevelFunction)
// and outside any if- or for- statements (!indented).
if (isToplevelFunction && !indented && fr.thread.postAssignHook != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
index 5320e0f..c7c5d0e 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
@@ -350,9 +350,8 @@
* Specifies a hook function to be run after each assignment at top level.
*
* <p>This is a short-term hack to allow us to consolidate all StarlarkFile execution in one place
- * even while StarlarkImportLookupFunction implements the old "export" behavior, in which rules,
- * aspects and providers are "exported" as soon as they are assigned, not at the end of file
- * execution.
+ * even while BzlLoadFunction implements the old "export" behavior, in which rules, aspects and
+ * providers are "exported" as soon as they are assigned, not at the end of file execution.
*/
public void setPostAssignHook(PostAssignHook postAssignHook) {
this.postAssignHook = postAssignHook;
diff --git a/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageHelperTest.java b/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageHelperTest.java
index 65d28f9..44921cb 100644
--- a/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageHelperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageHelperTest.java
@@ -152,7 +152,7 @@
.getPackageFactoryBuilderForTesting(directories)
.build(ruleClassProvider, fileSystem),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null));
+ /*bzlLoadFunctionForInlining=*/ null));
skyFunctions.put(
SkyFunctions.PACKAGE,
new PackageFunction(
diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java
index 5903414..aea10f1 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java
@@ -42,6 +42,7 @@
import com.google.devtools.build.lib.skyframe.ASTFileLookupFunction;
import com.google.devtools.build.lib.skyframe.BazelSkyframeExecutorConstants;
import com.google.devtools.build.lib.skyframe.BlacklistedPackagePrefixesFunction;
+import com.google.devtools.build.lib.skyframe.BzlLoadFunction;
import com.google.devtools.build.lib.skyframe.ContainingPackageLookupFunction;
import com.google.devtools.build.lib.skyframe.ExternalFilesHelper;
import com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction;
@@ -56,7 +57,6 @@
import com.google.devtools.build.lib.skyframe.PrecomputedFunction;
import com.google.devtools.build.lib.skyframe.PrecomputedValue;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
-import com.google.devtools.build.lib.skyframe.StarlarkImportLookupFunction;
import com.google.devtools.build.lib.skyframe.WorkspaceASTFunction;
import com.google.devtools.build.lib.skyframe.WorkspaceFileFunction;
import com.google.devtools.build.lib.skylarkbuildapi.repository.RepositoryBootstrap;
@@ -185,7 +185,7 @@
ruleClassProvider,
pkgFactory,
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null))
+ /*bzlLoadFunctionForInlining=*/ null))
.put(SkyFunctions.REPOSITORY, new RepositoryLoaderFunction())
.put(
SkyFunctions.LOCAL_REPOSITORY_LOOKUP,
@@ -200,8 +200,8 @@
SkyFunctions.AST_FILE_LOOKUP,
new ASTFileLookupFunction(ruleClassProvider, fileSystem.getDigestFunction()))
.put(
- SkyFunctions.STARLARK_IMPORTS_LOOKUP,
- StarlarkImportLookupFunction.create(
+ SkyFunctions.BZL_LOAD,
+ BzlLoadFunction.create(
ruleClassProvider,
pkgFactory,
fileSystem.getDigestFunction(),
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java
index 95472e0..1452078 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java
@@ -128,7 +128,7 @@
.builder(directories)
.build(TestRuleClassProvider.getRuleClassProvider(), fs),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null))
+ /*bzlLoadFunctionForInlining=*/ null))
.put(
SkyFunctions.EXTERNAL_PACKAGE,
new ExternalPackageFunction(
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD
index 34b6e36..40aaf3a 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD
@@ -171,8 +171,8 @@
"//src/main/java/com/google/devtools/build/lib/skyframe:broken_diff_awareness_exception",
"//src/main/java/com/google/devtools/build/lib/skyframe:build_configuration_value",
"//src/main/java/com/google/devtools/build/lib/skyframe:builder",
- "//src/main/java/com/google/devtools/build/lib/skyframe:cached_starlark_import_lookup_value_and_deps",
- "//src/main/java/com/google/devtools/build/lib/skyframe:cached_starlark_import_lookup_value_and_deps_builder_factory",
+ "//src/main/java/com/google/devtools/build/lib/skyframe:cached_bzl_load_value_and_deps",
+ "//src/main/java/com/google/devtools/build/lib/skyframe:cached_bzl_load_value_and_deps_builder_factory",
"//src/main/java/com/google/devtools/build/lib/skyframe:collect_packages_under_directory_value",
"//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_and_data",
"//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_key",
@@ -215,7 +215,7 @@
"//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions",
"//src/main/java/com/google/devtools/build/lib/skyframe:skyframe_aware_action",
"//src/main/java/com/google/devtools/build/lib/skyframe:skyframe_cluster",
- "//src/main/java/com/google/devtools/build/lib/skyframe:starlark_import_lookup_value",
+ "//src/main/java/com/google/devtools/build/lib/skyframe:bzl_load_value",
"//src/main/java/com/google/devtools/build/lib/skyframe:target_pattern_phase_value",
"//src/main/java/com/google/devtools/build/lib/skyframe:tests_for_target_pattern_value",
"//src/main/java/com/google/devtools/build/lib/skyframe:top_down_action_cache",
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/BzlLoadFunctionTest.java
similarity index 80%
rename from src/test/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupFunctionTest.java
rename to src/test/java/com/google/devtools/build/lib/skyframe/BzlLoadFunctionTest.java
index e7a4639..4413886 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/BzlLoadFunctionTest.java
@@ -27,7 +27,7 @@
import com.google.devtools.build.lib.packages.StarlarkSemanticsOptions;
import com.google.devtools.build.lib.pkgcache.PackageOptions;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
-import com.google.devtools.build.lib.skyframe.StarlarkImportLookupFunction.StarlarkImportFailedException;
+import com.google.devtools.build.lib.skyframe.BzlLoadFunction.BzlLoadFailedException;
import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils;
import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor;
import com.google.devtools.build.lib.vfs.FileStatus;
@@ -50,9 +50,9 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Tests for StarlarkImportLookupFunction. */
+/** Tests for BzlLoadFunction. */
@RunWith(JUnit4.class)
-public class StarlarkImportLookupFunctionTest extends BuildViewTestCase {
+public class BzlLoadFunctionTest extends BuildViewTestCase {
@Override
protected FileSystem createFileSystem() {
return new CustomInMemoryFs();
@@ -80,7 +80,7 @@
}
@Test
- public void testStarlarkImportLabels() throws Exception {
+ public void testBzlLoadLabels() throws Exception {
scratch.file("pkg1/BUILD");
scratch.file("pkg1/ext.bzl");
checkSuccessfulLookup("//pkg1:ext.bzl");
@@ -95,14 +95,14 @@
}
@Test
- public void testStarlarkImportLabelsAlternativeRoot() throws Exception {
+ public void testBzlLoadLabelsAlternativeRoot() throws Exception {
scratch.file("/root_2/pkg4/BUILD");
scratch.file("/root_2/pkg4/ext.bzl");
checkSuccessfulLookup("//pkg4:ext.bzl");
}
@Test
- public void testStarlarkImportLabelsMultipleBuildFiles() throws Exception {
+ public void testBzlLoadLabelsMultipleBuildFiles() throws Exception {
scratch.file("dir1/BUILD");
scratch.file("dir1/dir2/BUILD");
scratch.file("dir1/dir2/ext.bzl");
@@ -166,39 +166,37 @@
checkSuccessfulLookup("//pkg:subdir/ext2.bzl");
}
- private EvaluationResult<StarlarkImportLookupValue> get(SkyKey starlarkImportLookupKey)
- throws Exception {
- EvaluationResult<StarlarkImportLookupValue> result =
+ private EvaluationResult<BzlLoadValue> get(SkyKey skyKey) throws Exception {
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
- getSkyframeExecutor(), starlarkImportLookupKey, /*keepGoing=*/ false, reporter);
+ getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter);
if (result.hasError()) {
- fail(result.getError(starlarkImportLookupKey).getException().getMessage());
+ fail(result.getError(skyKey).getException().getMessage());
}
return result;
}
private static SkyKey key(String label) {
- return StarlarkImportLookupValue.packageBzlKey(Label.parseAbsoluteUnchecked(label));
+ return BzlLoadValue.packageBzlKey(Label.parseAbsoluteUnchecked(label));
}
// Ensures that a Starlark file has been successfully processed by checking that the
// the label in its dependency set corresponds to the requested label.
private void checkSuccessfulLookup(String label) throws Exception {
- SkyKey starlarkImportLookupKey = key(label);
- EvaluationResult<StarlarkImportLookupValue> result = get(starlarkImportLookupKey);
- assertThat(label)
- .isEqualTo(result.get(starlarkImportLookupKey).getDependency().getLabel().toString());
+ SkyKey skyKey = key(label);
+ EvaluationResult<BzlLoadValue> result = get(skyKey);
+ assertThat(label).isEqualTo(result.get(skyKey).getDependency().getLabel().toString());
}
@Test
- public void testStarlarkImportLookupNoBuildFile() throws Exception {
+ public void testBzlLoadNoBuildFile() throws Exception {
scratch.file("pkg/ext.bzl", "");
- SkyKey starlarkImportLookupKey = key("//pkg:ext.bzl");
- EvaluationResult<StarlarkImportLookupValue> result =
+ SkyKey skyKey = key("//pkg:ext.bzl");
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
- getSkyframeExecutor(), starlarkImportLookupKey, /*keepGoing=*/ false, reporter);
+ getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter);
assertThat(result.hasError()).isTrue();
- ErrorInfo errorInfo = result.getError(starlarkImportLookupKey);
+ ErrorInfo errorInfo = result.getError(skyKey);
String errorMessage = errorInfo.getException().getMessage();
assertThat(errorMessage)
.contains(
@@ -206,32 +204,31 @@
}
@Test
- public void testStarlarkImportLookupNoBuildFileForLoad() throws Exception {
+ public void testBzlLoadNoBuildFileForLoad() throws Exception {
scratch.file("pkg2/BUILD");
scratch.file("pkg1/ext.bzl", "a = 1");
scratch.file("pkg2/ext.bzl", "load('//pkg1:ext.bzl', 'a')");
- SkyKey starlarkImportLookupKey = key("//pkg:ext.bzl");
- EvaluationResult<StarlarkImportLookupValue> result =
+ SkyKey skyKey = key("//pkg:ext.bzl");
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
- getSkyframeExecutor(), starlarkImportLookupKey, /*keepGoing=*/ false, reporter);
+ getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter);
assertThat(result.hasError()).isTrue();
- ErrorInfo errorInfo = result.getError(starlarkImportLookupKey);
+ ErrorInfo errorInfo = result.getError(skyKey);
String errorMessage = errorInfo.getException().getMessage();
assertThat(errorMessage).contains("Every .bzl file must have a corresponding package");
}
@Test
- public void testStarlarkImportFilenameWithControlChars() throws Exception {
+ public void testBzlLoadFilenameWithControlChars() throws Exception {
scratch.file("pkg/BUILD", "");
scratch.file("pkg/ext.bzl", "load('//pkg:oops\u0000.bzl', 'a')");
- SkyKey starlarkImportLookupKey = key("//pkg:ext.bzl");
+ SkyKey skyKey = key("//pkg:ext.bzl");
AssertionError e =
assertThrows(
AssertionError.class,
() ->
SkyframeExecutorTestUtils.evaluate(
- getSkyframeExecutor(), starlarkImportLookupKey, /*keepGoing=*/ false,
- reporter));
+ getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter));
String errorMessage = e.getMessage();
assertThat(errorMessage)
.contains(
@@ -256,15 +253,15 @@
RootedPath.toRootedPath(
Root.fromPath(p.getParentDirectory()), PathFragment.create("WORKSPACE"));
- SkyKey starlarkImportLookupKey =
- StarlarkImportLookupValue.workspaceBzlKey(
+ SkyKey skyKey =
+ BzlLoadValue.workspaceBzlKey(
Label.parseAbsoluteUnchecked("@a_remote_repo//remote_pkg:ext.bzl"),
/* inWorkspace= */
/* workspaceChunk= */ 0,
rootedPath);
- EvaluationResult<StarlarkImportLookupValue> result =
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
- getSkyframeExecutor(), starlarkImportLookupKey, /*keepGoing=*/ false, reporter);
+ getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter);
assertThat(result.hasError()).isFalse();
}
@@ -333,17 +330,17 @@
// checkStrayLabel checks that execution of target fails because
// the label of its load statement strays into a subpackage.
private void checkStrayLabel(String target, String expectedMessage) throws InterruptedException {
- SkyKey starlarkImportLookupKey = key(target);
- EvaluationResult<StarlarkImportLookupValue> result =
+ SkyKey skyKey = key(target);
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
- getSkyframeExecutor(), starlarkImportLookupKey, /*keepGoing=*/ false, reporter);
+ getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter);
assertThat(result.hasError()).isTrue();
assertThatEvaluationResult(result)
- .hasErrorEntryForKeyThat(starlarkImportLookupKey)
+ .hasErrorEntryForKeyThat(skyKey)
.hasExceptionThat()
- .isInstanceOf(StarlarkImportFailedException.class);
+ .isInstanceOf(BzlLoadFailedException.class);
assertThatEvaluationResult(result)
- .hasErrorEntryForKeyThat(starlarkImportLookupKey)
+ .hasErrorEntryForKeyThat(skyKey)
.hasExceptionThat()
.hasMessageThat()
.contains(expectedMessage);
@@ -354,17 +351,17 @@
throws Exception {
scratch.file("BUILD", "load(\"@repository//dir:file.bzl\", \"foo\")");
- SkyKey starlarkImportLookupKey = key("@repository//dir:file.bzl");
- EvaluationResult<StarlarkImportLookupValue> result =
+ SkyKey skyKey = key("@repository//dir:file.bzl");
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
- getSkyframeExecutor(), starlarkImportLookupKey, /*keepGoing=*/ false, reporter);
+ getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter);
assertThat(result.hasError()).isTrue();
assertThatEvaluationResult(result)
- .hasErrorEntryForKeyThat(starlarkImportLookupKey)
+ .hasErrorEntryForKeyThat(skyKey)
.hasExceptionThat()
- .isInstanceOf(StarlarkImportFailedException.class);
+ .isInstanceOf(BzlLoadFailedException.class);
assertThatEvaluationResult(result)
- .hasErrorEntryForKeyThat(starlarkImportLookupKey)
+ .hasErrorEntryForKeyThat(skyKey)
.hasExceptionThat()
.hasMessageThat()
.contains(
@@ -399,16 +396,14 @@
Root root = Root.fromPath(p.getParentDirectory());
RootedPath rootedPath = RootedPath.toRootedPath(root, PathFragment.create("WORKSPACE"));
- SkyKey starlarkImportLookupKey =
- StarlarkImportLookupValue.workspaceBzlKey(
- Label.parseAbsoluteUnchecked("@a//:a.bzl"), 1, rootedPath);
+ SkyKey skyKey =
+ BzlLoadValue.workspaceBzlKey(Label.parseAbsoluteUnchecked("@a//:a.bzl"), 1, rootedPath);
- EvaluationResult<StarlarkImportLookupValue> result =
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
- getSkyframeExecutor(), starlarkImportLookupKey, /*keepGoing=*/ false, reporter);
+ getSkyframeExecutor(), skyKey, /*keepGoing=*/ false, reporter);
- assertThat(result.get(starlarkImportLookupKey).getModule().getGlobals())
- .containsEntry("a_symbol", 5);
+ assertThat(result.get(skyKey).getModule().getGlobals()).containsEntry("a_symbol", 5);
}
@Test
@@ -418,7 +413,7 @@
fs.badPathForRead = scratch.file("a/a1.bzl", "doesntmatter");
SkyKey key = key("//a:a1.bzl");
- EvaluationResult<StarlarkImportLookupValue> result =
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
getSkyframeExecutor(), key, /*keepGoing=*/ false, reporter);
assertThatEvaluationResult(result).hasErrorEntryForKeyThat(key).isTransient();
@@ -432,7 +427,7 @@
fs.badPathForRead = scratch.file("a/a2.bzl", "doesntmatter");
SkyKey key = key("//a:a1.bzl");
- EvaluationResult<StarlarkImportLookupValue> result =
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
getSkyframeExecutor(), key, /*keepGoing=*/ false, reporter);
assertThatEvaluationResult(result).hasErrorEntryForKeyThat(key).isNotTransient();
@@ -445,7 +440,7 @@
fs.badPathForStat = scratch.file("a/a1.bzl", "doesntmatter");
SkyKey key = key("//a:a1.bzl");
- EvaluationResult<StarlarkImportLookupValue> result =
+ EvaluationResult<BzlLoadValue> result =
SkyframeExecutorTestUtils.evaluate(
getSkyframeExecutor(), key, /*keepGoing=*/ false, reporter);
assertThatEvaluationResult(result).hasErrorEntryForKeyThat(key).isNotTransient();
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupKeyCodecTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/BzlLoadKeyCodecTest.java
similarity index 82%
rename from src/test/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupKeyCodecTest.java
rename to src/test/java/com/google/devtools/build/lib/skyframe/BzlLoadKeyCodecTest.java
index 7b016f6..5b5a101 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/StarlarkImportLookupKeyCodecTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/BzlLoadKeyCodecTest.java
@@ -21,17 +21,16 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Tests for {@link StarlarkImportLookupKey_AutoCodec}. */
+/** Tests for BzlLoadValue key's autocodec. */
@RunWith(JUnit4.class)
-public final class StarlarkImportLookupKeyCodecTest {
+public final class BzlLoadKeyCodecTest {
@Test
public void testCodec() throws Exception {
SerializationTester serializationTester =
new SerializationTester(
- StarlarkImportLookupValue.packageBzlKey(
- Label.parseAbsolute("//foo/bar:baz", ImmutableMap.of())),
- StarlarkImportLookupValue.workspaceBzlKey(
+ BzlLoadValue.packageBzlKey(Label.parseAbsolute("//foo/bar:baz", ImmutableMap.of())),
+ BzlLoadValue.workspaceBzlKey(
Label.parseAbsolute("//foo/bar:baz", ImmutableMap.of()),
/*workspaceChunk=*/ 4,
/*workspacePath=*/ FsUtils.TEST_ROOTED_PATH));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/CachedStarlarkImportLookupValueAndDepsTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/CachedBzlLoadValueAndDepsTest.java
similarity index 65%
rename from src/test/java/com/google/devtools/build/lib/skyframe/CachedStarlarkImportLookupValueAndDepsTest.java
rename to src/test/java/com/google/devtools/build/lib/skyframe/CachedBzlLoadValueAndDepsTest.java
index 8de0210..30bfc7c 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/CachedStarlarkImportLookupValueAndDepsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/CachedBzlLoadValueAndDepsTest.java
@@ -28,12 +28,12 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Tests for {@link CachedStarlarkImportLookupValueAndDeps}. */
+/** Tests for {@link CachedBzlLoadValueAndDeps}. */
@RunWith(JUnit4.class)
-public class CachedStarlarkImportLookupValueAndDepsTest {
+public class CachedBzlLoadValueAndDepsTest {
@Test
public void testDepsAreNotVisitedMultipleTimesForDiamondDependencies() throws Exception {
- // Graph structure of StarlarkImportLookupValues:
+ // Graph structure of BzlLoadValues:
//
// p
// / \
@@ -41,52 +41,51 @@
// \ /
// gc
- StarlarkImportLookupValue dummyValue = mock(StarlarkImportLookupValue.class);
- CachedStarlarkImportLookupValueAndDepsBuilderFactory
- cachedStarlarkImportLookupValueAndDepsBuilderFactory =
- new CachedStarlarkImportLookupValueAndDepsBuilderFactory();
+ BzlLoadValue dummyValue = mock(BzlLoadValue.class);
+ CachedBzlLoadValueAndDepsBuilderFactory cachedBzlLoadValueAndDepsBuilderFactory =
+ new CachedBzlLoadValueAndDepsBuilderFactory();
- StarlarkImportLookupValue.Key gcKey = createStarlarkKey("//gc");
+ BzlLoadValue.Key gcKey = createStarlarkKey("//gc");
SkyKey gcKey1 = createKey("gc key1");
SkyKey gcKey2 = createKey("gc key2");
SkyKey gcKey3 = createKey("gc key3");
- CachedStarlarkImportLookupValueAndDeps gc =
- cachedStarlarkImportLookupValueAndDepsBuilderFactory
- .newCachedStarlarkImportLookupValueAndDepsBuilder()
+ CachedBzlLoadValueAndDeps gc =
+ cachedBzlLoadValueAndDepsBuilderFactory
+ .newCachedBzlLoadValueAndDepsBuilder()
.addDep(gcKey1)
.addDeps(ImmutableList.of(gcKey2, gcKey3))
.setKey(gcKey)
.setValue(dummyValue)
.build();
- StarlarkImportLookupValue.Key c1Key = createStarlarkKey("//c1");
+ BzlLoadValue.Key c1Key = createStarlarkKey("//c1");
SkyKey c1Key1 = createKey("c1 key1");
- CachedStarlarkImportLookupValueAndDeps c1 =
- cachedStarlarkImportLookupValueAndDepsBuilderFactory
- .newCachedStarlarkImportLookupValueAndDepsBuilder()
+ CachedBzlLoadValueAndDeps c1 =
+ cachedBzlLoadValueAndDepsBuilderFactory
+ .newCachedBzlLoadValueAndDepsBuilder()
.addDep(c1Key1)
.addTransitiveDeps(gc)
.setValue(dummyValue)
.setKey(c1Key)
.build();
- StarlarkImportLookupValue.Key c2Key = createStarlarkKey("//c2");
+ BzlLoadValue.Key c2Key = createStarlarkKey("//c2");
SkyKey c2Key1 = createKey("c2 key1");
SkyKey c2Key2 = createKey("c2 key2");
- CachedStarlarkImportLookupValueAndDeps c2 =
- cachedStarlarkImportLookupValueAndDepsBuilderFactory
- .newCachedStarlarkImportLookupValueAndDepsBuilder()
+ CachedBzlLoadValueAndDeps c2 =
+ cachedBzlLoadValueAndDepsBuilderFactory
+ .newCachedBzlLoadValueAndDepsBuilder()
.addDeps(ImmutableList.of(c2Key1, c2Key2))
.addTransitiveDeps(gc)
.setValue(dummyValue)
.setKey(c2Key)
.build();
- StarlarkImportLookupValue.Key pKey = createStarlarkKey("//p");
+ BzlLoadValue.Key pKey = createStarlarkKey("//p");
SkyKey pKey1 = createKey("p key1");
- CachedStarlarkImportLookupValueAndDeps p =
- cachedStarlarkImportLookupValueAndDepsBuilderFactory
- .newCachedStarlarkImportLookupValueAndDepsBuilder()
+ CachedBzlLoadValueAndDeps p =
+ cachedBzlLoadValueAndDepsBuilderFactory
+ .newCachedBzlLoadValueAndDepsBuilder()
.addDep(pKey1)
.addTransitiveDeps(c1)
.addTransitiveDeps(c2)
@@ -95,8 +94,7 @@
.build();
List<Iterable<SkyKey>> registeredDeps = new ArrayList<>();
- Map<StarlarkImportLookupValue.Key, CachedStarlarkImportLookupValueAndDeps>
- visitedDepsInToplevelLoad = new HashMap<>();
+ Map<BzlLoadValue.Key, CachedBzlLoadValueAndDeps> visitedDepsInToplevelLoad = new HashMap<>();
p.traverse(registeredDeps::add, visitedDepsInToplevelLoad);
assertThat(registeredDeps)
@@ -127,7 +125,7 @@
};
}
- private static StarlarkImportLookupValue.Key createStarlarkKey(String name) {
- return StarlarkImportLookupValue.packageBzlKey(Label.parseAbsoluteUnchecked(name));
+ private static BzlLoadValue.Key createStarlarkKey(String name) {
+ return BzlLoadValue.packageBzlKey(Label.parseAbsoluteUnchecked(name));
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java
index 0ab1f82..ab98e0e 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java
@@ -139,7 +139,7 @@
.getPackageFactoryBuilderForTesting(directories)
.build(ruleClassProvider, fileSystem),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null));
+ /*bzlLoadFunctionForInlining=*/ null));
skyFunctions.put(
SkyFunctions.EXTERNAL_PACKAGE,
new ExternalPackageFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
index 6bb55df..1874dca 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
@@ -186,7 +186,7 @@
.builder(directories)
.build(ruleClassProvider, fs),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null))
+ /*bzlLoadFunctionForInlining=*/ null))
.put(
SkyFunctions.EXTERNAL_PACKAGE,
new ExternalPackageFunction(
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
index 2732dc1..dd58b95 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
@@ -170,7 +170,7 @@
.builder(directories)
.build(TestRuleClassProvider.getRuleClassProvider(), fs),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null));
+ /*bzlLoadFunctionForInlining=*/ null));
skyFunctions.put(
SkyFunctions.EXTERNAL_PACKAGE,
new ExternalPackageFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java
index 3ced1a8..5140f3e 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java
@@ -198,7 +198,7 @@
.getPackageFactoryBuilderForTesting(directories)
.build(ruleClassProvider, fs),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null));
+ /*bzlLoadFunctionForInlining=*/ null));
skyFunctions.put(
SkyFunctions.EXTERNAL_PACKAGE,
new ExternalPackageFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java
index 1c1c999..87ba175 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java
@@ -117,7 +117,7 @@
.getPackageFactoryBuilderForTesting(directories)
.build(ruleClassProvider, fileSystem),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null));
+ /*bzlLoadFunctionForInlining=*/ null));
skyFunctions.put(
SkyFunctions.EXTERNAL_PACKAGE,
new ExternalPackageFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java
index 08c0f64..0618e7f 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java
@@ -147,7 +147,7 @@
.getPackageFactoryBuilderForTesting(directories)
.build(ruleClassProvider, fileSystem),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null));
+ /*bzlLoadFunctionForInlining=*/ null));
skyFunctions.put(
SkyFunctions.EXTERNAL_PACKAGE,
new ExternalPackageFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java
index 316efdb..6192d6c 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java
@@ -173,7 +173,7 @@
.getPackageFactoryBuilderForTesting(directories)
.build(ruleClassProvider, fileSystem),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null));
+ /*bzlLoadFunctionForInlining=*/ null));
skyFunctions.put(
SkyFunctions.EXTERNAL_PACKAGE,
new ExternalPackageFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsFunctionTest.java
index 62dcc23..6847bc5 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/StarlarkBuiltinsFunctionTest.java
@@ -30,7 +30,7 @@
/**
* Tests for {@link StarlarkBuiltinsFunction}, and {@code @builtins} resolution behavior in {@link
- * {@link StarlarkImportLookupFunction}.
+ * {@link BzlLoadFunction}.
*/
@RunWith(JUnit4.class)
public class StarlarkBuiltinsFunctionTest extends BuildViewTestCase {
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java
index e3cf371..427a132 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java
@@ -261,7 +261,7 @@
.builder(directories)
.build(TestRuleClassProvider.getRuleClassProvider(), fileSystem),
directories,
- /*starlarkImportLookupFunctionForInlining=*/ null))
+ /*bzlLoadFunctionForInlining=*/ null))
.put(
SkyFunctions.EXTERNAL_PACKAGE,
new ExternalPackageFunction(
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java
index aeca3c9..f87afe0 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java
@@ -133,10 +133,7 @@
TestRuleClassProvider.getRuleClassProvider(true);
workspaceSkyFunc =
new WorkspaceFileFunction(
- ruleClassProvider,
- pkgFactory,
- directories,
- /*starlarkImportLookupFunctionForInlining=*/ null);
+ ruleClassProvider, pkgFactory, directories, /*bzlLoadFunctionForInlining=*/ null);
externalSkyFunc =
new ExternalPackageFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER);
astSkyFunc = new WorkspaceASTFunction(ruleClassProvider);
@@ -246,7 +243,7 @@
}
@Test
- public void testImportToChunkMapSimple() throws Exception {
+ public void testLoadToChunkMapSimple() throws Exception {
scratch.file("a.bzl", "a = 'a'");
scratch.file("b.bzl", "b = 'b'");
scratch.file("BUILD", "");
@@ -260,17 +257,17 @@
SkyKey key1 = WorkspaceFileValue.key(workspace, 1);
EvaluationResult<WorkspaceFileValue> result1 = eval(key1);
WorkspaceFileValue value1 = result1.get(key1);
- assertThat(value1.getImportToChunkMap()).containsEntry("//:a.bzl", 1);
+ assertThat(value1.getLoadToChunkMap()).containsEntry("//:a.bzl", 1);
SkyKey key2 = WorkspaceFileValue.key(workspace, 2);
EvaluationResult<WorkspaceFileValue> result2 = eval(key2);
WorkspaceFileValue value2 = result2.get(key2);
- assertThat(value2.getImportToChunkMap()).containsEntry("//:a.bzl", 1);
- assertThat(value2.getImportToChunkMap()).containsEntry("//:b.bzl", 2);
+ assertThat(value2.getLoadToChunkMap()).containsEntry("//:a.bzl", 1);
+ assertThat(value2.getLoadToChunkMap()).containsEntry("//:b.bzl", 2);
}
@Test
- public void testImportToChunkMapDoesNotOverrideDuplicate() throws Exception {
+ public void testLoadToChunkMapDoesNotOverrideDuplicate() throws Exception {
scratch.file("a.bzl", "a = 'a'");
scratch.file("BUILD", "");
RootedPath workspace =
@@ -283,13 +280,13 @@
SkyKey key1 = WorkspaceFileValue.key(workspace, 1);
EvaluationResult<WorkspaceFileValue> result1 = eval(key1);
WorkspaceFileValue value1 = result1.get(key1);
- assertThat(value1.getImportToChunkMap()).containsEntry("//:a.bzl", 1);
+ assertThat(value1.getLoadToChunkMap()).containsEntry("//:a.bzl", 1);
SkyKey key2 = WorkspaceFileValue.key(workspace, 2);
EvaluationResult<WorkspaceFileValue> result2 = eval(key2);
WorkspaceFileValue value2 = result2.get(key2);
- assertThat(value2.getImportToChunkMap()).containsEntry("//:a.bzl", 1);
- assertThat(value2.getImportToChunkMap()).doesNotContainEntry("//:a.bzl", 2);
+ assertThat(value2.getLoadToChunkMap()).containsEntry("//:a.bzl", 1);
+ assertThat(value2.getLoadToChunkMap()).doesNotContainEntry("//:a.bzl", 2);
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/StarlarkIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/skylark/StarlarkIntegrationTest.java
index 1ed71e2..7a7d311 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/StarlarkIntegrationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/StarlarkIntegrationTest.java
@@ -52,10 +52,10 @@
import com.google.devtools.build.lib.packages.StructImpl;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.objc.ObjcProvider;
+import com.google.devtools.build.lib.skyframe.BzlLoadFunction;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
import com.google.devtools.build.lib.skyframe.PackageFunction;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
-import com.google.devtools.build.lib.skyframe.StarlarkImportLookupFunction;
import com.google.devtools.build.lib.syntax.NoneType;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.Starlark;
@@ -1505,7 +1505,7 @@
}
@Test
- public void testMultipleImportsOfSameRule() throws Exception {
+ public void testMultipleLoadsOfSameRule() throws Exception {
scratch.file("test/skylark/BUILD");
scratch.file(
"test/skylark/extension.bzl",
@@ -1545,7 +1545,7 @@
}
@Test
- public void testImportInStarlark() throws Exception {
+ public void testLoadInStarlark() throws Exception {
scratch.file("test/skylark/implementation.bzl", "def custom_rule_impl(ctx):", " return None");
scratch.file(
@@ -1594,7 +1594,7 @@
}
@Test
- public void testRecursiveImport() throws Exception {
+ public void testRecursiveLoad() throws Exception {
scratch.file("test/skylark/ext2.bzl", "load('//test/skylark:ext1.bzl', 'symbol2')");
scratch.file("test/skylark/ext1.bzl", "load('//test/skylark:ext2.bzl', 'symbol1')");
@@ -1615,7 +1615,7 @@
}
@Test
- public void testRecursiveImport2() throws Exception {
+ public void testRecursiveLoad2() throws Exception {
scratch.file("test/skylark/ext1.bzl", "load('//test/skylark:ext2.bzl', 'symbol2')");
scratch.file("test/skylark/ext2.bzl", "load('//test/skylark:ext3.bzl', 'symbol3')");
scratch.file("test/skylark/ext3.bzl", "load('//test/skylark:ext4.bzl', 'symbol4')");
@@ -2952,19 +2952,17 @@
ImmutableMap<SkyFunctionName, ? extends SkyFunction> skyFunctions =
((InMemoryMemoizingEvaluator) getSkyframeExecutor().getEvaluatorForTesting())
.getSkyFunctionsForTesting();
- StarlarkImportLookupFunction starlarkImportLookupFunction =
- StarlarkImportLookupFunction.createForInliningSelfForPackageAndWorkspaceNodes(
- this.getRuleClassProvider(),
- this.getPackageFactory(),
- /*starlarkImportLookupValueCacheSize=*/ 2);
- starlarkImportLookupFunction.resetSelfInliningCache();
+ BzlLoadFunction bzlLoadFunction =
+ BzlLoadFunction.createForInliningSelfForPackageAndWorkspaceNodes(
+ this.getRuleClassProvider(), this.getPackageFactory(), /*bzlLoadValueCacheSize=*/ 2);
+ bzlLoadFunction.resetSelfInliningCache();
((PackageFunction) skyFunctions.get(SkyFunctions.PACKAGE))
- .setStarlarkImportLookupFunctionForInliningForTesting(starlarkImportLookupFunction);
+ .setBzlLoadFunctionForInliningForTesting(bzlLoadFunction);
}
@Override
@Test
- public void testRecursiveImport() throws Exception {
+ public void testRecursiveLoad() throws Exception {
scratch.file("test/skylark/ext2.bzl", "load('//test/skylark:ext1.bzl', 'symbol2')");
scratch.file("test/skylark/ext1.bzl", "load('//test/skylark:ext2.bzl', 'symbol1')");
@@ -2980,12 +2978,12 @@
BuildFileContainsErrorsException.class, () -> getTarget("//test/skylark:rule"));
assertThat(e)
.hasMessageThat()
- .contains("Starlark import cycle: [//test/skylark:ext1.bzl, //test/skylark:ext2.bzl]");
+ .contains("Starlark load cycle: [//test/skylark:ext1.bzl, //test/skylark:ext2.bzl]");
}
@Override
@Test
- public void testRecursiveImport2() throws Exception {
+ public void testRecursiveLoad2() throws Exception {
scratch.file("test/skylark/ext1.bzl", "load('//test/skylark:ext2.bzl', 'symbol2')");
scratch.file("test/skylark/ext2.bzl", "load('//test/skylark:ext3.bzl', 'symbol3')");
scratch.file("test/skylark/ext3.bzl", "load('//test/skylark:ext4.bzl', 'symbol4')");
@@ -3003,7 +3001,7 @@
assertThat(e)
.hasMessageThat()
.contains(
- "Starlark import cycle: [//test/skylark:ext2.bzl, "
+ "Starlark load cycle: [//test/skylark:ext2.bzl, "
+ "//test/skylark:ext3.bzl, //test/skylark:ext4.bzl]");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/StarlarkRuleClassFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/StarlarkRuleClassFunctionsTest.java
index ec72f3f..089115e 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/StarlarkRuleClassFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/StarlarkRuleClassFunctionsTest.java
@@ -49,7 +49,7 @@
import com.google.devtools.build.lib.packages.StructImpl;
import com.google.devtools.build.lib.packages.StructProvider;
import com.google.devtools.build.lib.packages.Type;
-import com.google.devtools.build.lib.skyframe.StarlarkImportLookupFunction;
+import com.google.devtools.build.lib.skyframe.BzlLoadFunction;
import com.google.devtools.build.lib.skylark.util.BazelEvaluationTestCase;
import com.google.devtools.build.lib.syntax.ClassObject;
import com.google.devtools.build.lib.syntax.Dict;
@@ -776,7 +776,7 @@
if (!file.ok()) {
throw new SyntaxError.Exception(file.errors());
}
- StarlarkImportLookupFunction.execAndExport(
+ BzlLoadFunction.execAndExport(
file, FAKE_LABEL, ev.getEventHandler(), module, ev.getStarlarkThread());
}