Search in sources :

Example 51 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver 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);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 52 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver 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);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 53 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver 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);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 54 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver 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());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) BorrowablePath(com.facebook.buck.io.BorrowablePath) LazyPath(com.facebook.buck.io.LazyPath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 55 with SourcePathResolver

use of com.facebook.buck.rules.SourcePathResolver 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();
}
Also used : BuildResult(com.facebook.buck.rules.BuildResult) Optional(java.util.Optional) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) LinkedHashMap(java.util.LinkedHashMap) Before(org.junit.Before)

Aggregations

SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)486 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)468 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)376 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)350 Test (org.junit.Test)330 BuildTarget (com.facebook.buck.model.BuildTarget)228 BuildRule (com.facebook.buck.rules.BuildRule)161 Path (java.nio.file.Path)154 SourcePath (com.facebook.buck.rules.SourcePath)148 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)138 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)126 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)86 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)82 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)79 TargetGraph (com.facebook.buck.rules.TargetGraph)76 RuleKey (com.facebook.buck.rules.RuleKey)72 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)70 ExecutionContext (com.facebook.buck.step.ExecutionContext)57 ImmutableList (com.google.common.collect.ImmutableList)55