use of com.facebook.buck.rules.AbstractBuildRule in project buck by facebook.
the class AppleTestDescription method getXctool.
private Optional<SourcePath> getXctool(BuildRuleParams params, BuildRuleResolver resolver) {
// can use that directly.
if (appleConfig.getXctoolZipTarget().isPresent()) {
final BuildRule xctoolZipBuildRule = resolver.getRule(appleConfig.getXctoolZipTarget().get());
BuildTarget unzipXctoolTarget = BuildTarget.builder(xctoolZipBuildRule.getBuildTarget()).addFlavors(UNZIP_XCTOOL_FLAVOR).build();
final Path outputDirectory = BuildTargets.getGenPath(params.getProjectFilesystem(), unzipXctoolTarget, "%s/unzipped");
if (!resolver.getRuleOptional(unzipXctoolTarget).isPresent()) {
BuildRuleParams unzipXctoolParams = params.withBuildTarget(unzipXctoolTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(xctoolZipBuildRule)), Suppliers.ofInstance(ImmutableSortedSet.of()));
resolver.addToIndex(new AbstractBuildRule(unzipXctoolParams) {
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(outputDirectory);
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory), new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(Preconditions.checkNotNull(xctoolZipBuildRule.getSourcePathToOutput())), outputDirectory));
}
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), outputDirectory);
}
});
}
return Optional.of(new ExplicitBuildTargetSourcePath(unzipXctoolTarget, outputDirectory.resolve("bin/xctool")));
} else if (appleConfig.getXctoolPath().isPresent()) {
return Optional.of(new PathSourcePath(params.getProjectFilesystem(), appleConfig.getXctoolPath().get()));
} else {
return Optional.empty();
}
}
use of com.facebook.buck.rules.AbstractBuildRule in project buck by facebook.
the class DefaultRuleKeyFactory method addDepsToRuleKey.
private void addDepsToRuleKey(BuildRule buildRule, RuleKeyObjectSink sink) {
if (buildRule instanceof AbstractBuildRule) {
// TODO(marcinkosiba): We really need to get rid of declared/extra deps in rules. Instead
// rules should explicitly take the needed sub-sets of deps as constructor args.
AbstractBuildRule abstractBuildRule = (AbstractBuildRule) buildRule;
sink.setReflectively("buck.extraDeps", abstractBuildRule.deprecatedGetExtraDeps());
sink.setReflectively("buck.declaredDeps", abstractBuildRule.getDeclaredDeps());
} else {
sink.setReflectively("buck.deps", buildRule.getDeps());
}
}
use of com.facebook.buck.rules.AbstractBuildRule in project buck by facebook.
the class PrebuiltJarDescription method createGwtModule.
@VisibleForTesting
static BuildRule createGwtModule(BuildRuleParams params, Arg arg) {
// Because a PrebuiltJar rarely requires any building whatsoever (it could if the source_jar
// is a BuildTargetSourcePath), we make the PrebuiltJar a dependency of the GWT module. If this
// becomes a performance issue in practice, then we will explore reducing the dependencies of
// the GWT module.
final SourcePath input;
if (arg.gwtJar.isPresent()) {
input = arg.gwtJar.get();
} else if (arg.sourceJar.isPresent()) {
input = arg.sourceJar.get();
} else {
input = arg.binaryJar;
}
class ExistingOuputs extends AbstractBuildRule {
@AddToRuleKey
private final SourcePath source;
private final Path output;
protected ExistingOuputs(BuildRuleParams params, SourcePath source) {
super(params);
this.source = source;
BuildTarget target = params.getBuildTarget();
this.output = BuildTargets.getGenPath(getProjectFilesystem(), target, String.format("%s/%%s-gwt.jar", target.getShortName()));
}
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(context.getSourcePathResolver().getRelativePath(getSourcePathToOutput()));
ImmutableList.Builder<Step> steps = ImmutableList.builder();
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), output.getParent()));
steps.add(CopyStep.forFile(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(source), output));
return steps.build();
}
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), output);
}
}
return new ExistingOuputs(params, input);
}
Aggregations