Search in sources :

Example 36 with FakeBuildableContext

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

the class CxxPrecompiledHeaderTest method generatesPchStepShouldUseCorrectLang.

@Test
public void generatesPchStepShouldUseCorrectLang() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    Preprocessor preprocessorSupportingPch = new GccPreprocessor(CxxPlatformUtils.DEFAULT_PLATFORM.getCpp().resolve(resolver)) {

        @Override
        public boolean supportsPrecompiledHeaders() {
            return true;
        }
    };
    Compiler compiler = CxxPlatformUtils.DEFAULT_PLATFORM.getCxx().resolve(resolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    CxxPrecompiledHeader precompiledHeader = new CxxPrecompiledHeader(params, Paths.get("foo.hash1.hash2.gch"), new PreprocessorDelegate(sourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), Paths.get("./"), preprocessorSupportingPch, PreprocessorFlags.builder().build(), CxxDescriptionEnhancer.frameworkPathToSearchPath(CxxPlatformUtils.DEFAULT_PLATFORM, sourcePathResolver), Optional.empty(), /* leadingIncludePaths */
    Optional.empty()), new CompilerDelegate(sourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, compiler, CxxToolFlags.of()), CxxToolFlags.of(), new FakeSourcePath("foo.h"), CxxSource.Type.C, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER);
    resolver.addToIndex(precompiledHeader);
    BuildContext buildContext = FakeBuildContext.withSourcePathResolver(sourcePathResolver);
    ImmutableList<Step> postBuildSteps = precompiledHeader.getBuildSteps(buildContext, new FakeBuildableContext());
    CxxPreprocessAndCompileStep step = Iterables.getOnlyElement(Iterables.filter(postBuildSteps, CxxPreprocessAndCompileStep.class));
    assertThat("step that generates pch should have correct flags", step.getCommand(), hasItem(CxxSource.Type.C.getPrecompiledHeaderLanguage().get()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) Step(com.facebook.buck.step.Step) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 37 with FakeBuildableContext

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

the class DirectHeaderMapTest method testBuildSteps.

@Test
public void testBuildSteps() throws IOException {
    BuildContext buildContext = FakeBuildContext.withSourcePathResolver(pathResolver);
    FakeBuildableContext buildableContext = new FakeBuildableContext();
    ImmutableList<Step> expectedBuildSteps = ImmutableList.of(new MkdirStep(projectFilesystem, headerMapPath.getParent()), new RmStep(projectFilesystem, headerMapPath), new HeaderMapStep(projectFilesystem, headerMapPath, ImmutableMap.of(Paths.get("file"), projectFilesystem.resolve(projectFilesystem.getBuckPaths().getBuckOut()).relativize(file1), Paths.get("directory/then/file"), projectFilesystem.resolve(projectFilesystem.getBuckPaths().getBuckOut()).relativize(file2))));
    ImmutableList<Step> actualBuildSteps = buildRule.getBuildSteps(buildContext, buildableContext);
    assertEquals(expectedBuildSteps, actualBuildSteps.subList(1, actualBuildSteps.size()));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) RmStep(com.facebook.buck.step.fs.RmStep) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Test(org.junit.Test)

Example 38 with FakeBuildableContext

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

the class KeystoreTest method testBuildInternal.

@Test
public void testBuildInternal() throws Exception {
    BuildContext buildContext = FakeBuildContext.NOOP_CONTEXT;
    BuildRule keystore = createKeystoreRuleForTest();
    List<Step> buildSteps = keystore.getBuildSteps(buildContext, new FakeBuildableContext());
    assertEquals(ImmutableList.<Step>of(), buildSteps);
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildRule(com.facebook.buck.rules.BuildRule) Step(com.facebook.buck.step.Step) Test(org.junit.Test)

Example 39 with FakeBuildableContext

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

the class PythonBinaryDescriptionTest method buildArgs.

@Test
public void buildArgs() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bin");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ImmutableList<String> buildArgs = ImmutableList.of("--some", "--args");
    PythonBinary binary = PythonBinaryBuilder.create(target).setMainModule("main").setBuildArgs(buildArgs).build(resolver);
    ImmutableList<Step> buildSteps = binary.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
    PexStep pexStep = FluentIterable.from(buildSteps).filter(PexStep.class).get(0);
    assertThat(pexStep.getCommandPrefix(), Matchers.hasItems(buildArgs.toArray(new String[buildArgs.size()])));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) BuildTarget(com.facebook.buck.model.BuildTarget) Step(com.facebook.buck.step.Step) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 40 with FakeBuildableContext

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

the class PythonTestDescriptionTest method buildArgs.

@Test
public void buildArgs() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildTarget target = BuildTargetFactory.newInstance("//foo:test");
    ImmutableList<String> buildArgs = ImmutableList.of("--some", "--args");
    PythonTestBuilder builder = PythonTestBuilder.create(target).setBuildArgs(buildArgs);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    PythonTest test = builder.build(resolver, filesystem, targetGraph);
    PythonBinary binary = test.getBinary();
    ImmutableList<Step> buildSteps = binary.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
    PexStep pexStep = RichStream.from(buildSteps).filter(PexStep.class).toImmutableList().get(0);
    assertThat(pexStep.getCommandPrefix(), Matchers.hasItems(buildArgs.toArray(new String[buildArgs.size()])));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) 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) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) 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