Search in sources :

Example 6 with BuildTarget

use of com.facebook.buck.model.BuildTarget 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 7 with BuildTarget

use of com.facebook.buck.model.BuildTarget 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 8 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class AppleTestDescription method createTestHostInfo.

private TestHostInfo createTestHostInfo(BuildRuleParams params, BuildRuleResolver resolver, BuildTarget testHostAppBuildTarget, AppleDebugFormat debugFormat, Iterable<Flavor> additionalFlavors, ImmutableList<CxxPlatform> cxxPlatforms) throws NoSuchBuildTargetException {
    BuildRule rule = resolver.requireRule(BuildTarget.builder(testHostAppBuildTarget).addAllFlavors(additionalFlavors).addFlavors(debugFormat.getFlavor()).addFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor()).build());
    if (!(rule instanceof AppleBundle)) {
        throw new HumanReadableException("Apple test rule '%s' has test_host_app '%s' not of type '%s'.", params.getBuildTarget(), testHostAppBuildTarget, Description.getBuildRuleType(AppleBundleDescription.class));
    }
    AppleBundle testHostApp = (AppleBundle) rule;
    SourcePath testHostAppBinarySourcePath = testHostApp.getBinaryBuildRule().getSourcePathToOutput();
    ImmutableMap<BuildTarget, NativeLinkable> roots = NativeLinkables.getNativeLinkableRoots(testHostApp.getBinary().get().getDeps(), x -> true);
    // Union the blacklist of all the platforms. This should give a superset for each particular
    // platform, which should be acceptable as items in the blacklist thare are unmatched are simply
    // ignored.
    ImmutableSet.Builder<BuildTarget> blacklistBuilder = ImmutableSet.builder();
    for (CxxPlatform platform : cxxPlatforms) {
        blacklistBuilder.addAll(NativeLinkables.getTransitiveNativeLinkables(platform, roots.values()).keySet());
    }
    return TestHostInfo.of(testHostApp, testHostAppBinarySourcePath, blacklistBuilder.build());
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRule(com.facebook.buck.rules.BuildRule)

Example 9 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class AppleTestDescription method createTestLibraryRule.

private <A extends Arg> BuildRule createTestLibraryRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args, Optional<SourcePath> testHostAppBinarySourcePath, ImmutableSet<BuildTarget> blacklist, BuildTarget libraryTarget) throws NoSuchBuildTargetException {
    BuildTarget existingLibraryTarget = libraryTarget.withAppendedFlavors(AppleDebuggableBinary.RULE_FLAVOR, CxxStrip.RULE_FLAVOR).withAppendedFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor());
    Optional<BuildRule> existingLibrary = resolver.getRuleOptional(existingLibraryTarget);
    BuildRule library;
    if (existingLibrary.isPresent()) {
        library = existingLibrary.get();
    } else {
        library = appleLibraryDescription.createLibraryBuildRule(targetGraph, params.withBuildTarget(libraryTarget), resolver, args, // we'll just link them statically.
        Optional.of(Linker.LinkableDepType.STATIC), testHostAppBinarySourcePath, blacklist);
        resolver.addToIndex(library);
    }
    return library;
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) BuildRule(com.facebook.buck.rules.BuildRule)

Example 10 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class ProjectGenerator method resolveSourcePath.

private Path resolveSourcePath(SourcePath sourcePath) {
    if (sourcePath instanceof PathSourcePath) {
        return ((PathSourcePath) sourcePath).getRelativePath();
    }
    Preconditions.checkArgument(sourcePath instanceof BuildTargetSourcePath);
    BuildTargetSourcePath<?> buildTargetSourcePath = (BuildTargetSourcePath<?>) sourcePath;
    BuildTarget buildTarget = buildTargetSourcePath.getTarget();
    TargetNode<?, ?> node = targetGraph.get(buildTarget);
    Optional<TargetNode<ExportFileDescription.Arg, ?>> exportFileNode = node.castArg(ExportFileDescription.Arg.class);
    if (!exportFileNode.isPresent()) {
        BuildRuleResolver resolver = buildRuleResolverForNode.apply(node);
        SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
        SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
        Path output = pathResolver.getRelativePath(sourcePath);
        if (output == null) {
            throw new HumanReadableException("The target '%s' does not have an output.", node.getBuildTarget());
        }
        requiredBuildTargetsBuilder.add(buildTarget);
        return output;
    }
    Optional<SourcePath> src = exportFileNode.get().getConstructorArg().src;
    if (!src.isPresent()) {
        return buildTarget.getBasePath().resolve(buildTarget.getShortNameAndFlavorPostfix());
    }
    return resolveSourcePath(src.get());
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) TargetNode(com.facebook.buck.rules.TargetNode) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ExportFileDescription(com.facebook.buck.shell.ExportFileDescription)

Aggregations

BuildTarget (com.facebook.buck.model.BuildTarget)1045 Test (org.junit.Test)758 Path (java.nio.file.Path)323 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)289 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)254 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)248 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)226 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)216 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)209 BuildRule (com.facebook.buck.rules.BuildRule)196 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)178 SourcePath (com.facebook.buck.rules.SourcePath)163 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)161 TargetGraph (com.facebook.buck.rules.TargetGraph)156 PathSourcePath (com.facebook.buck.rules.PathSourcePath)116 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)108 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)91 ImmutableSet (com.google.common.collect.ImmutableSet)90 ImmutableMap (com.google.common.collect.ImmutableMap)78 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)75