Search in sources :

Example 21 with DefaultBuildTargetSourcePath

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

the class CxxPrecompiledHeaderRuleTest method samePchIffSameFlags.

@Test
public void samePchIffSameFlags() throws Exception {
    assumeTrue(platformOkForPCHTests());
    BuildTarget pchTarget = newTarget("//test:pch");
    CxxPrecompiledHeaderTemplate pch = newPCH(pchTarget);
    ruleResolver.addToIndex(pch);
    BuildTarget lib1Target = newTarget("//test:lib1");
    BuildRuleParams lib1Params = newParams(lib1Target);
    CxxSourceRuleFactory factory1 = newFactoryBuilder(lib1Params, "-frtti").setPrecompiledHeader(new DefaultBuildTargetSourcePath(pchTarget)).build();
    CxxPreprocessAndCompile lib1 = factory1.createPreprocessAndCompileBuildRule("lib1.cpp", newSource("lib1.cpp"));
    ruleResolver.addToIndex(lib1);
    ImmutableList<String> cmd1 = lib1.makeMainStep(pathResolver, Paths.get("/tmp/x"), false).getCommand();
    BuildTarget lib2Target = newTarget("//test:lib2");
    BuildRuleParams lib2Params = newParams(lib2Target);
    CxxSourceRuleFactory factory2 = newFactoryBuilder(lib2Params, "-frtti").setPrecompiledHeader(new DefaultBuildTargetSourcePath(pchTarget)).build();
    CxxPreprocessAndCompile lib2 = factory2.createPreprocessAndCompileBuildRule("lib2.cpp", newSource("lib2.cpp"));
    ruleResolver.addToIndex(lib2);
    ImmutableList<String> cmd2 = lib2.makeMainStep(pathResolver, Paths.get("/tmp/x"), false).getCommand();
    BuildTarget lib3Target = newTarget("//test:lib3");
    BuildRuleParams lib3Params = newParams(lib3Target);
    CxxSourceRuleFactory factory3 = newFactoryBuilder(lib3Params, "-fno-rtti").setPrecompiledHeader(new DefaultBuildTargetSourcePath(pchTarget)).build();
    CxxPreprocessAndCompile lib3 = factory3.createPreprocessAndCompileBuildRule("lib3.cpp", newSource("lib3.cpp"));
    ruleResolver.addToIndex(lib3);
    ImmutableList<String> cmd3 = lib3.makeMainStep(pathResolver, Paths.get("/tmp/x"), false).getCommand();
    assertTrue(seek(cmd1, "-frtti").size() > 0);
    assertTrue(seek(cmd2, "-frtti").size() > 0);
    assertFalse(seek(cmd3, "-frtti").size() > 0);
    assertFalse(seek(cmd1, "-fno-rtti").size() > 0);
    assertFalse(seek(cmd2, "-fno-rtti").size() > 0);
    assertTrue(seek(cmd3, "-fno-rtti").size() > 0);
    List<String> pchFlag1 = seek(cmd1, "-include-pch");
    assertTrue(pchFlag1.size() >= 2);
    pchFlag1 = pchFlag1.subList(0, 2);
    List<String> pchFlag2 = seek(cmd2, "-include-pch");
    assertTrue(pchFlag2.size() >= 2);
    pchFlag2 = pchFlag2.subList(0, 2);
    List<String> pchFlag3 = seek(cmd3, "-include-pch");
    assertTrue(pchFlag3.size() >= 2);
    pchFlag3 = pchFlag3.subList(0, 2);
    assertEquals(pchFlag1, pchFlag2);
    assertNotEquals(pchFlag2, pchFlag3);
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 22 with DefaultBuildTargetSourcePath

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

the class PrebuiltCxxLibraryGroupDescriptionTest method cxxGenruleLib.

@Test
public void cxxGenruleLib() throws Exception {
    CxxGenruleBuilder cxxGenruleBuilder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("libtest.so");
    PrebuiltCxxLibraryGroupBuilder builder = new PrebuiltCxxLibraryGroupBuilder(BuildTargetFactory.newInstance("//:rule")).setStaticLink(ImmutableList.of("$(lib 0)")).setStaticLibs(ImmutableList.of(new DefaultBuildTargetSourcePath(cxxGenruleBuilder.getTarget())));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxGenruleBuilder.build(), builder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    CxxGenrule cxxGenrule = (CxxGenrule) cxxGenruleBuilder.build(resolver);
    NativeLinkable library = (NativeLinkable) builder.build(resolver);
    NativeLinkableInput input = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
    SourcePath lib = cxxGenrule.getGenrule(CxxPlatformUtils.DEFAULT_PLATFORM);
    assertThat(input.getArgs(), Matchers.contains(SourcePathArg.of(lib)));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 23 with DefaultBuildTargetSourcePath

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

the class DistBuildStateTest method createCrossCellTargetGraph.

private static TargetGraph createCrossCellTargetGraph(ProjectFilesystem cellOneFilesystem, ProjectFilesystem cellTwoFilesystem) {
    Preconditions.checkArgument(!cellOneFilesystem.equals(cellTwoFilesystem));
    BuildTarget target = BuildTargetFactory.newInstance(cellTwoFilesystem, "//:foo");
    return TargetGraphFactory.newInstance(JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance(cellOneFilesystem, "//:foo"), cellOneFilesystem).addSrc(new DefaultBuildTargetSourcePath(target)).build(), JavaLibraryBuilder.createBuilder(target, cellTwoFilesystem).build());
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath)

Example 24 with DefaultBuildTargetSourcePath

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

the class JsLibraryDescriptionTest method basePathReplacesBuildTargetSourcePath.

@Test
public void basePathReplacesBuildTargetSourcePath() throws NoSuchBuildTargetException {
    final String basePath = "base/path.js";
    final BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    scenarioBuilder.arbitraryRule(target);
    final JsTestScenario scenario = buildScenario(basePath, new DefaultBuildTargetSourcePath(target));
    assertEquals("arbitrary/path/base/path.js", findFileRule(scenario.resolver).getVirtualPath().get());
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 25 with DefaultBuildTargetSourcePath

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

the class JavaSourceJarTest method shouldOnlyIncludePathBasedSources.

@Test
public void shouldOnlyIncludePathBasedSources() {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    SourcePath fileBased = new FakeSourcePath("some/path/File.java");
    SourcePath ruleBased = new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//cheese:cake"));
    JavaPackageFinder finderStub = createNiceMock(JavaPackageFinder.class);
    expect(finderStub.findJavaPackageFolder((Path) anyObject())).andStubReturn(Paths.get("cheese"));
    expect(finderStub.findJavaPackage((Path) anyObject())).andStubReturn("cheese");
    // No need to verify. It's a stub. I don't care about the interactions.
    EasyMock.replay(finderStub);
    JavaSourceJar rule = new JavaSourceJar(new FakeBuildRuleParamsBuilder("//example:target").build(), ImmutableSortedSet.of(fileBased, ruleBased), Optional.empty());
    BuildContext buildContext = BuildContext.builder().setActionGraph(new ActionGraph(ImmutableList.of())).setSourcePathResolver(pathResolver).setJavaPackageFinder(finderStub).setEventBus(BuckEventBusFactory.newInstance()).build();
    ImmutableList<Step> steps = rule.getBuildSteps(buildContext, new FakeBuildableContext());
    // There should be a CopyStep per file being copied. Count 'em.
    int copyStepsCount = FluentIterable.from(steps).filter(CopyStep.class::isInstance).size();
    assertEquals(1, copyStepsCount);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) ActionGraph(com.facebook.buck.rules.ActionGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) BuildContext(com.facebook.buck.rules.BuildContext) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)71 Test (org.junit.Test)64 BuildTarget (com.facebook.buck.model.BuildTarget)53 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)26 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)25 SourcePath (com.facebook.buck.rules.SourcePath)25 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)21 TargetGraph (com.facebook.buck.rules.TargetGraph)19 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)18 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)18 Path (java.nio.file.Path)16 BuildRule (com.facebook.buck.rules.BuildRule)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)9 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)8 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)7 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)6 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)5