33//! [1]: https://doc.rust-lang.org/nightly/cargo/reference/registry-web-api.html#publish
44
55use std:: collections:: BTreeMap ;
6- use std:: collections:: BTreeSet ;
76use std:: collections:: HashSet ;
87use std:: fs:: File ;
98use std:: time:: Duration ;
@@ -21,7 +20,6 @@ use crate::core::dependency::DepKind;
2120use crate :: core:: manifest:: ManifestMetadata ;
2221use crate :: core:: resolver:: CliFeatures ;
2322use crate :: core:: Dependency ;
24- use crate :: core:: FeatureValue ;
2523use crate :: core:: Package ;
2624use crate :: core:: PackageIdSpecQuery ;
2725use crate :: core:: SourceId ;
@@ -35,7 +33,7 @@ use crate::sources::CRATES_IO_REGISTRY;
3533use crate :: util:: auth;
3634use crate :: util:: cache_lock:: CacheLockMode ;
3735use crate :: util:: context:: JobsConfig ;
38- use crate :: util:: interning :: InternedString ;
36+ use crate :: util:: toml :: prepare_for_publish ;
3937use crate :: util:: Progress ;
4038use crate :: util:: ProgressStyle ;
4139use crate :: CargoResult ;
@@ -184,6 +182,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
184182 . status ( "Uploading" , pkg. package_id ( ) . to_string ( ) ) ?;
185183 transmit (
186184 opts. gctx ,
185+ ws,
187186 pkg,
188187 tarball. file ( ) ,
189188 & mut registry,
@@ -323,19 +322,19 @@ fn verify_dependencies(
323322
324323fn transmit (
325324 gctx : & GlobalContext ,
326- pkg : & Package ,
325+ ws : & Workspace < ' _ > ,
326+ local_pkg : & Package ,
327327 tarball : & File ,
328328 registry : & mut Registry ,
329329 registry_id : SourceId ,
330330 dry_run : bool ,
331331) -> CargoResult < ( ) > {
332- let deps = pkg
332+ let included = None ; // don't filter build-targets
333+ let publish_pkg = prepare_for_publish ( local_pkg, ws, included) ?;
334+
335+ let deps = publish_pkg
333336 . dependencies ( )
334337 . iter ( )
335- . filter ( |dep| {
336- // Skip dev-dependency without version.
337- dep. is_transitive ( ) || dep. specified_req ( )
338- } )
339338 . map ( |dep| {
340339 // If the dependency is from a different registry, then include the
341340 // registry in the dependency.
@@ -380,7 +379,7 @@ fn transmit(
380379 } )
381380 } )
382381 . collect :: < CargoResult < Vec < NewCrateDependency > > > ( ) ?;
383- let manifest = pkg . manifest ( ) ;
382+ let manifest = publish_pkg . manifest ( ) ;
384383 let ManifestMetadata {
385384 ref authors,
386385 ref description,
@@ -397,15 +396,19 @@ fn transmit(
397396 ref rust_version,
398397 } = * manifest. metadata ( ) ;
399398 let rust_version = rust_version. as_ref ( ) . map ( ToString :: to_string) ;
400- let readme_content = readme
399+ let readme_content = local_pkg
400+ . manifest ( )
401+ . metadata ( )
402+ . readme
401403 . as_ref ( )
402404 . map ( |readme| {
403- paths:: read ( & pkg. root ( ) . join ( readme) )
404- . with_context ( || format ! ( "failed to read `readme` file for package `{}`" , pkg) )
405+ paths:: read ( & local_pkg. root ( ) . join ( readme) ) . with_context ( || {
406+ format ! ( "failed to read `readme` file for package `{}`" , local_pkg)
407+ } )
405408 } )
406409 . transpose ( ) ?;
407- if let Some ( ref file) = * license_file {
408- if !pkg . root ( ) . join ( file) . exists ( ) {
410+ if let Some ( ref file) = local_pkg . manifest ( ) . metadata ( ) . license_file {
411+ if !local_pkg . root ( ) . join ( file) . exists ( ) {
409412 bail ! ( "the license file `{}` does not exist" , file)
410413 }
411414 }
@@ -416,31 +419,13 @@ fn transmit(
416419 return Ok ( ( ) ) ;
417420 }
418421
419- let deps_set = deps
420- . iter ( )
421- . map ( |dep| dep. name . clone ( ) )
422- . collect :: < BTreeSet < String > > ( ) ;
423-
424422 let string_features = match manifest. resolved_toml ( ) . features ( ) {
425423 Some ( features) => features
426424 . iter ( )
427425 . map ( |( feat, values) | {
428426 (
429427 feat. to_string ( ) ,
430- values
431- . iter ( )
432- . filter ( |fv| {
433- let feature_value = FeatureValue :: new ( InternedString :: new ( fv) ) ;
434- match feature_value {
435- FeatureValue :: Dep { dep_name }
436- | FeatureValue :: DepFeature { dep_name, .. } => {
437- deps_set. contains ( & dep_name. to_string ( ) )
438- }
439- _ => true ,
440- }
441- } )
442- . map ( |fv| fv. to_string ( ) )
443- . collect ( ) ,
428+ values. iter ( ) . map ( |fv| fv. to_string ( ) ) . collect ( ) ,
444429 )
445430 } )
446431 . collect :: < BTreeMap < String , Vec < String > > > ( ) ,
@@ -450,8 +435,8 @@ fn transmit(
450435 let warnings = registry
451436 . publish (
452437 & NewCrate {
453- name : pkg . name ( ) . to_string ( ) ,
454- vers : pkg . version ( ) . to_string ( ) ,
438+ name : local_pkg . name ( ) . to_string ( ) ,
439+ vers : local_pkg . version ( ) . to_string ( ) ,
455440 deps,
456441 features : string_features,
457442 authors : authors. clone ( ) ,
0 commit comments