Search in sources :

Example 1 with BroadcastEventListener

use of com.facebook.buck.event.listener.BroadcastEventListener in project buck by facebook.

the class CleanCommandTest method createCommandRunnerParams.

private CommandRunnerParams createCommandRunnerParams() throws InterruptedException, IOException {
    projectFilesystem = new FakeProjectFilesystem();
    Cell cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
    Supplier<AndroidPlatformTarget> androidPlatformTargetSupplier = AndroidPlatformTarget.EXPLODING_ANDROID_PLATFORM_TARGET_SUPPLIER;
    return CommandRunnerParams.builder().setConsole(new TestConsole()).setStdIn(new ByteArrayInputStream("".getBytes("UTF-8"))).setCell(cell).setAndroidPlatformTargetSupplier(androidPlatformTargetSupplier).setArtifactCacheFactory(new SingletonArtifactCacheFactory(new NoopArtifactCache())).setBuckEventBus(BuckEventBusFactory.newInstance()).setParser(createMock(Parser.class)).setPlatform(Platform.detect()).setEnvironment(ImmutableMap.copyOf(System.getenv())).setJavaPackageFinder(new FakeJavaPackageFinder()).setObjectMapper(ObjectMappers.newDefaultInstance()).setClock(new DefaultClock()).setProcessManager(Optional.empty()).setWebServer(Optional.empty()).setBuckConfig(FakeBuckConfig.builder().build()).setFileHashCache(new StackedFileHashCache(ImmutableList.of())).setExecutors(ImmutableMap.of()).setBuildEnvironmentDescription(CommandRunnerParamsForTesting.BUILD_ENVIRONMENT_DESCRIPTION).setVersionedTargetGraphCache(new VersionedTargetGraphCache()).setActionGraphCache(new ActionGraphCache(new BroadcastEventListener())).setKnownBuildRuleTypesFactory(new KnownBuildRuleTypesFactory(new FakeProcessExecutor(), new FakeAndroidDirectoryResolver())).build();
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) KnownBuildRuleTypesFactory(com.facebook.buck.rules.KnownBuildRuleTypesFactory) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) VersionedTargetGraphCache(com.facebook.buck.versions.VersionedTargetGraphCache) SingletonArtifactCacheFactory(com.facebook.buck.artifact_cache.SingletonArtifactCacheFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) ActionGraphCache(com.facebook.buck.rules.ActionGraphCache) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) ByteArrayInputStream(java.io.ByteArrayInputStream) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) DefaultClock(com.facebook.buck.timing.DefaultClock) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell)

Example 2 with BroadcastEventListener

use of com.facebook.buck.event.listener.BroadcastEventListener in project buck by facebook.

the class InterCellIntegrationTest method parseTargetForXCellVisibility.

private void parseTargetForXCellVisibility(String targetName) throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
    Pair<ProjectWorkspace, ProjectWorkspace> cells = prepare("inter-cell/visibility/primary", "inter-cell/visibility/secondary");
    ProjectWorkspace primary = cells.getFirst();
    ProjectWorkspace secondary = cells.getSecond();
    registerCell(primary, "primary", primary);
    registerCell(secondary, "primary", primary);
    // We could just do a build, but that's a little extreme since all we need is the target graph
    TypeCoercerFactory coercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    Parser parser = new Parser(new BroadcastEventListener(), primary.asCell().getBuckConfig().getView(ParserConfig.class), coercerFactory, new ConstructorArgMarshaller(coercerFactory));
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    Cell primaryCell = primary.asCell();
    BuildTarget namedTarget = BuildTargetFactory.newInstance(primaryCell.getFilesystem(), targetName);
    // It's enough that this parses cleanly.
    parser.buildTargetGraph(eventBus, primaryCell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(namedTarget));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuildTarget(com.facebook.buck.model.BuildTarget) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Cell(com.facebook.buck.rules.Cell) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ParserConfig(com.facebook.buck.parser.ParserConfig) Parser(com.facebook.buck.parser.Parser)

Example 3 with BroadcastEventListener

use of com.facebook.buck.event.listener.BroadcastEventListener in project buck by facebook.

the class IntraCellIntegrationTest method shouldTreatCellBoundariesAsVisibilityBoundariesToo.

