use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.
the class BuildCommandTest method setUp.
@Before
public void setUp() {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
resolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
LinkedHashMap<BuildRule, Optional<BuildResult>> ruleToResult = new LinkedHashMap<>();
FakeBuildRule rule1 = new FakeBuildRule(BuildTargetFactory.newInstance("//fake:rule1"), resolver);
rule1.setOutputFile("buck-out/gen/fake/rule1.txt");
ruleResolver.addToIndex(rule1);
ruleToResult.put(rule1, Optional.of(BuildResult.success(rule1, BUILT_LOCALLY, CacheResult.miss())));
BuildRule rule2 = new FakeBuildRule(BuildTargetFactory.newInstance("//fake:rule2"), resolver);
BuildResult rule2Failure = BuildResult.failure(rule2, new RuntimeException("some"));
ruleToResult.put(rule2, Optional.of(rule2Failure));
ruleResolver.addToIndex(rule2);
BuildRule rule3 = new FakeBuildRule(BuildTargetFactory.newInstance("//fake:rule3"), resolver);
ruleToResult.put(rule3, Optional.of(BuildResult.success(rule3, FETCHED_FROM_CACHE, CacheResult.hit("dir"))));
ruleResolver.addToIndex(rule3);
BuildRule rule4 = new FakeBuildRule(BuildTargetFactory.newInstance("//fake:rule4"), resolver);
ruleToResult.put(rule4, Optional.empty());
ruleResolver.addToIndex(rule4);
buildExecutionResult = BuildExecutionResult.builder().setResults(ruleToResult).setFailures(ImmutableSet.of(rule2Failure)).build();
}
use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.
the class CxxPreprocessablesTest method getTransitiveNativeLinkableInputDoesNotTraversePastNonNativeLinkables.
@Test
public void getTransitiveNativeLinkableInputDoesNotTraversePastNonNativeLinkables() throws Exception {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
CxxPlatform cxxPlatform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build()));
// Create a native linkable that sits at the bottom of the dep chain.
String sentinal = "bottom";
CxxPreprocessorInput bottomInput = CxxPreprocessorInput.builder().putPreprocessorFlags(CxxSource.Type.C, sentinal).build();
BuildRule bottom = createFakeCxxPreprocessorDep("//:bottom", pathResolver, bottomInput);
// Create a non-native linkable that sits in the middle of the dep chain, preventing
// traversals to the bottom native linkable.
BuildRule middle = new FakeBuildRule("//:middle", pathResolver, bottom);
// Create a native linkable that sits at the top of the dep chain.
CxxPreprocessorInput topInput = CxxPreprocessorInput.EMPTY;
BuildRule top = createFakeCxxPreprocessorDep("//:top", pathResolver, topInput, middle);
// Now grab all input via traversing deps and verify that the middle rule prevents pulling
// in the bottom input.
CxxPreprocessorInput totalInput = CxxPreprocessorInput.concat(CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, ImmutableList.of(top)));
assertTrue(bottomInput.getPreprocessorFlags().get(CxxSource.Type.C).contains(sentinal));
assertFalse(totalInput.getPreprocessorFlags().get(CxxSource.Type.C).contains(sentinal));
}
use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.
the class CxxPreprocessablesTest method createHeaderSymlinkTreeBuildRuleHasNoDeps.
@Test
public void createHeaderSymlinkTreeBuildRuleHasNoDeps() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
// Setup up the main build target and build params, which some random dep. We'll make
// sure the dep doesn't get propagated to the symlink rule below.
FakeBuildRule dep = createFakeBuildRule(BuildTargetFactory.newInstance(filesystem, "//random:dep"), pathResolver);
BuildTarget target = BuildTargetFactory.newInstance(filesystem, "//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(dep)).setProjectFilesystem(filesystem).build();
Path root = Paths.get("root");
// Setup a simple genrule we can wrap in a ExplicitBuildTargetSourcePath to model a input source
// that is built by another rule.
Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance(filesystem, "//:genrule")).setOut("foo/bar.o").build(resolver);
// Setup the link map with both a regular path-based source path and one provided by
// another build rule.
ImmutableMap<Path, SourcePath> links = ImmutableMap.of(Paths.get("link1"), new FakeSourcePath("hello"), Paths.get("link2"), genrule.getSourcePathToOutput());
// Build our symlink tree rule using the helper method.
HeaderSymlinkTree symlinkTree = CxxPreprocessables.createHeaderSymlinkTreeBuildRule(target, params.getProjectFilesystem(), root, links, CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY, ruleFinder);
// Verify that the symlink tree has no deps. This is by design, since setting symlinks can
// be done completely independently from building the source that the links point to and
// independently from the original deps attached to the input build rule params.
assertTrue(symlinkTree.getDeps().isEmpty());
}
use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.
the class CxxDescriptionEnhancerTest method nonTestLibraryDepDoesNotIncludePrivateHeadersOfLibrary.
@Test
public void nonTestLibraryDepDoesNotIncludePrivateHeadersOfLibrary() throws Exception {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib");
BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).build();
FakeCxxLibrary libRule = new FakeCxxLibrary(libParams, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // This library has no tests.
ImmutableSortedSet.of());
BuildTarget otherLibDepTarget = BuildTargetFactory.newInstance("//:other");
BuildRuleParams otherLibDepParams = new FakeBuildRuleParamsBuilder(otherLibDepTarget).setDeclaredDeps(ImmutableSortedSet.of(libRule)).build();
ImmutableList<CxxPreprocessorInput> otherInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(otherLibDepParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.of(), ImmutableList.of(), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(otherLibDepParams.getDeps()).filter(CxxPreprocessorDep.class::isInstance)), ImmutableList.of(), Optional.empty());
Set<SourcePath> roots = new HashSet<>();
for (CxxHeaders headers : CxxPreprocessorInput.concat(otherInput).getIncludes()) {
roots.add(headers.getRoot());
}
assertThat("Non-test rule with library dep should include public and not private headers", roots, allOf(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:symlink"))), not(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:privatesymlink"))))));
}
use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.
the class CxxDescriptionEnhancerTest method libraryTestIncludesPublicHeadersOfDependenciesOfLibraryUnderTest.
@Test
public void libraryTestIncludesPublicHeadersOfDependenciesOfLibraryUnderTest() throws Exception {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
BuildTarget libTarget = BuildTargetFactory.newInstance("//:lib");
BuildTarget otherlibTarget = BuildTargetFactory.newInstance("//:otherlib");
BuildTarget testTarget = BuildTargetFactory.newInstance("//:test");
BuildRuleParams otherlibParams = new FakeBuildRuleParamsBuilder(otherlibTarget).build();
FakeCxxLibrary otherlibRule = new FakeCxxLibrary(otherlibParams, BuildTargetFactory.newInstance("//:otherheader"), BuildTargetFactory.newInstance("//:othersymlink"), BuildTargetFactory.newInstance("//:otherprivateheader"), BuildTargetFactory.newInstance("//:otherprivatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // This library has no tests.
ImmutableSortedSet.of());
BuildRuleParams libParams = new FakeBuildRuleParamsBuilder(libTarget).setDeclaredDeps(ImmutableSortedSet.of(otherlibRule)).build();
FakeCxxLibrary libRule = new FakeCxxLibrary(libParams, BuildTargetFactory.newInstance("//:header"), BuildTargetFactory.newInstance("//:symlink"), BuildTargetFactory.newInstance("//:privateheader"), BuildTargetFactory.newInstance("//:privatesymlink"), new FakeBuildRule("//:archive", pathResolver), new FakeBuildRule("//:shared", pathResolver), Paths.get("output/path/lib.so"), "lib.so", // Ensure the test is listed as a dep of the lib.
ImmutableSortedSet.of(testTarget));
BuildRuleParams testParams = new FakeBuildRuleParamsBuilder(testTarget).setDeclaredDeps(ImmutableSortedSet.of(libRule)).build();
ImmutableList<CxxPreprocessorInput> combinedInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(testParams, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableMultimap.of(), ImmutableList.of(), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(CxxPlatformUtils.DEFAULT_PLATFORM, FluentIterable.from(testParams.getDeps()).filter(CxxPreprocessorDep.class::isInstance)), ImmutableList.of(), Optional.empty());
Set<SourcePath> roots = new HashSet<>();
for (CxxHeaders headers : CxxPreprocessorInput.concat(combinedInput).getIncludes()) {
roots.add(headers.getRoot());
}
assertThat("Test of library should include public dependency headers", Iterables.transform(CxxPreprocessorInput.concat(combinedInput).getIncludes(), CxxHeaders::getRoot), allOf(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:othersymlink"))), not(hasItem(new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//:otherprivatesymlink"))))));
}
Aggregations