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);
}
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)));
}
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());
}
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());
}
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);
}
Aggregations