Search in sources :

Example 1 with ExplicitBuildTargetSourcePath

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

the class AppleResources method collectResourceDirsAndFiles.

public static <T> AppleBundleResources collectResourceDirsAndFiles(final TargetGraph targetGraph, final Optional<AppleDependenciesCache> cache, TargetNode<T, ?> targetNode) {
    AppleBundleResources.Builder builder = AppleBundleResources.builder();
    Iterable<TargetNode<?, ?>> resourceNodes = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, cache, AppleBuildRules.RecursiveDependenciesMode.COPYING, targetNode, Optional.of(APPLE_RESOURCE_DESCRIPTION_CLASSES));
    ProjectFilesystem filesystem = targetNode.getFilesystem();
    for (TargetNode<?, ?> resourceNode : resourceNodes) {
        Object constructorArg = resourceNode.getConstructorArg();
        if (constructorArg instanceof AppleResourceDescription.Arg) {
            AppleResourceDescription.Arg appleResource = (AppleResourceDescription.Arg) constructorArg;
            builder.addAllResourceDirs(appleResource.dirs);
            builder.addAllResourceFiles(appleResource.files);
            builder.addAllResourceVariantFiles(appleResource.variants);
        } else {
            Preconditions.checkState(constructorArg instanceof ReactNativeLibraryArgs);
            BuildTarget buildTarget = resourceNode.getBuildTarget();
            builder.addDirsContainingResourceDirs(new ExplicitBuildTargetSourcePath(buildTarget, ReactNativeBundle.getPathToJSBundleDir(buildTarget, filesystem)), new ExplicitBuildTargetSourcePath(buildTarget, ReactNativeBundle.getPathToResources(buildTarget, filesystem)));
        }
    }
    return builder.build();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) ReactNativeLibraryArgs(com.facebook.buck.js.ReactNativeLibraryArgs) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 2 with ExplicitBuildTargetSourcePath

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

the class AppleTestDescription method getXctool.

private Optional<SourcePath> getXctool(BuildRuleParams params, BuildRuleResolver resolver) {
    // can use that directly.
    if (appleConfig.getXctoolZipTarget().isPresent()) {
        final BuildRule xctoolZipBuildRule = resolver.getRule(appleConfig.getXctoolZipTarget().get());
        BuildTarget unzipXctoolTarget = BuildTarget.builder(xctoolZipBuildRule.getBuildTarget()).addFlavors(UNZIP_XCTOOL_FLAVOR).build();
        final Path outputDirectory = BuildTargets.getGenPath(params.getProjectFilesystem(), unzipXctoolTarget, "%s/unzipped");
        if (!resolver.getRuleOptional(unzipXctoolTarget).isPresent()) {
            BuildRuleParams unzipXctoolParams = params.withBuildTarget(unzipXctoolTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(xctoolZipBuildRule)), Suppliers.ofInstance(ImmutableSortedSet.of()));
            resolver.addToIndex(new AbstractBuildRule(unzipXctoolParams) {

                @Override
                public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
                    buildableContext.recordArtifact(outputDirectory);
                    return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory), new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(Preconditions.checkNotNull(xctoolZipBuildRule.getSourcePathToOutput())), outputDirectory));
                }

                @Override
                public SourcePath getSourcePathToOutput() {
                    return new ExplicitBuildTargetSourcePath(getBuildTarget(), outputDirectory);
                }
            });
        }
        return Optional.of(new ExplicitBuildTargetSourcePath(unzipXctoolTarget, outputDirectory.resolve("bin/xctool")));
    } else if (appleConfig.getXctoolPath().isPresent()) {
        return Optional.of(new PathSourcePath(params.getProjectFilesystem(), appleConfig.getXctoolPath().get()));
    } else {
        return Optional.empty();
    }
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) UnzipStep(com.facebook.buck.zip.UnzipStep) ImmutableList(com.google.common.collect.ImmutableList) PathSourcePath(com.facebook.buck.rules.PathSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) BuildableContext(com.facebook.buck.rules.BuildableContext) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 3 with ExplicitBuildTargetSourcePath

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

