Search in sources :

Example 36 with BuildRuleParams

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

the class AppleDescriptions method createBuildRulesForCoreDataDependencies.

public static Optional<CoreDataModel> createBuildRulesForCoreDataDependencies(TargetGraph targetGraph, BuildRuleParams params, String moduleName, AppleCxxPlatform appleCxxPlatform) {
    TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());
    ImmutableSet<AppleWrapperResourceArg> coreDataModelArgs = AppleBuildRules.collectTransitiveBuildRules(targetGraph, Optional.empty(), AppleBuildRules.CORE_DATA_MODEL_DESCRIPTION_CLASSES, ImmutableList.of(targetNode));
    BuildRuleParams coreDataModelParams = params.withAppendedFlavor(CoreDataModel.FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    if (coreDataModelArgs.isEmpty()) {
        return Optional.empty();
    } else {
        return Optional.of(new CoreDataModel(coreDataModelParams, appleCxxPlatform, moduleName, coreDataModelArgs.stream().map(input -> new PathSourcePath(params.getProjectFilesystem(), input.path)).collect(MoreCollectors.toImmutableSet())));
    }
}
Also used : OptionalCompat(com.facebook.buck.util.OptionalCompat) ProvidesLinkedBinaryDeps(com.facebook.buck.cxx.ProvidesLinkedBinaryDeps) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AbstractGenruleDescription(com.facebook.buck.shell.AbstractGenruleDescription) RichStream(com.facebook.buck.util.RichStream) InternalFlavor(com.facebook.buck.model.InternalFlavor) FlavorDomain(com.facebook.buck.model.FlavorDomain) CxxCompilationDatabase(com.facebook.buck.cxx.CxxCompilationDatabase) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourceList(com.facebook.buck.rules.coercer.SourceList) StripStyle(com.facebook.buck.cxx.StripStyle) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) BuildRules(com.facebook.buck.rules.BuildRules) FrameworkDependencies(com.facebook.buck.cxx.FrameworkDependencies) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) BuildTarget(com.facebook.buck.model.BuildTarget) Sets(com.google.common.collect.Sets) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Predicate(com.google.common.base.Predicate) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) CxxBinaryDescription(com.facebook.buck.cxx.CxxBinaryDescription) Joiner(com.google.common.base.Joiner) CxxStrip(com.facebook.buck.cxx.CxxStrip) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) BuildRule(com.facebook.buck.rules.BuildRule) HashSet(java.util.HashSet) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Predicates(com.google.common.base.Predicates) Suppliers(com.google.common.base.Suppliers) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) TargetNode(com.facebook.buck.rules.TargetNode) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) HumanReadableException(com.facebook.buck.util.HumanReadableException) MorePaths(com.facebook.buck.io.MorePaths) Ordering(com.google.common.collect.Ordering) BuildRuleWithBinary(com.facebook.buck.cxx.BuildRuleWithBinary) Paths(java.nio.file.Paths) SWIFT_EXTENSION(com.facebook.buck.swift.SwiftDescriptions.SWIFT_EXTENSION) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) PathSourcePath(com.facebook.buck.rules.PathSourcePath)

Example 37 with BuildRuleParams

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

the class AppleDescriptions method createBuildRuleForTransitiveAssetCatalogDependencies.

