Search in sources :

Example 71 with BuildRule

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

the class AppleLibraryDescription method requireSingleArchUnstrippedBuildRule.

private <A extends AppleNativeTargetDescriptionArg> BuildRule requireSingleArchUnstrippedBuildRule(BuildRuleParams params, BuildRuleResolver resolver, TargetGraph targetGraph, A args, Optional<Linker.LinkableDepType> linkableDepType, Optional<SourcePath> bundleLoader, ImmutableSet<BuildTarget> blacklist, SourcePathResolver pathResolver) throws NoSuchBuildTargetException {
    Optional<BuildRule> swiftCompanionBuildRule = swiftDelegate.createCompanionBuildRule(targetGraph, params, resolver, args);
    if (swiftCompanionBuildRule.isPresent()) {
        // otherwise, add this swift rule as a dependency.
        if (isSwiftTarget(params.getBuildTarget())) {
            return swiftCompanionBuildRule.get();
        } else {
            args.exportedDeps = ImmutableSortedSet.<BuildTarget>naturalOrder().addAll(args.exportedDeps).add(swiftCompanionBuildRule.get().getBuildTarget()).build();
            params = params.copyAppendingExtraDeps(ImmutableSet.of(swiftCompanionBuildRule.get()));
        }
    }
    CxxLibraryDescription.Arg delegateArg = delegate.createUnpopulatedConstructorArg();
    AppleDescriptions.populateCxxLibraryDescriptionArg(pathResolver, delegateArg, args, params.getBuildTarget());
    // remove some flavors from cxx rule that don't affect the rule output
    BuildTarget unstrippedTarget = params.getBuildTarget().withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors());
    if (AppleDescriptions.flavorsDoNotAllowLinkerMapMode(params)) {
        unstrippedTarget = unstrippedTarget.withoutFlavors(LinkerMapMode.NO_LINKER_MAP.getFlavor());
    }
    Optional<BuildRule> existingRule = resolver.getRuleOptional(unstrippedTarget);
    if (existingRule.isPresent()) {
        return existingRule.get();
    } else {
        BuildRule rule = delegate.createBuildRule(params.withBuildTarget(unstrippedTarget), resolver, delegateArg, linkableDepType, bundleLoader, blacklist);
        return resolver.addToIndex(rule);
    }
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) BuildRule(com.facebook.buck.rules.BuildRule)

Example 72 with BuildRule

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

the class NativeLibraryMergeEnhancer method enhance.

@SuppressWarnings("PMD.PrematureDeclaration")
static NativeLibraryMergeEnhancementResult enhance(CxxBuckConfig cxxBuckConfig, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, BuildRuleParams buildRuleParams, ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> nativePlatforms, Map<String, List<Pattern>> mergeMap, Optional<BuildTarget> nativeLibraryMergeGlue, ImmutableMultimap<APKModule, NativeLinkable> linkables, ImmutableMultimap<APKModule, NativeLinkable> linkablesAssets) throws NoSuchBuildTargetException {
    NativeLibraryMergeEnhancer.ruleFinder = ruleFinder;
    NativeLibraryMergeEnhancementResult.Builder builder = NativeLibraryMergeEnhancementResult.builder();
    ImmutableSet<APKModule> modules = ImmutableSet.<APKModule>builder().addAll(linkables.keySet()).addAll(linkablesAssets.keySet()).build();
    ImmutableSortedMap.Builder<String, String> sonameMapBuilder = ImmutableSortedMap.naturalOrder();
    for (APKModule module : modules) {
        // Sort by build target here to ensure consistent behavior.
        Iterable<NativeLinkable> allLinkables = Stream.concat(linkables.get(module).stream(), linkablesAssets.get(module).stream()).sorted(Comparator.comparing(NativeLinkable::getBuildTarget)).collect(MoreCollectors.toImmutableList());
        final ImmutableSet<NativeLinkable> linkableAssetSet = ImmutableSet.copyOf(linkablesAssets.get(module));
        Map<NativeLinkable, MergedNativeLibraryConstituents> linkableMembership = makeConstituentMap(buildRuleParams, mergeMap, allLinkables, linkableAssetSet);
        sonameMapBuilder.putAll(makeSonameMap(// so just pick the first platform and use that to get all the sonames.
        nativePlatforms.values().iterator().next().getCxxPlatform(), linkableMembership));
        Iterable<MergedNativeLibraryConstituents> orderedConstituents = getOrderedMergedConstituents(buildRuleParams, linkableMembership);
        Optional<NativeLinkable> glueLinkable = Optional.empty();
        if (nativeLibraryMergeGlue.isPresent()) {
            BuildRule rule = ruleResolver.getRule(nativeLibraryMergeGlue.get());
            if (!(rule instanceof NativeLinkable)) {
                throw new RuntimeException("Native library merge glue " + rule.getBuildTarget() + " for application " + buildRuleParams.getBuildTarget() + " is not linkable.");
            }
            glueLinkable = Optional.of(((NativeLinkable) rule));
        }
        Set<MergedLibNativeLinkable> mergedLinkables = createLinkables(cxxBuckConfig, ruleResolver, pathResolver, buildRuleParams, glueLinkable, orderedConstituents);
        for (MergedLibNativeLinkable linkable : mergedLinkables) {
            if (Collections.disjoint(linkable.constituents.getLinkables(), linkableAssetSet)) {
                builder.putMergedLinkables(module, linkable);
            } else if (linkableAssetSet.containsAll(linkable.constituents.getLinkables())) {
                builder.putMergedLinkablesAssets(module, linkable);
            }
        }
    }
    builder.setSonameMapping(sonameMapBuilder.build());
    return builder.build();
}
Also used : NativeLinkable(com.facebook.buck.cxx.NativeLinkable) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) BuildRule(com.facebook.buck.rules.BuildRule)

