public class ModernBuildRule<T extends Buildable> extends AbstractBuildRule implements SupportsInputBasedRuleKey
Deps, outputs, inputs and rulekeys are derived from the fields of the Buildable
.
For simple ModernBuildRules (e.g. those that don't have any fields that can't be added to the
rulekey), the build rule class itself can (and should) implement Buildable. In this case, the
constructor taking a Class<T>
should be used.
Example:
class WriteData extends ModernBuildRule<WriteData> implements Buildable {
final String data;
public WriteData(
SourcePathRuleFinder ruleFinder,
BuildTarget buildTarget,
ProjectFilesystem projectFilesystem,
String data) {
super(buildTarget, projectFilesystem, ruleFinder, WriteData.class);
this.data = data;
}
...
}
Some BuildRules contain more information than just that added to the rulekey and used for getBuildSteps(). For these rules, the part used for getBuildSteps should be split out into its own implementation of Buildable.
Example:
class CopyData extends ModernBuildRule<CopyData.Impl> implements Buildable {
BuildRule other;
public WriteData(
SourcePathRuleFinder ruleFinder,
BuildTarget buildTarget,
ProjectFilesystem projectFilesystem,
BuildRule other) {
super(buildTarget, projectFilesystem, ruleFinder, new Impl("hello"));
this.other = other;
}
private static class Impl implements Buildable {
...
}
...
}
Modifier | Constructor and Description |
---|---|
protected |
ModernBuildRule(BuildTarget buildTarget,
ProjectFilesystem filesystem,
SourcePathRuleFinder finder,
Class<T> clazz) |
protected |
ModernBuildRule(BuildTarget buildTarget,
ProjectFilesystem filesystem,
SourcePathRuleFinder ruleFinder,
T buildable) |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(BuildRule that) |
T |
getBuildable() |
protected static DefaultBuildCellRelativePathFactory |
getBuildCellPathFactory(BuildContext context,
ProjectFilesystem filesystem,
OutputPathResolver outputPathResolver) |
com.google.common.collect.ImmutableSortedSet<BuildRule> |
getBuildDeps() |
com.google.common.collect.ImmutableList<Step> |
getBuildSteps(BuildContext context,
BuildableContext buildableContext) |
OutputPathResolver |
getOutputPathResolver()
This field could be used unsafely, most ModernBuildRule should never need this directly and it
should only be used within the getBuildSteps() call.
|
static void |
getSetupStepsForBuildable(BuildContext context,
ProjectFilesystem filesystem,
Iterable<Path> outputs,
com.google.common.collect.ImmutableList.Builder<Step> stepBuilder,
OutputPathResolver outputPathResolver)
Gets the steps for preparing the output directories of the build rule.
|
protected BuildTargetSourcePath |
getSourcePath(OutputPath outputPath)
This should only be exposed to implementations of the ModernBuildRule, not of the Buildable.
|
protected com.google.common.collect.ImmutableSortedSet<SourcePath> |
getSourcePaths(Collection<OutputPath> outputPaths)
Same as
getSourcePath(com.facebook.buck.rules.modern.OutputPath) , but takes multiple OutputPath instances and returns
multiple SourcePath instances. |
SourcePath |
getSourcePathToOutput() |
static void |
injectFieldsIfNecessary(ProjectFilesystem filesystem,
BuildTarget target,
Buildable buildable,
SourcePathRuleFinder ruleFinder)
Allows injecting the AbstractBuildRule fields into a Buildable after construction.
|
boolean |
inputBasedRuleKeyIsEnabled() |
void |
recordOutputs(BuildableContext buildableContext)
Records the outputs of this buildrule.
|
static <T extends AddsToRuleKey> |
recordOutputs(BuildableContext buildableContext,
OutputPathResolver outputPathResolver,
ClassInfo<T> classInfo,
T buildable)
Records the outputs of this buildrule.
|
static <T extends AddsToRuleKey> |
recordOutputs(BuildableContext buildableContext,
OutputPathResolver outputPathResolver,
T buildable)
Records the outputs of this buildrule.
|
static <T extends Buildable> |
stepsForBuildable(BuildContext context,
T buildable,
ProjectFilesystem filesystem,
BuildTarget buildTarget)
Return the steps for a buildable.
|
static <T extends Buildable> |
stepsForBuildable(BuildContext context,
T buildable,
ProjectFilesystem filesystem,
BuildTarget buildTarget,
Iterable<Path> outputs)
Returns the build steps for the Buildable.
|
void |
updateBuildRuleResolver(BuildRuleResolver ruleResolver)
Updates the BuildRuleResolver and associated objects for this build rule.
|
equals, getBuildTarget, getDependencies, getProjectFilesystem, getSourcePathOutputs, getType, hasBuildSteps, hashCode, injectFields, isCacheable, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isSupported
getBuildTarget, getFullyQualifiedName, getProjectFilesystem, hasBuildSteps, isCacheable, outputFileCanBeCopied, shouldRespectInputSizeLimitForRemoteExecution, toString
getDependencies, getSourcePathOutputs
getType
protected ModernBuildRule(BuildTarget buildTarget, ProjectFilesystem filesystem, SourcePathRuleFinder finder, Class<T> clazz)
protected ModernBuildRule(BuildTarget buildTarget, ProjectFilesystem filesystem, SourcePathRuleFinder ruleFinder, T buildable)
public static void injectFieldsIfNecessary(ProjectFilesystem filesystem, BuildTarget target, Buildable buildable, SourcePathRuleFinder ruleFinder)
public final T getBuildable()
@Nullable public SourcePath getSourcePathToOutput()
getSourcePathToOutput
in interface BuildRule
public OutputPathResolver getOutputPathResolver()
public void updateBuildRuleResolver(BuildRuleResolver ruleResolver)
BuildRule
Build rules sometimes hold field references to build rule resolvers. If this build rule is to be cached, it must update its BuildRuleResolver when a new action graph is constructed to avoid leaking the entire action graph it was originally associated with.
updateBuildRuleResolver
in interface BuildRule
updateBuildRuleResolver
in class AbstractBuildRule
public final boolean inputBasedRuleKeyIsEnabled()
inputBasedRuleKeyIsEnabled
in interface SupportsInputBasedRuleKey
protected final BuildTargetSourcePath getSourcePath(OutputPath outputPath)
protected final com.google.common.collect.ImmutableSortedSet<SourcePath> getSourcePaths(Collection<OutputPath> outputPaths)
getSourcePath(com.facebook.buck.rules.modern.OutputPath)
, but takes multiple OutputPath
instances and returns
multiple SourcePath
instances.public final com.google.common.collect.ImmutableSortedSet<BuildRule> getBuildDeps()
getBuildDeps
in interface BuildRule
deps
argument for this build rule in the build file in which it was defined.
However, there are special cases where other arguments pull in implicit dependencies
(e.g., the keystore
argument in android_binary
). In these cases, the
implicit dependencies are also included in the set returned by this method. The value of
the original deps
argument, as defined in the build file, must be accessed via a
custom getter provided by the build rule.
public final com.google.common.collect.ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext)
getBuildSteps
in interface BuildRule
public static <T extends Buildable> com.google.common.collect.ImmutableList<Step> stepsForBuildable(BuildContext context, T buildable, ProjectFilesystem filesystem, BuildTarget buildTarget, Iterable<Path> outputs)
protected static DefaultBuildCellRelativePathFactory getBuildCellPathFactory(BuildContext context, ProjectFilesystem filesystem, OutputPathResolver outputPathResolver)
public static void getSetupStepsForBuildable(BuildContext context, ProjectFilesystem filesystem, Iterable<Path> outputs, com.google.common.collect.ImmutableList.Builder<Step> stepBuilder, OutputPathResolver outputPathResolver)
public static <T extends Buildable> com.google.common.collect.ImmutableList<Step> stepsForBuildable(BuildContext context, T buildable, ProjectFilesystem filesystem, BuildTarget buildTarget)
public void recordOutputs(BuildableContext buildableContext)
public static <T extends AddsToRuleKey> void recordOutputs(BuildableContext buildableContext, OutputPathResolver outputPathResolver, ClassInfo<T> classInfo, T buildable)
public static <T extends AddsToRuleKey> void recordOutputs(BuildableContext buildableContext, OutputPathResolver outputPathResolver, T buildable)