Search in sources :

Example 1 with LoadingResult

use of com.google.devtools.build.lib.pkgcache.LoadingResult in project bazel by bazelbuild.

the class AnalysisTestCase method update.

/**
   * Update the BuildView: syncs the package cache; loads and analyzes the given labels.
   */
protected AnalysisResult update(EventBus eventBus, FlagBuilder config, ImmutableList<String> aspects, String... labels) throws Exception {
    Set<Flag> flags = config.flags;
    LoadingOptions loadingOptions = Options.getDefaults(LoadingOptions.class);
    BuildView.Options viewOptions = optionsParser.getOptions(BuildView.Options.class);
    viewOptions.keepGoing = flags.contains(Flag.KEEP_GOING);
    viewOptions.loadingPhaseThreads = LOADING_PHASE_THREADS;
    BuildOptions buildOptions = ruleClassProvider.createBuildOptions(optionsParser);
    PackageCacheOptions packageCacheOptions = optionsParser.getOptions(PackageCacheOptions.class);
    PathPackageLocator pathPackageLocator = PathPackageLocator.create(outputBase, packageCacheOptions.packagePath, reporter, rootDirectory, rootDirectory);
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 7;
    skyframeExecutor.preparePackageLoading(pathPackageLocator, packageCacheOptions, ruleClassProvider.getDefaultsPackageContent(analysisMock.getInvocationPolicyEnforcer().getInvocationPolicy()), UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
    skyframeExecutor.invalidateFilesUnderPathForTesting(reporter, ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory);
    LoadingResult loadingResult = loadingPhaseRunner.execute(reporter, ImmutableList.copyOf(labels), PathFragment.EMPTY_FRAGMENT, loadingOptions, viewOptions.keepGoing, /*determineTests=*/
    false, /*callback=*/
    null);
    BuildRequestOptions requestOptions = optionsParser.getOptions(BuildRequestOptions.class);
    ImmutableSortedSet<String> multiCpu = ImmutableSortedSet.copyOf(requestOptions.multiCpus);
    masterConfig = skyframeExecutor.createConfigurations(reporter, configurationFactory, buildOptions, multiCpu, false);
    analysisResult = buildView.update(loadingResult, masterConfig, aspects, viewOptions, AnalysisTestUtil.TOP_LEVEL_ARTIFACT_CONTEXT, reporter, eventBus);
    return analysisResult;
}
Also used : BuildView(com.google.devtools.build.lib.analysis.BuildView) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) LoadingOptions(com.google.devtools.build.lib.pkgcache.LoadingOptions) PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) LoadingResult(com.google.devtools.build.lib.pkgcache.LoadingResult) BuildRequestOptions(com.google.devtools.build.lib.buildtool.BuildRequest.BuildRequestOptions) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)

Example 2 with LoadingResult

use of com.google.devtools.build.lib.pkgcache.LoadingResult in project bazel by bazelbuild.

the class BuildTool method buildTargets.

/**
   * The crux of the build system. Builds the targets specified in the request using the specified
   * Executor.
   *
   * <p>Performs loading, analysis and execution for the specified set of targets, honoring the
   * configuration options in the BuildRequest. Returns normally iff successful, throws an exception
   * otherwise.
   *
   * <p>Callers must ensure that {@link #stopRequest} is called after this method, even if it
   * throws.
   *
   * <p>The caller is responsible for setting up and syncing the package cache.
   *
   * <p>During this function's execution, the actualTargets and successfulTargets
   * fields of the request object are set.
   *
   * @param request the build request that this build tool is servicing, which specifies various
   *        options; during this method's execution, the actualTargets and successfulTargets fields
   *        of the request object are populated
   * @param result the build result that is the mutable result of this build
   * @param validator target validator
   */
