Search in sources :

Example 1 with BuildView

use of com.google.devtools.build.lib.analysis.BuildView 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 BuildView

use of com.google.devtools.build.lib.analysis.BuildView in project bazel by bazelbuild.

the class BuildTool method runAnalysisPhase.

/**
   * Performs the initial phases 0-2 of the build: Setup, Loading and Analysis.
   * <p>
   * Postcondition: On success, populates the BuildRequest's set of targets to
   * build.
   *
   * @return null if loading / analysis phases were successful; a useful error
   *         message if loading or analysis phase errors were encountered and
   *         request.keepGoing.
   * @throws InterruptedException if the current thread was interrupted.
   * @throws ViewCreationFailedException if analysis failed for any reason.
   */
private AnalysisResult runAnalysisPhase(BuildRequest request, LoadingResult loadingResult, BuildConfigurationCollection configurations) throws InterruptedException, ViewCreationFailedException {
    Stopwatch timer = Stopwatch.createStarted();
    getReporter().handle(Event.progress("Loading complete.  Analyzing..."));
    Profiler.instance().markPhase(ProfilePhase.ANALYZE);
    BuildView view = new BuildView(env.getDirectories(), runtime.getRuleClassProvider(), env.getSkyframeExecutor(), runtime.getCoverageReportActionFactory(request));
    AnalysisResult analysisResult = view.update(loadingResult, configurations, request.getAspects(), request.getViewOptions(), request.getTopLevelArtifactContext(), env.getReporter(), env.getEventBus());
    // TODO(bazel-team): Merge these into one event.
    env.getEventBus().post(new AnalysisPhaseCompleteEvent(analysisResult.getTargetsToBuild(), view.getTargetsVisited(), timer.stop().elapsed(TimeUnit.MILLISECONDS)));
    env.getEventBus().post(new TestFilteringCompleteEvent(analysisResult.getTargetsToBuild(), analysisResult.getTargetsToTest()));
    // Check licenses.
    // We check licenses if the first target configuration has license checking enabled. Right now,
    // it is not possible to have multiple target configurations with different settings for this
    // flag, which allows us to take this short cut.
    boolean checkLicenses = configurations.getTargetConfigurations().get(0).checkLicenses();
    if (checkLicenses) {
        Profiler.instance().markPhase(ProfilePhase.LICENSE);
        validateLicensingForTargets(analysisResult.getTargetsToBuild(), request.getViewOptions().keepGoing);
    }
    return analysisResult;
}
Also used : BuildView(com.google.devtools.build.lib.analysis.BuildView) AnalysisPhaseCompleteEvent(com.google.devtools.build.lib.analysis.AnalysisPhaseCompleteEvent) Stopwatch(com.google.common.base.Stopwatch) TestFilteringCompleteEvent(com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)

Example 3 with BuildView

use of com.google.devtools.build.lib.analysis.BuildView in project bazel by bazelbuild.

the class AnalysisTestCase method useRuleClassProvider.

/**
   * Changes the rule class provider to be used for the loading and the analysis phase.
   */
protected void useRuleClassProvider(ConfiguredRuleClassProvider ruleClassProvider) throws Exception {
    this.ruleClassProvider = ruleClassProvider;
    PackageFactory pkgFactory = analysisMock.getPackageFactoryForTesting().create(ruleClassProvider, scratch.getFileSystem());
    BinTools binTools = BinTools.forUnitTesting(directories, analysisMock.getEmbeddedTools());
    skyframeExecutor = SequencedSkyframeExecutor.create(pkgFactory, directories, binTools, workspaceStatusActionFactory, ruleClassProvider.getBuildInfoFactories(), ImmutableList.<DiffAwareness.Factory>of(), Predicates.<PathFragment>alwaysFalse(), Preprocessor.Factory.Supplier.NullSupplier.INSTANCE, analysisMock.getSkyFunctions(), getPrecomputedValues(), ImmutableList.<SkyValueDirtinessChecker>of(), analysisMock.getProductName(), CrossRepositoryLabelViolationStrategy.ERROR, ImmutableList.of(BuildFileName.BUILD_DOT_BAZEL, BuildFileName.BUILD));
    PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 3;
    skyframeExecutor.preparePackageLoading(pkgLocator, packageCacheOptions, ruleClassProvider.getDefaultsPackageContent(analysisMock.getInvocationPolicyEnforcer().getInvocationPolicy()), UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
    packageManager = skyframeExecutor.getPackageManager();
    loadingPhaseRunner = skyframeExecutor.getLoadingPhaseRunner(pkgFactory.getRuleClassNames(), defaultFlags().contains(Flag.SKYFRAME_LOADING_PHASE));
    buildView = new BuildView(directories, ruleClassProvider, skyframeExecutor, null);
    useConfiguration();
}
Also used : BinTools(com.google.devtools.build.lib.analysis.config.BinTools) PackageFactory(com.google.devtools.build.lib.packages.PackageFactory) BuildView(com.google.devtools.build.lib.analysis.BuildView) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ConfigurationFactory(com.google.devtools.build.lib.analysis.config.ConfigurationFactory) PackageFactory(com.google.devtools.build.lib.packages.PackageFactory) SkyValueDirtinessChecker(com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)

Example 4 with BuildView

use of com.google.devtools.build.lib.analysis.BuildView in project bazel by bazelbuild.

the class BuildViewTestCase method createBuildView.

/**
   * Creates BuildView using current hostConfig/targetConfig values.
   * Ensures that hostConfig is either identical to the targetConfig or has
   * 'host' short name.
   */
protected final void createBuildView() throws Exception {
    Preconditions.checkNotNull(masterConfig);
    Preconditions.checkState(getHostConfiguration().equals(getTargetConfiguration()) || getHostConfiguration().isHostConfiguration(), "Host configuration %s is not a host configuration' " + "and does not match target configuration %s", getHostConfiguration(), getTargetConfiguration());
    String defaultsPackageContent = ruleClassProvider.getDefaultsPackageContent(optionsParser);
    skyframeExecutor.setupDefaultPackage(defaultsPackageContent);
    skyframeExecutor.dropConfiguredTargets();
    view = new BuildView(directories, ruleClassProvider, skyframeExecutor, null);
    view.setConfigurationsForTesting(masterConfig);
    view.setArtifactRoots(ImmutableMap.of(PackageIdentifier.createInMainRepo(""), rootDirectory));
}
Also used : BuildView(com.google.devtools.build.lib.analysis.BuildView)

Aggregations

BuildView (com.google.devtools.build.lib.analysis.BuildView)4 PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)2 TimestampGranularityMonitor (com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)2 Stopwatch (com.google.common.base.Stopwatch)1 AnalysisPhaseCompleteEvent (com.google.devtools.build.lib.analysis.AnalysisPhaseCompleteEvent)1 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)1 BinTools (com.google.devtools.build.lib.analysis.config.BinTools)1 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)1 ConfigurationFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFactory)1 BuildRequestOptions (com.google.devtools.build.lib.buildtool.BuildRequest.BuildRequestOptions)1 TestFilteringCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent)1 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)1 LoadingOptions (com.google.devtools.build.lib.pkgcache.LoadingOptions)1 LoadingResult (com.google.devtools.build.lib.pkgcache.LoadingResult)1 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)1 SkyValueDirtinessChecker (com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1