Search in sources :

Example 46 with ImmutableSortedSet

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());
}
Also used : Optional(java.util.Optional) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule)

Example 47 with ImmutableSortedSet

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);
}
Also used : BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) InternalFlavor(com.facebook.buck.model.InternalFlavor) BuildRule(com.facebook.buck.rules.BuildRule) SymlinkTree(com.facebook.buck.rules.SymlinkTree) AbstractBreadthFirstThrowingTraversal(com.facebook.buck.graph.AbstractBreadthFirstThrowingTraversal) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) Files(com.google.common.io.Files) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) WriteFile(com.facebook.buck.file.WriteFile) Suppliers(com.google.common.base.Suppliers) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Logger(com.facebook.buck.log.Logger) Charsets(com.google.common.base.Charsets) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Resources(com.google.common.io.Resources) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) Maps(com.google.common.collect.Maps) MorePaths(com.facebook.buck.io.MorePaths) List(java.util.List) Paths(java.nio.file.Paths) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildTargets(com.facebook.buck.model.BuildTargets) SymlinkTree(com.facebook.buck.rules.SymlinkTree) BuildTarget(com.facebook.buck.model.BuildTarget) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 48 with ImmutableSortedSet

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()));
}
Also used : BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) ActionGraph(com.facebook.buck.rules.ActionGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ObjectMappers(com.facebook.buck.util.ObjectMappers) TestDataHelper(com.facebook.buck.testutil.integration.TestDataHelper) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuckConfig(com.facebook.buck.cli.BuckConfig) TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Platform(com.facebook.buck.util.environment.Platform) DefaultParserTargetNodeFactory(com.facebook.buck.parser.DefaultParserTargetNodeFactory) DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) BuildTarget(com.facebook.buck.model.BuildTarget) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) KnownBuildRuleTypesFactory(com.facebook.buck.rules.KnownBuildRuleTypesFactory) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) BuckEventBus(com.facebook.buck.event.BuckEventBus) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) Config(com.facebook.buck.config.Config) TemporaryPaths(com.facebook.buck.testutil.integration.TemporaryPaths) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) Lists(com.google.common.collect.Lists) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) ParserConfig(com.facebook.buck.parser.ParserConfig) ImmutableList(com.google.common.collect.ImmutableList) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ExpectedException(org.junit.rules.ExpectedException) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Functions(com.google.common.base.Functions) Parser(com.facebook.buck.parser.Parser) TargetNode(com.facebook.buck.rules.TargetNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) Architecture(com.facebook.buck.util.environment.Architecture) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) ConfigBuilder(com.facebook.buck.config.ConfigBuilder) ParserTargetNodeFactory(com.facebook.buck.parser.ParserTargetNodeFactory) Rule(org.junit.Rule) TestConsole(com.facebook.buck.testutil.TestConsole) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Preconditions(com.google.common.base.Preconditions) Assert.assertEquals(org.junit.Assert.assertEquals) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Parser(com.facebook.buck.parser.Parser) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

Example 49 with ImmutableSortedSet

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)));
}
Also used : CxxLibrary(com.facebook.buck.cxx.CxxLibrary) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) NativeLinkTarget(com.facebook.buck.cxx.NativeLinkTarget) Test(org.junit.Test)

Example 50 with ImmutableSortedSet

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));
    }
}
Also used : NativeLinkables(com.facebook.buck.cxx.NativeLinkables) Linker(com.facebook.buck.cxx.Linker) OcamlSource(com.facebook.buck.rules.coercer.OcamlSource) CxxPreprocessorDep(com.facebook.buck.cxx.CxxPreprocessorDep) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) InternalFlavor(com.facebook.buck.model.InternalFlavor) BuildRule(com.facebook.buck.rules.BuildRule) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FluentIterable(com.google.common.collect.FluentIterable) CxxPreprocessables(com.facebook.buck.cxx.CxxPreprocessables) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Suppliers(com.google.common.base.Suppliers) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableMap(com.google.common.collect.ImmutableMap) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) Set(java.util.Set) IOException(java.io.IOException) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) Console(com.facebook.buck.util.Console) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) BuildRuleDependencyVisitors(com.facebook.buck.rules.BuildRuleDependencyVisitors) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) List(java.util.List) Arg(com.facebook.buck.rules.args.Arg) Stream(java.util.stream.Stream) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) Optional(java.util.Optional) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TopologicalSort(com.facebook.buck.graph.TopologicalSort) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Joiner(com.google.common.base.Joiner) ImmutableList(com.google.common.collect.ImmutableList) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) CxxPreprocessorDep(com.facebook.buck.cxx.CxxPreprocessorDep) BuildRule(com.facebook.buck.rules.BuildRule) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Arg(com.facebook.buck.rules.args.Arg) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput)

Aggregations

ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)53 BuildTarget (com.facebook.buck.model.BuildTarget)26 BuildRule (com.facebook.buck.rules.BuildRule)26 Path (java.nio.file.Path)25 SourcePath (com.facebook.buck.rules.SourcePath)22 ImmutableList (com.google.common.collect.ImmutableList)22 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)21 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)19 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 Optional (java.util.Optional)17 ImmutableSet (com.google.common.collect.ImmutableSet)16 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)15 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)14 Map (java.util.Map)13 Flavor (com.facebook.buck.model.Flavor)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 IOException (java.io.IOException)12 Preconditions (com.google.common.base.Preconditions)11 Suppliers (com.google.common.base.Suppliers)10 TargetGraph (com.facebook.buck.rules.TargetGraph)9