Search in sources :

Example 16 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class AndroidManifestTest method testBuildInternal.

@Test
public void testBuildInternal() throws IOException {
    AndroidManifest androidManifest = createSimpleAndroidManifestRule();
    ProjectFilesystem filesystem = androidManifest.getProjectFilesystem();
    Path skeletonPath = Paths.get("java/com/example/AndroidManifestSkeleton.xml");
    // Mock out a BuildContext whose DependencyGraph will be traversed.
    BuildContext buildContext = FakeBuildContext.NOOP_CONTEXT;
    SourcePathResolver pathResolver = buildContext.getSourcePathResolver();
    expect(pathResolver.getAbsolutePath(new PathSourcePath(filesystem, skeletonPath))).andStubReturn(filesystem.resolve(skeletonPath));
    expect(pathResolver.getAllAbsolutePaths(ImmutableSortedSet.of())).andStubReturn(ImmutableSortedSet.of());
    Path outPath = Paths.get("foo/bar");
    expect(pathResolver.getRelativePath(androidManifest.getSourcePathToOutput())).andStubReturn(outPath);
    replay(pathResolver);
    List<Step> steps = androidManifest.getBuildSteps(buildContext, new FakeBuildableContext());
    Step generateManifestStep = steps.get(2);
    assertEquals(new GenerateManifestStep(filesystem, filesystem.resolve(skeletonPath), /* libraryManifestPaths */
    ImmutableSet.of(), outPath), generateManifestStep);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Step(com.facebook.buck.step.Step) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Test(org.junit.Test)

Example 17 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class NdkLibraryTest method testSimpleNdkLibraryRule.

@Test
public void testSimpleNdkLibraryRule() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildContext context = FakeBuildContext.NOOP_CONTEXT;
    String basePath = "java/src/com/facebook/base";
    BuildTarget target = BuildTargetFactory.newInstance(String.format("//%s:base", basePath));
    NdkLibrary ndkLibrary = new NdkLibraryBuilder(target).setFlags(ImmutableList.of("flag1", "flag2")).setIsAsset(true).build(ruleResolver, projectFilesystem);
    assertEquals("ndk_library", ndkLibrary.getType());
    assertTrue(ndkLibrary.getProperties().is(ANDROID));
    assertTrue(ndkLibrary.isAsset());
    assertEquals(projectFilesystem.getBuckPaths().getGenDir().resolve(basePath).resolve("__libbase"), ndkLibrary.getLibraryPath());
    List<Step> steps = ndkLibrary.getBuildSteps(context, new FakeBuildableContext());
    String libbase = projectFilesystem.getBuckPaths().getScratchDir().resolve(basePath).resolve("__libbase").toString();
    MoreAsserts.assertShellCommands("ndk_library() should invoke ndk-build on the given path with some -j value", ImmutableList.of(String.format("%s -j %d -C %s flag1 flag2 " + "APP_PROJECT_PATH=%s " + "APP_BUILD_SCRIPT=%s " + "NDK_OUT=%s " + "NDK_LIBS_OUT=%s " + "BUCK_PROJECT_DIR=../../../../.. " + "host-echo-build-step=%s " + "--silent", ndkBuildCommand, Runtime.getRuntime().availableProcessors(), Paths.get(basePath).toString(), /* APP_PROJECT_PATH */
    projectFilesystem.resolve(libbase) + File.separator, /* APP_BUILD_SCRIPT */
    projectFilesystem.resolve(NdkLibraryDescription.getGeneratedMakefilePath(target, projectFilesystem)), /* NDK_OUT */
    projectFilesystem.resolve(libbase) + File.separator, /* NDK_LIBS_OUT */
    projectFilesystem.resolve(Paths.get(libbase, "libs")), /* host-echo-build-step */
    Platform.detect() == Platform.WINDOWS ? "@REM" : "@#")), steps.subList(3, 4), executionContext);
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) Step(com.facebook.buck.step.Step) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 18 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class PreDexedFilesSorterTest method generatePreDexSorterResults.

