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);
}
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);
}
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);
}
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);
}
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));
}
}
Aggregations