Search in sources :

Example 6 with BuildContext

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

the class CxxPreprocessAndCompileTest method compilerAndPreprocessorAreAlwaysReturnedFromGetInputsAfterBuildingLocally.

@Test
public void compilerAndPreprocessorAreAlwaysReturnedFromGetInputsAfterBuildingLocally() throws Exception {
    ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    SourcePath preprocessor = new PathSourcePath(filesystem, Paths.get("preprocessor"));
    Tool preprocessorTool = new CommandTool.Builder().addInput(preprocessor).build();
    SourcePath compiler = new PathSourcePath(filesystem, Paths.get("compiler"));
    Tool compilerTool = new CommandTool.Builder().addInput(compiler).build();
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(filesystem).build();
    BuildContext context = FakeBuildContext.withSourcePathResolver(pathResolver);
    filesystem.writeContentsToPath("test.o: " + pathResolver.getRelativePath(DEFAULT_INPUT) + " ", filesystem.getPath("test.o.dep"));
    CxxPreprocessAndCompile cxxPreprocess = CxxPreprocessAndCompile.preprocessAndCompile(params, new PreprocessorDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), DEFAULT_WORKING_DIR, new GccPreprocessor(preprocessorTool), PreprocessorFlags.builder().build(), DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION, Optional.empty(), /* leadingIncludePaths */
    Optional.empty()), new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, CxxToolFlags.of()), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty());
    assertThat(cxxPreprocess.getInputsAfterBuildingLocally(context), hasItem(preprocessor));
    CxxPreprocessAndCompile cxxCompile = CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, new GccCompiler(compilerTool), CxxToolFlags.of()), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty());
    assertThat(cxxCompile.getInputsAfterBuildingLocally(context), hasItem(compiler));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) HashedFileTool(com.facebook.buck.rules.HashedFileTool) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) Test(org.junit.Test)

Example 7 with BuildContext

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

the class CxxLibraryDescriptionTest method verifySourcePaths.

/**
   * Verify that all source paths are resolvable, which wouldn't be the case if `cxx_genrule`
   * outputs were not handled correctly.
   */
private void verifySourcePaths(BuildRuleResolver resolver) {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildContext buildContext = FakeBuildContext.withSourcePathResolver(pathResolver);
    BuildableContext buildableContext = new FakeBuildableContext();
    for (BuildRule rule : resolver.getBuildRules()) {
        rule.getBuildSteps(buildContext, buildableContext);
    }
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildableContext(com.facebook.buck.rules.BuildableContext) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 8 with BuildContext

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

the class HeaderSymlinkTreeWithHeaderMapTest method testSymlinkTreeBuildSteps.

@Test
public void testSymlinkTreeBuildSteps() throws IOException {
    BuildContext buildContext = FakeBuildContext.withSourcePathResolver(resolver);
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    FakeBuildableContext buildableContext = new FakeBuildableContext();
    ImmutableList<Step> expectedBuildSteps = ImmutableList.of(new MakeCleanDirectoryStep(filesystem, symlinkTreeRoot), new SymlinkTreeStep(filesystem, symlinkTreeRoot, resolver.getMappedPaths(links)), new HeaderMapStep(filesystem, HeaderSymlinkTreeWithHeaderMap.getPath(filesystem, buildTarget), ImmutableMap.of(Paths.get("file"), filesystem.getBuckPaths().getBuckOut().relativize(symlinkTreeRoot).resolve("file"), Paths.get("directory/then/file"), filesystem.getBuckPaths().getBuckOut().relativize(symlinkTreeRoot).resolve("directory/then/file"))));
    ImmutableList<Step> actualBuildSteps = symlinkTreeBuildRule.getBuildSteps(buildContext, buildableContext);
    assertEquals(expectedBuildSteps, actualBuildSteps.subList(1, actualBuildSteps.size()));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SymlinkTreeStep(com.facebook.buck.step.fs.SymlinkTreeStep) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Step(com.facebook.buck.step.Step) SymlinkTreeStep(com.facebook.buck.step.fs.SymlinkTreeStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Test(org.junit.Test)

Example 9 with BuildContext

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

the class DefaultJavaLibraryTest method testBuildInternalWithAndroidBootclasspath.

/** Make sure that when isAndroidLibrary is true, that the Android bootclasspath is used. */
@Test
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
public void testBuildInternalWithAndroidBootclasspath() throws Exception {
    String folder = "android/java/src/com/facebook";
    tmp.newFolder(folder.split("/"));
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//" + folder + ":fb");
    Path src = Paths.get(folder, "Main.java");
    tmp.newFile(src.toString());
    BuildRule libraryRule = AndroidLibraryBuilder.createBuilder(buildTarget).addSrc(src).build(ruleResolver);
    DefaultJavaLibrary javaLibrary = (DefaultJavaLibrary) libraryRule;
    String bootclasspath = "effects.jar" + File.pathSeparator + "maps.jar" + File.pathSeparator + "usb.jar" + File.pathSeparator;
    BuildContext context = createBuildContext(libraryRule, bootclasspath);
    List<Step> steps = javaLibrary.getBuildSteps(context, new FakeBuildableContext());
    // Find the JavacStep and verify its bootclasspath.
    Step step = Iterables.find(steps, command -> command instanceof JavacStep);
    assertNotNull("Expected a JavacStep in the steplist.", step);
    JavacStep javac = (JavacStep) step;
    assertEquals("Should compile Main.java rather than generated R.java.", ImmutableSet.of(src), javac.getSrcs());
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) 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 10 with BuildContext

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

the class DefaultJavaLibraryTest method testJavacDirectToJarStepIsNotPresentWhenPostprocessClassesCommandsPresent.

@Test
public void testJavacDirectToJarStepIsNotPresentWhenPostprocessClassesCommandsPresent() {
    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.DIRECT_TO_JAR), /* postprocessClassesCommands */
    ImmutableList.of("process_class_files.py"));
    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)

Aggregations

BuildContext (com.facebook.buck.rules.BuildContext)28 Step (com.facebook.buck.step.Step)22 FakeBuildContext (com.facebook.buck.rules.FakeBuildContext)19 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)18 Test (org.junit.Test)18 BuildTarget (com.facebook.buck.model.BuildTarget)17 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)15 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)13 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)13 Path (java.nio.file.Path)13 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)12 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)12 BuildRule (com.facebook.buck.rules.BuildRule)9 SourcePath (com.facebook.buck.rules.SourcePath)9 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 BuildableContext (com.facebook.buck.rules.BuildableContext)8 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)8 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)8 ExecutionContext (com.facebook.buck.step.ExecutionContext)8 ImmutableList (com.google.common.collect.ImmutableList)8