use of com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory 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.facebook.buck.rules.coercer.DefaultTypeCoercerFactory in project buck by facebook.
the class ParserBenchmark method setUpBenchmark.
@BeforeExperiment
public void setUpBenchmark() throws Exception {
tempDir.before();
Path root = tempDir.getRoot();
Files.createDirectories(root);
filesystem = new ProjectFilesystem(root);
Path fbJavaRoot = root.resolve(root.resolve("java/com/facebook"));
Files.createDirectories(fbJavaRoot);
for (int i = 0; i < targetCount; i++) {
Path targetRoot = fbJavaRoot.resolve(String.format("target_%d", i));
Files.createDirectories(targetRoot);
Path buckFile = targetRoot.resolve("BUCK");
Files.createFile(buckFile);
Files.write(buckFile, ("java_library(name = 'foo', srcs = ['A.java'])\n" + "genrule(name = 'baz', out = '')\n").getBytes("UTF-8"));
Path javaFile = targetRoot.resolve("A.java");
Files.createFile(javaFile);
Files.write(javaFile, String.format("package com.facebook.target_%d; class A {}", i).getBytes("UTF-8"));
}
ImmutableMap.Builder<String, ImmutableMap<String, String>> configSectionsBuilder = ImmutableMap.builder();
if (threadCount > 1) {
configSectionsBuilder.put("project", ImmutableMap.of("parallel_parsing", "true", "parsing_threads", Integer.toString(threadCount)));
}
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(configSectionsBuilder.build()).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
eventBus = BuckEventBusFactory.newInstance();
executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadCount));
DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
ConstructorArgMarshaller marshaller = new ConstructorArgMarshaller(typeCoercerFactory);
parser = new Parser(new BroadcastEventListener(), config.getView(ParserConfig.class), typeCoercerFactory, marshaller);
}
use of com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory in project buck by facebook.
the class TargetNodeTest method createTargetNode.
private static TargetNode<Arg, ExampleDescription> createTargetNode(BuildTarget buildTarget, ImmutableSet<BuildTarget> declaredDeps, ImmutableMap<String, Object> rawNode) throws NoSuchBuildTargetException {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
ExampleDescription description = new ExampleDescription();
return new TargetNodeFactory(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())).create(Hashing.sha1().hashString(buildTarget.getFullyQualifiedName(), UTF_8), description, createPopulatedConstructorArg(description, buildTarget, rawNode), filesystem, buildTarget, declaredDeps, ImmutableSet.of(), createCellRoots(filesystem));
}
use of com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory in project buck by facebook.
the class GenruleDescriptionTest method testImplicitDepsAreAddedCorrectly.
@Test
public void testImplicitDepsAreAddedCorrectly() throws Exception {
Description<GenruleDescription.Arg> genruleDescription = new GenruleDescription();
Map<String, Object> instance = ImmutableMap.of("srcs", ImmutableList.of(":baz", "//biz:baz"), "out", "AndroidManifest.xml", "cmd", "$(exe //bin:executable) $(location :arg)");
ProjectFilesystem projectFilesystem = new AllExistingProjectFilesystem();
ConstructorArgMarshaller marshaller = new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance()));
ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder();
ImmutableSet.Builder<VisibilityPattern> visibilityPatterns = ImmutableSet.builder();
GenruleDescription.Arg constructorArg = genruleDescription.createUnpopulatedConstructorArg();
BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar");
marshaller.populate(createCellRoots(projectFilesystem), projectFilesystem, buildTarget, constructorArg, declaredDeps, visibilityPatterns, instance);
TargetNode<GenruleDescription.Arg, ?> targetNode = new TargetNodeFactory(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())).create(Hashing.sha1().hashString(buildTarget.getFullyQualifiedName(), UTF_8), genruleDescription, constructorArg, projectFilesystem, buildTarget, declaredDeps.build(), visibilityPatterns.build(), createCellRoots(projectFilesystem));
assertEquals("SourcePaths and targets from cmd string should be extracted as extra deps.", ImmutableSet.of("//foo:baz", "//biz:baz", "//bin:executable", "//foo:arg"), targetNode.getExtraDeps().stream().map(Object::toString).collect(MoreCollectors.toImmutableSet()));
}
use of com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory in project buck by facebook.
the class DistBuildFileHashesIntegrationTest method crossCellDoesNotCauseAbsolutePathSrcs.
@Test
public void crossCellDoesNotCauseAbsolutePathSrcs() throws Exception {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cross_cell", temporaryFolder);
workspace.setUp();
ProjectFilesystem rootFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("root_cell"));
ProjectFilesystem secondaryFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("secondary_cell"));
BuckConfig rootCellConfig = FakeBuckConfig.builder().setFilesystem(rootFs).setSections("[repositories]", "cross_cell_secondary = " + secondaryFs.getRootPath().toAbsolutePath()).build();
Cell rootCell = new TestCellBuilder().setBuckConfig(rootCellConfig).setFilesystem(rootFs).build();
TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
Parser parser = new Parser(new BroadcastEventListener(), rootCellConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), rootCell, /* enableProfiling */
false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
DistBuildTargetGraphCodec targetGraphCodec = DistBuildStateTest.createDefaultCodec(rootCell, Optional.of(parser));
BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCell), createDistBuildFileHashes(targetGraph, rootCell), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
assertNotNull(dump);
assertEquals(2, dump.getFileHashesSize());
List<BuildJobStateFileHashes> sortedHashes = dump.getFileHashes().stream().sorted(Comparator.comparingInt(BuildJobStateFileHashes::getCellIndex)).collect(Collectors.toList());
BuildJobStateFileHashes rootCellHashes = sortedHashes.get(0);
assertEquals(1, rootCellHashes.getEntriesSize());
assertEquals("A.java", rootCellHashes.getEntries().get(0).getPath().getPath());
BuildJobStateFileHashes secondaryCellHashes = sortedHashes.get(1);
assertEquals(1, secondaryCellHashes.getEntriesSize());
assertEquals("B.java", secondaryCellHashes.getEntries().get(0).getPath().getPath());
}
Aggregations