Example 73 with BuildRule

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

the class AppleBinaryDescription method createAppleDebuggableBinary.

private <A extends Arg> BuildRule createAppleDebuggableBinary(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args, BuildTarget unstrippedBinaryBuildTarget, ProvidesLinkedBinaryDeps unstrippedBinaryRule) throws NoSuchBuildTargetException {
    BuildTarget strippedBinaryBuildTarget = unstrippedBinaryBuildTarget.withAppendedFlavors(CxxStrip.RULE_FLAVOR, StripStyle.FLAVOR_DOMAIN.getFlavor(params.getBuildTarget().getFlavors()).orElse(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor()));
    BuildRule strippedBinaryRule = createBinary(targetGraph, params.withBuildTarget(strippedBinaryBuildTarget), resolver, args);
    return AppleDescriptions.createAppleDebuggableBinary(params.withBuildTarget(unstrippedBinaryBuildTarget), resolver, strippedBinaryRule, unstrippedBinaryRule, AppleDebugFormat.FLAVOR_DOMAIN.getRequiredValue(params.getBuildTarget()), delegate.getCxxPlatforms(), delegate.getDefaultCxxPlatform(), platformFlavorsToAppleCxxPlatforms);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule)

Example 74 with BuildRule

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

the class AppleBinaryDescription method createBinary.

private <A extends AppleBinaryDescription.Arg> BuildRule createBinary(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    if (AppleDescriptions.flavorsDoNotAllowLinkerMapMode(params)) {
        params = params.withoutFlavor(LinkerMapMode.NO_LINKER_MAP.getFlavor());
    }
    Optional<MultiarchFileInfo> fatBinaryInfo = MultiarchFileInfos.create(platformFlavorsToAppleCxxPlatforms, params.getBuildTarget());
    if (fatBinaryInfo.isPresent()) {
        if (shouldUseStubBinary(params)) {
            BuildTarget thinTarget = Iterables.getFirst(fatBinaryInfo.get().getThinTargets(), null);
            return requireThinBinary(targetGraph, params.withBuildTarget(thinTarget), resolver, args);
        }
        ImmutableSortedSet.Builder<BuildRule> thinRules = ImmutableSortedSet.naturalOrder();
        for (BuildTarget thinTarget : fatBinaryInfo.get().getThinTargets()) {
            Optional<BuildRule> existingThinRule = resolver.getRuleOptional(thinTarget);
            if (existingThinRule.isPresent()) {
                thinRules.add(existingThinRule.get());
                continue;
            }
            BuildRule thinRule = requireThinBinary(targetGraph, params.withBuildTarget(thinTarget), resolver, args);
            resolver.addToIndex(thinRule);
            thinRules.add(thinRule);
        }
        return MultiarchFileInfos.requireMultiarchRule(params, resolver, fatBinaryInfo.get(), thinRules.build());
    } else {
        return requireThinBinary(targetGraph, params, resolver, args);
    }
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule)

Example 75 with BuildRule

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

