use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class DefaultJavaLibraryTest method testStepsPresenceForIntermediateOutputToDiskSpooling.
@Test
public void testStepsPresenceForIntermediateOutputToDiskSpooling() {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//:lib");
BuildRule javaLibraryBuildRule = createDefaultJavaLibraryRuleWithAbiKey(buildTarget, /* srcs */
ImmutableSortedSet.of("foo/Bar.java"), /* deps */
ImmutableSortedSet.of(), /* exportedDeps */
ImmutableSortedSet.of(), Optional.of(AbstractJavacOptions.SpoolMode.INTERMEDIATE_TO_DISK), /* postprocessClassesCommands */
ImmutableList.of());
BuildContext buildContext = createBuildContext(javaLibraryBuildRule, /* bootclasspath */
null);
ImmutableList<Step> steps = javaLibraryBuildRule.getBuildSteps(buildContext, new FakeBuildableContext());
assertThat(steps, Matchers.not(Matchers.hasItem(Matchers.instanceOf(JavacDirectToJarStep.class))));
assertThat(steps, Matchers.hasItem(Matchers.instanceOf(JavacStep.class)));
assertThat(steps, Matchers.hasItem(Matchers.instanceOf(JarDirectoryStep.class)));
}
use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class DefaultJavaLibraryTest method testWhenJavacJarIsProvidedAJavacInMemoryStepIsAdded.
@Test
public void testWhenJavacJarIsProvidedAJavacInMemoryStepIsAdded() throws Exception {
BuildTarget libraryOneTarget = BuildTargetFactory.newInstance("//:libone");
BuildTarget javacTarget = BuildTargetFactory.newInstance("//langtools:javac");
TargetNode<?, ?> javacNode = PrebuiltJarBuilder.createBuilder(javacTarget).setBinaryJar(Paths.get("java/src/com/libone/JavacJar.jar")).build();
TargetNode<?, ?> ruleNode = JavaLibraryBuilder.createBuilder(libraryOneTarget).addSrc(Paths.get("java/src/com/libone/Bar.java")).setCompiler(new DefaultBuildTargetSourcePath(javacTarget)).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(javacNode, ruleNode);
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
BuildRule javac = ruleResolver.requireRule(javacTarget);
BuildRule rule = ruleResolver.requireRule(libraryOneTarget);
DefaultJavaLibrary buildable = (DefaultJavaLibrary) rule;
ImmutableList<Step> steps = buildable.getBuildSteps(FakeBuildContext.withSourcePathResolver(new SourcePathResolver(new SourcePathRuleFinder(ruleResolver))), new FakeBuildableContext());
assertEquals(10, steps.size());
Javac javacStep = ((JavacStep) steps.get(6)).getJavac();
assertTrue(javacStep instanceof Jsr199Javac);
JarBackedJavac jsrJavac = ((JarBackedJavac) javacStep);
assertEquals(RichStream.from(jsrJavac.getCompilerClassPath()).map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableSet()), ImmutableSet.of(pathResolver.getRelativePath(javac.getSourcePathToOutput())));
}
use of com.facebook.buck.rules.FakeBuildableContext 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.rules.FakeBuildableContext 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.rules.FakeBuildableContext in project buck by facebook.
the class ExternallyBuiltApplePackageTest method sdkrootEnvironmentVariableIsSet.
@Test
public void sdkrootEnvironmentVariableIsSet() {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(this.resolver));
ExternallyBuiltApplePackage rule = new ExternallyBuiltApplePackage(params, config, new FakeSourcePath(bundleLocation), true);
resolver.addToIndex(rule);
ShellStep step = Iterables.getOnlyElement(Iterables.filter(rule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext()), AbstractGenruleStep.class));
assertThat(step.getEnvironmentVariables(TestExecutionContext.newInstance()), hasEntry("SDKROOT", DEFAULT_IPHONEOS_I386_PLATFORM.getAppleSdkPaths().getSdkPath().toString()));
}
Aggregations