Search in sources :

Example 11 with SymlinkTree

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

the class PythonBinaryDescription method createInPlaceBinaryRule.

private PythonInPlaceBinary createInPlaceBinaryRule(BuildRuleParams params, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, PythonPlatform pythonPlatform, CxxPlatform cxxPlatform, String mainModule, Optional<String> extension, PythonPackageComponents components, ImmutableSet<String> preloadLibraries) {
    // We don't currently support targeting Windows.
    if (cxxPlatform.getLd().resolve(resolver) instanceof WindowsLinker) {
        throw new HumanReadableException("%s: cannot build in-place python binaries for Windows (%s)", params.getBuildTarget(), cxxPlatform.getFlavor());
    }
    // Add in any missing init modules into the python components.
    SourcePath emptyInit = createEmptyInitModule(params, resolver);
    components = components.withModules(addMissingInitModules(components.getModules(), emptyInit));
    BuildTarget linkTreeTarget = params.getBuildTarget().withAppendedFlavors(InternalFlavor.of("link-tree"));
    Path linkTreeRoot = BuildTargets.getGenPath(params.getProjectFilesystem(), linkTreeTarget, "%s");
    SymlinkTree linkTree = resolver.addToIndex(new SymlinkTree(linkTreeTarget, params.getProjectFilesystem(), linkTreeRoot, ImmutableMap.<Path, SourcePath>builder().putAll(components.getModules()).putAll(components.getResources()).putAll(components.getNativeLibraries()).build(), ruleFinder));
    return PythonInPlaceBinary.from(params, resolver, cxxPlatform, pythonPlatform, mainModule, components, extension.orElse(pythonBuckConfig.getPexExtension()), preloadLibraries, pythonBuckConfig.legacyOutputPath(), ruleFinder, linkTree, pythonPlatform.getEnvironment());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SymlinkTree(com.facebook.buck.rules.SymlinkTree) WindowsLinker(com.facebook.buck.cxx.WindowsLinker) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 12 with SymlinkTree

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

the class LuaBinaryDescriptionTest method versionLessNativeLibraryExtension.

@Test
public void versionLessNativeLibraryExtension() throws Exception {
    CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:lib")).setSoname("libfoo.so.1.0").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
    LuaBinaryBuilder binaryBuilder = new LuaBinaryBuilder(BuildTargetFactory.newInstance("//:rule"), FakeLuaConfig.DEFAULT.withPackageStyle(LuaConfig.PackageStyle.INPLACE)).setMainModule("main").setDeps(ImmutableSortedSet.of(cxxLibraryBuilder.getTarget()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    cxxLibraryBuilder.build(resolver);
    binaryBuilder.build(resolver);
    SymlinkTree tree = resolver.getRuleWithType(LuaBinaryDescription.getNativeLibsSymlinkTreeTarget(binaryBuilder.getTarget()), SymlinkTree.class);
    assertThat(tree.getLinks().keySet(), Matchers.hasItem(tree.getProjectFilesystem().getPath("libfoo.so")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 13 with SymlinkTree

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

the class AbstractCxxSourceRuleFactory method getSandboxedCxxSource.

private CxxSource getSandboxedCxxSource(CxxSource source) {
    if (getSandboxTree().isPresent()) {
        SymlinkTree sandboxTree = getSandboxTree().get();
        Path sourcePath = Paths.get(getPathResolver().getSourcePathName(getParams().getBuildTarget(), source.getPath()));
        Path sandboxPath = BuildTargets.getGenPath(getParams().getProjectFilesystem(), sandboxTree.getBuildTarget(), "%s");
        ExplicitBuildTargetSourcePath path = new ExplicitBuildTargetSourcePath(sandboxTree.getBuildTarget(), sandboxPath.resolve(sourcePath));
        source = CxxSource.copyOf(source).withPath(path);
    }
    return source;
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 14 with SymlinkTree

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

the class AbstractCxxSourceRuleFactory method getPreprocessDeps.

private ImmutableSortedSet<BuildRule> getPreprocessDeps() {
    ImmutableSortedSet.Builder<BuildRule> builder = ImmutableSortedSet.naturalOrder();
    for (CxxPreprocessorInput input : getCxxPreprocessorInput()) {
        builder.addAll(input.getDeps(getResolver(), getRuleFinder()));
    }
    if (getPrefixHeader().isPresent()) {
        builder.addAll(getRuleFinder().filterBuildRuleInputs(getPrefixHeader().get()));
    }
    if (getPrecompiledHeader().isPresent()) {
        builder.addAll(getRuleFinder().filterBuildRuleInputs(getPrecompiledHeader().get()));
    }
    if (getSandboxTree().isPresent()) {
        SymlinkTree tree = getSandboxTree().get();
        builder.add(tree);
        builder.addAll(getRuleFinder().filterBuildRuleInputs(tree.getLinks().values()));
    }
    return builder.build();
}
Also used : SymlinkTree(com.facebook.buck.rules.SymlinkTree) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule)

Example 15 with SymlinkTree

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

the class AndroidResourceDescription method collectInputSourcePaths.

private static Pair<Optional<SymlinkTree>, Optional<SourcePath>> collectInputSourcePaths(BuildRuleResolver ruleResolver, BuildTarget resourceRuleTarget, Flavor symlinkTreeFlavor, Optional<Either<SourcePath, ImmutableSortedMap<String, SourcePath>>> attribute) {
    if (!attribute.isPresent()) {
        return new Pair<>(Optional.empty(), Optional.empty());
    }
    if (attribute.get().isLeft()) {
        SourcePath inputSourcePath = attribute.get().getLeft();
        if (!(inputSourcePath instanceof PathSourcePath)) {
            // in advance to create a symlink tree.  Instead, we have to pass the source path as is.
            return new Pair<>(Optional.empty(), Optional.of(inputSourcePath));
        }
    }
    BuildTarget symlinkTreeTarget = resourceRuleTarget.withAppendedFlavors(symlinkTreeFlavor);
    SymlinkTree symlinkTree;
    try {
        symlinkTree = (SymlinkTree) ruleResolver.requireRule(symlinkTreeTarget);
    } catch (NoSuchBuildTargetException e) {
        throw new RuntimeException(e);
    }
    return new Pair<>(Optional.of(symlinkTree), Optional.of(symlinkTree.getSourcePathToOutput()));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) BuildTarget(com.facebook.buck.model.BuildTarget) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Pair(com.facebook.buck.model.Pair)

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