Search in sources :

Example 61 with HumanReadableException

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());
            }
        }
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroException(com.facebook.buck.model.MacroException) Flavor(com.facebook.buck.model.Flavor)

Example 62 with HumanReadableException

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());
}
Also used : CxxPlatform(com.facebook.buck.cxx.CxxPlatform) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 63 with HumanReadableException

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);
    }
}
Also used : ClassPath(com.google.common.reflect.ClassPath) Path(java.nio.file.Path) CommandMode(com.facebook.buck.util.environment.CommandMode) IOException(java.io.IOException) WatchmanWatcher(com.facebook.buck.util.WatchmanWatcher) InterruptionFailedException(com.facebook.buck.util.InterruptionFailedException) BuildId(com.facebook.buck.model.BuildId) BuckIsDyingException(com.facebook.buck.util.BuckIsDyingException) HumanReadableException(com.facebook.buck.util.HumanReadableException) Console(com.facebook.buck.util.Console) Ansi(com.facebook.buck.util.Ansi)

Example 64 with HumanReadableException

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();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) TargetNode(com.facebook.buck.rules.TargetNode) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) WorkspaceAndProjectGenerator(com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) ImmutableSet(com.google.common.collect.ImmutableSet) XcodeWorkspaceConfigDescription(com.facebook.buck.apple.XcodeWorkspaceConfigDescription) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) JavaBuckConfig(com.facebook.buck.jvm.java.JavaBuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 65 with HumanReadableException

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);
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) Path(java.nio.file.Path) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15