Search in sources :

Example 6 with PackageCacheOptions

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

the class FetchCommand method exec.

@Override
public ExitCode exec(CommandEnvironment env, OptionsProvider options) {
    BlazeRuntime runtime = env.getRuntime();
    if (options.getResidue().isEmpty()) {
        env.getReporter().handle(Event.error(String.format("missing fetch expression. Type '%s help fetch' for syntax and help", env.getRuntime().getProductName())));
        return ExitCode.COMMAND_LINE_ERROR;
    }
    try {
        env.setupPackageCache(options, runtime.getDefaultsPackageContent());
    } catch (InterruptedException e) {
        env.getReporter().handle(Event.error("fetch interrupted"));
        return ExitCode.INTERRUPTED;
    } catch (AbruptExitException e) {
        env.getReporter().handle(Event.error(null, "Unknown error: " + e.getMessage()));
        return e.getExitCode();
    }
    PackageCacheOptions pkgOptions = options.getOptions(PackageCacheOptions.class);
    if (!pkgOptions.fetch) {
        env.getReporter().handle(Event.error(null, "You cannot run fetch with --fetch=false"));
        return ExitCode.COMMAND_LINE_ERROR;
    }
    // Querying for all of the dependencies of the targets has the side-effect of populating the
    // Skyframe graph for external targets, which requires downloading them. The JDK is required to
    // build everything but isn't counted as a dep in the build graph so we add it manually.
    ImmutableList.Builder<String> labelsToLoad = new ImmutableList.Builder<String>().addAll(options.getResidue());
    String query = Joiner.on(" union ").join(labelsToLoad.build());
    query = "deps(" + query + ")";
    AbstractBlazeQueryEnvironment<Target> queryEnv = QueryCommand.newQueryEnvironment(env, options.getOptions(FetchOptions.class).keepGoing, false, Lists.<String>newArrayList(), 200, Sets.<Setting>newHashSet());
    // 1. Parse query:
    QueryExpression expr;
    try {
        expr = QueryExpression.parse(query, queryEnv);
    } catch (QueryException e) {
        env.getReporter().handle(Event.error(null, "Error while parsing '" + query + "': " + e.getMessage()));
        return ExitCode.COMMAND_LINE_ERROR;
    }
    // 2. Evaluate expression:
    try {
        queryEnv.evaluateQuery(expr, new ThreadSafeOutputFormatterCallback<Target>() {

            @Override
            public void processOutput(Iterable<Target> partialResult) {
            // Throw away the result.
            }
        });
    } catch (InterruptedException e) {
        return ExitCode.COMMAND_LINE_ERROR;
    } catch (QueryException e) {
        // Keep consistent with reportBuildFileError()
        env.getReporter().handle(Event.error(e.getMessage()));
        return ExitCode.COMMAND_LINE_ERROR;
    } catch (IOException e) {
        // Should be impossible since our OutputFormatterCallback doesn't throw IOException.
        throw new IllegalStateException(e);
    }
    env.getReporter().handle(Event.progress("All external dependencies fetched successfully."));
    return ExitCode.SUCCESS;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) BlazeRuntime(com.google.devtools.build.lib.runtime.BlazeRuntime) Target(com.google.devtools.build.lib.packages.Target) QueryException(com.google.devtools.build.lib.query2.engine.QueryException) AbruptExitException(com.google.devtools.build.lib.util.AbruptExitException) QueryExpression(com.google.devtools.build.lib.query2.engine.QueryExpression)

Example 7 with PackageCacheOptions

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

the class SkylarkFileContentHashTests method getHash.

/**
   * Returns the hash code of the rule target defined by the pkg and the target name parameters.
   * Asserts that the targets and it's Skylark dependencies were loaded properly.
   */
private String getHash(String pkg, String name) throws Exception {
    PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
    packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PUBLIC;
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 7;
    getSkyframeExecutor().preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)), packageCacheOptions, "", UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
    SkyKey pkgLookupKey = PackageValue.key(PackageIdentifier.parse("@//" + pkg));
    EvaluationResult<PackageValue> result = SkyframeExecutorTestUtils.evaluate(getSkyframeExecutor(), pkgLookupKey, /*keepGoing=*/
    false, reporter);
    assertFalse(result.hasError());
    Collection<Target> targets = result.get(pkgLookupKey).getPackage().getTargets();
    for (Target target : targets) {
        if (target.getName().equals(name)) {
            return ((Rule) target).getRuleClassObject().getRuleDefinitionEnvironment().getTransitiveContentHashCode();
        }
    }
    throw new IllegalStateException("target not found: " + name);
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) SkyKey(com.google.devtools.build.skyframe.SkyKey) Target(com.google.devtools.build.lib.packages.Target) Rule(com.google.devtools.build.lib.packages.Rule) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)

Example 8 with PackageCacheOptions

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

the class SkylarkImportLookupFunctionTest method preparePackageLoading.

@Before
public final void preparePackageLoading() throws Exception {
    Path alternativeRoot = scratch.dir("/root_2");
    PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
    packageCacheOptions.defaultVisibility = ConstantRuleVisibility.PUBLIC;
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = 7;
    getSkyframeExecutor().preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory, alternativeRoot)), packageCacheOptions, "", UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor) Before(org.junit.Before)

Example 9 with PackageCacheOptions

use of com.google.devtools.build.lib.pkgcache.PackageCacheOptions 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 10 with PackageCacheOptions

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

the class PackageLoadingTestCase method setUpSkyframe.

protected void setUpSkyframe(RuleVisibility defaultVisibility, String defaultsPackageContents) {
    PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class);
    packageCacheOptions.defaultVisibility = defaultVisibility;
    packageCacheOptions.showLoadingProgress = true;
    packageCacheOptions.globbingThreads = GLOBBING_THREADS;
    skyframeExecutor.preparePackageLoading(new PathPackageLocator(outputBase, ImmutableList.of(rootDirectory)), packageCacheOptions, defaultsPackageContents, UUID.randomUUID(), ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance()));
}
Also used : PathPackageLocator(com.google.devtools.build.lib.pkgcache.PathPackageLocator) PackageCacheOptions(com.google.devtools.build.lib.pkgcache.PackageCacheOptions) TimestampGranularityMonitor(com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)

Aggregations

PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)12 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)9 TimestampGranularityMonitor (com.google.devtools.build.lib.util.io.TimestampGranularityMonitor)9 Path (com.google.devtools.build.lib.vfs.Path)4 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 Test (org.junit.Test)3 BuildView (com.google.devtools.build.lib.analysis.BuildView)2 ConfigurationFactory (com.google.devtools.build.lib.analysis.config.ConfigurationFactory)2 PackageFactory (com.google.devtools.build.lib.packages.PackageFactory)2 Target (com.google.devtools.build.lib.packages.Target)2 SubincludePreprocessor (com.google.devtools.build.lib.packages.util.SubincludePreprocessor)2 SkyValueDirtinessChecker (com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker)2 SkyKey (com.google.devtools.build.skyframe.SkyKey)2 Before (org.junit.Before)2 ImmutableList (com.google.common.collect.ImmutableList)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 ConfiguredRuleClassProvider (com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider)1 BinTools (com.google.devtools.build.lib.analysis.config.BinTools)1 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)1 RepositoryOptions (com.google.devtools.build.lib.bazel.repository.RepositoryOptions)1