public static Optional<AppleAssetCatalog> createBuildRuleForTransitiveAssetCatalogDependencies(TargetGraph targetGraph, BuildRuleParams params, SourcePathResolver sourcePathResolver, ApplePlatform applePlatform, Tool actool) {
    TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());
    ImmutableSet<AppleAssetCatalogDescription.Arg> assetCatalogArgs = AppleBuildRules.collectRecursiveAssetCatalogs(targetGraph, Optional.empty(), ImmutableList.of(targetNode));
    ImmutableSortedSet.Builder<SourcePath> assetCatalogDirsBuilder = ImmutableSortedSet.naturalOrder();
    Optional<String> appIcon = Optional.empty();
    Optional<String> launchImage = Optional.empty();
    AppleAssetCatalogDescription.Optimization optimization = null;
    for (AppleAssetCatalogDescription.Arg arg : assetCatalogArgs) {
        if (optimization == null) {
            optimization = arg.optimization;
        }
        assetCatalogDirsBuilder.addAll(arg.dirs);
        if (arg.appIcon.isPresent()) {
            if (appIcon.isPresent()) {
                throw new HumanReadableException("At most one asset catalog in the dependencies of %s " + "can have a app_icon", params.getBuildTarget());
            }
            appIcon = arg.appIcon;
        }
        if (arg.launchImage.isPresent()) {
            if (launchImage.isPresent()) {
                throw new HumanReadableException("At most one asset catalog in the dependencies of %s " + "can have a launch_image", params.getBuildTarget());
            }
            launchImage = arg.launchImage;
        }
        if (arg.optimization != optimization) {
            throw new HumanReadableException("At most one asset catalog optimisation style can be " + "specified in the dependencies %s", params.getBuildTarget());
        }
    }
    ImmutableSortedSet<SourcePath> assetCatalogDirs = assetCatalogDirsBuilder.build();
    if (assetCatalogDirs.isEmpty()) {
        return Optional.empty();
    }
    Preconditions.checkNotNull(optimization, "optimization was null even though assetCatalogArgs was not empty");
    for (SourcePath assetCatalogDir : assetCatalogDirs) {
        Path baseName = sourcePathResolver.getRelativePath(assetCatalogDir).getFileName();
        if (!baseName.toString().endsWith(".xcassets")) {
            throw new HumanReadableException("Target %s had asset catalog dir %s - asset catalog dirs must end with .xcassets", params.getBuildTarget(), assetCatalogDir);
        }
    }
    BuildRuleParams assetCatalogParams = params.withAppendedFlavor(AppleAssetCatalog.FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    return Optional.of(new AppleAssetCatalog(assetCatalogParams, applePlatform.getName(), actool, assetCatalogDirs, appIcon, launchImage, optimization, MERGED_ASSET_CATALOG_NAME));
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) HumanReadableException(com.facebook.buck.util.HumanReadableException) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet)

Example 38 with BuildRuleParams

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

the class AppleDescriptions method createAppleBundle.