the class HalideLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildTarget target = params.getBuildTarget();
    ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(target.getFlavors());
    CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
    if (flavors.contains(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR)) {
        ImmutableMap.Builder<Path, SourcePath> headersBuilder = ImmutableMap.builder();
        BuildTarget compileTarget = resolver.requireRule(target.withFlavors(HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor())).getBuildTarget();
        Path outputPath = HalideCompile.headerOutputPath(compileTarget, params.getProjectFilesystem(), args.functionName);
        headersBuilder.put(outputPath.getFileName(), new ExplicitBuildTargetSourcePath(compileTarget, outputPath));
        return CxxDescriptionEnhancer.createHeaderSymlinkTree(params, resolver, cxxPlatform, headersBuilder.build(), HeaderVisibility.PUBLIC, true);
    } else if (flavors.contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
        CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
        return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, hostCxxPlatform, params);
    } else if (flavors.contains(HALIDE_COMPILER_FLAVOR)) {
        // We always want to build the halide "compiler" for the host platform, so
        // we use the host flavor here, regardless of the flavors on the build
        // target.
        CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
        final ImmutableSortedSet<BuildTarget> compilerDeps = args.compilerDeps;
        return createHalideCompiler(params.withAppendedFlavor(HALIDE_COMPILER_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(resolver.getAllRules(compilerDeps)), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, pathResolver, ruleFinder, hostCxxPlatform, args.srcs, args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, args.linkerFlags, args.platformLinkerFlags, args.includeDirs);
    } else if (flavors.contains(CxxDescriptionEnhancer.STATIC_FLAVOR) || flavors.contains(CxxDescriptionEnhancer.STATIC_PIC_FLAVOR)) {
        // See: https://github.com/halide/Halide/blob/e3c301f3/src/LLVM_Output.cpp#L152
        return createHalideStaticLibrary(params, resolver, ruleFinder, cxxPlatform, args);
    } else if (flavors.contains(CxxDescriptionEnhancer.SHARED_FLAVOR)) {
        throw new HumanReadableException("halide_library '%s' does not support shared libraries as output", params.getBuildTarget());
    } else if (flavors.contains(HALIDE_COMPILE_FLAVOR)) {
        return createHalideCompile(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, cxxPlatform, Optional.of(args.compilerInvocationFlags), args.functionName);
    }
    return new HalideLibrary(params, resolver, args.supportedPlatformsRegex);
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) ImmutableMap(com.google.common.collect.ImmutableMap) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 4 with ExplicitBuildTargetSourcePath

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

the class HalideLibraryDescription method createHalideStaticLibrary.

private BuildRule createHalideStaticLibrary(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder, CxxPlatform platform, Arg args) throws NoSuchBuildTargetException {
    if (!isPlatformSupported(args, platform)) {
        return new NoopBuildRule(params);
    }
    BuildRule halideCompile = ruleResolver.requireRule(params.getBuildTarget().withFlavors(HALIDE_COMPILE_FLAVOR, platform.getFlavor()));
    BuildTarget buildTarget = halideCompile.getBuildTarget();
    return Archive.from(params.getBuildTarget(), params, ruleFinder, platform, cxxBuckConfig.getArchiveContents(), CxxDescriptionEnhancer.getStaticLibraryPath(params.getProjectFilesystem(), params.getBuildTarget(), platform.getFlavor(), CxxSourceRuleFactory.PicType.PIC, platform.getStaticLibraryExtension()), ImmutableList.of(new ExplicitBuildTargetSourcePath(buildTarget, HalideCompile.objectOutputPath(buildTarget, params.getProjectFilesystem(), args.functionName))));
}
Also used : NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 5 with ExplicitBuildTargetSourcePath

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

the class PrebuiltCxxLibraryDescription method getApplicableSourcePath.

private static SourcePath getApplicableSourcePath(final BuildTarget target, final CellPathResolver cellRoots, final ProjectFilesystem filesystem, final BuildRuleResolver ruleResolver, final CxxPlatform cxxPlatform, Optional<String> versionSubDir, final String basePathString, final Optional<String> addedPathString) {
    ImmutableList<BuildRule> deps;
    MacroHandler handler = getMacroHandler(Optional.of(cxxPlatform));
    try {
        deps = handler.extractBuildTimeDeps(target, cellRoots, ruleResolver, basePathString);
    } catch (MacroException e) {
        deps = ImmutableList.of();
    }
    Path libDirPath = filesystem.getPath(expandMacros(handler, target, cellRoots, ruleResolver, basePathString));
    if (versionSubDir.isPresent()) {
        libDirPath = filesystem.getPath(versionSubDir.get()).resolve(libDirPath);
    }
    // So just expand the macros and return a PathSourcePath
    if (deps.isEmpty()) {
        Path resultPath = libDirPath;
        if (addedPathString.isPresent()) {
            resultPath = libDirPath.resolve(expandMacros(handler, target, cellRoots, ruleResolver, addedPathString.get()));
        }
        resultPath = target.getBasePath().resolve(resultPath);
        return new PathSourcePath(filesystem, resultPath);
    }
    // If we get here then this is referencing the output from a build rule.
    // This always return a ExplicitBuildTargetSourcePath
    Path p = filesystem.resolve(libDirPath);
    if (addedPathString.isPresent()) {
        p = p.resolve(addedPathString.get());
    }
    p = filesystem.relativize(p);
    return new ExplicitBuildTargetSourcePath(deps.iterator().next().getBuildTarget(), p);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) MacroException(com.facebook.buck.model.MacroException) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Aggregations

ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)21 SourcePath (com.facebook.buck.rules.SourcePath)13 BuildTarget (com.facebook.buck.model.BuildTarget)10 Path (java.nio.file.Path)9 BuildRule (com.facebook.buck.rules.BuildRule)8 Test (org.junit.Test)8 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)7 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)7 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)7 ImmutableList (com.google.common.collect.ImmutableList)6 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)3 NativeLinkableInput (com.facebook.buck.cxx.NativeLinkableInput)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 Flavor (com.facebook.buck.model.Flavor)3 InternalFlavor (com.facebook.buck.model.InternalFlavor)3 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)3 PathSourcePath (com.facebook.buck.rules.PathSourcePath)3 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)3 Step (com.facebook.buck.step.Step)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3