Search in sources :

Example 6 with SymlinkTree

use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.

the class GoDescriptors method makeSymlinkTree.

private static SymlinkTree makeSymlinkTree(BuildRuleParams params, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, ImmutableSet<GoLinkable> linkables) {
    ImmutableMap.Builder<Path, SourcePath> treeMapBuilder = ImmutableMap.builder();
    for (GoLinkable linkable : linkables) {
        for (Map.Entry<Path, SourcePath> linkInput : linkable.getGoLinkInput().entrySet()) {
            treeMapBuilder.put(getPathInSymlinkTree(pathResolver, linkInput.getKey(), linkInput.getValue()), linkInput.getValue());
        }
    }
    ImmutableMap<Path, SourcePath> treeMap;
    try {
        treeMap = treeMapBuilder.build();
    } catch (IllegalArgumentException ex) {
        throw new HumanReadableException(ex, "Multiple go targets have the same package name when compiling %s", params.getBuildTarget().getFullyQualifiedName());
    }
    Path root = BuildTargets.getScratchPath(params.getProjectFilesystem(), params.getBuildTarget(), "__%s__tree");
    return new SymlinkTree(params.getBuildTarget(), params.getProjectFilesystem(), root, treeMap, ruleFinder);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) HumanReadableException(com.facebook.buck.util.HumanReadableException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with SymlinkTree

use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.

the class CxxLuaExtensionDescription method getExtensionArgs.

private ImmutableList<com.facebook.buck.rules.args.Arg> getExtensionArgs(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, Arg args) throws NoSuchBuildTargetException {
    // Extract all C/C++ sources from the constructor arg.
    ImmutableMap<String, CxxSource> srcs = CxxDescriptionEnhancer.parseCxxSources(params.getBuildTarget(), ruleResolver, ruleFinder, pathResolver, cxxPlatform, args);
    ImmutableMap<Path, SourcePath> headers = CxxDescriptionEnhancer.parseHeaders(params.getBuildTarget(), ruleResolver, ruleFinder, pathResolver, Optional.of(cxxPlatform), args);
    // Setup the header symlink tree and combine all the preprocessor input from this rule
    // and all dependencies.
    HeaderSymlinkTree headerSymlinkTree = CxxDescriptionEnhancer.requireHeaderSymlinkTree(params, ruleResolver, cxxPlatform, headers, HeaderVisibility.PRIVATE, true);
    Optional<SymlinkTree> sandboxTree = Optional.empty();
    if (cxxBuckConfig.sandboxSources()) {
        sandboxTree = CxxDescriptionEnhancer.createSandboxTree(params, ruleResolver, cxxPlatform);
    }
    ImmutableList<CxxPreprocessorInput> cxxPreprocessorInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(params, cxxPlatform, CxxFlags.getLanguageFlags(args.preprocessorFlags, args.platformPreprocessorFlags, args.langPreprocessorFlags, cxxPlatform), ImmutableList.of(headerSymlinkTree), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, params.getDeps()), args.includeDirs, sandboxTree);
    // Generate rule to build the object files.
    ImmutableMap<CxxPreprocessAndCompile, SourcePath> picObjects = CxxSourceRuleFactory.requirePreprocessAndCompileRules(params, ruleResolver, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, cxxPreprocessorInput, CxxFlags.getLanguageFlags(args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, cxxPlatform), args.prefixHeader, args.precompiledHeader, srcs, CxxSourceRuleFactory.PicType.PIC, sandboxTree);
    ImmutableList.Builder<com.facebook.buck.rules.args.Arg> argsBuilder = ImmutableList.builder();
    argsBuilder.addAll(CxxDescriptionEnhancer.toStringWithMacrosArgs(params.getBuildTarget(), params.getCellRoots(), ruleResolver, cxxPlatform, CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(args.linkerFlags, args.platformLinkerFlags, cxxPlatform)));
    // Add object files into the args.
    argsBuilder.addAll(SourcePathArg.from(picObjects.values()));
    return argsBuilder.build();
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) ImmutableList(com.google.common.collect.ImmutableList) CxxSource(com.facebook.buck.cxx.CxxSource) SourcePath(com.facebook.buck.rules.SourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput)

Example 8 with SymlinkTree

use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.

the class DTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver buildRuleResolver, A args) throws NoSuchBuildTargetException {
    BuildTarget target = params.getBuildTarget();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    SymlinkTree sourceTree = buildRuleResolver.addToIndex(DDescriptionUtils.createSourceSymlinkTree(DDescriptionUtils.getSymlinkTreeTarget(params.getBuildTarget()), params, ruleFinder, pathResolver, args.srcs));
    // Create a helper rule to build the test binary.
    // The rule needs its own target so that we can depend on it without creating cycles.
    BuildTarget binaryTarget = DDescriptionUtils.createBuildTargetForFile(target, "build-", target.getFullyQualifiedName(), cxxPlatform);
    BuildRule binaryRule = DDescriptionUtils.createNativeLinkable(params.withBuildTarget(binaryTarget), buildRuleResolver, cxxPlatform, dBuckConfig, cxxBuckConfig, ImmutableList.of("-unittest"), args.srcs, args.linkerFlags, DIncludes.builder().setLinkTree(sourceTree.getSourcePathToOutput()).addAllSources(args.srcs.getPaths()).build());
    buildRuleResolver.addToIndex(binaryRule);
    return new DTest(params.copyAppendingExtraDeps(ImmutableList.of(binaryRule)), binaryRule, args.contacts, args.labels, args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs));
}
Also used : SymlinkTree(com.facebook.buck.rules.SymlinkTree) Optional(java.util.Optional) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 9 with SymlinkTree

