Search in sources :

Example 96 with Step

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());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) ImmutableList(com.google.common.collect.ImmutableList) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Step(com.facebook.buck.step.Step) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 97 with Step

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);
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Step(com.facebook.buck.step.Step) ReadValuesStep(com.facebook.buck.android.AndroidBuildConfig.ReadValuesStep) Test(org.junit.Test)

Example 98 with Step

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();
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) CopyStep(com.facebook.buck.step.fs.CopyStep) UnzipStep(com.facebook.buck.zip.UnzipStep) ZipStep(com.facebook.buck.zip.ZipStep) DefaultShellStep(com.facebook.buck.shell.DefaultShellStep)

Example 99 with Step

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep) Tool(com.facebook.buck.rules.Tool)

Example 100 with Step

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;
        }
    });
}
Also used : AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) IOException(java.io.IOException) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableSet(com.google.common.collect.ImmutableSet) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) CxxLink(com.facebook.buck.cxx.CxxLink)

Aggregations

Step (com.facebook.buck.step.Step)143 ImmutableList (com.google.common.collect.ImmutableList)82 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)65 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)62 Test (org.junit.Test)54 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)49 MkdirStep (com.facebook.buck.step.fs.MkdirStep)44 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)42 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)41 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)40 BuildTarget (com.facebook.buck.model.BuildTarget)39 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)36 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)35 ExecutionContext (com.facebook.buck.step.ExecutionContext)34 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)31 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)30 BuildContext (com.facebook.buck.rules.BuildContext)25 RmStep (com.facebook.buck.step.fs.RmStep)24 CopyStep (com.facebook.buck.step.fs.CopyStep)23