private ImmutableMap<String, PreDexedFilesSorter.Result> generatePreDexSorterResults(int numberOfPrimaryDexes, int numberOfSecondaryDexes, int numberOfExtraDexes) throws IOException {
    ImmutableMultimap.Builder<APKModule, DexWithClasses> inputDexes = ImmutableMultimap.builder();
    for (int i = 0; i < numberOfPrimaryDexes; i++) {
        inputDexes.put(moduleGraph.getRootAPKModule(), createFakeDexWithClasses(Paths.get("primary").resolve(String.format("/primary%d.dex", i)), ImmutableSet.of(String.format("primary.primary%d.class", i)), STANDARD_DEX_FILE_ESTIMATE));
    }
    for (int i = 0; i < numberOfSecondaryDexes; i++) {
        inputDexes.put(moduleGraph.getRootAPKModule(), createFakeDexWithClasses(Paths.get("secondary").resolve(String.format("secondary%d.dex", i)), ImmutableSet.of(String.format("secondary.secondary%d.class", i)), STANDARD_DEX_FILE_ESTIMATE));
    }
    for (int i = 0; i < numberOfExtraDexes; i++) {
        inputDexes.put(extraModule, createFakeDexWithClasses(Paths.get("extra").resolve(String.format("extra%d.dex", i)), ImmutableSet.of(String.format("extra.extra%d.class", i)), STANDARD_DEX_FILE_ESTIMATE));
    }
    PreDexedFilesSorter sorter = new PreDexedFilesSorter(Optional.empty(), inputDexes.build(), ImmutableSet.of(PRIMARY_DEX_PATTERN), moduleGraph, tempDir.newFolder("scratch").toPath(), DEX_WEIGHT_LIMIT, DexStore.JAR, tempDir.newFolder("secondary").toPath(), tempDir.newFolder("additional").toPath());
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    return sorter.sortIntoPrimaryAndSecondaryDexes(filesystem, steps);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Step(com.facebook.buck.step.Step)

Example 19 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class ProGuardObfuscateStepTest method testAdditionalLibraryJarsParameterFormatting.

@Test
public void testAdditionalLibraryJarsParameterFormatting() {
    Path cwd = Paths.get("root");
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    ProGuardObfuscateStep.create(JavaCompilationConstants.DEFAULT_JAVA_OPTIONS.getJavaRuntimeLauncher(), new FakeProjectFilesystem(), /* proguardJarOverride */
    Optional.empty(), "1024M", Optional.empty(), Paths.get("generated/proguard.txt"), /* customProguardConfigs */
    ImmutableSet.of(), ProGuardObfuscateStep.SdkProguardType.DEFAULT, /* optimizationPasses */
    Optional.empty(), /* proguardJvmArgs */
    Optional.empty(), /* inputAndOutputEntries */
    ImmutableMap.of(), /* additionalLibraryJarsForProguard */
    ImmutableSet.of(Paths.get("myfavorite.jar"), Paths.get("another.jar")), Paths.get("proguard-directory"), new FakeBuildableContext(), false, steps);
    ProGuardObfuscateStep.CommandLineHelperStep commandLineHelperStep = (ProGuardObfuscateStep.CommandLineHelperStep) steps.build().get(1);
    ImmutableList<String> parameters = commandLineHelperStep.getParameters(executionContext, cwd);
    int libraryJarsArgIndex = parameters.indexOf("-libraryjars");
    int libraryJarsValueIndex = parameters.indexOf("myfavorite.jar" + File.pathSeparatorChar + "another.jar");
    assertNotEquals(-1, libraryJarsArgIndex);
    assertEquals(libraryJarsValueIndex, libraryJarsArgIndex + 1);
}
Also used : 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) Test(org.junit.Test)

Example 20 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class ProGuardObfuscateStepTest method checkSdkConfig.

private void checkSdkConfig(ExecutionContext context, Path cwd, ProGuardObfuscateStep.SdkProguardType sdkProguardConfig, Optional<String> proguardAgentPath, String expectedPath) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    ProGuardObfuscateStep.create(JavaCompilationConstants.DEFAULT_JAVA_OPTIONS.getJavaRuntimeLauncher(), new FakeProjectFilesystem(), /* proguardJarOverride */
    Optional.empty(), "1024M", proguardAgentPath, Paths.get("generated/proguard.txt"), /* customProguardConfigs */
    ImmutableSet.of(), sdkProguardConfig, /* optimizationPasses */
    Optional.empty(), /* proguardJvmArgs */
    Optional.empty(), /* inputAndOutputEntries */
    ImmutableMap.of(), /* additionalLibraryJarsForProguard */
    ImmutableSet.of(), Paths.get("proguard-directory"), new FakeBuildableContext(), false, steps);
    ProGuardObfuscateStep.CommandLineHelperStep commandLineHelperStep = (ProGuardObfuscateStep.CommandLineHelperStep) steps.build().get(1);
    String found = null;
    Iterator<String> argsIt = commandLineHelperStep.getParameters(context, cwd).iterator();
    while (argsIt.hasNext()) {
        String arg = argsIt.next();
        if (!arg.equals("-include")) {
            continue;
        }
        assertTrue(argsIt.hasNext());
        String file = argsIt.next();
        if (file.startsWith("sdk-")) {
            found = file;
            break;
        }
    }
    assertEquals(expectedPath, found);
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) ImmutableList(com.google.common.collect.ImmutableList) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Step(com.facebook.buck.step.Step)

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