Search in sources :

Example 1 with FakeBuildableContext

use of com.facebook.buck.rules.FakeBuildableContext 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 2 with FakeBuildableContext

use of com.facebook.buck.rules.FakeBuildableContext 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 3 with FakeBuildableContext

use of com.facebook.buck.rules.FakeBuildableContext 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 4 with FakeBuildableContext

use of com.facebook.buck.rules.FakeBuildableContext 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)

Example 5 with FakeBuildableContext

use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.

the class ProGuardObfuscateStepTest method testProguardJvmArgs.

@Test
public void testProguardJvmArgs() {
    List<String> proguardJvmArgs = Arrays.asList("-Dparam1=value1", "-Dparam2=value2");
    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(), Optional.of(proguardJvmArgs), /* inputAndOutputEntries */
    ImmutableMap.of(), /* additionalLibraryJarsForProguard */
    ImmutableSet.of(Paths.get("myfavorite.jar"), Paths.get("another.jar")), Paths.get("proguard-directory"), new FakeBuildableContext(), false, steps);
    ProGuardObfuscateStep proguardStep = (ProGuardObfuscateStep) steps.build().get(2);
    ImmutableList<String> parameters = proguardStep.getShellCommandInternal(executionContext);
    for (String s : proguardJvmArgs) {
        assertNotEquals(-1, parameters.indexOf(s));
    }
}
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) Test(org.junit.Test)

Aggregations

FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)48 Test (org.junit.Test)43 Step (com.facebook.buck.step.Step)42 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)33 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)32 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)29 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)28 BuildTarget (com.facebook.buck.model.BuildTarget)26 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)20 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)20 BuildContext (com.facebook.buck.rules.BuildContext)18 FakeBuildContext (com.facebook.buck.rules.FakeBuildContext)18 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)17 BuildRule (com.facebook.buck.rules.BuildRule)15 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)14 Path (java.nio.file.Path)14 ExecutionContext (com.facebook.buck.step.ExecutionContext)11 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)11 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)10 PathSourcePath (com.facebook.buck.rules.PathSourcePath)6