use of com.facebook.buck.rules.BuildableContext 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.BuildableContext in project buck by facebook.
the class PreDexMerge method addStepsForSplitDex.
private void addStepsForSplitDex(ImmutableList.Builder<Step> steps, BuildableContext buildableContext) {
// Collect all of the DexWithClasses objects to use for merging.
ImmutableMultimap.Builder<APKModule, DexWithClasses> dexFilesToMergeBuilder = ImmutableMultimap.builder();
dexFilesToMergeBuilder.putAll(FluentIterable.from(preDexDeps.entries()).transform(input -> new AbstractMap.SimpleEntry<>(input.getKey(), DexWithClasses.TO_DEX_WITH_CLASSES.apply(input.getValue()))).filter(input -> input.getValue() != null).toSet());
final SplitDexPaths paths = new SplitDexPaths();
final ImmutableSet.Builder<Path> secondaryDexDirectories = ImmutableSet.builder();
if (dexSplitMode.getDexStore() == DexStore.RAW) {
// Raw classes*.dex files go in the top-level of the APK.
secondaryDexDirectories.add(paths.jarfilesSubdir);
} else {
// Otherwise, we want to include the metadata and jars as assets.
secondaryDexDirectories.add(paths.metadataDir);
secondaryDexDirectories.add(paths.jarfilesDir);
}
//always add additional dex stores and metadata as assets
secondaryDexDirectories.add(paths.additionalJarfilesDir);
// Do not clear existing directory which might contain secondary dex files that are not
// re-merged (since their contents did not change).
steps.add(new MkdirStep(getProjectFilesystem(), paths.jarfilesSubdir));
steps.add(new MkdirStep(getProjectFilesystem(), paths.additionalJarfilesSubdir));
steps.add(new MkdirStep(getProjectFilesystem(), paths.successDir));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), paths.metadataSubdir));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), paths.scratchDir));
buildableContext.addMetadata(SECONDARY_DEX_DIRECTORIES_KEY, secondaryDexDirectories.build().stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
buildableContext.recordArtifact(primaryDexPath);
buildableContext.recordArtifact(paths.jarfilesSubdir);
buildableContext.recordArtifact(paths.metadataSubdir);
buildableContext.recordArtifact(paths.successDir);
buildableContext.recordArtifact(paths.additionalJarfilesSubdir);
PreDexedFilesSorter preDexedFilesSorter = new PreDexedFilesSorter(Optional.ofNullable(DexWithClasses.TO_DEX_WITH_CLASSES.apply(dexForUberRDotJava)), dexFilesToMergeBuilder.build(), dexSplitMode.getPrimaryDexPatterns(), apkModuleGraph, paths.scratchDir, // to set the dex weight limit during pre-dex merging.
dexSplitMode.getLinearAllocHardLimit(), dexSplitMode.getDexStore(), paths.jarfilesSubdir, paths.additionalJarfilesSubdir);
final ImmutableMap<String, PreDexedFilesSorter.Result> sortResults = preDexedFilesSorter.sortIntoPrimaryAndSecondaryDexes(getProjectFilesystem(), steps);
PreDexedFilesSorter.Result rootApkModuleResult = sortResults.get(APKModuleGraph.ROOT_APKMODULE_NAME);
if (rootApkModuleResult == null) {
throw new HumanReadableException("No classes found in primary or secondary dexes");
}
Multimap<Path, Path> aggregatedOutputToInputs = HashMultimap.create();
ImmutableMap.Builder<Path, Sha1HashCode> dexInputHashesBuilder = ImmutableMap.builder();
for (PreDexedFilesSorter.Result result : sortResults.values()) {
if (!result.apkModule.equals(apkModuleGraph.getRootAPKModule())) {
Path dexOutputPath = paths.additionalJarfilesSubdir.resolve(result.apkModule.getName());
steps.add(new MkdirStep(getProjectFilesystem(), dexOutputPath));
}
aggregatedOutputToInputs.putAll(result.secondaryOutputToInputs);
dexInputHashesBuilder.putAll(result.dexInputHashes);
}
final ImmutableMap<Path, Sha1HashCode> dexInputHashes = dexInputHashesBuilder.build();
steps.add(new SmartDexingStep(getProjectFilesystem(), primaryDexPath, Suppliers.ofInstance(rootApkModuleResult.primaryDexInputs), Optional.of(paths.jarfilesSubdir), Optional.of(Suppliers.ofInstance(aggregatedOutputToInputs)), () -> dexInputHashes, paths.successDir, DX_MERGE_OPTIONS, dxExecutorService, xzCompressionLevel, dxMaxHeapSize));
// Record the primary dex SHA1 so exopackage apks can use it to compute their ABI keys.
// Single dex apks cannot be exopackages, so they will never need ABI keys.
steps.add(new RecordFileSha1Step(getProjectFilesystem(), primaryDexPath, PRIMARY_DEX_HASH_KEY, buildableContext));
for (PreDexedFilesSorter.Result result : sortResults.values()) {
if (!result.apkModule.equals(apkModuleGraph.getRootAPKModule())) {
Path dexMetadataOutputPath = paths.additionalJarfilesSubdir.resolve(result.apkModule.getName()).resolve("metadata.txt");
addMetadataWriteStep(result, steps, dexMetadataOutputPath);
}
}
addMetadataWriteStep(rootApkModuleResult, steps, paths.metadataFile);
}
use of com.facebook.buck.rules.BuildableContext in project buck by facebook.
the class CxxLibraryDescriptionTest method verifySourcePaths.
/**
* Verify that all source paths are resolvable, which wouldn't be the case if `cxx_genrule`
* outputs were not handled correctly.
*/
private void verifySourcePaths(BuildRuleResolver resolver) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildContext buildContext = FakeBuildContext.withSourcePathResolver(pathResolver);
BuildableContext buildableContext = new FakeBuildableContext();
for (BuildRule rule : resolver.getBuildRules()) {
rule.getBuildSteps(buildContext, buildableContext);
}
}
use of com.facebook.buck.rules.BuildableContext in project buck by facebook.
the class RemoteFileTest method ensureOutputIsAddedToBuildableContextSoItIsCached.
@Test
public void ensureOutputIsAddedToBuildableContextSoItIsCached() throws Exception {
Downloader downloader = new ExplodingDownloader();
BuildTarget target = BuildTargetFactory.newInstance("//cheese:cake");
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
RemoteFile remoteFile = new RemoteFileBuilder(downloader, target).setUrl("http://www.facebook.com/").setSha1(Hashing.sha1().hashLong(42)).build(resolver);
BuildableContext buildableContext = EasyMock.createNiceMock(BuildableContext.class);
buildableContext.recordArtifact(pathResolver.getRelativePath(remoteFile.getSourcePathToOutput()));
EasyMock.replay(buildableContext);
remoteFile.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), buildableContext);
EasyMock.verify(buildableContext);
}
use of com.facebook.buck.rules.BuildableContext in project buck by facebook.
the class AndroidBinary method addProguardCommands.
/**
* @return the resulting set of ProGuarded classpath entries to dex.
*/
@VisibleForTesting
ImmutableSet<Path> addProguardCommands(Set<Path> classpathEntriesToDex, Set<Path> depsProguardConfigs, boolean skipProguard, ImmutableList.Builder<Step> steps, BuildableContext buildableContext, SourcePathResolver resolver) {
ImmutableSet.Builder<Path> additionalLibraryJarsForProguardBuilder = ImmutableSet.builder();
for (JavaLibrary buildRule : rulesToExcludeFromDex) {
additionalLibraryJarsForProguardBuilder.addAll(buildRule.getImmediateClasspaths().stream().map(resolver::getAbsolutePath).collect(MoreCollectors.toImmutableSet()));
}
// Create list of proguard Configs for the app project and its dependencies
ImmutableSet.Builder<Path> proguardConfigsBuilder = ImmutableSet.builder();
proguardConfigsBuilder.addAll(depsProguardConfigs);
if (proguardConfig.isPresent()) {
proguardConfigsBuilder.add(resolver.getAbsolutePath(proguardConfig.get()));
}
Path proguardConfigDir = getProguardTextFilesPath();
// Transform our input classpath to a set of output locations for each input classpath.
// TODO(jasta): the output path we choose is the result of a slicing function against
// input classpath. This is fragile and should be replaced with knowledge of the BuildTarget.
final ImmutableMap<Path, Path> inputOutputEntries = classpathEntriesToDex.stream().collect(MoreCollectors.toImmutableMap(java.util.function.Function.identity(), (path) -> getProguardOutputFromInputClasspath(proguardConfigDir, path)));
// Run ProGuard on the classpath entries.
ProGuardObfuscateStep.create(javaRuntimeLauncher, getProjectFilesystem(), proguardJarOverride.isPresent() ? Optional.of(resolver.getAbsolutePath(proguardJarOverride.get())) : Optional.empty(), proguardMaxHeapSize, proguardAgentPath, resolver.getRelativePath(aaptGeneratedProguardConfigFile), proguardConfigsBuilder.build(), sdkProguardConfig, optimizationPasses, proguardJvmArgs, inputOutputEntries, additionalLibraryJarsForProguardBuilder.build(), proguardConfigDir, buildableContext, skipProguard, steps);
// ProGuard then return the input classes to dex.
if (skipProguard) {
return ImmutableSet.copyOf(inputOutputEntries.keySet());
} else {
return ImmutableSet.copyOf(inputOutputEntries.values());
}
}
Aggregations