Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion module/core/clone_dyn_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion module/move/willbe/src/action/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
3 changes: 1 addition & 2 deletions module/move/willbe/src/action/publish_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )? )?;
Expand All @@ -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()
Expand Down
41 changes: 37 additions & 4 deletions module/move/willbe/src/entity/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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( () ) ) );
Expand All @@ -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
{
Expand All @@ -212,10 +244,11 @@ mod private
items.push( item );
}
}

report.0.insert( path.to_path_buf(), DiffItem::Content( items ) );
}
}

report
}
}
Expand Down
4 changes: 2 additions & 2 deletions module/move/willbe/src/entity/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand All @@ -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() )
}

}
Expand Down
7 changes: 0 additions & 7 deletions module/move/willbe/src/entity/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ]
Expand All @@ -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,
};
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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 );
Expand Down
79 changes: 3 additions & 76 deletions module/move/willbe/src/tool/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion module/move/willbe/src/tool/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -305,7 +306,7 @@ mod private
.allow_dirty( true )
.form()
)?;
if publish_need( package, temp_path.clone() ).unwrap()
if publish_need( package, temp_path.clone(), exclude_dev_dependencies ).unwrap()
{
nodes.insert( n );
}
Expand Down
Loading