use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class AndroidNativeLibsPackageableGraphEnhancer method enhance.
public AndroidNativeLibsGraphEnhancementResult enhance(AndroidPackageableCollection packageableCollection) throws NoSuchBuildTargetException {
@SuppressWarnings("PMD.PrematureDeclaration") AndroidNativeLibsGraphEnhancementResult.Builder resultBuilder = AndroidNativeLibsGraphEnhancementResult.builder();
ImmutableMultimap<APKModule, NativeLinkable> nativeLinkables = packageableCollection.getNativeLinkables();
ImmutableMultimap<APKModule, NativeLinkable> nativeLinkablesAssets = packageableCollection.getNativeLinkablesAssets();
if (nativeLibraryMergeMap.isPresent() && !nativeLibraryMergeMap.get().isEmpty()) {
NativeLibraryMergeEnhancementResult enhancement = NativeLibraryMergeEnhancer.enhance(cxxBuckConfig, ruleResolver, pathResolver, ruleFinder, buildRuleParams, nativePlatforms, nativeLibraryMergeMap.get(), nativeLibraryMergeGlue, nativeLinkables, nativeLinkablesAssets);
nativeLinkables = enhancement.getMergedLinkables();
nativeLinkablesAssets = enhancement.getMergedLinkablesAssets();
resultBuilder.setSonameMergeMap(enhancement.getSonameMapping());
}
// Iterate over all the {@link AndroidNativeLinkable}s from the collector and grab the shared
// libraries for all the {@link TargetCpuType}s that we care about. We deposit them into a map
// of CPU type and SONAME to the shared library path, which the {@link CopyNativeLibraries}
// rule will use to compose the destination name.
ImmutableMap.Builder<APKModule, CopyNativeLibraries> moduleMappedCopyNativeLibriesBuilder = ImmutableMap.builder();
boolean hasCopyNativeLibraries = false;
List<NdkCxxPlatform> platformsWithNativeLibs = new ArrayList<>();
List<NdkCxxPlatform> platformsWithNativeLibsAssets = new ArrayList<>();
// Make sure we process the root module last so that we know if any of the module contain
// libraries that depend on a non-system runtime and add it to the root module if needed.
ImmutableSet<APKModule> apkModules = FluentIterable.from(apkModuleGraph.getAPKModules()).filter(input -> !input.isRootModule()).append(apkModuleGraph.getRootAPKModule()).toSet();
for (APKModule module : apkModules) {
ImmutableMap.Builder<Pair<NdkCxxPlatforms.TargetCpuType, String>, SourcePath> nativeLinkableLibsBuilder = ImmutableMap.builder();
ImmutableMap.Builder<Pair<NdkCxxPlatforms.TargetCpuType, String>, SourcePath> nativeLinkableLibsAssetsBuilder = ImmutableMap.builder();
// TODO(andrewjcg): We currently treat an empty set of filters to mean to allow everything.
// We should fix this by assigning a default list of CPU filters in the descriptions, but
// until we do, if the set of filters is empty, just build for all available platforms.
ImmutableSet<NdkCxxPlatforms.TargetCpuType> filters = cpuFilters.isEmpty() ? nativePlatforms.keySet() : cpuFilters;
for (NdkCxxPlatforms.TargetCpuType targetCpuType : filters) {
NdkCxxPlatform platform = Preconditions.checkNotNull(nativePlatforms.get(targetCpuType), "Unknown platform type " + targetCpuType.toString());
// Populate nativeLinkableLibs and nativeLinkableLibsAssets with the appropriate entries.
if (populateMapWithLinkables(nativeLinkables.get(module), nativeLinkableLibsBuilder, targetCpuType, platform) && !platformsWithNativeLibs.contains(platform)) {
platformsWithNativeLibs.add(platform);
}
if (populateMapWithLinkables(nativeLinkablesAssets.get(module), nativeLinkableLibsAssetsBuilder, targetCpuType, platform) && !platformsWithNativeLibsAssets.contains(platform)) {
platformsWithNativeLibsAssets.add(platform);
}
if (module.isRootModule()) {
// If we're using a C/C++ runtime other than the system one, add it to the APK.
NdkCxxPlatforms.CxxRuntime cxxRuntime = platform.getCxxRuntime();
if ((platformsWithNativeLibs.contains(platform) || platformsWithNativeLibsAssets.contains(platform)) && !cxxRuntime.equals(NdkCxxPlatforms.CxxRuntime.SYSTEM)) {
nativeLinkableLibsBuilder.put(new Pair<>(targetCpuType, cxxRuntime.getSoname()), new PathSourcePath(buildRuleParams.getProjectFilesystem(), platform.getCxxSharedRuntimePath().get()));
}
}
}
ImmutableMap<Pair<NdkCxxPlatforms.TargetCpuType, String>, SourcePath> nativeLinkableLibs = nativeLinkableLibsBuilder.build();
ImmutableMap<Pair<NdkCxxPlatforms.TargetCpuType, String>, SourcePath> nativeLinkableLibsAssets = nativeLinkableLibsAssetsBuilder.build();
if (packageableCollection.getNativeLibsDirectories().get(module).isEmpty() && nativeLinkableLibs.isEmpty() && nativeLinkableLibsAssets.isEmpty()) {
continue;
}
if (relinkerMode == RelinkerMode.ENABLED && (!nativeLinkableLibs.isEmpty() || !nativeLinkableLibsAssets.isEmpty())) {
NativeRelinker relinker = new NativeRelinker(buildRuleParams.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(nativeLinkableLibs.values())).addAll(ruleFinder.filterBuildRuleInputs(nativeLinkableLibsAssets.values())).build())), pathResolver, ruleFinder, cxxBuckConfig, nativePlatforms, nativeLinkableLibs, nativeLinkableLibsAssets);
nativeLinkableLibs = relinker.getRelinkedLibs();
nativeLinkableLibsAssets = relinker.getRelinkedLibsAssets();
for (BuildRule rule : relinker.getRules()) {
ruleResolver.addToIndex(rule);
}
}
ImmutableMap<StripLinkable, StrippedObjectDescription> strippedLibsMap = generateStripRules(buildRuleParams, ruleFinder, ruleResolver, originalBuildTarget, nativePlatforms, nativeLinkableLibs);
ImmutableMap<StripLinkable, StrippedObjectDescription> strippedLibsAssetsMap = generateStripRules(buildRuleParams, ruleFinder, ruleResolver, originalBuildTarget, nativePlatforms, nativeLinkableLibsAssets);
ImmutableSortedSet<BuildRule> nativeLibsRules = BuildRules.toBuildRulesFor(originalBuildTarget, ruleResolver, packageableCollection.getNativeLibsTargets().get(module));
BuildRuleParams paramsForCopyNativeLibraries = buildRuleParams.withAppendedFlavor(InternalFlavor.of(COPY_NATIVE_LIBS + "_" + module.getName())).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(nativeLibsRules).addAll(ruleFinder.filterBuildRuleInputs(packageableCollection.getNativeLibsDirectories().get(module))).addAll(strippedLibsMap.keySet()).addAll(strippedLibsAssetsMap.keySet()).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
moduleMappedCopyNativeLibriesBuilder.put(module, new CopyNativeLibraries(paramsForCopyNativeLibraries, ImmutableSet.copyOf(packageableCollection.getNativeLibsDirectories().get(module)), ImmutableSet.copyOf(strippedLibsMap.values()), ImmutableSet.copyOf(strippedLibsAssetsMap.values()), cpuFilters, module.getName()));
hasCopyNativeLibraries = true;
}
return resultBuilder.setCopyNativeLibraries(hasCopyNativeLibraries ? Optional.of(moduleMappedCopyNativeLibriesBuilder.build()) : Optional.empty()).build();
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class AndroidBinaryGraphEnhancer method createPreDexRulesForLibraries.
@VisibleForTesting
ImmutableMultimap<APKModule, DexProducedFromJavaLibrary> createPreDexRulesForLibraries(Iterable<BuildRule> additionalJavaLibrariesToDex, AndroidPackageableCollection packageableCollection) {
Iterable<BuildTarget> additionalJavaLibraryTargets = FluentIterable.from(additionalJavaLibrariesToDex).transform(BuildRule::getBuildTarget);
ImmutableMultimap.Builder<APKModule, DexProducedFromJavaLibrary> preDexDeps = ImmutableMultimap.builder();
for (BuildTarget buildTarget : Iterables.concat(packageableCollection.getJavaLibrariesToDex(), additionalJavaLibraryTargets)) {
Preconditions.checkState(!buildTargetsToExcludeFromDex.contains(buildTarget), "JavaLibrary should have been excluded from target to dex: %s", buildTarget);
BuildRule libraryRule = ruleResolver.getRule(buildTarget);
Preconditions.checkState(libraryRule instanceof JavaLibrary);
JavaLibrary javaLibrary = (JavaLibrary) libraryRule;
// resources, but export_deps is true), then there will not be anything to dx.
if (javaLibrary.getSourcePathToOutput() == null) {
continue;
}
// See whether the corresponding IntermediateDexRule has already been added to the
// ruleResolver.
BuildTarget originalTarget = javaLibrary.getBuildTarget();
BuildTarget preDexTarget = BuildTarget.builder(originalTarget).addFlavors(DEX_FLAVOR).build();
Optional<BuildRule> preDexRule = ruleResolver.getRuleOptional(preDexTarget);
if (preDexRule.isPresent()) {
preDexDeps.put(apkModuleGraph.findModuleForTarget(buildTarget), (DexProducedFromJavaLibrary) preDexRule.get());
continue;
}
// Create the IntermediateDexRule and add it to both the ruleResolver and preDexDeps.
BuildRuleParams paramsForPreDex = buildRuleParams.withBuildTarget(preDexTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(ruleResolver.getRule(javaLibrary.getBuildTarget()))), Suppliers.ofInstance(ImmutableSortedSet.of()));
DexProducedFromJavaLibrary preDex = new DexProducedFromJavaLibrary(paramsForPreDex, javaLibrary);
ruleResolver.addToIndex(preDex);
preDexDeps.put(apkModuleGraph.findModuleForTarget(buildTarget), preDex);
}
return preDexDeps.build();
}
use of com.facebook.buck.rules.BuildRule in project buck by facebook.
the class AndroidBinaryGraphEnhancer method createAdditionalBuildables.
AndroidGraphEnhancementResult createAdditionalBuildables() throws NoSuchBuildTargetException {
ImmutableSortedSet.Builder<BuildRule> enhancedDeps = ImmutableSortedSet.naturalOrder();
enhancedDeps.addAll(originalDeps);
ImmutableList.Builder<BuildRule> additionalJavaLibrariesBuilder = ImmutableList.builder();
AndroidPackageableCollector collector = new AndroidPackageableCollector(originalBuildTarget, buildTargetsToExcludeFromDex, resourcesToExclude, apkModuleGraph);
collector.addPackageables(AndroidPackageableCollector.getPackageableRules(originalDeps));
AndroidPackageableCollection packageableCollection = collector.build();
AndroidPackageableCollection.ResourceDetails resourceDetails = packageableCollection.getResourceDetails();
AndroidNativeLibsGraphEnhancementResult nativeLibsEnhancementResult = nativeLibsEnhancer.enhance(packageableCollection);
Optional<ImmutableMap<APKModule, CopyNativeLibraries>> copyNativeLibraries = nativeLibsEnhancementResult.getCopyNativeLibraries();
if (copyNativeLibraries.isPresent()) {
ruleResolver.addAllToIndex(copyNativeLibraries.get().values());
enhancedDeps.addAll(copyNativeLibraries.get().values());
}
Optional<ImmutableSortedMap<String, String>> sonameMergeMap = nativeLibsEnhancementResult.getSonameMergeMap();
if (sonameMergeMap.isPresent() && nativeLibraryMergeCodeGenerator.isPresent()) {
BuildRule generatorRule = ruleResolver.getRule(nativeLibraryMergeCodeGenerator.get());
GenerateCodeForMergedLibraryMap generateCodeForMergedLibraryMap = new GenerateCodeForMergedLibraryMap(buildRuleParams.withAppendedFlavor(GENERATE_NATIVE_LIB_MERGE_MAP_GENERATED_CODE_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(generatorRule)), Suppliers.ofInstance(ImmutableSortedSet.of())), sonameMergeMap.get(), generatorRule);
ruleResolver.addToIndex(generateCodeForMergedLibraryMap);
BuildRuleParams paramsForCompileGenCode = buildRuleParams.withAppendedFlavor(COMPILE_NATIVE_LIB_MERGE_MAP_GENERATED_CODE_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(generateCodeForMergedLibraryMap)), Suppliers.ofInstance(ImmutableSortedSet.of()));
DefaultJavaLibrary compileMergedNativeLibMapGenCode = new DefaultJavaLibrary(paramsForCompileGenCode, pathResolver, ruleFinder, ImmutableSet.of(generateCodeForMergedLibraryMap.getSourcePathToOutput()), /* resources */
ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
Optional.empty(), /* postprocessClassesCommands */
ImmutableList.of(), /* exportedDeps */
ImmutableSortedSet.of(), /* providedDeps */
ImmutableSortedSet.of(), JavaLibraryRules.getAbiInputs(ruleResolver, paramsForCompileGenCode.getDeps()), /* trackClassUsage */
false, /* additionalClasspathEntries */
ImmutableSet.of(), new JavacToJarStepFactory(// to 6 in their .buckconfig.
javacOptions.withSourceLevel("7").withTargetLevel("7"), JavacOptionsAmender.IDENTITY), /* resourcesRoot */
Optional.empty(), /* manifest file */
Optional.empty(), /* mavenCoords */
Optional.empty(), ImmutableSortedSet.of(), /* classesToRemoveFromJar */
ImmutableSet.of());
ruleResolver.addToIndex(compileMergedNativeLibMapGenCode);
additionalJavaLibrariesBuilder.add(compileMergedNativeLibMapGenCode);
enhancedDeps.add(compileMergedNativeLibMapGenCode);
}
ImmutableSortedSet<BuildRule> resourceRules = getTargetsAsRules(resourceDetails.getResourcesWithNonEmptyResDir());
ImmutableCollection<BuildRule> rulesWithResourceDirectories = ruleFinder.filterBuildRuleInputs(resourceDetails.getResourceDirectories());
FilteredResourcesProvider filteredResourcesProvider;
boolean needsResourceFiltering = resourceFilter.isEnabled() || resourceCompressionMode.isStoreStringsAsAssets() || !locales.isEmpty();
if (needsResourceFiltering) {
BuildRuleParams paramsForResourcesFilter = buildRuleParams.withAppendedFlavor(RESOURCES_FILTER_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(resourceRules).addAll(rulesWithResourceDirectories).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
ResourcesFilter resourcesFilter = new ResourcesFilter(paramsForResourcesFilter, resourceDetails.getResourceDirectories(), ImmutableSet.copyOf(resourceDetails.getWhitelistedStringDirectories()), locales, resourceCompressionMode, resourceFilter);
ruleResolver.addToIndex(resourcesFilter);
filteredResourcesProvider = resourcesFilter;
enhancedDeps.add(resourcesFilter);
resourceRules = ImmutableSortedSet.of(resourcesFilter);
} else {
filteredResourcesProvider = new IdentityResourcesProvider(resourceDetails.getResourceDirectories().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableList()));
}
// Create the AaptPackageResourcesBuildable.
BuildRuleParams paramsForAaptPackageResources = buildRuleParams.withAppendedFlavor(AAPT_PACKAGE_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
AaptPackageResources aaptPackageResources = new AaptPackageResources(paramsForAaptPackageResources, ruleFinder, ruleResolver, manifest, filteredResourcesProvider, getTargetsAsResourceDeps(resourceDetails.getResourcesWithNonEmptyResDir()), getTargetsAsRules(resourceDetails.getResourcesWithEmptyResButNonEmptyAssetsDir()), packageableCollection.getAssetsDirectories(), resourceUnionPackage, shouldBuildStringSourceMap, skipCrunchPngs, includesVectorDrawables, bannedDuplicateResourceTypes, manifestEntries);
ruleResolver.addToIndex(aaptPackageResources);
enhancedDeps.add(aaptPackageResources);
Optional<PackageStringAssets> packageStringAssets = Optional.empty();
if (resourceCompressionMode.isStoreStringsAsAssets()) {
BuildRuleParams paramsForPackageStringAssets = buildRuleParams.withAppendedFlavor(PACKAGE_STRING_ASSETS_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(aaptPackageResources).addAll(resourceRules).addAll(rulesWithResourceDirectories).addAll(Iterables.filter(ImmutableList.of(filteredResourcesProvider), BuildRule.class)).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
packageStringAssets = Optional.of(new PackageStringAssets(paramsForPackageStringAssets, locales, filteredResourcesProvider, aaptPackageResources));
ruleResolver.addToIndex(packageStringAssets.get());
enhancedDeps.add(packageStringAssets.get());
}
// already been added to the APK under test.
if (packageType != PackageType.INSTRUMENTED) {
ImmutableSortedSet<JavaLibrary> buildConfigDepsRules = addBuildConfigDeps(buildRuleParams, packageType, exopackageModes, buildConfigValues, buildConfigValuesFile, ruleResolver, javacOptions, packageableCollection);
enhancedDeps.addAll(buildConfigDepsRules);
additionalJavaLibrariesBuilder.addAll(buildConfigDepsRules);
}
ImmutableList<BuildRule> additionalJavaLibraries = additionalJavaLibrariesBuilder.build();
ImmutableMultimap<APKModule, DexProducedFromJavaLibrary> preDexedLibraries = ImmutableMultimap.of();
if (shouldPreDex) {
preDexedLibraries = createPreDexRulesForLibraries(// TODO(dreiss): Put R.java here.
additionalJavaLibraries, packageableCollection);
}
// Create rule to trim uber R.java sources.
Collection<DexProducedFromJavaLibrary> preDexedLibrariesForResourceIdFiltering = trimResourceIds ? preDexedLibraries.values() : ImmutableList.of();
BuildRuleParams paramsForTrimUberRDotJava = buildRuleParams.withAppendedFlavor(TRIM_UBER_R_DOT_JAVA_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(aaptPackageResources).addAll(preDexedLibrariesForResourceIdFiltering).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
TrimUberRDotJava trimUberRDotJava = new TrimUberRDotJava(paramsForTrimUberRDotJava, aaptPackageResources, preDexedLibrariesForResourceIdFiltering, keepResourcePattern);
ruleResolver.addToIndex(trimUberRDotJava);
// Create rule to compile uber R.java sources.
BuildRuleParams paramsForCompileUberRDotJava = buildRuleParams.withAppendedFlavor(COMPILE_UBER_R_DOT_JAVA_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(trimUberRDotJava)), Suppliers.ofInstance(ImmutableSortedSet.of()));
JavaLibrary compileUberRDotJava = new DefaultJavaLibrary(paramsForCompileUberRDotJava, pathResolver, ruleFinder, ImmutableSet.of(trimUberRDotJava.getSourcePathToOutput()), /* resources */
ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
Optional.empty(), /* postprocessClassesCommands */
ImmutableList.of(), /* exportedDeps */
ImmutableSortedSet.of(), /* providedDeps */
ImmutableSortedSet.of(), // we can just use its output as the ABI.
JavaLibraryRules.getAbiInputs(ruleResolver, paramsForCompileUberRDotJava.getDeps()), /* trackClassUsage */
false, /* additionalClasspathEntries */
ImmutableSet.of(), new JavacToJarStepFactory(javacOptions.withSourceLevel("7").withTargetLevel("7"), JavacOptionsAmender.IDENTITY), /* resourcesRoot */
Optional.empty(), /* manifest file */
Optional.empty(), /* mavenCoords */
Optional.empty(), ImmutableSortedSet.of(), /* classesToRemoveFromJar */
ImmutableSet.of());
ruleResolver.addToIndex(compileUberRDotJava);
// Create rule to dex uber R.java sources.
BuildRuleParams paramsForDexUberRDotJava = buildRuleParams.withAppendedFlavor(DEX_UBER_R_DOT_JAVA_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(compileUberRDotJava)), Suppliers.ofInstance(ImmutableSortedSet.of()));
DexProducedFromJavaLibrary dexUberRDotJava = new DexProducedFromJavaLibrary(paramsForDexUberRDotJava, compileUberRDotJava);
ruleResolver.addToIndex(dexUberRDotJava);
Optional<PreDexMerge> preDexMerge = Optional.empty();
if (shouldPreDex) {
preDexMerge = Optional.of(createPreDexMergeRule(preDexedLibraries, dexUberRDotJava));
enhancedDeps.add(preDexMerge.get());
} else {
enhancedDeps.addAll(getTargetsAsRules(packageableCollection.getJavaLibrariesToDex()));
// If not pre-dexing, AndroidBinary needs to ProGuard and/or dex the compiled R.java.
enhancedDeps.add(compileUberRDotJava);
}
// Add dependencies on all the build rules generating third-party JARs. This is mainly to
// correctly capture deps when a prebuilt_jar forwards the output from another build rule.
enhancedDeps.addAll(ruleFinder.filterBuildRuleInputs(packageableCollection.getPathsToThirdPartyJars()));
Optional<ComputeExopackageDepsAbi> computeExopackageDepsAbi = Optional.empty();
if (!exopackageModes.isEmpty()) {
BuildRuleParams paramsForComputeExopackageAbi = buildRuleParams.withAppendedFlavor(CALCULATE_ABI_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(enhancedDeps.build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
computeExopackageDepsAbi = Optional.of(new ComputeExopackageDepsAbi(paramsForComputeExopackageAbi, exopackageModes, packageableCollection, copyNativeLibraries, preDexMerge));
ruleResolver.addToIndex(computeExopackageDepsAbi.get());
enhancedDeps.add(computeExopackageDepsAbi.get());
}
return AndroidGraphEnhancementResult.builder().setPackageableCollection(packageableCollection).setAaptPackageResources(aaptPackageResources).setCompiledUberRDotJava(compileUberRDotJava).setCopyNativeLibraries(copyNativeLibraries).setPackageStringAssets(packageStringAssets).setPreDexMerge(preDexMerge).setComputeExopackageDepsAbi(computeExopackageDepsAbi).setClasspathEntriesToDex(ImmutableSet.<SourcePath>builder().addAll(packageableCollection.getClasspathEntriesToDex()).addAll(additionalJavaLibraries.stream().map(BuildRule::getSourcePathToOutput).collect(MoreCollectors.toImmutableList())).build()).setFinalDeps(enhancedDeps.build()).setAPKModuleGraph(apkModuleGraph).build();
}
use of com.facebook.buck.rules.BuildRule 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();
}
}
use of com.facebook.buck.rules.BuildRule 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());
}
Aggregations