Search in sources :

Example 1 with MissingSymbolEvent

use of com.facebook.buck.event.MissingSymbolEvent in project buck by facebook.

the class MissingSymbolsHandler method createListener.

/**
   * Instantiate a MissingSymbolsHandler and wrap it in a listener that calls it on the appropriate
   * events. This is done as part of the global listener setup in Main, and it's the entry point
   * into most of the dependency autodetection code.
   */
public static BuckEventListener createListener(ProjectFilesystem projectFilesystem, ImmutableSet<Description<?>> descriptions, BuckConfig config, BuckEventBus buckEventBus, Console console, JavacOptions javacOptions, ImmutableMap<String, String> environment) {
    final MissingSymbolsHandler missingSymbolsHandler = create(projectFilesystem, descriptions, config, buckEventBus, console, javacOptions, environment);
    final Multimap<BuildId, MissingSymbolEvent> missingSymbolEvents = HashMultimap.create();
    BuckEventListener missingSymbolsListener = new BuckEventListener() {

        @Override
        public void outputTrace(BuildId buildId) {
        // If we put {@link #printNeededDependencies} here, it's output won't be visible in buckd.
        // Instead, we listen for BuildEvent.Finished, below.
        }

        @Subscribe
        public void onMissingSymbol(MissingSymbolEvent event) {
            missingSymbolEvents.put(event.getBuildId(), event);
        }

        @Subscribe
        public void onBuildFinished(BuildEvent.Finished event) {
            // Shortcircuit if there aren't any failures.
            if (missingSymbolEvents.get(event.getBuildId()).isEmpty()) {
                return;
            }
            try {
                missingSymbolsHandler.printNeededDependencies(missingSymbolEvents.get(event.getBuildId()));
            } catch (InterruptedException e) {
                LOG.debug(e, "Missing symbols handler did not complete in time.");
            } catch (RuntimeException e) {
                if (e.getCause() instanceof ClosedByInterruptException) {
                    LOG.debug(e.getCause(), "Missing symbols handler did not complete in time.");
                } else {
                    throw e;
                }
            }
            missingSymbolEvents.removeAll(event.getBuildId());
        }
    };
    return missingSymbolsListener;
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) BuildId(com.facebook.buck.model.BuildId) MissingSymbolEvent(com.facebook.buck.event.MissingSymbolEvent) BuckEventListener(com.facebook.buck.event.BuckEventListener)

Example 2 with MissingSymbolEvent

use of com.facebook.buck.event.MissingSymbolEvent in project buck by facebook.

the class MissingSymbolsHandlerIntegrationTest method shouldFindNeededDependenciesFromSymbols.

@Test
public void shouldFindNeededDependenciesFromSymbols() throws IOException, InterruptedException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symbol_finder", temporaryFolder);
    workspace.setUp();
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    ImmutableMap<String, String> environment = ImmutableMap.copyOf(System.getenv());
    Config rawConfig = Configs.createDefaultConfig(projectFilesystem.getRootPath());
    BuckConfig config = new BuckConfig(rawConfig, projectFilesystem, Architecture.detect(), Platform.detect(), environment, new DefaultCellPathResolver(projectFilesystem.getRootPath(), rawConfig));
    ImmutableSet<Description<?>> allDescriptions = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(projectFilesystem, environment).getAllDescriptions();
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
    MissingSymbolsHandler missingSymbolsHandler = MissingSymbolsHandler.create(projectFilesystem, allDescriptions, config, buckEventBus, new TestConsole(), DEFAULT_JAVAC_OPTIONS, environment);
    MissingSymbolEvent missingSymbolEvent = MissingSymbolEvent.create(BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/b:b"), "com.example.a.A", MissingSymbolEvent.SymbolType.Java);
    ImmutableSetMultimap<BuildTarget, BuildTarget> neededDeps = missingSymbolsHandler.getNeededDependencies(ImmutableList.of(missingSymbolEvent));
    assertEquals("MissingSymbolsHandler failed to find the needed dependency.", neededDeps, ImmutableSetMultimap.of(BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/b:b"), BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/a:a")));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) Description(com.facebook.buck.rules.Description) Config(com.facebook.buck.config.Config) BuckConfig(com.facebook.buck.cli.BuckConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) MissingSymbolsHandler(com.facebook.buck.cli.MissingSymbolsHandler) MissingSymbolEvent(com.facebook.buck.event.MissingSymbolEvent) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuckConfig(com.facebook.buck.cli.BuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 3 with MissingSymbolEvent

use of com.facebook.buck.event.MissingSymbolEvent in project buck by facebook.

the class MissingSymbolsHandler method getNeededDependencies.

/**
   * Using missing symbol events from the build and the JavaSymbolFinder class, build a list of
   * missing dependencies for each broken target.
   */
public ImmutableSetMultimap<BuildTarget, BuildTarget> getNeededDependencies(Collection<MissingSymbolEvent> missingSymbolEvents) throws InterruptedException, IOException {
    ImmutableSetMultimap.Builder<BuildTarget, String> targetsMissingSymbolsBuilder = ImmutableSetMultimap.builder();
    for (MissingSymbolEvent event : missingSymbolEvents) {
        if (event.getType() != MissingSymbolEvent.SymbolType.Java) {
            throw new UnsupportedOperationException("Only implemented for Java.");
        }
        targetsMissingSymbolsBuilder.put(event.getTarget(), event.getSymbol());
    }
    ImmutableSetMultimap<BuildTarget, String> targetsMissingSymbols = targetsMissingSymbolsBuilder.build();
    ImmutableSetMultimap<String, BuildTarget> symbolProviders = javaSymbolFinder.findTargetsForSymbols(ImmutableSet.copyOf(targetsMissingSymbols.values()));
    ImmutableSetMultimap.Builder<BuildTarget, BuildTarget> neededDeps = ImmutableSetMultimap.builder();
    for (BuildTarget target : targetsMissingSymbols.keySet()) {
        for (String symbol : targetsMissingSymbols.get(target)) {
            // TODO(oconnor663): Properly handle symbols that are defined in more than one place.
            // TODO(oconnor663): Properly handle target visibility.
            neededDeps.putAll(target, ImmutableSortedSet.copyOf(symbolProviders.get(symbol)));
        }
    }
    return neededDeps.build();
}
Also used : ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) BuildTarget(com.facebook.buck.model.BuildTarget) MissingSymbolEvent(com.facebook.buck.event.MissingSymbolEvent)

Aggregations

MissingSymbolEvent (com.facebook.buck.event.MissingSymbolEvent)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 BuckConfig (com.facebook.buck.cli.BuckConfig)1 MissingSymbolsHandler (com.facebook.buck.cli.MissingSymbolsHandler)1 Config (com.facebook.buck.config.Config)1 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 BuckEventListener (com.facebook.buck.event.BuckEventListener)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 BuildId (com.facebook.buck.model.BuildId)1 DefaultCellPathResolver (com.facebook.buck.rules.DefaultCellPathResolver)1 Description (com.facebook.buck.rules.Description)1 TestConsole (com.facebook.buck.testutil.TestConsole)1 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1