use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxTestDescriptionTest method testArgsArePropagated.
@Test
public void testArgsArePropagated() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
addFramework(resolver, filesystem);
BuildRule someRule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:some_rule")).setOut("someRule").build(resolver);
CxxTestBuilder builder = createTestBuilder().setArgs(ImmutableList.of("value $(location //:some_rule)"));
addSandbox(resolver, filesystem, builder.getTarget());
CxxTest cxxTest = builder.build(resolver);
TestRunningOptions testOptions = TestRunningOptions.builder().setShufflingTests(false).setTestSelectorList(TestSelectorList.empty()).build();
ImmutableList<Step> steps = cxxTest.runTests(TestExecutionContext.newInstance(), testOptions, pathResolver, TestRule.NOOP_REPORTING_CALLBACK);
CxxTestStep testStep = (CxxTestStep) Iterables.getLast(steps);
assertThat(testStep.getCommand(), Matchers.hasItem("value " + pathResolver.getAbsolutePath(Preconditions.checkNotNull(someRule.getSourcePathToOutput()))));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxTestDescriptionTest method locationMacro.
@Test
public void locationMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
CxxTestBuilder builder = createTestBuilder().setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
addFramework(resolver, filesystem);
addSandbox(resolver, filesystem, builder.getTarget());
assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
CxxTest test = builder.build(resolver);
CxxLink binary = (CxxLink) resolver.getRule(CxxDescriptionEnhancer.createCxxLinkTarget(test.getBuildTarget(), Optional.empty()));
assertThat(Arg.stringify(binary.getArgs(), pathResolver), Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
assertThat(binary.getDeps(), Matchers.hasItem(dep));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxLibraryDescriptionTest method forceStatic.
@Test
public void forceStatic() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule"), cxxBuckConfig).setPreferredLinkage(NativeLinkable.Linkage.STATIC);
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxLibraryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
CxxLibrary rule = (CxxLibrary) cxxLibraryBuilder.build(resolver, filesystem);
assertThat(rule.getPreferredLinkage(CxxPlatformUtils.DEFAULT_PLATFORM), equalTo(NativeLinkable.Linkage.STATIC));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxLibraryDescriptionTest method exportedDepsArePropagatedToRuntimeDeps.
@Test
public void exportedDepsArePropagatedToRuntimeDeps() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep"));
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:lib"), cxxBuckConfig).setExportedDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), cxxBinaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
cxxBinaryBuilder.build(resolver, filesystem);
CxxLibrary cxxLibrary = (CxxLibrary) cxxLibraryBuilder.build(resolver, filesystem);
assertThat(cxxLibrary.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), hasItem(cxxBinaryBuilder.getTarget()));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxLibraryDescriptionTest method linkerFlagsLocationMacro.
@Test
public void linkerFlagsLocationMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//:rule").withFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR, CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor());
GenruleBuilder depBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out");
CxxLibraryBuilder builder = new CxxLibraryBuilder(target, cxxBuckConfig).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(depBuilder.getTarget())))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = depBuilder.build(resolver, filesystem, targetGraph);
assertThat(builder.build().getExtraDeps(), hasItem(dep.getBuildTarget()));
BuildRule binary = builder.build(resolver, filesystem, targetGraph);
assertThat(binary, instanceOf(CxxLink.class));
assertThat(Arg.stringify(((CxxLink) binary).getArgs(), pathResolver), hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
assertThat(binary.getDeps(), hasItem(dep));
}
Aggregations