Skip to content

Commit

Permalink
Implement materializer functions for dormant dependencies.
Browse files Browse the repository at this point in the history
RELNOTES[NEW]: Dormant dependencies and materializer functions are now available with the --experimental_dormant_deps flag.

PiperOrigin-RevId: 676716164
Change-Id: I539f647cbdec99ae0f4f4d8c3107c3dff7321256
  • Loading branch information
lberki authored and copybara-github committed Sep 20, 2024
1 parent 439e7e1 commit 9d6afc3
Show file tree
Hide file tree
Showing 15 changed files with 582 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.devtools.build.lib.analysis.config.Fragment;
import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.analysis.starlark.StarlarkMaterializingLateBoundDefault;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Aspect;
import com.google.devtools.build.lib.packages.AspectClass;
Expand Down Expand Up @@ -414,6 +415,12 @@ private static <T> void resolveAttribute(
? computedDefault.getDefault(attributeMap)
: defaultValue);
}
} else if (attribute.isLateBound()
&& attribute.getLateBoundDefault() instanceof StarlarkMaterializingLateBoundDefault<?, ?>) {
// These attributes are resolved by calling the materializer function in
// DependencyMapProducer. The reason is that they need the analyzed versions some direct
// dependencies and we can't do that here.
outgoingLabels.put(dependencyKind, null);
} else if (attribute.isLateBound()) {
attributeValue =
type.cast(resolveLateBoundDefault(rule, attributeMap, attribute, ruleConfig));
Expand Down Expand Up @@ -454,12 +461,16 @@ static <FragmentT> Object resolveLateBoundDefault(
rule,
attributeMap,
fragmentClass.cast(ruleConfig),
/* ctx= */ null,
/* analysisContext= */ null,
/* eventHandler= */ null);
}
if (Void.class.equals(fragmentClass)) {
return lateBoundDefault.resolve(
rule, attributeMap, /* input= */ null, /* ctx= */ null, /* eventHandler= */ null);
rule,
attributeMap,
/* input= */ null,
/* analysisContext= */ null,
/* eventHandler= */ null);
}
@SuppressWarnings("unchecked")
FragmentT fragment =
Expand All @@ -468,7 +479,7 @@ static <FragmentT> Object resolveLateBoundDefault(
return null;
}
return lateBoundDefault.resolve(
rule, attributeMap, fragment, /* ctx= */ null, /* eventHandler= */ null);
rule, attributeMap, fragment, /* analysisContext= */ null, /* eventHandler= */ null);
} catch (EvalException e) {
// Materializers should not be called here and those are the only kind of late-bound defaults
// that can throw these exceptions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:platform_configuration",
"//src/main/java/com/google/devtools/build/lib/analysis:platform_options",
"//src/main/java/com/google/devtools/build/lib/analysis:starlark/starlark_build_settings_details_value",
"//src/main/java/com/google/devtools/build/lib/analysis:starlark/starlark_materializing_late_bound_default",
"//src/main/java/com/google/devtools/build/lib/analysis:starlark/starlark_transition",
"//src/main/java/com/google/devtools/build/lib/analysis:target_and_configuration",
"//src/main/java/com/google/devtools/build/lib/analysis:toolchain_collection",
Expand All @@ -62,6 +63,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto",
"//src/main/java/com/google/devtools/build/lib/causes",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/collect",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/packages",
Expand All @@ -87,6 +89,7 @@ java_library(
"//src/main/java/com/google/devtools/build/skyframe",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//src/main/java/com/google/devtools/common/options",
"//src/main/java/net/starlark/java/eval",
"//src/main/java/net/starlark/java/syntax",
"//src/main/protobuf:failure_details_java_proto",
"//third_party:auto_value",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.devtools.build.lib.analysis.InvalidVisibilityDependencyException;
import com.google.devtools.build.lib.analysis.config.DependencyEvaluationException;
import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory.TransitionCreationException;
import com.google.devtools.build.lib.analysis.producers.DependencyMapProducer.MaterializerException;
import com.google.devtools.build.lib.analysis.starlark.StarlarkTransition.TransitionException;
import com.google.devtools.build.lib.skyframe.AspectCreationException;
import com.google.devtools.build.lib.skyframe.config.PlatformMappingException;
Expand All @@ -35,6 +36,7 @@ public abstract class DependencyError {
public enum Kind {
DEPENDENCY_OPTIONS_PARSING,
DEPENDENCY_TRANSITION,
MATERIALIZER,
INVALID_VISIBILITY,
/** An error occurred either computing the aspect collection or merging the aspect values. */
ASPECT_EVALUATION,
Expand All @@ -54,6 +56,8 @@ public enum Kind {

public abstract TransitionException dependencyTransition();

public abstract MaterializerException materializer();

public abstract InvalidVisibilityDependencyException invalidVisibility();

public abstract DependencyEvaluationException aspectEvaluation();
Expand All @@ -75,6 +79,7 @@ public Exception getException() {
return switch (kind()) {
case DEPENDENCY_OPTIONS_PARSING -> dependencyOptionsParsing();
case DEPENDENCY_TRANSITION -> dependencyTransition();
case MATERIALIZER -> materializer();
case INVALID_VISIBILITY -> invalidVisibility();
case ASPECT_EVALUATION -> aspectEvaluation();
case ASPECT_CREATION -> aspectCreation();
Expand All @@ -92,6 +97,10 @@ static DependencyError of(OptionsParsingException e) {
return AutoOneOf_DependencyError.dependencyOptionsParsing(e);
}

static DependencyError of(MaterializerException e) {
return AutoOneOf_DependencyError.materializer(e);
}

static DependencyError of(InvalidVisibilityDependencyException e) {
return AutoOneOf_DependencyError.invalidVisibility(e);
}
Expand Down
Loading

0 comments on commit 9d6afc3

Please sign in to comment.