use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class ParserTest method whenBuildFileContainsSourcesUnderSymLinkDeletedSourcesNotRemovedUntilCacheCleaned.
@Test
public void whenBuildFileContainsSourcesUnderSymLinkDeletedSourcesNotRemovedUntilCacheCleaned() throws Exception {
// This test depends on creating symbolic links which we cannot do on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
tempDir.newFolder("bar");
tempDir.newFile("bar/Bar.java");
tempDir.newFolder("foo");
Path bazSourceFile = tempDir.newFile("bar/Baz.java");
Path rootPath = tempDir.getRoot().toRealPath();
Files.createSymbolicLink(rootPath.resolve("foo/bar"), rootPath.resolve("bar"));
Path testBuckFile = rootPath.resolve("foo").resolve("BUCK");
Files.write(testBuckFile, "java_library(name = 'lib', srcs=glob(['bar/*.java']))\n".getBytes(UTF_8));
// Fetch //:lib to put it in cache.
BuildTarget libTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
Iterable<BuildTarget> buildTargets = ImmutableList.of(libTarget);
{
TargetGraph targetGraph = parser.buildTargetGraph(eventBus, cell, false, executorService, buildTargets);
BuildRuleResolver resolver = buildActionGraph(eventBus, targetGraph);
JavaLibrary libRule = (JavaLibrary) resolver.requireRule(libTarget);
assertEquals(ImmutableSortedSet.of(new PathSourcePath(filesystem, Paths.get("foo/bar/Bar.java")), new PathSourcePath(filesystem, Paths.get("foo/bar/Baz.java"))), libRule.getJavaSrcs());
}
Files.delete(bazSourceFile);
WatchEvent<Path> deleteEvent = createPathEvent(Paths.get("bar/Baz.java"), StandardWatchEventKinds.ENTRY_DELETE);
parser.onFileSystemChange(deleteEvent);
{
TargetGraph targetGraph = parser.buildTargetGraph(eventBus, cell, false, executorService, buildTargets);
BuildRuleResolver resolver = buildActionGraph(eventBus, targetGraph);
JavaLibrary libRule = (JavaLibrary) resolver.requireRule(libTarget);
assertEquals(ImmutableSortedSet.of(new PathSourcePath(filesystem, Paths.get("foo/bar/Bar.java"))), libRule.getJavaSrcs());
}
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyDoesNotChangeIfNonHashingSourcePathContentChanges.
@Test
public void ruleKeyDoesNotChangeIfNonHashingSourcePathContentChanges() throws NoSuchBuildTargetException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final ProjectFilesystem fileSystem = new FakeProjectFilesystem();
// Build a rule key with a particular hash set for the output for the above rule.
Path filePath = fileSystem.getPath("file.txt");
FakeFileHashCache hashCache = new FakeFileHashCache(new HashMap<>());
hashCache.set(filePath.toAbsolutePath(), HashCode.fromInt(0));
PathSourcePath sourcePath = new PathSourcePath(fileSystem, filePath);
NonHashableSourcePathContainer nonHashablePath = new NonHashableSourcePathContainer(sourcePath);
RuleKey inputKey1 = computeRuleKey(hashCache, pathResolver, ruleFinder, nonHashablePath);
hashCache.set(filePath.toAbsolutePath(), HashCode.fromInt(1));
RuleKey inputKey2 = computeRuleKey(hashCache, pathResolver, ruleFinder, nonHashablePath);
assertThat(inputKey1, Matchers.equalTo(inputKey2));
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeysForOversizedRules.
@Test
public void ruleKeysForOversizedRules() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
final int sizeLimit = 200;
InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, sizeLimit);
// Create rule with inputs that make it go past the size limit, and verify the rule key factory
// doesn't create a rule key.
final int tooLargeRuleSize = 300;
assertThat(tooLargeRuleSize, Matchers.greaterThan(sizeLimit));
Path tooLargeInput = filesystem.getPath("too_large_input");
filesystem.writeBytesToPath(new byte[tooLargeRuleSize], tooLargeInput);
BuildRule tooLargeRule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:large_rule")).setOut("out").setSrc(new PathSourcePath(filesystem, tooLargeInput)).build(resolver, filesystem);
expectedException.expect(SizeLimiter.SizeLimitException.class);
factory.build(tooLargeRule);
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyNotCalculatedIfSizeLimitHitWithDirectory.
@Test
public void ruleKeyNotCalculatedIfSizeLimitHitWithDirectory() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
// Create a directory of files which combine to pass size limit.
Path input = filesystem.getPath("input");
filesystem.mkdirs(input);
filesystem.writeBytesToPath(new byte[150], input.resolve("file1"));
filesystem.writeBytesToPath(new byte[150], input.resolve("file2"));
// Construct rule which uses inputs.
BuildRule rule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrc(new PathSourcePath(filesystem, input)).build(resolver, filesystem);
// Verify rule key isn't calculated.
expectedException.expect(SizeLimiter.SizeLimitException.class);
new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, 200).build(rule);
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges.
@Test
public void ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final Path output = Paths.get("output");
BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setProjectFilesystem(filesystem).build();
BuildRule rule = new NoopBuildRule(params) {
@AddToRuleKey
RuleKeyAppendableWithInput input = new RuleKeyAppendableWithInput(new PathSourcePath(filesystem, output));
};
// Build a rule key with a particular hash set for the output for the above rule.
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(0)));
RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
// Now, build a rule key with a different hash for the output for the above rule.
hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(1)));
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2)));
}
Aggregations