public void buildTargets(BuildRequest request, BuildResult result, TargetValidator validator) throws BuildFailedException, InterruptedException, ViewCreationFailedException, TargetParsingException, LoadingFailedException, AbruptExitException, InvalidConfigurationException, TestExecException {
    validateOptions(request);
    BuildOptions buildOptions = runtime.createBuildOptions(request);
    // Sync the package manager before sending the BuildStartingEvent in runLoadingPhase()
    env.setupPackageCache(request, DefaultsPackage.getDefaultsPackageContent(buildOptions));
    ExecutionTool executionTool = null;
    boolean catastrophe = false;
    try {
        env.getEventBus().post(new BuildStartingEvent(env, request));
        LOG.info("Build identifier: " + request.getId());
        executionTool = new ExecutionTool(env, request);
        if (needsExecutionPhase(request.getBuildOptions())) {
            // Initialize the execution tool early if we need it. This hides the latency of setting up
            // the execution backends.
            executionTool.init();
        }
        // Error out early if multi_cpus is set, but we're not in build or test command.
        if (!request.getMultiCpus().isEmpty()) {
            getReporter().handle(Event.warn("The --experimental_multi_cpu option is _very_ experimental and only intended for " + "internal testing at this time. If you do not work on the build tool, then you " + "should stop now!"));
            if (!"build".equals(request.getCommandName()) && !"test".equals(request.getCommandName())) {
                throw new InvalidConfigurationException("The experimental setting to select multiple CPUs is only supported for 'build' and " + "'test' right now!");
            }
        }
        // Exit if there are any pending exceptions from modules.
        env.throwPendingException();
        // Target pattern evaluation.
        LoadingResult loadingResult = evaluateTargetPatterns(request, validator);
        // Exit if there are any pending exceptions from modules.
        env.throwPendingException();
        // Configuration creation.
        BuildConfigurationCollection configurations = env.getSkyframeExecutor().createConfigurations(env.getReporter(), runtime.getConfigurationFactory(), buildOptions, request.getMultiCpus(), request.getViewOptions().keepGoing);
        env.throwPendingException();
        if (configurations.getTargetConfigurations().size() == 1) {
            // TODO(bazel-team): This is not optimal - we retain backwards compatibility in the case
            // where there's only a single configuration, but we don't send an event in the multi-config
            // case. Can we do better? [multi-config]
            env.getEventBus().post(new MakeEnvironmentEvent(configurations.getTargetConfigurations().get(0).getMakeEnvironment()));
        }
        LOG.info("Configurations created");
        if (request.getBuildOptions().performAnalysisPhase) {
            AnalysisResult analysisResult = runAnalysisPhase(request, loadingResult, configurations);
            result.setBuildConfigurationCollection(configurations);
            result.setActualTargets(analysisResult.getTargetsToBuild());
            result.setTestTargets(analysisResult.getTargetsToTest());
            LoadedPackageProvider bridge = new LoadedPackageProvider(env.getPackageManager(), env.getReporter());
            checkTargetEnvironmentRestrictions(analysisResult.getTargetsToBuild(), bridge);
            reportTargets(analysisResult);
            // Execution phase.
            if (needsExecutionPhase(request.getBuildOptions())) {
                executionTool.executeBuild(request.getId(), analysisResult, result, configurations, analysisResult.getPackageRoots(), request.getTopLevelArtifactContext());
            }
            String delayedErrorMsg = analysisResult.getError();
            if (delayedErrorMsg != null) {
                throw new BuildFailedException(delayedErrorMsg);
            }
        } else {
            getReporter().handle(Event.progress("Loading complete."));
            LOG.info("No analysis requested, so finished");
            String errorMessage = BuildView.createErrorMessage(loadingResult, null);
            if (errorMessage != null) {
                throw new BuildFailedException(errorMessage);
            }
        // Return.
        }
    } catch (RuntimeException e) {
        // Print an error message for unchecked runtime exceptions. This does not concern Error
        // subclasses such as OutOfMemoryError.
        request.getOutErr().printErrLn("Unhandled exception thrown during build; message: " + e.getMessage());
        catastrophe = true;
        throw e;
    } catch (Error e) {
        catastrophe = true;
        throw e;
    } catch (InvalidConfigurationException e) {
        // TODO(gregce): With "global configurations" we cannot tie a configuration creation failure
        // to a single target and have to halt the entire build. Once configurations are genuinely
        // created as part of the analysis phase they should report their error on the level of the
        // target(s) that triggered them.
        catastrophe = true;
        throw e;
    } finally {
        if (!catastrophe) {
            // Delete dirty nodes to ensure that they do not accumulate indefinitely.
            long versionWindow = request.getViewOptions().versionWindowForDirtyNodeGc;
            if (versionWindow != -1) {
                env.getSkyframeExecutor().deleteOldNodes(versionWindow);
            }
            if (executionTool != null) {
                executionTool.shutdown();
            }
            // The workspace status actions will not run with certain flags, or if an error
            // occurs early in the build. Tell a lie so that the event is not missing.
            // If multiple build_info events are sent, only the first is kept, so this does not harm
            // successful runs (which use the workspace status action).
            env.getEventBus().post(new BuildInfoEvent(env.getBlazeWorkspace().getWorkspaceStatusActionFactory().createDummyWorkspaceStatus()));
        }
    }
}
Also used : BuildStartingEvent(com.google.devtools.build.lib.buildtool.buildevent.BuildStartingEvent) MakeEnvironmentEvent(com.google.devtools.build.lib.analysis.MakeEnvironmentEvent) LoadedPackageProvider(com.google.devtools.build.lib.pkgcache.LoadedPackageProvider) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) InvalidConfigurationException(com.google.devtools.build.lib.analysis.config.InvalidConfigurationException) LoadingResult(com.google.devtools.build.lib.pkgcache.LoadingResult) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) BuildInfoEvent(com.google.devtools.build.lib.analysis.BuildInfoEvent) BuildConfigurationCollection(com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection)

Example 3 with LoadingResult

use of com.google.devtools.build.lib.pkgcache.LoadingResult in project bazel by bazelbuild.

the class BuildViewTestCase method update.

