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