use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class JavaLibraryDescription 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();
// We know that the flavour we're being asked to create is valid, since the check is done when
// creating the action graph from the target graph.
ImmutableSortedSet<Flavor> flavors = target.getFlavors();
if (flavors.contains(Javadoc.DOC_JAR)) {
BuildTarget unflavored = BuildTarget.of(target.getUnflavoredBuildTarget());
BuildRule baseLibrary = resolver.requireRule(unflavored);
JarShape shape = params.getBuildTarget().getFlavors().contains(JavaLibrary.MAVEN_JAR) ? JarShape.MAVEN : JarShape.SINGLE;
JarShape.Summary summary = shape.gatherDeps(baseLibrary);
ImmutableSet<SourcePath> sources = summary.getPackagedRules().stream().filter(HasSources.class::isInstance).map(rule -> ((HasSources) rule).getSources()).flatMap(Collection::stream).collect(MoreCollectors.toImmutableSet());
// In theory, the only deps we need are the ones that contribute to the sourcepaths. However,
// javadoc wants to have classes being documented have all their deps be available somewhere.
// Ideally, we'd not build everything, but then we're not able to document any classes that
// rely on auto-generated classes, such as those created by the Immutables library. Oh well.
// Might as well add them as deps. *sigh*
ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder();
// Sourcepath deps
deps.addAll(ruleFinder.filterBuildRuleInputs(sources));
// Classpath deps
deps.add(baseLibrary);
deps.addAll(summary.getClasspath().stream().filter(rule -> HasClasspathEntries.class.isAssignableFrom(rule.getClass())).flatMap(rule -> rule.getTransitiveClasspathDeps().stream()).iterator());
BuildRuleParams emptyParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(deps.build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
return new Javadoc(emptyParams, args.mavenCoords, args.mavenPomTemplate, summary.getMavenDeps(), sources);
}
if (CalculateAbi.isAbiTarget(target)) {
BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(target);
BuildRule libraryRule = resolver.requireRule(libraryTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
}
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))));
DefaultJavaLibrary defaultJavaLibrary = new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), javacOptions.getGeneratedSourceFolderName(), args.proguardConfig, args.postprocessClassesCommands, exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), javacOptions.trackClassUsage(), /* additionalClasspathEntries */
ImmutableSet.of(), new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, javacOptions.getClassesToRemoveFromJar());
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return defaultJavaLibrary;
} else {
resolver.addToIndex(defaultJavaLibrary);
return MavenUberJar.create(defaultJavaLibrary, Preconditions.checkNotNull(paramsWithMavenFlavor), args.mavenCoords, args.mavenPomTemplate);
}
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class ReactNativeLibraryGraphEnhancer method enhanceForAndroid.
public AndroidReactNativeLibrary enhanceForAndroid(BuildRuleParams params, BuildRuleResolver resolver, AndroidReactNativeLibraryDescription.Args args) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
BuildTarget originalBuildTarget = params.getBuildTarget();
ReactNativeBundle bundle = createReactNativeBundle(params, resolver, ruleFinder, BuildTarget.builder(originalBuildTarget).addFlavors(REACT_NATIVE_BUNDLE_FLAVOR).build(), args, ReactNativePlatform.ANDROID);
resolver.addToIndex(bundle);
ImmutableList.Builder<BuildRule> extraDeps = ImmutableList.builder();
extraDeps.add(bundle);
if (args.rDotJavaPackage.isPresent()) {
BuildRuleParams paramsForResource = params.withAppendedFlavor(REACT_NATIVE_ANDROID_RES_FLAVOR).copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(bundle)));
SourcePath resources = new ExplicitBuildTargetSourcePath(bundle.getBuildTarget(), bundle.getResources());
BuildRule resource = new AndroidResource(paramsForResource, ruleFinder, /* deps */
ImmutableSortedSet.of(), resources, /* resSrcs */
ImmutableSortedMap.of(), args.rDotJavaPackage.get(), /* assets */
null, /* assetsSrcs */
ImmutableSortedMap.of(), /* manifest */
null, /* hasWhitelistedStrings */
false);
resolver.addToIndex(resource);
extraDeps.add(resource);
}
return new AndroidReactNativeLibrary(params.copyAppendingExtraDeps(extraDeps.build()), bundle);
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class JsLibraryDescription method changePathPrefix.
private static Path changePathPrefix(SourcePath sourcePath, String basePath, BuildRuleParams params, SourcePathResolver sourcePathResolver, UnflavoredBuildTarget target) {
final Path directoryOfBuildFile = target.getCellPath().resolve(target.getBasePath());
final Path transplantTo = MorePaths.normalize(directoryOfBuildFile.resolve(basePath));
final Path absolutePath = sourcePathResolver.getPathSourcePath(sourcePath).map(// for sub paths, replace the leading directory with the base path
pathSourcePath -> transplantTo.resolve(MorePaths.relativize(directoryOfBuildFile, sourcePathResolver.getAbsolutePath(sourcePath)))).orElse(// build target output paths are replaced completely
transplantTo);
return params.getProjectFilesystem().getPathRelativeToProjectRoot(absolutePath).orElseThrow(() -> new HumanReadableException("%s: Using '%s' as base path for '%s' would move the file " + "out of the project root.", target, basePath, sourcePathResolver.getRelativePath(sourcePath)));
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class JsLibraryDescription method createDevFileRule.
private static <A extends Arg> BuildRule createDevFileRule(BuildRuleParams params, SourcePathRuleFinder ruleFinder, SourcePathResolver sourcePathResolver, A args, Either<SourcePath, Pair<SourcePath, String>> source, WorkerTool worker) {
final SourcePath sourcePath = source.transform(x -> x, Pair::getFirst);
final Optional<String> subPath = Optional.ofNullable(source.transform(x -> null, Pair::getSecond));
final Optional<Path> virtualPath = args.basePath.map(basePath -> changePathPrefix(sourcePath, basePath, params, sourcePathResolver, params.getBuildTarget().getUnflavoredBuildTarget()).resolve(subPath.orElse("")));
return new JsFile.JsFileDev(ruleFinder.getRule(sourcePath).map(params::copyAppendingExtraDeps).orElse(params), sourcePath, subPath, virtualPath, args.extraArgs, worker);
}
use of com.facebook.buck.rules.BuildRuleParams in project buck by facebook.
the class GroovyLibraryDescription 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 libraryTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
BuildRule libraryRule = resolver.requireRule(libraryTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
}
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps))));
JavacOptions javacOptions = JavacOptionsFactory.create(defaultJavacOptions, params, resolver, ruleFinder, args).withAbiGenerationMode(JavacOptions.AbiGenerationMode.CLASS);
return new DefaultJavaLibrary(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()), /* trackClassUsage */
false, /* additionalClasspathEntries */
ImmutableSet.of(), new GroovycToJarStepFactory(groovyBuckConfig.getGroovyCompiler().get(), Optional.of(args.extraGroovycArguments), javacOptions), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, args.removeClasses);
}
Aggregations