protected AnalysisResult update(List<String> targets, List<String> aspects, boolean keepGoing, int loadingPhaseThreads, boolean doAnalysis, EventBus eventBus) throws Exception {
    LoadingOptions loadingOptions = Options.getDefaults(LoadingOptions.class);
    BuildView.Options viewOptions = Options.getDefaults(BuildView.Options.class);
    viewOptions.keepGoing = keepGoing;
    viewOptions.loadingPhaseThreads = loadingPhaseThreads;
    LoadingPhaseRunner runner = new LegacyLoadingPhaseRunner(getPackageManager(), Collections.unmodifiableSet(ruleClassProvider.getRuleClassMap().keySet()));
    LoadingResult loadingResult = runner.execute(reporter, targets, PathFragment.EMPTY_FRAGMENT, loadingOptions, viewOptions.keepGoing, /*determineTests=*/
    false, /*callback=*/
    null);
    if (!doAnalysis) {
        // TODO(bazel-team): What's supposed to happen in this case?
        return null;
    }
    return view.update(loadingResult, masterConfig, aspects, viewOptions, AnalysisTestUtil.TOP_LEVEL_ARTIFACT_CONTEXT, reporter, eventBus);
}
Also used : BuildView(com.google.devtools.build.lib.analysis.BuildView) LoadingResult(com.google.devtools.build.lib.pkgcache.LoadingResult) LoadingPhaseRunner(com.google.devtools.build.lib.pkgcache.LoadingPhaseRunner) LegacyLoadingPhaseRunner(com.google.devtools.build.lib.skyframe.LegacyLoadingPhaseRunner) LegacyLoadingPhaseRunner(com.google.devtools.build.lib.skyframe.LegacyLoadingPhaseRunner) LoadingOptions(com.google.devtools.build.lib.pkgcache.LoadingOptions)

Example 4 with LoadingResult

use of com.google.devtools.build.lib.pkgcache.LoadingResult in project bazel by bazelbuild.

the class BuildTool method evaluateTargetPatterns.

private final LoadingResult evaluateTargetPatterns(final BuildRequest request, final TargetValidator validator) throws LoadingFailedException, TargetParsingException, InterruptedException {
    Profiler.instance().markPhase(ProfilePhase.LOAD);
    initializeOutputFilter(request);
    final boolean keepGoing = request.getViewOptions().keepGoing;
    LoadingCallback callback = new LoadingCallback() {

        @Override
        public void notifyTargets(Collection<Target> targets) throws LoadingFailedException {
            if (validator != null) {
                validator.validateTargets(targets, keepGoing);
            }
        }
    };
    LoadingPhaseRunner loadingPhaseRunner = env.getSkyframeExecutor().getLoadingPhaseRunner(runtime.getPackageFactory().getRuleClassNames(), request.getLoadingOptions().useSkyframeTargetPatternEvaluator);
    LoadingResult result = loadingPhaseRunner.execute(getReporter(), request.getTargets(), env.getRelativeWorkingDirectory(), request.getLoadingOptions(), keepGoing, request.shouldRunTests(), callback);
    return result;
}
Also used : LoadingCallback(com.google.devtools.build.lib.pkgcache.LoadingCallback) LoadingResult(com.google.devtools.build.lib.pkgcache.LoadingResult) LoadingPhaseRunner(com.google.devtools.build.lib.pkgcache.LoadingPhaseRunner) BuildConfigurationCollection(com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection) Collection(java.util.Collection) EnvironmentCollection(com.google.devtools.build.lib.analysis.constraints.EnvironmentCollection)

Aggregations

LoadingResult (com.google.devtools.build.lib.pkgcache.LoadingResult)4 BuildView (com.google.devtools.build.lib.analysis.BuildView)2 BuildConfigurationCollection (com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection)2 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)2 LoadingOptions (com.google.devtools.build.lib.pkgcache.LoadingOptions)2 LoadingPhaseRunner (com.google.devtools.build.lib.pkgcache.LoadingPhaseRunner)2 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 BuildInfoEvent (com.google.devtools.build.lib.analysis.BuildInfoEvent)1 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)1 MakeEnvironmentEvent (com.google.devtools.build.lib.analysis.MakeEnvironmentEvent)1 InvalidConfigurationException (com.google.devtools.build.lib.analysis.config.InvalidConfigurationException)1 EnvironmentCollection (com.google.devtools.build.lib.analysis.constraints.EnvironmentCollection)1 BuildRequestOptions (com.google.devtools.build.lib.buildtool.BuildRequest.BuildRequestOptions)1 BuildStartingEvent (com.google.devtools.build.lib.buildtool.buildevent.BuildStartingEvent)1 LoadedPackageProvider (com.google.devtools.build.lib.pkgcache.LoadedPackageProvider)1 LoadingCallback (com.google.devtools.build.lib.pkgcache.LoadingCallback)1 PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)1 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)1 LegacyLoadingPhaseRunner (com.google.devtools.build.lib.skyframe.LegacyLoadingPhaseRunner)1 TimestampGranularityMonitor (com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)1