the class RobolectricTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    JavacOptions javacOptions = JavacOptionsFactory.create(templateOptions, params, resolver, ruleFinder, args);
    AndroidLibraryGraphEnhancer graphEnhancer = new AndroidLibraryGraphEnhancer(params.getBuildTarget(), params.copyReplacingExtraDeps(Suppliers.ofInstance(resolver.getAllRules(args.exportedDeps))), javacOptions, DependencyMode.TRANSITIVE, /* forceFinalResourceIds */
    true, /* resourceUnionPackage */
    Optional.empty(), /* rName */
    Optional.empty(), args.useOldStyleableFormat);
    if (CalculateAbi.isAbiTarget(params.getBuildTarget())) {
        if (params.getBuildTarget().getFlavors().contains(AndroidLibraryGraphEnhancer.DUMMY_R_DOT_JAVA_FLAVOR)) {
            return graphEnhancer.getBuildableForAndroidResourcesAbi(resolver, ruleFinder);
        }
        BuildTarget testTarget = CalculateAbi.getLibraryTarget(params.getBuildTarget());
        BuildRule testRule = resolver.requireRule(testTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
    }
    ImmutableList<String> vmArgs = args.vmArgs;
    Optional<DummyRDotJava> dummyRDotJava = graphEnhancer.getBuildableForAndroidResources(resolver, /* createBuildableIfEmpty */
    true);
    ImmutableSet<Either<SourcePath, Path>> additionalClasspathEntries = ImmutableSet.of();
    if (dummyRDotJava.isPresent()) {
        additionalClasspathEntries = ImmutableSet.of(Either.ofLeft(dummyRDotJava.get().getSourcePathToOutput()));
        ImmutableSortedSet<BuildRule> newExtraDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getExtraDeps().get()).add(dummyRDotJava.get()).build();
        params = params.copyReplacingExtraDeps(Suppliers.ofInstance(newExtraDeps));
    }
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    JavaTestDescription.CxxLibraryEnhancement cxxLibraryEnhancement = new JavaTestDescription.CxxLibraryEnhancement(params, args.useCxxLibraries, args.cxxLibraryWhitelist, resolver, ruleFinder, cxxPlatform);
    params = cxxLibraryEnhancement.updatedParams;
    // Rewrite dependencies on tests to actually depend on the code which backs the test.
    BuildRuleParams testsLibraryParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).addAll(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps)))).build()), Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getExtraDeps().get()).addAll(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))).build())).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
    JavaLibrary testsLibrary = resolver.addToIndex(new DefaultJavaLibrary(testsLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), javacOptions.getGeneratedSourceFolderName(), args.proguardConfig, /* postprocessClassesCommands */
    ImmutableList.of(), /* exportDeps */
    ImmutableSortedSet.of(), /* providedDeps */
    resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, testsLibraryParams.getDeps()), javacOptions.trackClassUsage(), additionalClasspathEntries, new JavacToJarStepFactory(javacOptions, new BootClasspathAppender()), args.resourcesRoot, args.manifestFile, args.mavenCoords, /* tests */
    ImmutableSortedSet.of(), /* classesToRemoveFromJar */
    ImmutableSet.of()));
    return new RobolectricTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), ruleFinder, testsLibrary, additionalClasspathEntries, args.labels, args.contacts, TestType.JUNIT, javaOptions, vmArgs, cxxLibraryEnhancement.nativeLibsEnvironment, dummyRDotJava, args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs, args.env, args.getRunTestSeparately(), args.getForkMode(), args.stdOutLogLevel, args.stdErrLogLevel, args.robolectricRuntimeDependency, args.robolectricManifest);
}
Also used : JavacOptions(com.facebook.buck.jvm.java.JavacOptions) JavacToJarStepFactory(com.facebook.buck.jvm.java.JavacToJarStepFactory) Optional(java.util.Optional) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) Either(com.facebook.buck.model.Either) JavaTestDescription(com.facebook.buck.jvm.java.JavaTestDescription) BuildRule(com.facebook.buck.rules.BuildRule)

Aggregations

BuildRule (com.facebook.buck.rules.BuildRule)361 BuildTarget (com.facebook.buck.model.BuildTarget)199 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)190 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)189 Test (org.junit.Test)175 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)165 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)162 SourcePath (com.facebook.buck.rules.SourcePath)118 Path (java.nio.file.Path)95 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)70 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)70 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)66 TargetGraph (com.facebook.buck.rules.TargetGraph)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)61 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)61 ImmutableList (com.google.common.collect.ImmutableList)58 PathSourcePath (com.facebook.buck.rules.PathSourcePath)51 ImmutableSet (com.google.common.collect.ImmutableSet)45 ImmutableMap (com.google.common.collect.ImmutableMap)44 RuleKey (com.facebook.buck.rules.RuleKey)43