use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class RuleUtilsTest method creatingGroupsFromSourcePathsRemovesLongestCommonPrefix.
@Test
public void creatingGroupsFromSourcePathsRemovesLongestCommonPrefix() {
ImmutableList<SourcePath> input = ImmutableList.of(new FakeSourcePath("Lib/Foo/File1.h"), new FakeSourcePath("Lib/Foo/File2.h"), new FakeSourcePath("Lib/Bar/File1.h"));
ImmutableList<GroupedSource> expected = ImmutableList.of(GroupedSource.ofSourceGroup("Bar", Paths.get("Lib/Bar"), ImmutableList.of(GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Bar/File1.h")))), GroupedSource.ofSourceGroup("Foo", Paths.get("Lib/Foo"), ImmutableList.of(GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File1.h")), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File2.h")))));
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ImmutableList<GroupedSource> actual = RuleUtils.createGroupsFromSourcePaths(resolver::getRelativePath, ImmutableList.of(), ImmutableSortedSet.of(), ImmutableList.of(), input);
assertEquals(expected, actual);
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class RuleUtilsTest method creatingGroupsFromEmptyEntryMaps.
@Test
public void creatingGroupsFromEmptyEntryMaps() {
ImmutableMultimap<Path, String> subgroups = ImmutableMultimap.of();
ImmutableMultimap<Path, GroupedSource> entries = ImmutableMultimap.of();
ImmutableList<GroupedSource> expected = ImmutableList.of();
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ImmutableList<GroupedSource> actual = RuleUtils.createGroupsFromEntryMaps(subgroups, entries, new RuleUtils.GroupedSourceNameComparator(resolver::getRelativePath), Paths.get("root"), Paths.get("root"));
assertEquals(expected, actual);
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class RuleUtilsTest method creatingGroupsFromSourcePaths.
@Test
public void creatingGroupsFromSourcePaths() {
ImmutableList<SourcePath> input = ImmutableList.of(new FakeSourcePath("File.h"), new FakeSourcePath("Lib/Foo/File2.h"), new FakeSourcePath("App/Foo/File.h"), new FakeSourcePath("Lib/Bar/File1.h"), new FakeSourcePath("App/File.h"), new FakeSourcePath("Lib/Foo/File1.h"), new FakeSourcePath("App/Foo/Bar/File.h"));
ImmutableList<GroupedSource> expected = ImmutableList.of(GroupedSource.ofSourceGroup("App", Paths.get("App"), ImmutableList.of(GroupedSource.ofSourceGroup("Foo", Paths.get("App/Foo"), ImmutableList.of(GroupedSource.ofSourceGroup("Bar", Paths.get("App/Foo/Bar"), ImmutableList.of(GroupedSource.ofPrivateHeader(new FakeSourcePath("App/Foo/Bar/File.h")))), GroupedSource.ofPrivateHeader(new FakeSourcePath("App/Foo/File.h")))), GroupedSource.ofPrivateHeader(new FakeSourcePath("App/File.h")))), GroupedSource.ofSourceGroup("Lib", Paths.get("Lib"), ImmutableList.of(GroupedSource.ofSourceGroup("Bar", Paths.get("Lib/Bar"), ImmutableList.of(GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Bar/File1.h")))), GroupedSource.ofSourceGroup("Foo", Paths.get("Lib/Foo"), ImmutableList.of(GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File1.h")), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File2.h")))))), GroupedSource.ofPrivateHeader(new FakeSourcePath("File.h")));
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ImmutableList<GroupedSource> actual = RuleUtils.createGroupsFromSourcePaths(resolver::getRelativePath, ImmutableList.of(), ImmutableSortedSet.of(), ImmutableList.of(), input);
assertEquals(expected, actual);
}
use of com.facebook.buck.rules.SourcePathRuleFinder in project buck by facebook.
the class DirArtifactCacheTest method testCacheFetchMiss.
@Test
public void testCacheFetchMiss() throws IOException {
Path cacheDir = tmpDir.newFolder();
Path fileX = tmpDir.newFile("x");
fileHashCache = new FakeFileHashCache(ImmutableMap.of(fileX, HashCode.fromInt(0)));
dirArtifactCache = new DirArtifactCache("dir", new ProjectFilesystem(cacheDir), Paths.get("."), /* doStore */
true, /* maxCacheSizeBytes */
Optional.of(0L));
Files.write(fileX, "x".getBytes(UTF_8));
BuildRule inputRuleX = new BuildRuleForTest(fileX);
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleResolver.addToIndex(inputRuleX);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
RuleKey ruleKeyX = new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder).build(inputRuleX);
assertEquals(CacheResultType.MISS, dirArtifactCache.fetch(ruleKeyX, LazyPath.ofInstance(fileX)).getType());
}
use of com.facebook.buck.rules.SourcePathRuleFinder 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();
}
Aggregations