예제 #1
0
파일: classpath.py 프로젝트: hephex/pants
async def classpath(
    coarsened_targets: CoarsenedTargets,
    union_membership: UnionMembership,
) -> Classpath:
    targets = Targets(t for ct in coarsened_targets.closure()
                      for t in ct.members)

    resolve = await Get(CoursierResolveKey, Targets, targets)

    transitive_classpath_entries = await MultiGet(
        Get(
            ClasspathEntry,
            ClasspathEntryRequest,
            ClasspathEntryRequest.for_targets(
                union_membership, component=t, resolve=resolve),
        ) for t in coarsened_targets.closure())
    merged_transitive_classpath_entries_digest = await Get(
        Digest,
        MergeDigests(classfiles.digest
                     for classfiles in transitive_classpath_entries))

    return Classpath(await Get(
        Snapshot,
        AddPrefix(merged_transitive_classpath_entries_digest,
                  _USERCP_RELPATH)))
예제 #2
0
async def select_coursier_resolve_for_targets(
        coarsened_targets: CoarsenedTargets,
        jvm: JvmSubsystem) -> CoursierResolveKey:
    """Selects and validates (transitively) a single resolve for a set of roots in a compile graph.

    In most cases, a `CoursierResolveKey` should be requested for a single `CoarsenedTarget` root,
    which avoids coupling un-related roots unnecessarily. But in other cases, a single compatible
    resolve is required for multiple roots (such as when running a `repl` over unrelated code), and
    in that case there might be multiple CoarsenedTargets.
    """
    targets = list(coarsened_targets.closure())

    # Find a single resolve that is compatible with all targets in the closure.
    compatible_resolve: str | None = None
    all_compatible = True
    for tgt in targets:
        if not tgt.has_field(JvmResolveField):
            continue
        resolve = tgt[JvmResolveField].normalized_value(jvm)
        if compatible_resolve is None:
            compatible_resolve = resolve
        elif resolve != compatible_resolve:
            all_compatible = False

    if not all_compatible:
        raise NoCompatibleResolve(
            jvm, "The selected targets did not have a resolve in common",
            targets)
    resolve = compatible_resolve or jvm.default_resolve

    # Load the resolve.
    resolve_path = jvm.resolves[resolve]
    lockfile_source = PathGlobs(
        [resolve_path],
        glob_match_error_behavior=GlobMatchErrorBehavior.error,
        description_of_origin=f"The resolve `{resolve}` from `[jvm].resolves`",
    )
    resolve_digest = await Get(Digest, PathGlobs, lockfile_source)
    return CoursierResolveKey(resolve, resolve_path, resolve_digest)