use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class AppleDescriptions method createBuildRulesForSceneKitAssetsDependencies.
public static Optional<SceneKitAssets> createBuildRulesForSceneKitAssetsDependencies(TargetGraph targetGraph, BuildRuleParams params, AppleCxxPlatform appleCxxPlatform) {
TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());
ImmutableSet<AppleWrapperResourceArg> sceneKitAssetsArgs = AppleBuildRules.collectTransitiveBuildRules(targetGraph, Optional.empty(), AppleBuildRules.SCENEKIT_ASSETS_DESCRIPTION_CLASSES, ImmutableList.of(targetNode));
BuildRuleParams sceneKitAssetsParams = params.withAppendedFlavor(SceneKitAssets.FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
if (sceneKitAssetsArgs.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(new SceneKitAssets(sceneKitAssetsParams, appleCxxPlatform, sceneKitAssetsArgs.stream().map(input -> new PathSourcePath(params.getProjectFilesystem(), input.path)).collect(MoreCollectors.toImmutableSet())));
}
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class PrebuiltJarDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, args.binaryJar);
}
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule prebuilt = new PrebuiltJar(params, pathResolver, args.binaryJar, args.sourceJar, args.gwtJar, args.javadocUrl, args.mavenCoords, args.provided.orElse(false));
UnflavoredBuildTarget prebuiltJarBuildTarget = params.getBuildTarget().checkUnflavored();
BuildTarget flavoredBuildTarget = BuildTargets.createFlavoredBuildTarget(prebuiltJarBuildTarget, JavaLibrary.GWT_MODULE_FLAVOR);
BuildRuleParams gwtParams = params.withBuildTarget(flavoredBuildTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(prebuilt)), Suppliers.ofInstance(ImmutableSortedSet.of()));
BuildRule gwtModule = createGwtModule(gwtParams, args);
resolver.addToIndex(gwtModule);
return prebuilt;
}
use of com.facebook.buck.rules.BuildRuleParams 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);
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class KotlinLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
BuildTarget target = params.getBuildTarget();
// creating the action graph from the target graph.
if (CalculateAbi.isAbiTarget(target)) {
BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
BuildRule libraryRule = resolver.requireRule(libraryTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
}
ImmutableSortedSet<Flavor> flavors = target.getFlavors();
BuildRuleParams paramsWithMavenFlavor = null;
if (flavors.contains(JavaLibrary.MAVEN_JAR)) {
paramsWithMavenFlavor = params;
// Maven rules will depend upon their vanilla versions, so the latter have to be constructed
// without the maven flavor to prevent output-path conflict
params = params.withoutFlavor(JavaLibrary.MAVEN_JAR);
}
if (flavors.contains(JavaLibrary.SRC_JAR)) {
args.mavenCoords = args.mavenCoords.map(input -> AetherUtil.addClassifier(input, AetherUtil.CLASSIFIER_SOURCES));
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return new JavaSourceJar(params, args.srcs, args.mavenCoords);
} else {
return MavenUberJar.SourceJar.create(Preconditions.checkNotNull(paramsWithMavenFlavor), args.srcs, args.mavenCoords, args.mavenPomTemplate);
}
}
JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps))), ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))));
DefaultKotlinLibrary defaultKotlinLibrary = new DefaultKotlinLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), Optional.empty(), Optional.empty(), ImmutableList.of(), exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), false, ImmutableSet.of(), new KotlincToJarStepFactory(kotlinBuckConfig.getKotlinCompiler().get(), args.extraKotlincArguments), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, args.removeClasses);
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return defaultKotlinLibrary;
} else {
return MavenUberJar.create(defaultKotlinLibrary, Preconditions.checkNotNull(paramsWithMavenFlavor), args.mavenCoords, args.mavenPomTemplate);
}
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class KotlinTestDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
BuildTarget testTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
BuildRule testRule = resolver.requireRule(testTarget);
return CalculateAbi.of(testTarget, ruleFinder, params, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
}
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
JavacOptions javacOptions = JavacOptionsFactory.create(templateJavacOptions, params, resolver, ruleFinder, args);
KotlincToJarStepFactory stepFactory = new KotlincToJarStepFactory(kotlinBuckConfig.getKotlinCompiler().get(), args.extraKotlincArguments);
BuildRuleParams testsLibraryParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps)))).addAll(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))).build()), params.getExtraDeps()).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
JavaLibrary testsLibrary = resolver.addToIndex(new DefaultKotlinLibrary(testsLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), templateJavacOptions.getGeneratedSourceFolderName(), Optional.empty(), /* proguardConfig */
ImmutableList.of(), /* postprocessClassesCommands */
ImmutableSortedSet.of(), /* exportedDeps */
ImmutableSortedSet.of(), /* providedDeps */
JavaLibraryRules.getAbiInputs(resolver, testsLibraryParams.getDeps()), false, /* trackClassUsage */
ImmutableSet.of(), /* additionalClasspathEntries */
stepFactory, args.resourcesRoot, args.manifestFile, args.mavenCoords, ImmutableSortedSet.of(), /* tests */
ImmutableSet.of()));
return new KotlinTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, testsLibrary, ImmutableSet.<Either<SourcePath, Path>>of(kotlinBuckConfig.getPathToRuntimeJar()), args.labels, args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(), args.vmArgs, ImmutableMap.of(), /* nativeLibsEnvironment */
args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs, args.env, args.getRunTestSeparately(), args.getForkMode(), args.stdOutLogLevel, args.stdErrLogLevel);
}
Aggregations