Search in sources :

Example 26 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class CxxHeadersDirTest method dirContentsAffectsRuleKey.

@Test
public void dirContentsAffectsRuleKey() throws IOException {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Path headerDir = filesystem.getPath("foo");
    filesystem.mkdirs(headerDir);
    CxxHeadersDir cxxHeaders = CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new PathSourcePath(filesystem, headerDir));
    filesystem.writeContentsToPath("something", headerDir.resolve("bar.h"));
    RuleKey ruleKey1 = getRuleKey(filesystem, cxxHeaders);
    filesystem.writeContentsToPath("something else", headerDir.resolve("bar.h"));
    RuleKey ruleKey2 = getRuleKey(filesystem, cxxHeaders);
    assertThat(ruleKey1, Matchers.not(Matchers.equalTo(ruleKey2)));
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) Path(java.nio.file.Path) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 27 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class CxxHeadersDirTest method typeAffectsRuleKey.

@Test
public void typeAffectsRuleKey() throws IOException {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Path headerDir = filesystem.getPath("foo");
    filesystem.mkdirs(headerDir);
    RuleKey ruleKey1 = getRuleKey(filesystem, CxxHeadersDir.of(CxxPreprocessables.IncludeType.LOCAL, new PathSourcePath(filesystem, headerDir)));
    RuleKey ruleKey2 = getRuleKey(filesystem, CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new PathSourcePath(filesystem, headerDir)));
    assertThat(ruleKey1, Matchers.not(Matchers.equalTo(ruleKey2)));
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) Path(java.nio.file.Path) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 28 with RuleKey

use of com.facebook.buck.rules.RuleKey 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);
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) 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 29 with RuleKey

use of com.facebook.buck.rules.RuleKey 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);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 30 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class HeaderSymlinkTreeWithHeaderMapTest method testSymlinkTreeRuleKeyChangesIfLinkMapChanges.

@Test
public void testSymlinkTreeRuleKeyChangesIfLinkMapChanges() throws Exception {
    Path aFile = tmpDir.newFile();
    Files.write(aFile, "hello world".getBytes(Charsets.UTF_8));
    HeaderSymlinkTreeWithHeaderMap modifiedSymlinkTreeBuildRule = HeaderSymlinkTreeWithHeaderMap.create(buildTarget, projectFilesystem, symlinkTreeRoot, ImmutableMap.of(Paths.get("different/link"), new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), aFile))), 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 key1 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(symlinkTreeBuildRule);
    RuleKey key2 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(modifiedSymlinkTreeBuildRule);
    assertNotEquals(key1, key2);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) PathSourcePath(com.facebook.buck.rules.PathSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Aggregations

RuleKey (com.facebook.buck.rules.RuleKey)149 Test (org.junit.Test)112 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)71 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)71 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)71 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)70 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)57 Path (java.nio.file.Path)57 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)42 BuildTarget (com.facebook.buck.model.BuildTarget)42 BuildRule (com.facebook.buck.rules.BuildRule)42 LazyPath (com.facebook.buck.io.LazyPath)34 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)34 PathSourcePath (com.facebook.buck.rules.PathSourcePath)33 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)30 SourcePath (com.facebook.buck.rules.SourcePath)28 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)27 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)25 IOException (java.io.IOException)25 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)23