Search in sources :

Example 31 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class ParserTest method buildTargetGraphAndGetHashCodes.

private ImmutableMap<BuildTarget, HashCode> buildTargetGraphAndGetHashCodes(Parser parser, BuildTarget... buildTargets) throws Exception {
    // Build the target graph so we can access the hash code cache.
    ImmutableList<BuildTarget> buildTargetsList = ImmutableList.copyOf(buildTargets);
    TargetGraph targetGraph = parser.buildTargetGraph(eventBus, cell, false, executorService, buildTargetsList);
    ImmutableMap.Builder<BuildTarget, HashCode> toReturn = ImmutableMap.builder();
    for (TargetNode<?, ?> node : targetGraph.getNodes()) {
        toReturn.put(node.getBuildTarget(), node.getRawInputsHashCode());
    }
    return toReturn.build();
}
Also used : HashCode(com.google.common.hash.HashCode) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 32 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class ParserTest method targetWithSourceFileChangesHash.

@Test
public void targetWithSourceFileChangesHash() throws Exception {
    tempDir.newFolder("foo");
    Path testFooBuckFile = tempDir.newFile("foo/BUCK");
    Files.write(testFooBuckFile, "java_library(name = 'lib', srcs=glob(['*.java']), visibility=['PUBLIC'])\n".getBytes(UTF_8));
    BuildTarget fooLibTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
    HashCode original = buildTargetGraphAndGetHashCodes(parser, fooLibTarget).get(fooLibTarget);
    DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), typeCoercerFactory, new ConstructorArgMarshaller(typeCoercerFactory));
    Path testFooJavaFile = tempDir.newFile("foo/Foo.java");
    Files.write(testFooJavaFile, "// Ceci n'est pas une Javafile\n".getBytes(UTF_8));
    HashCode updated = buildTargetGraphAndGetHashCodes(parser, fooLibTarget).get(fooLibTarget);
    assertNotEquals(original, updated);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) HashCode(com.google.common.hash.HashCode) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Test(org.junit.Test)

Example 33 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class ParserTest method addingDepToTargetChangesHashOfDependingTargetOnly.

@Test
public void addingDepToTargetChangesHashOfDependingTargetOnly() throws Exception {
    tempDir.newFolder("foo");
    Path testFooBuckFile = tempDir.newFile("foo/BUCK");
    Files.write(testFooBuckFile, ("java_library(name = 'lib', deps = [], visibility=['PUBLIC'])\n" + "java_library(name = 'lib2', deps = [], visibility=['PUBLIC'])\n").getBytes(UTF_8));
    BuildTarget fooLibTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
    BuildTarget fooLib2Target = BuildTarget.builder(cellRoot, "//foo", "lib2").build();
    ImmutableMap<BuildTarget, HashCode> hashes = buildTargetGraphAndGetHashCodes(parser, fooLibTarget, fooLib2Target);
    HashCode libKey = hashes.get(fooLibTarget);
    HashCode lib2Key = hashes.get(fooLib2Target);
    DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), typeCoercerFactory, new ConstructorArgMarshaller(typeCoercerFactory));
    Files.write(testFooBuckFile, ("java_library(name = 'lib', deps = [], visibility=['PUBLIC'])\n" + "java_library(name = 'lib2', deps = [':lib'], visibility=['PUBLIC'])\n").getBytes(UTF_8));
    hashes = buildTargetGraphAndGetHashCodes(parser, fooLibTarget, fooLib2Target);
    assertEquals(libKey, hashes.get(fooLibTarget));
    assertNotEquals(lib2Key, hashes.get(fooLib2Target));
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) HashCode(com.google.common.hash.HashCode) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Test(org.junit.Test)

Example 34 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class ResolverIntegrationTest method shouldSetUpAPrivateLibraryIfGivenAMavenCoordWithoutDeps.

@Test
public void shouldSetUpAPrivateLibraryIfGivenAMavenCoordWithoutDeps() throws Exception {
    resolveWithArtifacts("com.example:no-deps:jar:1.0");
    Path groupDir = thirdParty.resolve("example");
    assertTrue(Files.exists(groupDir));
    Path original = repo.resolve("com/example/no-deps/1.0/no-deps-1.0.jar");
    HashCode expected = MorePaths.asByteSource(original).hash(Hashing.sha1());
    Path jarFile = groupDir.resolve("no-deps-1.0.jar");
    HashCode seen = MorePaths.asByteSource(jarFile).hash(Hashing.sha1());
    assertEquals(expected, seen);
    List<Map<String, Object>> rules = buildFileParser.getAll(groupDir.resolve("BUCK"));
    assertEquals(1, rules.size());
    Map<String, Object> rule = rules.get(0);
    // Name is derived from the project identifier
    assertEquals("no-deps", rule.get("name"));
    // The binary jar should be set
    assertEquals("no-deps-1.0.jar", rule.get("binaryJar"));
    // There was no source jar in the repo
    assertTrue(rule.containsKey("sourceJar"));
    assertNull(rule.get("sourceJar"));
    // It's a library that's requested on the CLI, so it gets full visibility.
    assertEquals(ImmutableList.of("PUBLIC"), rule.get("visibility"));
    // And it doesn't depend on anything
    assertNull(rule.get("deps"));
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 35 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class ParserTest method buildTargetHashCodePopulatesCorrectly.

@Test
public void buildTargetHashCodePopulatesCorrectly() throws Exception {
    tempDir.newFolder("foo");
    Path testFooBuckFile = tempDir.newFile("foo/BUCK");
    Files.write(testFooBuckFile, "java_library(name = 'lib', visibility=['PUBLIC'])\n".getBytes(UTF_8));
    BuildTarget fooLibTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
    // We can't precalculate the hash, since it depends on the buck version. Check for the presence
    // of a hash for the right key.
    HashCode hashCode = buildTargetGraphAndGetHashCodes(parser, fooLibTarget).get(fooLibTarget);
    assertNotNull(hashCode);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) HashCode(com.google.common.hash.HashCode) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) Test(org.junit.Test)

Aggregations

HashCode (com.google.common.hash.HashCode)115 Path (java.nio.file.Path)41 Test (org.junit.Test)39 BuildTarget (com.facebook.buck.model.BuildTarget)19 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)13 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 IOException (java.io.IOException)12 PathSourcePath (com.facebook.buck.rules.PathSourcePath)11 FileHashCache (com.facebook.buck.util.cache.FileHashCache)11 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)10 Hasher (com.google.common.hash.Hasher)10 Map (java.util.Map)8 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)7 SourcePath (com.facebook.buck.rules.SourcePath)7 BuckEventBus (com.facebook.buck.event.BuckEventBus)6 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5