use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class PrebuiltJarSymbolsFinderTest method contentsOfBinaryJarShouldAffectRuleKey.
@Test
public void contentsOfBinaryJarShouldAffectRuleKey() throws IOException {
// The path to the JAR file to use as the binaryJar of the PrebuiltJarSymbolsFinder.
final Path relativePathToJar = Paths.get("common.jar");
final Path absolutePathToJar = tmp.getRoot().resolve(relativePathToJar);
// Mock out calls to a SourcePathResolver so we can create a legitimate
// DefaultRuleKeyFactory.
final SourcePathRuleFinder ruleFinder = createMock(SourcePathRuleFinder.class);
final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
createMock(SourcePathResolver.class);
expect(ruleFinder.getRule(anyObject(SourcePath.class))).andReturn(Optional.empty()).anyTimes();
// Calculates the RuleKey for a JavaSymbolsRule with a PrebuiltJarSymbolsFinder whose binaryJar
// is a JAR file with the specified entries.
Function<ImmutableSet<String>, RuleKey> createRuleKey = entries -> {
File jarFile = absolutePathToJar.toFile();
JavaSymbolsRule javaSymbolsRule;
FakeFileHashCache fileHashCache;
try {
PrebuiltJarSymbolsFinder finder = createFinderForFileWithEntries(relativePathToJar.getFileName().toString(), entries);
HashCode hash = Files.hash(jarFile, Hashing.sha1());
Map<Path, HashCode> pathsToHashes = ImmutableMap.of(absolutePathToJar, hash);
fileHashCache = new FakeFileHashCache(pathsToHashes);
javaSymbolsRule = new JavaSymbolsRule(BuildTargetFactory.newInstance("//foo:rule"), finder, ImmutableSortedSet.of(), ObjectMappers.newDefaultInstance(), new ProjectFilesystem(tmp.getRoot()));
} catch (IOException e) {
throw new RuntimeException(e);
}
RuleKey ruleKey = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(javaSymbolsRule);
jarFile.delete();
return ruleKey;
};
RuleKey key1 = createRuleKey.apply(ImmutableSet.of("entry1", "entry2"));
RuleKey key2 = createRuleKey.apply(ImmutableSet.of("entry1", "entry2"));
RuleKey key3 = createRuleKey.apply(ImmutableSet.of("entry1", "entry2", "entry3"));
assertNotNull(key1);
assertNotNull(key2);
assertNotNull(key3);
assertEquals("Two instances of a JavaSymbolsRule with the same inputs should have the same RuleKey.", key1, key2);
assertNotEquals("Changing the contents of the binaryJar for the PrebuiltJarSymbolsFinder should change " + "the RuleKey of the JavaSymbolsRule that contains it.", key1, key3);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class PythonTestDescriptionTest method calculateRuleKey.
private RuleKey calculateRuleKey(BuildRuleResolver ruleResolver, BuildRule rule) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(new RuleKeyFieldLoader(0), new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(rule.getProjectFilesystem()))), new SourcePathResolver(ruleFinder), ruleFinder);
return ruleKeyFactory.build(rule);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class PythonBinaryDescriptionTest method calculateRuleKey.
private RuleKey calculateRuleKey(BuildRuleResolver ruleResolver, BuildRule rule) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(new RuleKeyFieldLoader(0), new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(rule.getProjectFilesystem()))), new SourcePathResolver(ruleFinder), ruleFinder);
return ruleKeyFactory.build(rule);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class CommandToolTest method sourcePathsContributeToRuleKeys.
@Test
public void sourcePathsContributeToRuleKeys() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
SourcePath path = new FakeSourcePath("input");
CommandTool tool = new CommandTool.Builder().addArg(SourcePathArg.of(path)).build();
FileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of("input", Strings.repeat("a", 40)));
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder);
RuleKey ruleKey = new UncachedRuleKeyBuilder(ruleFinder, pathResolver, hashCache, ruleKeyFactory).setReflectively("key", tool).build();
hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of("input", Strings.repeat("b", 40)));
ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder);
RuleKey changedRuleKey = new UncachedRuleKeyBuilder(ruleFinder, pathResolver, hashCache, ruleKeyFactory).setReflectively("key", tool).build();
assertThat(ruleKey, Matchers.not(Matchers.equalTo(changedRuleKey)));
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class KnownBuildRuleTypesTest method whenJavacIsSetInBuckConfigConfiguredRulesCreateJavaLibraryRuleWithDifferentRuleKey.
@Test
public void whenJavacIsSetInBuckConfigConfiguredRulesCreateJavaLibraryRuleWithDifferentRuleKey() throws Exception {
final Path javac;
if (Platform.detect() == Platform.WINDOWS) {
javac = Paths.get("C:/Windows/system32/rundll32.exe");
} else {
javac = temporaryFolder.newExecutableFile();
}
ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("tools", ImmutableMap.of("javac", javac.toString()));
BuckConfig buckConfig = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(sections).build();
KnownBuildRuleTypes buildRuleTypes = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(filesystem, environment);
DefaultJavaLibrary libraryRule = createJavaLibrary(buildRuleTypes);
ProcessExecutor processExecutor = createExecutor(javac.toString(), "fakeVersion 0.1");
KnownBuildRuleTypes configuredBuildRuleTypes = KnownBuildRuleTypes.createBuilder(buckConfig, filesystem, processExecutor, new FakeAndroidDirectoryResolver()).build();
DefaultJavaLibrary configuredRule = createJavaLibrary(configuredBuildRuleTypes);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(javac, MorePaths.asByteSource(javac).hash(Hashing.sha1())));
RuleKey configuredKey = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(configuredRule);
RuleKey libraryKey = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(libraryRule);
assertNotEquals(libraryKey, configuredKey);
}
Aggregations