use of com.facebook.buck.step.Step in project buck by facebook.
the class AndroidBinaryTest method testAndroidBinaryNoDx.
@Test
public void testAndroidBinaryNoDx() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
// Two android_library deps, neither with an assets directory.
BuildRule libraryOne = createAndroidLibraryRule("//java/src/com/facebook/base:libraryOne", ruleResolver, null, /* resDirectory */
null, /* assetDirectory */
null);
BuildRule libraryOneRule = ruleResolver.getRule(libraryOne.getBuildTarget());
BuildRule libraryTwo = createAndroidLibraryRule("//java/src/com/facebook/base:libraryTwo", ruleResolver, null, /* resDirectory */
null, /* assetDirectory */
null);
BuildRule libraryTwoRule = ruleResolver.getRule(libraryTwo.getBuildTarget());
// One android_binary rule that depends on the two android_library rules.
BuildTarget binaryBuildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/base:apk");
ImmutableSortedSet<BuildTarget> originalDepsTargets = ImmutableSortedSet.of(libraryOneRule.getBuildTarget(), libraryTwoRule.getBuildTarget());
BuildRule keystoreRule = addKeystoreRule(ruleResolver);
AndroidBinary androidBinary = AndroidBinaryBuilder.createBuilder(binaryBuildTarget).setOriginalDeps(originalDepsTargets).setBuildTargetsToExcludeFromDex(ImmutableSet.of(libraryTwoRule.getBuildTarget())).setManifest(new FakeSourcePath("java/src/com/facebook/base/AndroidManifest.xml")).setKeystore(keystoreRule.getBuildTarget()).setPackageType("release").build(ruleResolver);
AndroidPackageableCollection packageableCollection = androidBinary.getAndroidPackageableCollection();
ImmutableList.Builder<Step> commands = ImmutableList.builder();
FakeBuildableContext buildableContext = new FakeBuildableContext();
androidBinary.addProguardCommands(packageableCollection.getClasspathEntriesToDex().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableSet()), pathResolver.getAllAbsolutePaths(packageableCollection.getProguardConfigs()), false, commands, buildableContext, pathResolver);
BuildTarget aaptPackageTarget = binaryBuildTarget.withFlavors(AndroidBinaryGraphEnhancer.AAPT_PACKAGE_FLAVOR);
Path aaptProguardDir = BuildTargets.getGenPath(androidBinary.getProjectFilesystem(), aaptPackageTarget, "%s/proguard/");
Path proguardOutputDir = BuildTargets.getGenPath(androidBinary.getProjectFilesystem(), binaryBuildTarget, "%s/proguard/");
ImmutableSet<Path> expectedRecordedArtifacts = ImmutableSet.of(proguardOutputDir.resolve("configuration.txt"), proguardOutputDir.resolve("mapping.txt"), proguardOutputDir.resolve("seeds.txt"));
assertEquals(expectedRecordedArtifacts, buildableContext.getRecordedArtifacts());
buildableContext = new FakeBuildableContext();
ImmutableList.Builder<Step> expectedSteps = ImmutableList.builder();
ProGuardObfuscateStep.create(JavaCompilationConstants.DEFAULT_JAVA_OPTIONS.getJavaRuntimeLauncher(), new FakeProjectFilesystem(), /* proguardJarOverride */
Optional.empty(), /* proguardMaxHeapSize */
"1024M", /* proguardAgentPath */
Optional.empty(), aaptProguardDir.resolve("proguard.txt"), /* customProguardConfigs */
ImmutableSet.of(), ProGuardObfuscateStep.SdkProguardType.DEFAULT, /* optimizationPasses */
Optional.empty(), /* proguardJvmArgs */
Optional.empty(), ImmutableMap.of(BuildTargets.getGenPath(libraryOneRule.getProjectFilesystem(), libraryOneRule.getBuildTarget(), "lib__%s__output").resolve(libraryOneRule.getBuildTarget().getShortName() + ".jar"), proguardOutputDir.resolve(BuildTargets.getGenPath(libraryOneRule.getProjectFilesystem(), libraryOneRule.getBuildTarget(), "lib__%s__output/").resolve(libraryOne.getBuildTarget().getShortNameAndFlavorPostfix() + "-obfuscated.jar"))), ImmutableSet.of(libraryTwo.getBuildTarget().getUnflavoredBuildTarget().getCellPath().resolve(BuildTargets.getGenPath(libraryTwoRule.getProjectFilesystem(), libraryTwoRule.getBuildTarget(), "lib__%s__output").resolve(libraryTwoRule.getBuildTarget().getShortNameAndFlavorPostfix() + ".jar"))), proguardOutputDir, buildableContext, false, expectedSteps);
assertEquals(expectedSteps.build(), commands.build());
assertEquals(expectedRecordedArtifacts, buildableContext.getRecordedArtifacts());
}
use of com.facebook.buck.step.Step in project buck by facebook.
the class AndroidBuildConfigTest method testBuildInternal.
@Test
public void testBuildInternal() throws IOException {
AndroidBuildConfig buildConfig = createSimpleBuildConfigRule();
List<Step> steps = buildConfig.getBuildSteps(FakeBuildContext.NOOP_CONTEXT, new FakeBuildableContext());
Step generateBuildConfigStep = steps.get(1);
GenerateBuildConfigStep expectedStep = new GenerateBuildConfigStep(new FakeProjectFilesystem(), BuildTargetFactory.newInstance("//java/com/example:build_config").getUnflavoredBuildTarget(), /* javaPackage */
"com.example", /* useConstantExpressions */
false, /* constants */
Suppliers.ofInstance(BuildConfigFields.empty()), BuildTargets.getGenPath(filesystem, BUILD_TARGET, "__%s__/BuildConfig.java"));
assertEquals(expectedStep, generateBuildConfigStep);
}
use of com.facebook.buck.step.Step in project buck by facebook.
the class IntraDexReorderStep method generateReorderCommands.
private ImmutableList<Step> generateReorderCommands() {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
reorderEntry(inputPrimaryDexPath, true, steps);
if (secondaryDexMap.isPresent()) {
Set<Path> secondaryDexSet = secondaryDexMap.get().get().keySet();
for (Path secondaryDexPath : secondaryDexSet) {
reorderEntry(secondaryDexPath, false, steps);
}
}
return steps.build();
}
use of com.facebook.buck.step.Step in project buck by facebook.
the class ReDexStep method createSteps.
public static ImmutableList<Step> createSteps(final ProjectFilesystem filesystem, SourcePathResolver resolver, RedexOptions redexOptions, Path inputApkPath, Path outputApkPath, Supplier<KeystoreProperties> keystorePropertiesSupplier, Path proguardConfigDir, SourcePathResolver pathResolver) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
Tool redexBinary = redexOptions.getRedex();
ReDexStep redexStep = new ReDexStep(filesystem.getRootPath(), redexBinary.getCommandPrefix(resolver), redexBinary.getEnvironment(resolver), inputApkPath, outputApkPath, keystorePropertiesSupplier, redexOptions.getRedexConfig().map(resolver::getAbsolutePath), redexOptions.getRedexExtraArgs(), proguardConfigDir.resolve("mapping.txt"), proguardConfigDir.resolve("command-line.txt"), proguardConfigDir.resolve("seeds.txt"), pathResolver);
steps.add(redexStep);
return steps.build();
}
use of com.facebook.buck.step.Step in project buck by facebook.
the class RelinkerRule method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, final BuildableContext buildableContext) {
final ImmutableList.Builder<Step> relinkerSteps = ImmutableList.builder();
if (linker != null) {
ImmutableList<Arg> args = ImmutableList.<Arg>builder().addAll(linkerArgs).add(StringArg.of("-Wl,--version-script=" + getRelativeVersionFilePath().toString())).build();
relinkerSteps.addAll(new CxxLink(buildRuleParams.withAppendedFlavor(InternalFlavor.of("cxx-link")).withoutFlavor(LinkerMapMode.NO_LINKER_MAP.getFlavor()), linker, getLibFilePath(), args, cxxBuckConfig.getLinkScheduleInfo(), cxxBuckConfig.shouldCacheLinks()).getBuildSteps(context, buildableContext));
buildableContext.recordArtifact(getRelativeVersionFilePath());
}
buildableContext.recordArtifact(getSymbolsNeededOutPath());
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), getScratchDirPath()), new AbstractExecutionStep("xdso-dce relinker") {
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
ImmutableSet<String> symbolsNeeded = readSymbolsNeeded();
if (linker == null) {
getProjectFilesystem().copyFile(getBaseLibPath(), getLibFilePath());
buildableContext.recordArtifact(getLibFilePath());
} else {
writeVersionScript(context.getProcessExecutor(), symbolsNeeded);
for (Step s : relinkerSteps.build()) {
StepExecutionResult executionResult = s.execute(context);
if (!executionResult.isSuccess()) {
return StepExecutionResult.ERROR;
}
}
}
writeSymbols(getSymbolsNeededOutPath(), Sets.union(symbolsNeeded, getSymbols(context.getProcessExecutor(), getLibFilePath()).undefined));
return StepExecutionResult.SUCCESS;
}
});
}
Aggregations