@@ -86,6 +86,19 @@ pub struct PackageOpts<'gctx> {
86
86
pub targets : Vec < String > ,
87
87
pub cli_features : CliFeatures ,
88
88
pub reg_or_index : Option < ops:: RegistryOrIndex > ,
89
+ /// Whether this packaging job is meant for a publishing dry-run.
90
+ ///
91
+ /// Packaging on its own has no side effects, so a dry-run doesn't
92
+ /// make sense from that point of view. But dry-run publishing needs
93
+ /// special packaging behavior, which this flag turns on.
94
+ ///
95
+ /// Specifically, we want dry-run packaging to work even if versions
96
+ /// have not yet been bumped. But then if you dry-run packaging in
97
+ /// a workspace with some declared versions that are already published,
98
+ /// the package verification step can fail with checksum mismatches.
99
+ /// So when dry-run is true, the verification step does some extra
100
+ /// checksum fudging in the lock file.
101
+ pub dry_run : bool ,
89
102
}
90
103
91
104
const ORIGINAL_MANIFEST_FILE : & str = "Cargo.toml.orig" ;
@@ -125,6 +138,7 @@ enum GeneratedFile {
125
138
#[ tracing:: instrument( skip_all) ]
126
139
fn create_package (
127
140
ws : & Workspace < ' _ > ,
141
+ opts : & PackageOpts < ' _ > ,
128
142
pkg : & Package ,
129
143
ar_files : Vec < ArchiveFile > ,
130
144
local_reg : Option < & TmpRegistry < ' _ > > ,
@@ -159,7 +173,7 @@ fn create_package(
159
173
gctx. shell ( )
160
174
. status ( "Packaging" , pkg. package_id ( ) . to_string ( ) ) ?;
161
175
dst. file ( ) . set_len ( 0 ) ?;
162
- let uncompressed_size = tar ( ws, pkg, local_reg, ar_files, dst. file ( ) , & filename)
176
+ let uncompressed_size = tar ( ws, opts , pkg, local_reg, ar_files, dst. file ( ) , & filename)
163
177
. context ( "failed to prepare local package for uploading" ) ?;
164
178
165
179
dst. seek ( SeekFrom :: Start ( 0 ) ) ?;
@@ -311,7 +325,7 @@ fn do_package<'a>(
311
325
}
312
326
}
313
327
} else {
314
- let tarball = create_package ( ws, & pkg, ar_files, local_reg. as_ref ( ) ) ?;
328
+ let tarball = create_package ( ws, & opts , & pkg, ar_files, local_reg. as_ref ( ) ) ?;
315
329
if let Some ( local_reg) = local_reg. as_mut ( ) {
316
330
if pkg. publish ( ) != & Some ( Vec :: new ( ) ) {
317
331
local_reg. add_package ( ws, & pkg, & tarball) ?;
@@ -720,11 +734,12 @@ fn error_custom_build_file_not_in_package(
720
734
/// Construct `Cargo.lock` for the package to be published.
721
735
fn build_lock (
722
736
ws : & Workspace < ' _ > ,
737
+ opts : & PackageOpts < ' _ > ,
723
738
publish_pkg : & Package ,
724
739
local_reg : Option < & TmpRegistry < ' _ > > ,
725
740
) -> CargoResult < String > {
726
741
let gctx = ws. gctx ( ) ;
727
- let orig_resolve = ops:: load_pkg_lockfile ( ws) ?;
742
+ let mut orig_resolve = ops:: load_pkg_lockfile ( ws) ?;
728
743
729
744
let mut tmp_ws = Workspace :: ephemeral ( publish_pkg. clone ( ) , ws. gctx ( ) , None , true ) ?;
730
745
@@ -736,6 +751,18 @@ fn build_lock(
736
751
local_reg. upstream ,
737
752
local_reg. root . as_path_unlocked ( ) . to_owned ( ) ,
738
753
) ;
754
+ if opts. dry_run {
755
+ if let Some ( orig_resolve) = orig_resolve. as_mut ( ) {
756
+ let upstream_in_lock = if local_reg. upstream . is_crates_io ( ) {
757
+ SourceId :: crates_io ( gctx) ?
758
+ } else {
759
+ local_reg. upstream
760
+ } ;
761
+ for ( p, s) in local_reg. checksums ( ) {
762
+ orig_resolve. set_checksum ( p. with_source_id ( upstream_in_lock) , s. to_owned ( ) ) ;
763
+ }
764
+ }
765
+ }
739
766
}
740
767
let mut tmp_reg = tmp_ws. package_registry ( ) ?;
741
768
@@ -811,6 +838,7 @@ fn check_metadata(pkg: &Package, gctx: &GlobalContext) -> CargoResult<()> {
811
838
/// Returns the uncompressed size of the contents of the new archive file.
812
839
fn tar (
813
840
ws : & Workspace < ' _ > ,
841
+ opts : & PackageOpts < ' _ > ,
814
842
pkg : & Package ,
815
843
local_reg : Option < & TmpRegistry < ' _ > > ,
816
844
ar_files : Vec < ArchiveFile > ,
@@ -868,7 +896,7 @@ fn tar(
868
896
GeneratedFile :: Manifest ( _) => {
869
897
publish_pkg. manifest ( ) . to_normalized_contents ( ) ?
870
898
}
871
- GeneratedFile :: Lockfile ( _) => build_lock ( ws, & publish_pkg, local_reg) ?,
899
+ GeneratedFile :: Lockfile ( _) => build_lock ( ws, opts , & publish_pkg, local_reg) ?,
872
900
GeneratedFile :: VcsInfo ( ref s) => serde_json:: to_string_pretty ( s) ?,
873
901
} ;
874
902
header. set_entry_type ( EntryType :: file ( ) ) ;
@@ -1062,6 +1090,7 @@ struct TmpRegistry<'a> {
1062
1090
gctx : & ' a GlobalContext ,
1063
1091
upstream : SourceId ,
1064
1092
root : Filesystem ,
1093
+ checksums : HashMap < PackageId , String > ,
1065
1094
_lock : FileLock ,
1066
1095
}
1067
1096
@@ -1073,6 +1102,7 @@ impl<'a> TmpRegistry<'a> {
1073
1102
gctx,
1074
1103
root,
1075
1104
upstream,
1105
+ checksums : HashMap :: new ( ) ,
1076
1106
_lock,
1077
1107
} ;
1078
1108
// If there's an old temporary registry, delete it.
@@ -1118,6 +1148,8 @@ impl<'a> TmpRegistry<'a> {
1118
1148
. update_file ( tar. file ( ) ) ?
1119
1149
. finish_hex ( ) ;
1120
1150
1151
+ self . checksums . insert ( package. package_id ( ) , cksum. clone ( ) ) ;
1152
+
1121
1153
let deps: Vec < _ > = new_crate
1122
1154
. deps
1123
1155
. into_iter ( )
@@ -1178,4 +1210,8 @@ impl<'a> TmpRegistry<'a> {
1178
1210
dst. write_all ( index_line. as_bytes ( ) ) ?;
1179
1211
Ok ( ( ) )
1180
1212
}
1213
+
1214
+ fn checksums ( & self ) -> impl Iterator < Item = ( PackageId , & str ) > {
1215
+ self . checksums . iter ( ) . map ( |( p, s) | ( * p, s. as_str ( ) ) )
1216
+ }
1181
1217
}
0 commit comments