static AppleBundle createAppleBundle(FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain, CxxPlatform defaultCxxPlatform, FlavorDomain<AppleCxxPlatform> appleCxxPlatforms, TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, CodeSignIdentityStore codeSignIdentityStore, ProvisioningProfileStore provisioningProfileStore, BuildTarget binary, Either<AppleBundleExtension, String> extension, Optional<String> productName, final SourcePath infoPlist, ImmutableMap<String, String> infoPlistSubstitutions, ImmutableSortedSet<BuildTarget> deps, ImmutableSortedSet<BuildTarget> tests, AppleDebugFormat debugFormat, boolean dryRunCodeSigning, boolean cacheable) throws NoSuchBuildTargetException {
    AppleCxxPlatform appleCxxPlatform = ApplePlatforms.getAppleCxxPlatformForBuildTarget(cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms, params.getBuildTarget(), MultiarchFileInfos.create(appleCxxPlatforms, params.getBuildTarget()));
    AppleBundleDestinations destinations;
    if (extension.isLeft() && extension.getLeft().equals(AppleBundleExtension.FRAMEWORK)) {
        destinations = AppleBundleDestinations.platformFrameworkDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
    } else {
        destinations = AppleBundleDestinations.platformDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
    }
    AppleBundleResources collectedResources = AppleResources.collectResourceDirsAndFiles(targetGraph, Optional.empty(), targetGraph.get(params.getBuildTarget()));
    ImmutableSet.Builder<SourcePath> frameworksBuilder = ImmutableSet.builder();
    if (INCLUDE_FRAMEWORKS.getRequiredValue(params.getBuildTarget())) {
        for (BuildTarget dep : deps) {
            Optional<FrameworkDependencies> frameworkDependencies = resolver.requireMetadata(BuildTarget.builder(dep).addFlavors(FRAMEWORK_FLAVOR).addFlavors(NO_INCLUDE_FRAMEWORKS_FLAVOR).addFlavors(appleCxxPlatform.getCxxPlatform().getFlavor()).build(), FrameworkDependencies.class);
            if (frameworkDependencies.isPresent()) {
                frameworksBuilder.addAll(frameworkDependencies.get().getSourcePaths());
            }
        }
    }
    ImmutableSet<SourcePath> frameworks = frameworksBuilder.build();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    BuildRuleParams paramsWithoutBundleSpecificFlavors = stripBundleSpecificFlavors(params);
    Optional<AppleAssetCatalog> assetCatalog = createBuildRuleForTransitiveAssetCatalogDependencies(targetGraph, paramsWithoutBundleSpecificFlavors, sourcePathResolver, appleCxxPlatform.getAppleSdk().getApplePlatform(), appleCxxPlatform.getActool());
    addToIndex(resolver, assetCatalog);
    Optional<CoreDataModel> coreDataModel = createBuildRulesForCoreDataDependencies(targetGraph, paramsWithoutBundleSpecificFlavors, AppleBundle.getBinaryName(params.getBuildTarget(), productName), appleCxxPlatform);
    addToIndex(resolver, coreDataModel);
    Optional<SceneKitAssets> sceneKitAssets = createBuildRulesForSceneKitAssetsDependencies(targetGraph, paramsWithoutBundleSpecificFlavors, appleCxxPlatform);
    addToIndex(resolver, sceneKitAssets);
    // TODO(bhamiltoncx): Sort through the changes needed to make project generation work with
    // binary being optional.
    BuildRule flavoredBinaryRule = getFlavoredBinaryRule(cxxPlatformFlavorDomain, defaultCxxPlatform, targetGraph, paramsWithoutBundleSpecificFlavors.getBuildTarget().getFlavors(), resolver, binary);
    if (!AppleDebuggableBinary.isBuildRuleDebuggable(flavoredBinaryRule)) {
        debugFormat = AppleDebugFormat.NONE;
    }
    BuildTarget unstrippedTarget = flavoredBinaryRule.getBuildTarget().withoutFlavors(CxxStrip.RULE_FLAVOR, AppleDebuggableBinary.RULE_FLAVOR, AppleBinaryDescription.APP_FLAVOR).withoutFlavors(StripStyle.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebuggableBinary.RULE_FLAVOR).withoutFlavors(ImmutableSet.of(AppleBinaryDescription.APP_FLAVOR));
    Optional<LinkerMapMode> linkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
    if (linkerMapMode.isPresent()) {
        unstrippedTarget = unstrippedTarget.withAppendedFlavors(linkerMapMode.get().getFlavor());
    }
    BuildRule unstrippedBinaryRule = resolver.requireRule(unstrippedTarget);
    BuildRule targetDebuggableBinaryRule;
    Optional<AppleDsym> appleDsym;
    if (unstrippedBinaryRule instanceof ProvidesLinkedBinaryDeps) {
        BuildTarget binaryBuildTarget = getBinaryFromBuildRuleWithBinary(flavoredBinaryRule).getBuildTarget().withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors());
        BuildRuleParams binaryParams = params.withBuildTarget(binaryBuildTarget);
        targetDebuggableBinaryRule = createAppleDebuggableBinary(binaryParams, resolver, getBinaryFromBuildRuleWithBinary(flavoredBinaryRule), (ProvidesLinkedBinaryDeps) unstrippedBinaryRule, debugFormat, cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms);
        appleDsym = createAppleDsymForDebugFormat(debugFormat, binaryParams, resolver, (ProvidesLinkedBinaryDeps) unstrippedBinaryRule, cxxPlatformFlavorDomain, defaultCxxPlatform, appleCxxPlatforms);
    } else {
        targetDebuggableBinaryRule = unstrippedBinaryRule;
        appleDsym = Optional.empty();
    }
    BuildRuleParams bundleParamsWithFlavoredBinaryDep = getBundleParamsWithUpdatedDeps(params, binary, ImmutableSet.<BuildRule>builder().add(targetDebuggableBinaryRule).addAll(OptionalCompat.asSet(assetCatalog)).addAll(OptionalCompat.asSet(coreDataModel)).addAll(OptionalCompat.asSet(sceneKitAssets)).addAll(BuildRules.toBuildRulesFor(params.getBuildTarget(), resolver, RichStream.from(collectedResources.getAll()).concat(frameworks.stream()).filter(BuildTargetSourcePath.class).map(BuildTargetSourcePath::getTarget).collect(MoreCollectors.toImmutableSet()))).addAll(OptionalCompat.asSet(appleDsym)).build());
    ImmutableMap<SourcePath, String> extensionBundlePaths = collectFirstLevelAppleDependencyBundles(params.getDeps(), destinations);
    return new AppleBundle(bundleParamsWithFlavoredBinaryDep, resolver, extension, productName, infoPlist, infoPlistSubstitutions, Optional.of(getBinaryFromBuildRuleWithBinary(flavoredBinaryRule)), appleDsym, destinations, collectedResources, extensionBundlePaths, frameworks, appleCxxPlatform, assetCatalog, coreDataModel, sceneKitAssets, tests, codeSignIdentityStore, provisioningProfileStore, dryRunCodeSigning, cacheable);
}
Also used : FrameworkDependencies(com.facebook.buck.cxx.FrameworkDependencies) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) ProvidesLinkedBinaryDeps(com.facebook.buck.cxx.ProvidesLinkedBinaryDeps) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams)

