Search in sources :

Example 6 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.

the class PackageProgressReceiverTest method testReset.

@Test
public void testReset() {
    // After resetting, messages should be as immediately after creation.
    PackageProgressReceiver progress = new PackageProgressReceiver();
    String defaultState = progress.progressState().getFirst();
    String defaultActivity = progress.progressState().getSecond();
    PackageIdentifier id = PackageIdentifier.createInMainRepo("foo/bar/baz");
    progress.startReadPackage(id);
    progress.doneReadPackage(id);
    progress.reset();
    assertEquals(defaultState, progress.progressState().getFirst());
    assertEquals(defaultActivity, progress.progressState().getSecond());
}
Also used : PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) Test(org.junit.Test)

Example 7 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.

the class BuildView method setArtifactRoots.

/**
   * Sets the possible artifact roots in the artifact factory. This allows the factory to resolve
   * paths with unknown roots to artifacts.
   */
// for BuildViewTestCase
@VisibleForTesting
public void setArtifactRoots(ImmutableMap<PackageIdentifier, Path> packageRoots) {
    Map<Path, Root> rootMap = new HashMap<>();
    Map<PackageIdentifier, Root> realPackageRoots = new HashMap<>();
    for (Map.Entry<PackageIdentifier, Path> entry : packageRoots.entrySet()) {
        Root root = rootMap.get(entry.getValue());
        if (root == null) {
            root = Root.asSourceRoot(entry.getValue(), entry.getKey().getRepository().isMain());
            rootMap.put(entry.getValue(), root);
        }
        realPackageRoots.put(entry.getKey(), root);
    }
    // Source Artifact roots:
    getArtifactFactory().setPackageRoots(realPackageRoots);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Root(com.google.devtools.build.lib.actions.Root) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.

the class ContainingPackageLookupFunction method compute.

@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws InterruptedException {
    PackageIdentifier dir = (PackageIdentifier) skyKey.argument();
    PackageLookupValue pkgLookupValue = (PackageLookupValue) env.getValue(PackageLookupValue.key(dir));
    if (pkgLookupValue == null) {
        return null;
    }
    if (pkgLookupValue.packageExists()) {
        return ContainingPackageLookupValue.withContainingPackage(dir, pkgLookupValue.getRoot());
    }
    PathFragment parentDir = dir.getPackageFragment().getParentDirectory();
    if (parentDir == null) {
        return ContainingPackageLookupValue.NONE;
    }
    PackageIdentifier parentId = PackageIdentifier.create(dir.getRepository(), parentDir);
    return env.getValue(ContainingPackageLookupValue.key(parentId));
}
Also used : PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 9 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.

the class CollectTargetsInPackageFunction method compute.

@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException {
    CollectTargetsInPackageValue.CollectTargetsInPackageKey argument = (CollectTargetsInPackageValue.CollectTargetsInPackageKey) skyKey.argument();
    PackageIdentifier packageId = argument.getPackageId();
    PackageValue packageValue = (PackageValue) env.getValue(PackageValue.key(packageId));
    if (env.valuesMissing()) {
        return null;
    }
    Package pkg = packageValue.getPackage();
    if (pkg.containsErrors()) {
        env.getListener().handle(Event.error("package contains errors: " + packageId.getPackageFragment().getPathString()));
    }
    env.getValues(Iterables.transform(TargetPatternResolverUtil.resolvePackageTargets(pkg, argument.getFilteringPolicy()).getTargets(), TO_TRANSITIVE_TRAVERSAL_KEY));
    if (env.valuesMissing()) {
        return null;
    }
    return CollectTargetsInPackageValue.INSTANCE;
}
Also used : PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) Package(com.google.devtools.build.lib.packages.Package) Nullable(javax.annotation.Nullable)

Example 10 with PackageIdentifier

use of com.google.devtools.build.lib.cmdline.PackageIdentifier in project bazel by bazelbuild.

the class GraphBackedRecursivePackageProvider method bulkGetPackages.

@Override
public Map<PackageIdentifier, Package> bulkGetPackages(Iterable<PackageIdentifier> pkgIds) throws NoSuchPackageException, InterruptedException {
    Set<SkyKey> pkgKeys = ImmutableSet.copyOf(PackageValue.keys(pkgIds));
    ImmutableMap.Builder<PackageIdentifier, Package> pkgResults = ImmutableMap.builder();
    Map<SkyKey, SkyValue> packages = graph.getSuccessfulValues(pkgKeys);
    for (Map.Entry<SkyKey, SkyValue> pkgEntry : packages.entrySet()) {
        PackageIdentifier pkgId = (PackageIdentifier) pkgEntry.getKey().argument();
        PackageValue pkgValue = (PackageValue) pkgEntry.getValue();
        pkgResults.put(pkgId, Preconditions.checkNotNull(pkgValue.getPackage(), pkgId));
    }
    SetView<SkyKey> unknownKeys = Sets.difference(pkgKeys, packages.keySet());
    if (!Iterables.isEmpty(unknownKeys)) {
        LOGGER.warning("Unable to find " + unknownKeys + " in the batch lookup of " + pkgKeys + ". Successfully looked up " + packages.keySet());
    }
    for (Map.Entry<SkyKey, Exception> missingOrExceptionEntry : graph.getMissingAndExceptions(unknownKeys).entrySet()) {
        PackageIdentifier pkgIdentifier = (PackageIdentifier) missingOrExceptionEntry.getKey().argument();
        Exception exception = missingOrExceptionEntry.getValue();
        if (exception == null) {
            // package, because the SkyQuery environment has already loaded the universe.
            throw new BuildFileNotFoundException(pkgIdentifier, "Package not found");
        }
        Throwables.propagateIfInstanceOf(exception, NoSuchPackageException.class);
        Throwables.propagate(exception);
    }
    return pkgResults.build();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap) NoSuchPackageException(com.google.devtools.build.lib.packages.NoSuchPackageException) BuildFileNotFoundException(com.google.devtools.build.lib.packages.BuildFileNotFoundException) NoSuchTargetException(com.google.devtools.build.lib.packages.NoSuchTargetException) SkyValue(com.google.devtools.build.skyframe.SkyValue) PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) Package(com.google.devtools.build.lib.packages.Package) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)49 SkyKey (com.google.devtools.build.skyframe.SkyKey)17 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)16 Package (com.google.devtools.build.lib.packages.Package)14 Label (com.google.devtools.build.lib.cmdline.Label)12 Path (com.google.devtools.build.lib.vfs.Path)11 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 NoSuchPackageException (com.google.devtools.build.lib.packages.NoSuchPackageException)8 BuildFileNotFoundException (com.google.devtools.build.lib.packages.BuildFileNotFoundException)7 Target (com.google.devtools.build.lib.packages.Target)7 Nullable (javax.annotation.Nullable)7 NoSuchTargetException (com.google.devtools.build.lib.packages.NoSuchTargetException)6 LabelSyntaxException (com.google.devtools.build.lib.cmdline.LabelSyntaxException)5 Map (java.util.Map)5 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)4 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)3 ResolvedTargets (com.google.devtools.build.lib.cmdline.ResolvedTargets)3