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();
}
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);
}
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));
}
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"));
}
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);
}
Aggregations