Search in sources :

Example 21 with FakeBuildableContext

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)));
}
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) BuildRule(com.facebook.buck.rules.BuildRule) Step(com.facebook.buck.step.Step) Test(org.junit.Test)

Example 22 with FakeBuildableContext

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())));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) TargetGraph(com.facebook.buck.rules.TargetGraph) Step(com.facebook.buck.step.Step) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) 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 23 with FakeBuildableContext

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());
}
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 24 with FakeBuildableContext

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);
}
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 25 with FakeBuildableContext

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()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) ShellStep(com.facebook.buck.shell.ShellStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AbstractGenruleStep(com.facebook.buck.shell.AbstractGenruleStep) 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