use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class JavaLibraryRules method getAbiInputs.
public static ImmutableSortedSet<SourcePath> getAbiInputs(BuildRuleResolver resolver, Iterable<BuildRule> inputs) throws NoSuchBuildTargetException {
ImmutableSortedSet.Builder<SourcePath> abiRules = ImmutableSortedSet.naturalOrder();
for (BuildRule dep : inputs) {
if (dep instanceof HasJavaAbi) {
Optional<BuildTarget> abiJarTarget = ((HasJavaAbi) dep).getAbiJar();
if (abiJarTarget.isPresent()) {
BuildRule abiJarRule = resolver.requireRule(abiJarTarget.get());
abiRules.add(Preconditions.checkNotNull(abiJarRule.getSourcePathToOutput()));
}
}
}
return abiRules.build();
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class JavacOptionsFactory method create.
public static JavacOptions create(JavacOptions defaultOptions, BuildRuleParams params, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, JvmLibraryArg jvmLibraryArg) {
if ((jvmLibraryArg.source.isPresent() || jvmLibraryArg.target.isPresent()) && jvmLibraryArg.javaVersion.isPresent()) {
throw new HumanReadableException("Please set either source and target or java_version.");
}
JavacOptions.Builder builder = JavacOptions.builder(defaultOptions);
if (jvmLibraryArg.javaVersion.isPresent()) {
builder.setSourceLevel(jvmLibraryArg.javaVersion.get());
builder.setTargetLevel(jvmLibraryArg.javaVersion.get());
}
if (jvmLibraryArg.source.isPresent()) {
builder.setSourceLevel(jvmLibraryArg.source.get());
}
if (jvmLibraryArg.target.isPresent()) {
builder.setTargetLevel(jvmLibraryArg.target.get());
}
if (jvmLibraryArg.generateAbiFromSource.isPresent() && !jvmLibraryArg.generateAbiFromSource.get()) {
// This parameter can only be used to turn off ABI generation from source where it would
// otherwise be employed.
builder.setAbiGenerationMode(AbstractJavacOptions.AbiGenerationMode.CLASS);
}
builder.addAllExtraArguments(jvmLibraryArg.extraArguments);
builder.addAllClassesToRemoveFromJar(jvmLibraryArg.removeClasses);
if (jvmLibraryArg.compiler.isPresent()) {
Either<BuiltInJavac, SourcePath> either = jvmLibraryArg.compiler.get();
if (either.isRight()) {
SourcePath sourcePath = either.getRight();
Optional<BuildRule> possibleRule = ruleFinder.getRule(sourcePath);
if (possibleRule.isPresent() && possibleRule.get() instanceof PrebuiltJar) {
builder.setJavacJarPath(((PrebuiltJar) possibleRule.get()).getSourcePathToOutput());
} else {
builder.setJavacPath(Either.ofRight(sourcePath));
}
}
} else {
if (jvmLibraryArg.javac.isPresent() || jvmLibraryArg.javacJar.isPresent()) {
if (jvmLibraryArg.javac.isPresent() && jvmLibraryArg.javacJar.isPresent()) {
throw new HumanReadableException("Cannot set both javac and javacjar");
}
builder.setJavacPath(jvmLibraryArg.javac.map(Either::ofLeft));
builder.setJavacJarPath(jvmLibraryArg.javacJar);
builder.setCompilerClassName(jvmLibraryArg.compilerClassName);
}
}
AnnotationProcessingParams annotationParams = jvmLibraryArg.buildAnnotationProcessingParams(params.getBuildTarget(), params.getProjectFilesystem(), resolver, defaultOptions.getSafeAnnotationProcessors());
builder.setAnnotationProcessingParams(annotationParams);
return builder.build();
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class JvmLibraryArg method addProcessors.
void addProcessors(AnnotationProcessingParams.Builder builder, BuildRuleResolver resolver, BuildTarget owner) {
for (BuildTarget pluginTarget : plugins) {
BuildRule pluginRule = resolver.getRule(pluginTarget);
if (!(pluginRule instanceof JavaAnnotationProcessor)) {
throw new HumanReadableException(String.format("%s: only java_annotation_processor rules can be specified as plugins. " + "%s is not a java_annotation_processor.", owner, pluginTarget));
}
JavaAnnotationProcessor plugin = (JavaAnnotationProcessor) pluginRule;
builder.addProcessor(plugin.getProcessorProperties());
}
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class JvmLibraryArg method addLegacyProcessors.
void addLegacyProcessors(AnnotationProcessingParams.Builder builder, BuildRuleResolver resolver) {
builder.addAllProcessors(annotationProcessors);
ImmutableSortedSet<BuildRule> processorDeps = resolver.getAllRules(annotationProcessorDeps);
for (BuildRule processorDep : processorDeps) {
builder.addProcessorBuildTarget(processorDep);
}
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class PythonTestDescription method createBuildRule.
@Override
public <A extends Arg> PythonTest createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, final A args) throws HumanReadableException, NoSuchBuildTargetException {
PythonPlatform pythonPlatform = pythonPlatforms.getValue(params.getBuildTarget()).orElse(pythonPlatforms.getValue(args.platform.<Flavor>map(InternalFlavor::of).orElse(pythonPlatforms.getFlavors().iterator().next())));
CxxPlatform cxxPlatform = cxxPlatforms.getValue(params.getBuildTarget()).orElse(defaultCxxPlatform);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Path baseModule = PythonUtil.getBasePath(params.getBuildTarget(), args.baseModule);
Optional<ImmutableMap<BuildTarget, Version>> selectedVersions = targetGraph.get(params.getBuildTarget()).getSelectedVersions();
ImmutableMap<Path, SourcePath> srcs = PythonUtil.getModules(params.getBuildTarget(), resolver, ruleFinder, pathResolver, pythonPlatform, cxxPlatform, "srcs", baseModule, args.srcs, args.platformSrcs, args.versionedSrcs, selectedVersions);
ImmutableMap<Path, SourcePath> resources = PythonUtil.getModules(params.getBuildTarget(), resolver, ruleFinder, pathResolver, pythonPlatform, cxxPlatform, "resources", baseModule, args.resources, args.platformResources, args.versionedResources, selectedVersions);
// Convert the passed in module paths into test module names.
ImmutableSet.Builder<String> testModulesBuilder = ImmutableSet.builder();
for (Path name : srcs.keySet()) {
testModulesBuilder.add(PythonUtil.toModuleName(params.getBuildTarget(), name.toString()));
}
ImmutableSet<String> testModules = testModulesBuilder.build();
// Construct a build rule to generate the test modules list source file and
// add it to the build.
BuildRule testModulesBuildRule = createTestModulesSourceBuildRule(params, getTestModulesListPath(params.getBuildTarget(), params.getProjectFilesystem()), testModules);
resolver.addToIndex(testModulesBuildRule);
String mainModule;
if (args.mainModule.isPresent()) {
mainModule = args.mainModule.get();
} else {
mainModule = PythonUtil.toModuleName(params.getBuildTarget(), getTestMainName().toString());
}
// Build up the list of everything going into the python test.
PythonPackageComponents testComponents = PythonPackageComponents.of(ImmutableMap.<Path, SourcePath>builder().put(getTestModulesListName(), testModulesBuildRule.getSourcePathToOutput()).put(getTestMainName(), pythonBuckConfig.getPathToTestMain(params.getProjectFilesystem())).putAll(srcs).build(), resources, ImmutableMap.of(), ImmutableSet.of(), args.zipSafe);
PythonPackageComponents allComponents = PythonUtil.getAllComponents(params, resolver, ruleFinder, testComponents, pythonPlatform, cxxBuckConfig, cxxPlatform, args.linkerFlags.stream().map(MacroArg.toMacroArgFunction(PythonUtil.MACRO_HANDLER, params.getBuildTarget(), params.getCellRoots(), resolver)::apply).collect(MoreCollectors.toImmutableList()), pythonBuckConfig.getNativeLinkStrategy(), args.preloadDeps);
// Build the PEX using a python binary rule with the minimum dependencies.
PythonBinary binary = binaryDescription.createPackageRule(params.withBuildTarget(getBinaryBuildTarget(params.getBuildTarget())), resolver, ruleFinder, pythonPlatform, cxxPlatform, mainModule, args.extension, allComponents, args.buildArgs, args.packageStyle.orElse(pythonBuckConfig.getPackageStyle()), PythonUtil.getPreloadNames(resolver, cxxPlatform, args.preloadDeps));
resolver.addToIndex(binary);
ImmutableList.Builder<Pair<Float, ImmutableSet<Path>>> neededCoverageBuilder = ImmutableList.builder();
for (NeededCoverageSpec coverageSpec : args.neededCoverage) {
BuildRule buildRule = resolver.getRule(coverageSpec.getBuildTarget());
if (params.getDeps().contains(buildRule) && buildRule instanceof PythonLibrary) {
PythonLibrary pythonLibrary = (PythonLibrary) buildRule;
ImmutableSortedSet<Path> paths;
if (coverageSpec.getPathName().isPresent()) {
Path path = coverageSpec.getBuildTarget().getBasePath().resolve(coverageSpec.getPathName().get());
if (!pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform).getModules().keySet().contains(path)) {
throw new HumanReadableException("%s: path %s specified in needed_coverage not found in target %s", params.getBuildTarget(), path, buildRule.getBuildTarget());
}
paths = ImmutableSortedSet.of(path);
} else {
paths = ImmutableSortedSet.copyOf(pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform).getModules().keySet());
}
neededCoverageBuilder.add(new Pair<Float, ImmutableSet<Path>>(coverageSpec.getNeededCoverageRatio(), paths));
} else {
throw new HumanReadableException("%s: needed_coverage requires a python library dependency. Found %s instead", params.getBuildTarget(), buildRule);
}
}
Supplier<ImmutableMap<String, String>> testEnv = () -> ImmutableMap.copyOf(Maps.transformValues(args.env, MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)));
// Generate and return the python test rule, which depends on the python binary rule above.
return PythonTest.from(params, ruleFinder, testEnv, binary, args.labels, neededCoverageBuilder.build(), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.contacts);
}
Aggregations