use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.

the class DBinaryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver buildRuleResolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    SymlinkTree sourceTree = buildRuleResolver.addToIndex(DDescriptionUtils.createSourceSymlinkTree(DDescriptionUtils.getSymlinkTreeTarget(params.getBuildTarget()), params, ruleFinder, pathResolver, args.srcs));
    // Create a rule that actually builds the binary, and add that
    // rule to the index.
    CxxLink nativeLinkable = DDescriptionUtils.createNativeLinkable(params.withAppendedFlavor(BINARY_FLAVOR), buildRuleResolver, cxxPlatform, dBuckConfig, cxxBuckConfig, /* compilerFlags */
    ImmutableList.of(), args.srcs, args.linkerFlags, DIncludes.builder().setLinkTree(sourceTree.getSourcePathToOutput()).addAllSources(args.srcs.getPaths()).build());
    buildRuleResolver.addToIndex(nativeLinkable);
    // Create a Tool for the executable.
    CommandTool.Builder executableBuilder = new CommandTool.Builder();
    executableBuilder.addArg(SourcePathArg.of(nativeLinkable.getSourcePathToOutput()));
    // with buck run etc.
    return new DBinary(params.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(nativeLinkable))), ruleFinder, executableBuilder.build(), nativeLinkable.getSourcePathToOutput());
}
Also used : SymlinkTree(com.facebook.buck.rules.SymlinkTree) CommandTool(com.facebook.buck.rules.CommandTool) CxxLink(com.facebook.buck.cxx.CxxLink) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 10 with SymlinkTree

use of com.facebook.buck.rules.SymlinkTree in project buck by facebook.

the class CxxPythonExtensionDescription method getExtensionArgs.

private ImmutableList<com.facebook.buck.rules.args.Arg> getExtensionArgs(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, Arg args) throws NoSuchBuildTargetException {
    // Extract all C/C++ sources from the constructor arg.
    ImmutableMap<String, CxxSource> srcs = CxxDescriptionEnhancer.parseCxxSources(params.getBuildTarget(), ruleResolver, ruleFinder, pathResolver, cxxPlatform, args);
    ImmutableMap<Path, SourcePath> headers = CxxDescriptionEnhancer.parseHeaders(params.getBuildTarget(), ruleResolver, ruleFinder, pathResolver, Optional.of(cxxPlatform), args);
    // Setup the header symlink tree and combine all the preprocessor input from this rule
    // and all dependencies.
    HeaderSymlinkTree headerSymlinkTree = CxxDescriptionEnhancer.requireHeaderSymlinkTree(params, ruleResolver, cxxPlatform, headers, HeaderVisibility.PRIVATE, true);
    Optional<SymlinkTree> sandboxTree = Optional.empty();
    if (cxxBuckConfig.sandboxSources()) {
        sandboxTree = CxxDescriptionEnhancer.createSandboxTree(params, ruleResolver, cxxPlatform);
    }
    ImmutableList<CxxPreprocessorInput> cxxPreprocessorInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(params, cxxPlatform, CxxFlags.getLanguageFlags(args.preprocessorFlags, args.platformPreprocessorFlags, args.langPreprocessorFlags, cxxPlatform), ImmutableList.of(headerSymlinkTree), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, params.getDeps()), args.includeDirs, sandboxTree);
    // Generate rule to build the object files.
    ImmutableMap<CxxPreprocessAndCompile, SourcePath> picObjects = CxxSourceRuleFactory.requirePreprocessAndCompileRules(params, ruleResolver, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, cxxPreprocessorInput, CxxFlags.getLanguageFlags(args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, cxxPlatform), args.prefixHeader, args.precompiledHeader, srcs, CxxSourceRuleFactory.PicType.PIC, sandboxTree);
    ImmutableList.Builder<com.facebook.buck.rules.args.Arg> argsBuilder = ImmutableList.builder();
    argsBuilder.addAll(CxxDescriptionEnhancer.toStringWithMacrosArgs(params.getBuildTarget(), params.getCellRoots(), ruleResolver, cxxPlatform, CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(args.linkerFlags, args.platformLinkerFlags, cxxPlatform)));
    // Embed a origin-relative library path into the binary so it can find the shared libraries.
    argsBuilder.addAll(StringArg.from(Linkers.iXlinker("-rpath", String.format("%s/", cxxPlatform.getLd().resolve(ruleResolver).libOrigin()))));
    // Add object files into the args.
    argsBuilder.addAll(SourcePathArg.from(picObjects.values()));
    return argsBuilder.build();
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) ImmutableList(com.google.common.collect.ImmutableList) CxxSource(com.facebook.buck.cxx.CxxSource) SourcePath(com.facebook.buck.rules.SourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) StringArg(com.facebook.buck.rules.args.StringArg) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput)

Aggregations

SymlinkTree (com.facebook.buck.rules.SymlinkTree)21 SourcePath (com.facebook.buck.rules.SourcePath)13 BuildTarget (com.facebook.buck.model.BuildTarget)12 Path (java.nio.file.Path)12 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)10 BuildRule (com.facebook.buck.rules.BuildRule)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 ImmutableList (com.google.common.collect.ImmutableList)6 HumanReadableException (com.facebook.buck.util.HumanReadableException)5 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)4 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)4 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)4 CommandTool (com.facebook.buck.rules.CommandTool)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)4 Optional (java.util.Optional)4 MorePaths (com.facebook.buck.io.MorePaths)3 BuildTargets (com.facebook.buck.model.BuildTargets)3 Flavor (com.facebook.buck.model.Flavor)3