use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class GwtBinaryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, A args) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
final ImmutableSortedSet.Builder<BuildRule> extraDeps = ImmutableSortedSet.naturalOrder();
// Find all of the reachable JavaLibrary rules and grab their associated GwtModules.
final ImmutableSortedSet.Builder<SourcePath> gwtModuleJarsBuilder = ImmutableSortedSet.naturalOrder();
ImmutableSortedSet<BuildRule> moduleDependencies = resolver.getAllRules(args.moduleDeps);
new AbstractBreadthFirstTraversal<BuildRule>(moduleDependencies) {
@Override
public ImmutableSet<BuildRule> visit(BuildRule rule) {
if (!(rule instanceof JavaLibrary)) {
return ImmutableSet.of();
}
// If the java library doesn't generate any output, it doesn't contribute a GwtModule
JavaLibrary javaLibrary = (JavaLibrary) rule;
if (javaLibrary.getSourcePathToOutput() == null) {
return rule.getDeps();
}
BuildTarget gwtModuleTarget = BuildTargets.createFlavoredBuildTarget(javaLibrary.getBuildTarget().checkUnflavored(), JavaLibrary.GWT_MODULE_FLAVOR);
Optional<BuildRule> gwtModule = resolver.getRuleOptional(gwtModuleTarget);
if (!gwtModule.isPresent() && javaLibrary.getSourcePathToOutput() != null) {
ImmutableSortedSet<SourcePath> filesForGwtModule = ImmutableSortedSet.<SourcePath>naturalOrder().addAll(javaLibrary.getSources()).addAll(javaLibrary.getResources()).build();
ImmutableSortedSet<BuildRule> deps = ImmutableSortedSet.copyOf(ruleFinder.filterBuildRuleInputs(filesForGwtModule));
BuildRule module = resolver.addToIndex(new GwtModule(params.withBuildTarget(gwtModuleTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(deps), Suppliers.ofInstance(ImmutableSortedSet.of())), ruleFinder, filesForGwtModule));
gwtModule = Optional.of(module);
}
// but a rule that exists only as a collection of deps.
if (gwtModule.isPresent()) {
extraDeps.add(gwtModule.get());
gwtModuleJarsBuilder.add(Preconditions.checkNotNull(gwtModule.get().getSourcePathToOutput()));
}
// Traverse all of the deps of this rule.
return rule.getDeps();
}
}.start();
return new GwtBinary(params.copyReplacingExtraDeps(Suppliers.ofInstance(extraDeps.build())), args.modules, javaOptions.getJavaRuntimeLauncher(), args.vmArgs, args.style.orElse(DEFAULT_STYLE), args.draftCompile.orElse(DEFAULT_DRAFT_COMPILE), args.optimize.orElse(DEFAULT_OPTIMIZE), args.localWorkers.orElse(DEFAULT_NUM_LOCAL_WORKERS), args.strict.orElse(DEFAULT_STRICT), args.experimentalArgs, gwtModuleJarsBuilder.build());
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class GoDescriptors method createGoBinaryRule.
static GoBinary createGoBinaryRule(BuildRuleParams params, final BuildRuleResolver resolver, GoBuckConfig goBuckConfig, ImmutableSet<SourcePath> srcs, List<String> compilerFlags, List<String> assemblerFlags, List<String> linkerFlags, GoPlatform platform) throws NoSuchBuildTargetException {
BuildTarget libraryTarget = params.getBuildTarget().withAppendedFlavors(InternalFlavor.of("compile"), platform.getFlavor());
GoCompile library = GoDescriptors.createGoCompileRule(params.withBuildTarget(libraryTarget), resolver, goBuckConfig, Paths.get("main"), srcs, compilerFlags, assemblerFlags, platform, FluentIterable.from(params.getDeclaredDeps().get()).transform(BuildRule::getBuildTarget));
resolver.addToIndex(library);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = createTransitiveSymlinkTreeTarget(params.getBuildTarget());
SymlinkTree symlinkTree = makeSymlinkTree(params.withBuildTarget(target), pathResolver, ruleFinder, requireTransitiveGoLinkables(params.getBuildTarget(), resolver, platform, FluentIterable.from(params.getDeclaredDeps().get()).transform(BuildRule::getBuildTarget), /* includeSelf */
false));
resolver.addToIndex(symlinkTree);
LOG.verbose("Symlink tree for linking of %s: %s", params.getBuildTarget(), symlinkTree);
return new GoBinary(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(symlinkTree.getLinks().values())).add(symlinkTree).add(library).build()), Suppliers.ofInstance(ImmutableSortedSet.of())), platform.getCxxPlatform().map(input -> input.getLd().resolve(resolver)), symlinkTree, library, goBuckConfig.getLinker(), ImmutableList.copyOf(linkerFlags), platform);
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class DistBuildStateTest method canReconstructGraphAndTopLevelBuildTargets.
@Test
public void canReconstructGraphAndTopLevelBuildTargets() throws Exception {
ProjectWorkspace projectWorkspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple_java_target", temporaryFolder);
projectWorkspace.setUp();
Cell cell = projectWorkspace.asCell();
ProjectFilesystem projectFilesystem = cell.getFilesystem();
projectFilesystem.mkdirs(projectFilesystem.getBuckPaths().getBuckOut());
BuckConfig buckConfig = cell.getBuckConfig();
TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
Parser parser = new Parser(new BroadcastEventListener(), buckConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), cell, /* enableProfiling */
false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib1"), BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib2"), BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib3")));
DistBuildTargetGraphCodec targetGraphCodec = createDefaultCodec(cell, Optional.of(parser));
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(cell), emptyActionGraph(), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib1"), BuildTargetFactory.newInstance(projectFilesystem.getRootPath(), "//:lib2")));
Cell rootCellWhenLoading = new TestCellBuilder().setFilesystem(createJavaOnlyFilesystem("/loading")).build();
DistBuildState distributedBuildState = DistBuildState.load(Optional.empty(), dump, rootCellWhenLoading, knownBuildRuleTypesFactory);
ProjectFilesystem reconstructedCellFilesystem = distributedBuildState.getCells().get(0).getFilesystem();
TargetGraph reconstructedGraph = distributedBuildState.createTargetGraph(targetGraphCodec).getTargetGraph();
assertEquals(reconstructedGraph.getNodes().stream().map(targetNode -> targetNode.castArg(JavaLibraryDescription.Arg.class).get()).sorted().map(targetNode -> targetNode.getConstructorArg().srcs).collect(Collectors.toList()), Lists.newArrayList("A.java", "B.java", "C.java").stream().map(f -> reconstructedCellFilesystem.getPath(f)).map(p -> new PathSourcePath(reconstructedCellFilesystem, p)).map(ImmutableSortedSet::of).collect(Collectors.toList()));
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method platformDeps.
@Test
public void platformDeps() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
CxxLibrary dep = (CxxLibrary) new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).build(resolver);
CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:rule"), FlavorDomain.of("Python Platform", PY2, PY3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
CxxPythonExtension rule = builder.setPlatformDeps(PatternMatchedCollection.<ImmutableSortedSet<BuildTarget>>builder().add(Pattern.compile(PY2.getFlavor().toString()), ImmutableSortedSet.of(dep.getBuildTarget())).build()).build(resolver);
NativeLinkTarget py2NativeLinkTarget = rule.getNativeLinkTarget(PY2);
assertThat(ImmutableList.copyOf(py2NativeLinkTarget.getNativeLinkTargetDeps(CxxPlatformUtils.DEFAULT_PLATFORM)), Matchers.<NativeLinkable>hasItem(dep));
NativeLinkTarget py3NativeLinkTarget = rule.getNativeLinkTarget(PY3);
assertThat(ImmutableList.copyOf(py3NativeLinkTarget.getNativeLinkTargetDeps(CxxPlatformUtils.DEFAULT_PLATFORM)), Matchers.not(Matchers.<NativeLinkable>hasItem(dep)));
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class OcamlRuleBuilder method createFineGrainedBuildRule.
public static BuildRule createFineGrainedBuildRule(OcamlBuckConfig ocamlBuckConfig, final BuildRuleParams params, BuildRuleResolver resolver, ImmutableList<OcamlSource> srcs, boolean isLibrary, boolean bytecodeOnly, ImmutableList<Arg> argFlags, final ImmutableList<String> linkerFlags, boolean buildNativePlugin) throws NoSuchBuildTargetException {
CxxPreprocessorInput cxxPreprocessorInputFromDeps = CxxPreprocessorInput.concat(CxxPreprocessables.getTransitiveCxxPreprocessorInput(ocamlBuckConfig.getCxxPlatform(), FluentIterable.from(params.getDeps()).filter(CxxPreprocessorDep.class::isInstance)));
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableList<String> nativeIncludes = FluentIterable.from(params.getDeps()).transformAndConcat(getLibInclude(false)).toList();
ImmutableList<String> bytecodeIncludes = FluentIterable.from(params.getDeps()).transformAndConcat(getLibInclude(true)).toList();
NativeLinkableInput nativeLinkableInput = getNativeLinkableInput(params.getDeps());
NativeLinkableInput bytecodeLinkableInput = getBytecodeLinkableInput(params.getDeps());
NativeLinkableInput cLinkableInput = getCLinkableInput(ocamlBuckConfig.getCxxPlatform(), params.getDeps());
ImmutableList<OcamlLibrary> ocamlInput = OcamlUtil.getTransitiveOcamlInput(params.getDeps());
BuildTarget buildTarget = isLibrary ? createStaticLibraryBuildTarget(params.getBuildTarget()) : createOcamlLinkTarget(params.getBuildTarget());
final BuildRuleParams compileParams = params.withBuildTarget(buildTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(getInput(srcs))).addAll(Stream.of(nativeLinkableInput, bytecodeLinkableInput, cLinkableInput).flatMap(input -> input.getArgs().stream()).flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).addAll(argFlags.stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).addAll(ruleFinder.filterBuildRuleInputs(ocamlBuckConfig.getCCompiler().resolve(resolver).getInputs())).addAll(ruleFinder.filterBuildRuleInputs(ocamlBuckConfig.getCxxCompiler().resolve(resolver).getInputs())).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
ImmutableList.Builder<Arg> flagsBuilder = ImmutableList.builder();
flagsBuilder.addAll(argFlags);
ImmutableSortedSet.Builder<BuildRule> nativeCompileDepsBuilder = ImmutableSortedSet.naturalOrder();
ImmutableSortedSet.Builder<BuildRule> bytecodeCompileDepsBuilder = ImmutableSortedSet.naturalOrder();
ImmutableSortedSet.Builder<BuildRule> bytecodeLinkDepsBuilder = ImmutableSortedSet.naturalOrder();
for (OcamlLibrary library : ocamlInput) {
nativeCompileDepsBuilder.addAll(library.getNativeCompileDeps());
bytecodeCompileDepsBuilder.addAll(library.getBytecodeCompileDeps());
bytecodeLinkDepsBuilder.addAll(library.getBytecodeLinkDeps());
}
OcamlBuildContext ocamlContext = OcamlBuildContext.builder(ocamlBuckConfig).setProjectFilesystem(params.getProjectFilesystem()).setSourcePathResolver(pathResolver).setFlags(flagsBuilder.build()).setNativeIncludes(nativeIncludes).setBytecodeIncludes(bytecodeIncludes).setOcamlInput(ocamlInput).setNativeLinkableInput(nativeLinkableInput).setBytecodeLinkableInput(bytecodeLinkableInput).setCLinkableInput(cLinkableInput).setBuildTarget(buildTarget.getUnflavoredBuildTarget()).setLibrary(isLibrary).setCxxPreprocessorInput(cxxPreprocessorInputFromDeps).setInput(getInput(srcs)).setNativeCompileDeps(nativeCompileDepsBuilder.build()).setBytecodeCompileDeps(bytecodeCompileDepsBuilder.build()).setBytecodeLinkDeps(bytecodeLinkDepsBuilder.build()).setCPreprocessor(ocamlBuckConfig.getCPreprocessor().resolve(resolver)).build();
Path baseDir = params.getProjectFilesystem().getRootPath().toAbsolutePath();
ImmutableMap<Path, ImmutableList<Path>> mlInput = getMLInputWithDeps(baseDir, ocamlContext);
ImmutableList<SourcePath> cInput = getCInput(pathResolver, getInput(srcs));
OcamlBuildRulesGenerator generator = new OcamlBuildRulesGenerator(compileParams, pathResolver, ruleFinder, resolver, ocamlContext, mlInput, cInput, ocamlBuckConfig.getCCompiler().resolve(resolver), ocamlBuckConfig.getCxxCompiler().resolve(resolver), bytecodeOnly, buildNativePlugin);
OcamlGeneratedBuildRules result = generator.generate();
if (isLibrary) {
return new OcamlStaticLibrary(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(result.getRules()).build()), params.getExtraDeps()), compileParams, linkerFlags, result.getObjectFiles(), ocamlContext, result.getRules().get(0), result.getNativeCompileDeps(), result.getBytecodeCompileDeps(), ImmutableSortedSet.<BuildRule>naturalOrder().add(result.getBytecodeLink()).addAll(ruleFinder.filterBuildRuleInputs(result.getObjectFiles())).build());
} else {
return new OcamlBinary(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(result.getRules()).build()), params.getExtraDeps()), result.getRules().get(0));
}
}
Aggregations