Example 39 with BuildRuleParams

use of com.facebook.buck.rules.BuildRuleParams 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)

Example 40 with BuildRuleParams

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

the class NativeRelinker method makeRelinkerRule.

private RelinkerRule makeRelinkerRule(TargetCpuType cpuType, SourcePath source, ImmutableList<RelinkerRule> relinkerDeps) {
    Function<RelinkerRule, SourcePath> getSymbolsNeeded = RelinkerRule::getSymbolsNeededPath;
    String libname = resolver.getAbsolutePath(source).getFileName().toString();
    BuildRuleParams relinkerParams = buildRuleParams.withAppendedFlavor(InternalFlavor.of("xdso-dce")).withAppendedFlavor(InternalFlavor.of(Flavor.replaceInvalidCharacters(cpuType.toString()))).withAppendedFlavor(InternalFlavor.of(Flavor.replaceInvalidCharacters(libname))).copyAppendingExtraDeps(relinkerDeps);
    BuildRule baseRule = ruleFinder.getRule(source).orElse(null);
    ImmutableList<Arg> linkerArgs = ImmutableList.of();
    Linker linker = null;
    if (baseRule != null && baseRule instanceof CxxLink) {
        CxxLink link = (CxxLink) baseRule;
        linkerArgs = link.getArgs();
        linker = link.getLinker();
    }
    return new RelinkerRule(relinkerParams, resolver, ruleFinder, ImmutableSortedSet.copyOf(Lists.transform(relinkerDeps, getSymbolsNeeded)), cpuType, Preconditions.checkNotNull(nativePlatforms.get(cpuType)).getObjdump(), cxxBuckConfig, source, linker, linkerArgs);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Arg(com.facebook.buck.rules.args.Arg) BuildRule(com.facebook.buck.rules.BuildRule) CxxLink(com.facebook.buck.cxx.CxxLink) Linker(com.facebook.buck.cxx.Linker)

Aggregations

BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)145 BuildTarget (com.facebook.buck.model.BuildTarget)113 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)99 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)90 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)80 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)74 Test (org.junit.Test)73 BuildRule (com.facebook.buck.rules.BuildRule)72 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)69 SourcePath (com.facebook.buck.rules.SourcePath)58 Path (java.nio.file.Path)47 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)40 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)31 ImmutableList (com.google.common.collect.ImmutableList)27 PathSourcePath (com.facebook.buck.rules.PathSourcePath)26 Optional (java.util.Optional)26 Flavor (com.facebook.buck.model.Flavor)23 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)23 TargetGraph (com.facebook.buck.rules.TargetGraph)22 HumanReadableException (com.facebook.buck.util.HumanReadableException)22