@@ -4,10 +4,11 @@ use crate::{
44 error:: Result ,
55 registry_api:: { CrateData , CrateOwner , ReleaseData } ,
66 storage:: CompressionAlgorithm ,
7- utils:: { MetadataPackage , rustc_version:: parse_rustc_date} ,
7+ utils:: { cargo_metadata :: PackageExt as _ , rustc_version:: parse_rustc_date} ,
88 web:: crate_details:: { latest_release, releases_for_crate} ,
99} ;
1010use anyhow:: { Context , anyhow} ;
11+ use cargo_metadata:: DependencyKind ;
1112use derive_more:: Display ;
1213use futures_util:: stream:: TryStreamExt ;
1314use semver:: VersionReq ;
@@ -46,7 +47,7 @@ pub(crate) async fn finish_release(
4647 conn : & mut sqlx:: PgConnection ,
4748 crate_id : CrateId ,
4849 release_id : ReleaseId ,
49- metadata_pkg : & MetadataPackage ,
50+ metadata_pkg : & cargo_metadata :: Package ,
5051 source_dir : & Path ,
5152 default_target : & str ,
5253 source_files : Value ,
@@ -394,24 +395,22 @@ pub(crate) async fn initialize_build(
394395 Ok ( build_id)
395396}
396397
397- /// Convert dependencies into Vec<(String, VersionReq, String, bool)>
398- fn convert_dependencies ( pkg : & MetadataPackage ) -> Vec < ( String , VersionReq , String , bool ) > {
398+ fn convert_dependencies (
399+ pkg : & cargo_metadata:: Package ,
400+ ) -> Vec < ( String , VersionReq , DependencyKind , bool ) > {
399401 pkg. dependencies
400402 . iter ( )
401403 . map ( |dependency| {
402404 let name = dependency. name . clone ( ) ;
403405 let version = dependency. req . clone ( ) ;
404- let kind = dependency
405- . kind
406- . clone ( )
407- . unwrap_or_else ( || "normal" . to_string ( ) ) ;
406+ let kind = dependency. kind ;
408407 ( name, version, kind, dependency. optional )
409408 } )
410409 . collect ( )
411410}
412411
413412/// Reads features and converts them to Vec<Feature> with default being first
414- fn get_features ( pkg : & MetadataPackage ) -> Vec < Feature > {
413+ fn get_features ( pkg : & cargo_metadata :: Package ) -> Vec < Feature > {
415414 let mut features = Vec :: with_capacity ( pkg. features . len ( ) ) ;
416415 if let Some ( subfeatures) = pkg. features . get ( "default" ) {
417416 features. push ( Feature :: new ( "default" . into ( ) , subfeatures. clone ( ) ) ) ;
@@ -426,8 +425,8 @@ fn get_features(pkg: &MetadataPackage) -> Vec<Feature> {
426425}
427426
428427/// Reads readme if there is any read defined in Cargo.toml of a Package
429- fn get_readme ( pkg : & MetadataPackage , source_dir : & Path ) -> Result < Option < String > > {
430- let readme_path = source_dir. join ( pkg. readme . as_deref ( ) . unwrap_or ( "README.md" ) ) ;
428+ fn get_readme ( pkg : & cargo_metadata :: Package , source_dir : & Path ) -> Result < Option < String > > {
429+ let readme_path = source_dir. join ( pkg. readme . as_deref ( ) . unwrap_or ( "README.md" . into ( ) ) ) ;
431430
432431 if !readme_path. exists ( ) {
433432 return Ok ( None ) ;
@@ -447,8 +446,8 @@ fn get_readme(pkg: &MetadataPackage, source_dir: &Path) -> Result<Option<String>
447446 }
448447}
449448
450- fn get_rustdoc ( pkg : & MetadataPackage , source_dir : & Path ) -> Result < Option < String > > {
451- if let Some ( src_path) = & pkg. targets . first ( ) . and_then ( |t| t. src_path . as_ref ( ) ) {
449+ fn get_rustdoc ( pkg : & cargo_metadata :: Package , source_dir : & Path ) -> Result < Option < String > > {
450+ if let Some ( src_path) = & pkg. targets . first ( ) . map ( |t| & t. src_path ) {
452451 let src_path = Path :: new ( src_path) ;
453452 if src_path. is_absolute ( ) {
454453 read_rust_doc ( src_path)
@@ -496,7 +495,7 @@ fn read_rust_doc(file_path: &Path) -> Result<Option<String>> {
496495/// Adds keywords into database
497496async fn add_keywords_into_database (
498497 conn : & mut sqlx:: PgConnection ,
499- pkg : & MetadataPackage ,
498+ pkg : & cargo_metadata :: Package ,
500499 release_id : ReleaseId ,
501500) -> Result < ( ) > {
502501 let wanted_keywords: HashMap < String , String > = pkg
@@ -648,7 +647,7 @@ mod test {
648647 use super :: * ;
649648 use crate :: registry_api:: OwnerKind ;
650649 use crate :: test:: * ;
651- use crate :: utils:: CargoMetadata ;
650+ use crate :: utils:: cargo_metadata :: { MetadataExt as _ , load_cargo_metadata_from_host_path } ;
652651 use chrono:: NaiveDate ;
653652 use std:: slice;
654653 use test_case:: test_case;
@@ -1194,7 +1193,7 @@ mod test {
11941193 "# ;
11951194
11961195 std:: fs:: write ( dir. path ( ) . join ( "Cargo.toml" ) , [ base, extra] . concat ( ) ) ?;
1197- let metadata = CargoMetadata :: load_from_host_path ( dir. path ( ) ) ?;
1196+ let metadata = load_cargo_metadata_from_host_path ( dir. path ( ) ) ?;
11981197 let features = super :: get_features ( metadata. root ( ) ) ;
11991198 assert_eq ! ( features, expected. as_ref( ) ) ;
12001199
0 commit comments