Search in sources :

Example 6 with DefaultTypeCoercerFactory

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));
}
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 7 with DefaultTypeCoercerFactory

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);
}
Also used : Path(java.nio.file.Path) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) BeforeExperiment(com.google.caliper.BeforeExperiment)

Example 8 with DefaultTypeCoercerFactory

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));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)

Example 9 with DefaultTypeCoercerFactory

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()));
}
Also used : DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) VisibilityPattern(com.facebook.buck.rules.VisibilityPattern) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 10 with DefaultTypeCoercerFactory

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());
}
Also used : BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TargetGraph(com.facebook.buck.rules.TargetGraph) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Parser(com.facebook.buck.parser.Parser) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

Aggregations

DefaultTypeCoercerFactory (com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)20 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)16 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)12 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)11 ParserConfig (com.facebook.buck.parser.ParserConfig)10 Path (java.nio.file.Path)8 Test (org.junit.Test)8 BuckConfig (com.facebook.buck.cli.BuckConfig)7 Parser (com.facebook.buck.parser.Parser)7 Cell (com.facebook.buck.rules.Cell)7 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)7 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)6 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)6 TypeCoercerFactory (com.facebook.buck.rules.coercer.TypeCoercerFactory)6 BuckEventBus (com.facebook.buck.event.BuckEventBus)5 BuildTarget (com.facebook.buck.model.BuildTarget)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 PathSourcePath (com.facebook.buck.rules.PathSourcePath)4 TestConsole (com.facebook.buck.testutil.TestConsole)4 Config (com.facebook.buck.config.Config)3