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