use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class CxxPreprocessAndCompileTest method inputChangesCauseRuleKeyChangesForCompilation.
@Test
public void inputChangesCauseRuleKeyChangesForCompilation() throws Exception {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("preprocessor", Strings.repeat("a", 40)).put("compiler", Strings.repeat("a", 40)).put("test.o", Strings.repeat("b", 40)).put("test.cpp", Strings.repeat("c", 40)).put("different", Strings.repeat("d", 40)).put("foo/test.h", Strings.repeat("e", 40)).put("path/to/a/plugin.so", Strings.repeat("f", 40)).put("path/to/a/different/plugin.so", Strings.repeat("a0", 40)).build());
// Generate a rule key for the defaults.
RuleKey defaultRuleKey = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, DEFAULT_TOOL_FLAGS), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
// Verify that changing the compiler causes a rulekey change.
RuleKey compilerChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, new GccCompiler(new HashedFileTool(Paths.get("different"))), DEFAULT_TOOL_FLAGS), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
assertNotEquals(defaultRuleKey, compilerChange);
// Verify that changing the operation causes a rulekey change.
RuleKey operationChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.preprocessAndCompile(params, new PreprocessorDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), DEFAULT_WORKING_DIR, DEFAULT_PREPROCESSOR, PreprocessorFlags.builder().build(), DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION, Optional.empty(), /* leadingIncludePaths */
Optional.empty()), new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, DEFAULT_TOOL_FLAGS), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
assertNotEquals(defaultRuleKey, operationChange);
// Verify that changing the platform flags causes a rulekey change.
RuleKey platformFlagsChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, CxxToolFlags.explicitBuilder().addPlatformFlags("-different").setRuleFlags(DEFAULT_TOOL_FLAGS.getRuleFlags()).build()), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
assertNotEquals(defaultRuleKey, platformFlagsChange);
// Verify that changing the rule flags causes a rulekey change.
RuleKey ruleFlagsChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, CxxToolFlags.explicitBuilder().setPlatformFlags(DEFAULT_TOOL_FLAGS.getPlatformFlags()).addRuleFlags("-other", "flags").build()), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
assertNotEquals(defaultRuleKey, ruleFlagsChange);
// Verify that changing the input causes a rulekey change.
RuleKey inputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, DEFAULT_TOOL_FLAGS), DEFAULT_OUTPUT, new FakeSourcePath("different"), DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty()));
assertNotEquals(defaultRuleKey, inputChange);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class CxxTestDescriptionTest method getRuleKey.
private RuleKey getRuleKey(BuildRuleResolver resolver, BuildRule rule) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(rule.getProjectFilesystem())));
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
return factory.build(rule);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class CxxHeadersDirTest method getRuleKey.
private RuleKey getRuleKey(ProjectFilesystem filesystem, CxxHeaders cxxHeaders) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
UncachedRuleKeyBuilder builder = new UncachedRuleKeyBuilder(ruleFinder, pathResolver, fileHashCache, factory);
cxxHeaders.appendToRuleKey(builder);
return builder.build();
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class DirectHeaderMapTest method testRuleKeyDoesNotChangeIfLinkTargetsChange.
@Test
public void testRuleKeyDoesNotChangeIfLinkTargetsChange() throws IOException {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleResolver.addToIndex(buildRule);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
// Calculate their rule keys and verify they're different.
DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
RuleKey defaultKey1 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(buildRule);
RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(buildRule);
Files.write(file1, "hello other world".getBytes());
hashCache.invalidateAll();
RuleKey defaultKey2 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(buildRule);
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(buildRule);
// When the file content changes, the rulekey should change but the input rulekey should be
// unchanged. This ensures that a dependent's rulekey changes correctly.
assertNotEquals(defaultKey1, defaultKey2);
assertEquals(inputKey1, inputKey2);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class DirectHeaderMapTest method testSymlinkTreeRuleKeysChangeIfLinkMapChanges.
@Test
public void testSymlinkTreeRuleKeysChangeIfLinkMapChanges() throws Exception {
Path aFile = tmpDir.newFile();
Files.write(aFile, "hello world".getBytes(Charsets.UTF_8));
ImmutableMap.Builder<Path, SourcePath> modifiedLinksBuilder = ImmutableMap.builder();
for (Path p : links.keySet()) {
modifiedLinksBuilder.put(tmpDir.getRoot().resolve("modified-" + p.toString()), links.get(p));
}
DirectHeaderMap modifiedBuildRule = new DirectHeaderMap(buildTarget, projectFilesystem, symlinkTreeRoot, modifiedLinksBuilder.build(), ruleFinder);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
// Calculate their rule keys and verify they're different.
FileHashLoader hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()))));
RuleKey key1 = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(buildRule);
RuleKey key2 = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(modifiedBuildRule);
assertNotEquals(key1, key2);
key1 = new InputBasedRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(buildRule);
key2 = new InputBasedRuleKeyFactory(0, hashCache, resolver, ruleFinder).build(modifiedBuildRule);
assertNotEquals(key1, key2);
}
Aggregations