@SuppressWarnings("PMD.EmptyCatchBlock")
@Test
public void shouldTreatCellBoundariesAsVisibilityBoundariesToo() throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "intracell/visibility", tmp);
    workspace.setUp();
    // We don't need to do a build. It's enough to just parse these things.
    Cell cell = workspace.asCell();
    TypeCoercerFactory coercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    Parser parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), coercerFactory, new ConstructorArgMarshaller(coercerFactory));
    // This parses cleanly
    parser.buildTargetGraph(BuckEventBusFactory.newInstance(), cell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(cell.getFilesystem(), "//just-a-directory:rule")));
    Cell childCell = cell.getCell(BuildTargetFactory.newInstance(workspace.getDestPath().resolve("child-repo"), "//:child-target"));
    try {
        // Whereas, because visibility is limited to the same cell, this won't.
        parser.buildTargetGraph(BuckEventBusFactory.newInstance(), childCell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(childCell.getFilesystem(), "//:child-target")));
        fail("Didn't expect parsing to work because of visibility");
    } catch (HumanReadableException e) {
    // This is expected
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) HumanReadableException(com.facebook.buck.util.HumanReadableException) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Cell(com.facebook.buck.rules.Cell) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ParserConfig(com.facebook.buck.parser.ParserConfig) Parser(com.facebook.buck.parser.Parser) Test(org.junit.Test)

Example 4 with BroadcastEventListener

use of com.facebook.buck.event.listener.BroadcastEventListener in project buck by facebook.

the class DistBuildFileHashesIntegrationTest method createDistBuildFileHashes.

private DistBuildFileHashes createDistBuildFileHashes(TargetGraph targetGraph, Cell rootCell) throws IOException {
    ActionGraphCache cache = new ActionGraphCache(new BroadcastEventListener());
    ActionGraphAndResolver actionGraphAndResolver = cache.getActionGraph(BuckEventBusFactory.newInstance(), true, false, targetGraph, KEY_SEED);
    BuildRuleResolver ruleResolver = actionGraphAndResolver.getResolver();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    DistBuildCellIndexer cellIndexer = new DistBuildCellIndexer(rootCell);
    ImmutableList.Builder<ProjectFileHashCache> allCaches = ImmutableList.builder();
    allCaches.add(DefaultFileHashCache.createDefaultFileHashCache(rootCell.getFilesystem()));
    for (Path cellPath : rootCell.getKnownRoots()) {
        Cell cell = rootCell.getCell(cellPath);
        allCaches.add(DefaultFileHashCache.createDefaultFileHashCache(cell.getFilesystem()));
    }
    allCaches.addAll(DefaultFileHashCache.createOsRootDirectoriesCaches());
    StackedFileHashCache stackedCache = new StackedFileHashCache(allCaches.build());
    return new DistBuildFileHashes(actionGraphAndResolver.getActionGraph(), sourcePathResolver, ruleFinder, stackedCache, cellIndexer, MoreExecutors.newDirectExecutorService(), /* keySeed */
    KEY_SEED, rootCell);
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ActionGraphCache(com.facebook.buck.rules.ActionGraphCache) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) Cell(com.facebook.buck.rules.Cell)

Example 5 with BroadcastEventListener

use of com.facebook.buck.event.listener.BroadcastEventListener 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)

Aggregations

BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)14 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)11 DefaultTypeCoercerFactory (com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)11 Cell (com.facebook.buck.rules.Cell)9 Path (java.nio.file.Path)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 Parser (com.facebook.buck.parser.Parser)7 ParserConfig (com.facebook.buck.parser.ParserConfig)7 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)7 TypeCoercerFactory (com.facebook.buck.rules.coercer.TypeCoercerFactory)6 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)6 Test (org.junit.Test)6 BuckConfig (com.facebook.buck.cli.BuckConfig)5 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)5 BuckEventBus (com.facebook.buck.event.BuckEventBus)4 PathSourcePath (com.facebook.buck.rules.PathSourcePath)4 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)4 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)3 BuildTarget (com.facebook.buck.model.BuildTarget)3 KnownBuildRuleTypesFactory (com.facebook.buck.rules.KnownBuildRuleTypesFactory)3