From 4b0b1439c2aae3a654876ece6c9ba8911be2ab87 Mon Sep 17 00:00:00 2001 From: SupperZum Date: Wed, 9 Apr 2025 19:34:09 +0300 Subject: [PATCH 1/3] fix willbe .publish --- module/move/willbe/src/action/publish.rs | 3 ++- module/move/willbe/src/tool/graph.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/module/move/willbe/src/action/publish.rs b/module/move/willbe/src/action/publish.rs index 9230753d96..862e1b6931 100644 --- a/module/move/willbe/src/action/publish.rs +++ b/module/move/willbe/src/action/publish.rs @@ -217,7 +217,8 @@ mod private &package_map, &tmp, &packages_to_publish, - dir.clone() + dir.clone(), + exclude_dev_dependencies )?; let subgraph = subgraph .map( | _, n | n, | _, e | e ); diff --git a/module/move/willbe/src/tool/graph.rs b/module/move/willbe/src/tool/graph.rs index e0ba9bc109..390b30c45a 100644 --- a/module/move/willbe/src/tool/graph.rs +++ b/module/move/willbe/src/tool/graph.rs @@ -273,6 +273,7 @@ mod private graph : &Graph< String, String >, roots : &[ String ], temp_path : Option< PathBuf >, + exclude_dev_dependencies : bool, ) -> error::untyped::Result< Graph< String, String > > // qqq : use typed error! @@ -303,6 +304,7 @@ mod private .option_temp_path( temp_path.clone() ) .dry( false ) .allow_dirty( true ) + .exclude_dev_dependencies( exclude_dev_dependencies ) .form() )?; if publish_need( package, temp_path.clone() ).unwrap() From 9b492f0293c38232d1b116002dfaafeed83b3887 Mon Sep 17 00:00:00 2001 From: SupperZum Date: Wed, 9 Apr 2025 19:34:34 +0300 Subject: [PATCH 2/3] fix clippy --- module/core/clone_dyn_types/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/core/clone_dyn_types/src/lib.rs b/module/core/clone_dyn_types/src/lib.rs index a89d569ef0..afb3ba2395 100644 --- a/module/core/clone_dyn_types/src/lib.rs +++ b/module/core/clone_dyn_types/src/lib.rs @@ -186,7 +186,7 @@ mod private // The safety of this function relies on the correct implementation of the `CloneDyn` trait for the given type `T`. // Specifically, `__clone_dyn` must return a valid pointer to a cloned instance of `T`. // - #[ allow( unsafe_code, clippy::implicit_return, clippy::as_conversions, clippy::ptr_cast_constness, clippy::ptr_as_ptr, clippy::multiple_unsafe_ops_per_block, clippy::undocumented_unsafe_blocks, clippy::ref_as_ptr ) ] + #[ allow( unsafe_code, clippy::implicit_return, clippy::as_conversions, clippy::ptr_cast_constness, clippy::ptr_as_ptr, clippy::multiple_unsafe_ops_per_block, clippy::undocumented_unsafe_blocks, clippy::ref_as_ptr, clippy::borrow_as_ptr ) ] unsafe { let mut ptr = ref_dyn as *const T; From def6caa4fd125ebecb8ee758a9e9489652efe64f Mon Sep 17 00:00:00 2001 From: SupperZum Date: Mon, 21 Apr 2025 18:47:39 +0300 Subject: [PATCH 3/3] full re-write exclude_dev_dependencies logic --- module/move/willbe/src/action/publish_diff.rs | 3 +- module/move/willbe/src/entity/diff.rs | 41 +++++++++- module/move/willbe/src/entity/package.rs | 4 +- module/move/willbe/src/entity/publish.rs | 7 -- module/move/willbe/src/tool/cargo.rs | 79 +------------------ module/move/willbe/src/tool/graph.rs | 3 +- 6 files changed, 44 insertions(+), 93 deletions(-) diff --git a/module/move/willbe/src/action/publish_diff.rs b/module/move/willbe/src/action/publish_diff.rs index 4cacfa4a94..f170053773 100644 --- a/module/move/willbe/src/action/publish_diff.rs +++ b/module/move/willbe/src/action/publish_diff.rs @@ -149,7 +149,6 @@ mod private .path( dir.as_ref() ) .allow_dirty( true ) .checking_consistency( false ) - .exclude_dev_dependencies( o.exclude_dev_dependencies) .dry( false ).form() )?; let l = CrateArchive::read( packed_crate::local_path( name, version, dir )? )?; @@ -170,7 +169,7 @@ mod private std::fs::write( local_path, content )?; } } - diffs.insert( path, crate_diff( &l, &r ).exclude( diff::PUBLISH_IGNORE_LIST ) ); + diffs.insert( path, crate_diff( &l, &r, o.exclude_dev_dependencies ).exclude( diff::PUBLISH_IGNORE_LIST ) ); let report = tasks[ current_idx ].info.normal_dependencies.clone(); let printer : Vec< TreePrinter > = report .iter() diff --git a/module/move/willbe/src/entity/diff.rs b/module/move/willbe/src/entity/diff.rs index 6298a5762f..ead58599d1 100644 --- a/module/move/willbe/src/entity/diff.rs +++ b/module/move/willbe/src/entity/diff.rs @@ -162,17 +162,19 @@ mod private /// # Panics /// qqq: doc #[ must_use ] - pub fn crate_diff( left : &CrateArchive, right : &CrateArchive ) -> DiffReport + pub fn crate_diff( left : &CrateArchive, right : &CrateArchive, exclude_dev_dependencies : bool ) -> DiffReport { let mut report = DiffReport::default(); let local_package_files : HashSet< _ > = left.list().into_iter().collect(); let remote_package_files : HashSet< _ > = right.list().into_iter().collect(); + let local_only = local_package_files.difference( &remote_package_files ); let remote_only = remote_package_files.difference( &local_package_files ); let both = local_package_files.intersection( &remote_package_files ); + for &path in local_only { report.0.insert( path.to_path_buf(), DiffItem::File( Diff::Add( () ) ) ); @@ -185,9 +187,39 @@ mod private for &path in both { + // unwraps are safe because the paths to the files was compared previously - let local = left.content_bytes( path ).unwrap(); - let remote = right.content_bytes( path ).unwrap(); + let mut local = left.content_bytes( path ).unwrap(); + let mut remote = right.content_bytes( path ).unwrap(); + + + let ( l, r ) = if path.ends_with( "Cargo.toml.orig" ) && exclude_dev_dependencies + { + + let local = std::str::from_utf8( left.content_bytes( path ).unwrap() ).unwrap(); + let mut local_data = local.parse::< toml_edit::Document >().unwrap(); + local_data.remove( "dev-dependencies" ); + let local = local_data.to_string().as_bytes().to_vec(); + + + let remote = std::str::from_utf8( right.content_bytes( path ).unwrap() ).unwrap(); + let mut remote_data = remote.parse::< toml_edit::Document >().unwrap(); + remote_data.remove( "dev-dependencies" ); + let remote = remote_data.to_string().as_bytes().to_vec(); + + ( local, remote ) + } + else + { + ( vec![], vec![] ) + }; + + + if !l.is_empty() && !r.is_empty() + { + local = l.as_slice(); + remote = r.as_slice(); + } if local == remote { @@ -212,10 +244,11 @@ mod private items.push( item ); } } + report.0.insert( path.to_path_buf(), DiffItem::Content( items ) ); } } - + report } } diff --git a/module/move/willbe/src/entity/package.rs b/module/move/willbe/src/entity/package.rs index b5de716391..dc8965e209 100644 --- a/module/move/willbe/src/entity/package.rs +++ b/module/move/willbe/src/entity/package.rs @@ -219,7 +219,7 @@ mod private /// Panics if the package is not loaded or local package is not packed. /// # Errors /// qqq: doc - pub fn publish_need( package : &Package< '_ >, path : Option< path::PathBuf > ) -> Result< bool, PackageError > + pub fn publish_need( package : &Package< '_ >, path : Option< path::PathBuf >, exclude_dev_dependencies : bool ) -> Result< bool, PackageError > { let name = package.name()?; let version = package.version()?; @@ -236,7 +236,7 @@ mod private _ => return Err( PackageError::LoadRemotePackage ), }; - Ok( diff::crate_diff( &local_package, &remote_package ).exclude( diff::PUBLISH_IGNORE_LIST ).has_changes() ) + Ok( diff::crate_diff( &local_package, &remote_package, exclude_dev_dependencies ).exclude( diff::PUBLISH_IGNORE_LIST ).has_changes() ) } } diff --git a/module/move/willbe/src/entity/publish.rs b/module/move/willbe/src/entity/publish.rs index 6e1476fa0f..f5e03c4fe7 100644 --- a/module/move/willbe/src/entity/publish.rs +++ b/module/move/willbe/src/entity/publish.rs @@ -44,7 +44,6 @@ mod private package : package::Package< 'a >, channel : channel::Channel, base_temp_dir : Option< path::PathBuf >, - exclude_dev_dependencies : bool, #[ former( default = true ) ] commit_changes : bool, #[ former( default = true ) ] @@ -63,7 +62,6 @@ mod private channel : self.channel, allow_dirty : self.dry, checking_consistency : !self.dry, - exclude_dev_dependencies : self.exclude_dev_dependencies, temp_path : self.base_temp_dir.clone(), dry : self.dry, }; @@ -93,7 +91,6 @@ mod private { path : crate_dir.clone().absolute_path().inner(), temp_path : self.base_temp_dir.clone(), - exclude_dev_dependencies : self.exclude_dev_dependencies, retry_count : 2, dry : self.dry, }; @@ -265,10 +262,6 @@ mod private { plan = plan.dry( dry ); } - if let Some( exclude_dev_dependencies ) = &self.storage.exclude_dev_dependencies - { - plan = plan.exclude_dev_dependencies( *exclude_dev_dependencies ); - } if let Some( commit_changes ) = &self.storage.commit_changes { plan = plan.commit_changes( *commit_changes ); diff --git a/module/move/willbe/src/tool/cargo.rs b/module/move/willbe/src/tool/cargo.rs index 1dd5ef240d..6d0f687c40 100644 --- a/module/move/willbe/src/tool/cargo.rs +++ b/module/move/willbe/src/tool/cargo.rs @@ -2,8 +2,6 @@ #[ allow( clippy::std_instead_of_alloc, clippy::std_instead_of_core ) ] mod private { - #[ allow( clippy::wildcard_imports ) ] - use crate::*; #[ allow( unused_imports, clippy::wildcard_imports ) ] use crate::tool::*; @@ -52,9 +50,7 @@ mod private // aaa : don't abuse negative form, rename to checking_consistency // renamed and changed logic pub( crate ) checking_consistency : bool, - /// Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward. - #[ former( default = true ) ] - pub( crate ) exclude_dev_dependencies : bool, + /// An optional temporary path to be used during packaging. /// /// This field may contain a path to a temporary directory that will be used during the packaging process. @@ -88,52 +84,6 @@ mod private } } - #[ derive( Debug ) ] - struct TemporaryManifestFile - { - original : PathBuf, - temporary : PathBuf, - } - - impl TemporaryManifestFile - { - /// Creates a backup copy of the original file, allowing the original file location to serve as a temporary workspace. - /// When the object is dropped, the temporary file at the original location is replaced by the backup, restoring the original file. - fn new( path : impl Into< PathBuf > ) -> error::untyped::Result< Self > - { - let path = path.into(); - if !path.ends_with( "Cargo.toml" ) - { - error::untyped::bail!( "Wrong path to temporary manifest" ); - } - - let mut index = 0; - let original = loop - { - let temp_path = PathBuf::from( format!( "{}.temp_{index}", path.display() ) ); - if !temp_path.exists() - { - _ = std::fs::copy( &path, &temp_path )?; - break temp_path; - } - index += 1; - }; - - Ok( Self - { - original, - temporary : path, - }) - } - } - - impl Drop for TemporaryManifestFile - { - fn drop( &mut self ) - { - _ = std::fs::rename( &self.original, &self.temporary ).ok(); - } - } /// /// Assemble the local package into a distributable tarball. @@ -152,18 +102,7 @@ mod private // qqq : use typed error pub fn pack( args : PackOptions ) -> error::untyped::Result< process::Report > { - let _temp = if args.exclude_dev_dependencies - { - let manifest = TemporaryManifestFile::new( args.path.join( "Cargo.toml" ) )?; - let mut file = Manifest::try_from( ManifestFile::try_from( &manifest.temporary )? )?; - let data = file.data(); - - _ = data.remove( "dev-dependencies" ); - file.store()?; - - Some( manifest ) - } - else { None }; + let ( program, options ) = ( "rustup", args.to_pack_args() ); if args.dry @@ -197,7 +136,6 @@ mod private { pub( crate ) path : PathBuf, pub( crate ) temp_path : Option< PathBuf >, - pub( crate ) exclude_dev_dependencies : bool, #[ former( default = 0usize ) ] pub( crate ) retry_count : usize, pub( crate ) dry : bool, @@ -231,18 +169,7 @@ mod private pub fn publish( args : PublishOptions ) -> error::untyped::Result< process::Report > // qqq : use typed error { - let _temp = if args.exclude_dev_dependencies - { - let manifest = TemporaryManifestFile::new( args.path.join( "Cargo.toml" ) )?; - let mut file = Manifest::try_from( ManifestFile::try_from( &manifest.temporary )? )?; - let data = file.data(); - - _ = data.remove( "dev-dependencies" ); - file.store()?; - - Some( manifest ) - } - else { None }; + let ( program, arguments) = ( "cargo", args.as_publish_args() ); if args.dry diff --git a/module/move/willbe/src/tool/graph.rs b/module/move/willbe/src/tool/graph.rs index 390b30c45a..92a4f61ff1 100644 --- a/module/move/willbe/src/tool/graph.rs +++ b/module/move/willbe/src/tool/graph.rs @@ -304,10 +304,9 @@ mod private .option_temp_path( temp_path.clone() ) .dry( false ) .allow_dirty( true ) - .exclude_dev_dependencies( exclude_dev_dependencies ) .form() )?; - if publish_need( package, temp_path.clone() ).unwrap() + if publish_need( package, temp_path.clone(), exclude_dev_dependencies ).unwrap() { nodes.insert( n ); }