Example #1
0
async def hydrate_sources_snapshot(hydrated_struct: HydratedStruct) -> SourcesSnapshot:
    """Construct a SourcesSnapshot from a TargetAdaptor without hydrating any other fields."""
    target_adaptor = cast(TargetAdaptor, hydrated_struct.value)
    sources_field = next(
        (fa for fa in target_adaptor.field_adaptors if isinstance(fa, SourcesField)), None
    )
    if sources_field is None:
        return SourcesSnapshot(EMPTY_SNAPSHOT)
    hydrated_sources_field = await Get[HydratedField](HydrateableField, sources_field)
    efws = cast(EagerFilesetWithSpec, hydrated_sources_field.value)
    return SourcesSnapshot(efws.snapshot)
Example #2
0
async def resolve_sources_snapshot(
        specs: Specs, global_options: GlobalOptions) -> SourcesSnapshot:
    """Request a snapshot for the given specs.

    Address specs will use their `Sources` field, and Filesystem specs will use whatever args were
    given. Filesystem specs may safely refer to files with no owning target.
    """
    targets = await Get(Targets, AddressSpecs, specs.address_specs)
    all_hydrated_sources = await MultiGet(
        Get(HydratedSources, HydrateSourcesRequest(tgt[Sources]))
        for tgt in targets if tgt.has_field(Sources))

    filesystem_specs_digest = (await Get(
        Digest,
        PathGlobs,
        specs.filesystem_specs.to_path_globs(
            global_options.options.owners_not_found_behavior.
            to_glob_match_error_behavior()),
    ) if specs.filesystem_specs else None)

    # NB: We merge into a single snapshot to avoid the same files being duplicated if they were
    # covered both by address specs and filesystem specs.
    digests = [
        hydrated_sources.snapshot.digest
        for hydrated_sources in all_hydrated_sources
    ]
    if filesystem_specs_digest:
        digests.append(filesystem_specs_digest)
    result = await Get(Snapshot, MergeDigests(digests))
    return SourcesSnapshot(result)
Example #3
0
async def sources_snapshots_from_filesystem_specs(
    filesystem_specs: FilesystemSpecs, global_options: GlobalOptions,
) -> SourcesSnapshots:
    """Resolve the snapshot associated with the provided filesystem specs."""
    snapshot = await Get[Snapshot](
        PathGlobs,
        filesystem_specs.to_path_globs(
            global_options.options.owners_not_found_behavior.to_glob_match_error_behavior()
        ),
    )
    return SourcesSnapshots([SourcesSnapshot(snapshot)])
Example #4
0
async def sources_snapshot_from_target(wrapped_tgt: WrappedTarget) -> SourcesSnapshot:
    """Construct a SourcesSnapshot from a Target without hydrating any other fields."""
    hydrated_sources = await Get[HydratedSources](
        HydrateSourcesRequest(wrapped_tgt.target.get(Sources))
    )
    return SourcesSnapshot(hydrated_sources.snapshot)