use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class ApplePackageDescription method addDepsFromParam.
/**
* Retrieve deps from macros in externally configured rules.
*
* This is used for ImplicitDepsInferringDescription, so it is flavor agnostic.
*/
private void addDepsFromParam(ImmutableSet.Builder<BuildTarget> builder, BuildTarget target, CellPathResolver cellNames) {
// Add all macro expanded dependencies for these platforms.
for (Flavor flavor : appleCxxPlatformFlavorDomain.getFlavors()) {
AppleCxxPlatform platform = appleCxxPlatformFlavorDomain.getValue(flavor);
Optional<ApplePackageConfig> packageConfig = config.getPackageConfigForPlatform(platform.getAppleSdk().getApplePlatform());
if (packageConfig.isPresent()) {
try {
builder.addAll(AbstractGenruleDescription.PARSE_TIME_MACRO_HANDLER.extractParseTimeDeps(target, cellNames, packageConfig.get().getCommand()));
} catch (MacroException e) {
throw new HumanReadableException(e, "%s (for platform %s): %s", target, platform.getAppleSdk().getApplePlatform().getName(), e.getMessage());
}
}
}
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class AppleBinaryDescription method createBundleBuildRule.
private <A extends Arg> BuildRule createBundleBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
if (!args.infoPlist.isPresent()) {
throw new HumanReadableException("Cannot create application for apple_binary '%s':\n", "No value specified for 'info_plist' attribute.", params.getBuildTarget().getUnflavoredBuildTarget());
}
AppleDebugFormat flavoredDebugFormat = AppleDebugFormat.FLAVOR_DOMAIN.getValue(params.getBuildTarget()).orElse(appleConfig.getDefaultDebugInfoFormatForBinaries());
if (!params.getBuildTarget().getFlavors().contains(flavoredDebugFormat.getFlavor())) {
return resolver.requireRule(params.getBuildTarget().withAppendedFlavors(flavoredDebugFormat.getFlavor()));
}
if (!AppleDescriptions.INCLUDE_FRAMEWORKS.getValue(params.getBuildTarget()).isPresent()) {
CxxPlatform cxxPlatform = delegate.getCxxPlatforms().getValue(params.getBuildTarget()).orElse(delegate.getDefaultCxxPlatform());
ApplePlatform applePlatform = platformFlavorsToAppleCxxPlatforms.getValue(cxxPlatform.getFlavor()).getAppleSdk().getApplePlatform();
if (applePlatform.getAppIncludesFrameworks()) {
return resolver.requireRule(params.getBuildTarget().withAppendedFlavors(AppleDescriptions.INCLUDE_FRAMEWORKS_FLAVOR));
}
return resolver.requireRule(params.getBuildTarget().withAppendedFlavors(AppleDescriptions.NO_INCLUDE_FRAMEWORKS_FLAVOR));
}
BuildTarget binaryTarget = params.withoutFlavor(APP_FLAVOR).getBuildTarget();
return AppleDescriptions.createAppleBundle(delegate.getCxxPlatforms(), delegate.getDefaultCxxPlatform(), platformFlavorsToAppleCxxPlatforms, targetGraph, params, resolver, codeSignIdentityStore, provisioningProfileStore, binaryTarget, Either.ofLeft(AppleBundleExtension.APP), Optional.empty(), args.infoPlist.get(), args.infoPlistSubstitutions, args.deps, args.tests, flavoredDebugFormat, appleConfig.useDryRunCodeSigning(), appleConfig.cacheBundlesAndPackages());
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class Main method runMainThenExit.
/* Define all error handling surrounding main command */
private void runMainThenExit(String[] args, Optional<NGContext> context, final long initTimestamp) {
installUncaughtExceptionHandler(context);
Path projectRoot = Paths.get(".");
int exitCode = FAIL_EXIT_CODE;
BuildId buildId = getBuildId(context);
// Only post an overflow event if Watchman indicates a fresh instance event
// after our initial query.
WatchmanWatcher.FreshInstanceAction watchmanFreshInstanceAction = daemon == null ? WatchmanWatcher.FreshInstanceAction.NONE : WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT;
// Get the client environment, either from this process or from the Nailgun context.
ImmutableMap<String, String> clientEnvironment = getClientEnvironment(context);
try {
CommandMode commandMode = CommandMode.RELEASE;
exitCode = runMainWithExitCode(buildId, projectRoot, context, clientEnvironment, commandMode, watchmanFreshInstanceAction, initTimestamp, args);
} catch (IOException e) {
if (e.getMessage().startsWith("No space left on device")) {
(new Console(Verbosity.STANDARD_INFORMATION, stdOut, stdErr, new Ansi(AnsiEnvironmentChecking.environmentSupportsAnsiEscapes(platform, clientEnvironment)))).printBuildFailure(e.getMessage());
} else {
LOG.error(e);
}
} catch (HumanReadableException e) {
Console console = new Console(Verbosity.STANDARD_INFORMATION, stdOut, stdErr, new Ansi(AnsiEnvironmentChecking.environmentSupportsAnsiEscapes(platform, clientEnvironment)));
console.printBuildFailure(e.getHumanReadableErrorMessage());
} catch (InterruptionFailedException e) {
// Command could not be interrupted.
if (context.isPresent()) {
// Exit process to halt command execution.
context.get().getNGServer().shutdown(true);
}
} catch (BuckIsDyingException e) {
LOG.warn(e, "Fallout because buck was already dying");
} catch (Throwable t) {
LOG.error(t, "Uncaught exception at top level");
} finally {
LOG.debug("Done.");
LogConfig.flushLogs();
// Exit explicitly so that non-daemon threads (of which we use many) don't
// keep the VM alive.
System.exit(exitCode);
}
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class ProjectCommand method generateWorkspacesForTargets.
@VisibleForTesting
static ImmutableSet<BuildTarget> generateWorkspacesForTargets(final CommandRunnerParams params, final TargetGraphAndTargets targetGraphAndTargets, ImmutableSet<BuildTarget> passedInTargetsSet, ImmutableSet<ProjectGenerator.Option> options, ImmutableList<String> buildWithBuckFlags, Optional<ImmutableSet<UnflavoredBuildTarget>> focusModules, Map<Path, ProjectGenerator> projectGenerators, boolean combinedProject, boolean buildWithBuck) throws IOException, InterruptedException {
ImmutableSet<BuildTarget> targets;
if (passedInTargetsSet.isEmpty()) {
targets = targetGraphAndTargets.getProjectRoots().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet());
} else {
targets = passedInTargetsSet;
}
LOG.debug("Generating workspace for config targets %s", targets);
ImmutableSet.Builder<BuildTarget> requiredBuildTargetsBuilder = ImmutableSet.builder();
for (final BuildTarget inputTarget : targets) {
TargetNode<?, ?> inputNode = targetGraphAndTargets.getTargetGraph().get(inputTarget);
XcodeWorkspaceConfigDescription.Arg workspaceArgs;
if (inputNode.getDescription() instanceof XcodeWorkspaceConfigDescription) {
TargetNode<XcodeWorkspaceConfigDescription.Arg, ?> castedWorkspaceNode = castToXcodeWorkspaceTargetNode(inputNode);
workspaceArgs = castedWorkspaceNode.getConstructorArg();
} else if (canGenerateImplicitWorkspaceForDescription(inputNode.getDescription())) {
workspaceArgs = createImplicitWorkspaceArgs(inputNode);
} else {
throw new HumanReadableException("%s must be a xcode_workspace_config, apple_binary, apple_bundle, or apple_library", inputNode);
}
BuckConfig buckConfig = params.getBuckConfig();
AppleConfig appleConfig = new AppleConfig(buckConfig);
HalideBuckConfig halideBuckConfig = new HalideBuckConfig(buckConfig);
CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(buckConfig);
SwiftBuckConfig swiftBuckConfig = new SwiftBuckConfig(buckConfig);
CxxPlatform defaultCxxPlatform = params.getCell().getKnownBuildRuleTypes().getDefaultCxxPlatforms();
WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(params.getCell(), targetGraphAndTargets.getTargetGraph(), workspaceArgs, inputTarget, options, combinedProject, buildWithBuck, buildWithBuckFlags, focusModules, !appleConfig.getXcodeDisableParallelizeBuild(), new ExecutableFinder(), params.getEnvironment(), params.getCell().getKnownBuildRuleTypes().getCxxPlatforms(), defaultCxxPlatform, params.getBuckConfig().getView(ParserConfig.class).getBuildFileName(), input -> ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph().getSubgraph(ImmutableSet.of(input))).getResolver(), params.getBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
ListeningExecutorService executorService = params.getExecutors().get(ExecutorPool.PROJECT);
Preconditions.checkNotNull(executorService, "CommandRunnerParams does not have executor for PROJECT pool");
generator.generateWorkspaceAndDependentProjects(projectGenerators, executorService);
ImmutableSet<BuildTarget> requiredBuildTargetsForWorkspace = generator.getRequiredBuildTargets();
LOG.debug("Required build targets for workspace %s: %s", inputTarget, requiredBuildTargetsForWorkspace);
requiredBuildTargetsBuilder.addAll(requiredBuildTargetsForWorkspace);
}
return requiredBuildTargetsBuilder.build();
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class ProjectCommand method getFocusModules.
private Optional<ImmutableSet<UnflavoredBuildTarget>> getFocusModules(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException {
if (modulesToFocusOn == null) {
return Optional.empty();
}
Iterable<String> patterns = Splitter.onPattern("\\s+").split(modulesToFocusOn);
// Parse patterns with the following syntax:
// https://buckbuild.com/concept/build_target_pattern.html
ImmutableList<TargetNodeSpec> specs = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), patterns);
// Resolve the list of targets matching the patterns.
ImmutableSet<BuildTarget> passedInTargetsSet;
ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
try {
passedInTargetsSet = params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, specs, SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode()).stream().flatMap(Collection::stream).map(target -> target.withoutCell()).collect(MoreCollectors.toImmutableSet());
} catch (BuildTargetException | BuildFileParseException | HumanReadableException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
return Optional.empty();
}
LOG.debug("Selected targets: %s", passedInTargetsSet.toString());
// Retrieve mapping: cell name -> path.
ImmutableMap<String, Path> cellPaths = params.getCell().getCellPathResolver().getCellPaths();
ImmutableMap<Path, String> cellNames = ImmutableBiMap.copyOf(cellPaths).inverse();
// Create a set of unflavored targets that have cell names.
ImmutableSet.Builder<UnflavoredBuildTarget> builder = ImmutableSet.builder();
for (BuildTarget target : passedInTargetsSet) {
String cell = cellNames.get(target.getCellPath());
if (cell == null) {
builder.add(target.getUnflavoredBuildTarget());
} else {
UnflavoredBuildTarget targetWithCell = UnflavoredBuildTarget.of(target.getCellPath(), Optional.of(cell), target.getBaseName(), target.getShortName());
builder.add(targetWithCell);
}
}
ImmutableSet<UnflavoredBuildTarget> passedInUnflavoredTargetsSet = builder.build();
LOG.debug("Selected unflavored targets: %s", passedInUnflavoredTargetsSet.toString());
return Optional.of(passedInUnflavoredTargetsSet);
}
Aggregations