async def package_archive_target( field_set: ArchiveFieldSet, global_options: GlobalOptions) -> BuiltPackage: package_targets, files_targets = await MultiGet( Get( Targets, UnparsedAddressInputs(field_set.packages.value or (), owning_address=field_set.address), ), Get( Targets, UnparsedAddressInputs(field_set.files.value or (), owning_address=field_set.address), ), ) package_field_sets_per_target = await Get( FieldSetsPerTarget, FieldSetsPerTargetRequest(PackageFieldSet, package_targets)) packages = await MultiGet( Get(BuiltPackage, PackageFieldSet, field_set) for field_set in package_field_sets_per_target.field_sets) files_sources = await MultiGet( Get( HydratedSources, HydrateSourcesRequest(tgt.get(Sources), for_sources_types=(FilesSources, ), enable_codegen=True), ) for tgt in files_targets) input_snapshot = await Get( Snapshot, MergeDigests(( *(package.digest for package in packages), *(sources.snapshot.digest for sources in files_sources), )), ) output_filename = field_set.output_path.value_or_default( field_set.address, file_ending=field_set.format_field.value, use_legacy_format=global_options.options.pants_distdir_legacy_paths, ) archive = await Get( Digest, CreateArchive( input_snapshot, output_filename=output_filename, format=ArchiveFormat(field_set.format_field.value), ), ) return BuiltPackage(archive, relpath=output_filename)
async def package_archive_target(field_set: ArchiveFieldSet) -> BuiltPackage: # TODO(#13086): Because we're using `Targets` instead of `UnexpandedTargets`, the # `files` target generator gets replaced by its generated `file` targets. That replacement is # necessary because we only hydrate sources for `FileSourcesField`, which is only for the # `file` target. That's really subtle! package_targets, file_targets = await MultiGet( Get(Targets, UnparsedAddressInputs, field_set.packages.to_unparsed_address_inputs()), Get(Targets, UnparsedAddressInputs, field_set.files.to_unparsed_address_inputs()), ) package_field_sets_per_target = await Get( FieldSetsPerTarget, FieldSetsPerTargetRequest(PackageFieldSet, package_targets)) packages = await MultiGet( Get(BuiltPackage, PackageFieldSet, field_set) for field_set in package_field_sets_per_target.field_sets) file_sources = await MultiGet( Get( HydratedSources, HydrateSourcesRequest( tgt.get(SourcesField), for_sources_types=(FileSourceField, ), enable_codegen=True, ), ) for tgt in file_targets) input_snapshot = await Get( Snapshot, MergeDigests(( *(package.digest for package in packages), *(sources.snapshot.digest for sources in file_sources), )), ) output_filename = field_set.output_path.value_or_default( file_ending=field_set.format_field.value) archive = await Get( Digest, CreateArchive( input_snapshot, output_filename=output_filename, format=ArchiveFormat(field_set.format_field.value), ), ) return BuiltPackage(archive, (BuiltPackageArtifact(output_filename), ))
async def package_archive_target(field_set: ArchiveFieldSet) -> BuiltPackage: package_targets, files_targets = await MultiGet( Get(Targets, UnparsedAddressInputs, field_set.packages.to_unparsed_address_inputs()), Get(Targets, UnparsedAddressInputs, field_set.files.to_unparsed_address_inputs()), ) package_field_sets_per_target = await Get( FieldSetsPerTarget, FieldSetsPerTargetRequest(PackageFieldSet, package_targets) ) packages = await MultiGet( Get(BuiltPackage, PackageFieldSet, field_set) for field_set in package_field_sets_per_target.field_sets ) files_sources = await MultiGet( Get( HydratedSources, HydrateSourcesRequest( tgt.get(Sources), for_sources_types=(FilesSources,), enable_codegen=True ), ) for tgt in files_targets ) input_snapshot = await Get( Snapshot, MergeDigests( ( *(package.digest for package in packages), *(sources.snapshot.digest for sources in files_sources), ) ), ) output_filename = field_set.output_path.value_or_default( field_set.address, file_ending=field_set.format_field.value ) archive = await Get( Digest, CreateArchive( input_snapshot, output_filename=output_filename, format=ArchiveFormat(field_set.format_field.value), ), ) return BuiltPackage(archive, (BuiltPackageArtifact(output_filename),))