File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,20 @@ pub fn generate(opt: GenerateOptions) -> Result<()> {
228228 Ok ( ( ) )
229229}
230230
231+ fn remove_internal_dependencies_from_cargo_lockfile ( cargo_lockfile : Lockfile ) -> Lockfile {
232+ let filtered_packages: Vec < _ > = cargo_lockfile
233+ . packages
234+ . into_iter ( )
235+ // Filter packages to only keep external dependencies (those with a source)
236+ . filter ( |pkg| pkg. source . is_some ( ) )
237+ . collect ( ) ;
238+
239+ Lockfile {
240+ packages : filtered_packages,
241+ ..cargo_lockfile
242+ }
243+ }
244+
231245fn update_cargo_lockfile ( path : & Path , cargo_lockfile : Lockfile ) -> Result < ( ) > {
232246 let old_contents = fs:: read_to_string ( path) . ok ( ) ;
233247 let new_contents = cargo_lockfile. to_string ( ) ;
@@ -293,3 +307,21 @@ fn write_paths_to_track<
293307 . context ( "Failed to write warnings file" ) ?;
294308 Ok ( ( ) )
295309}
310+
311+ #[ cfg( test) ]
312+ mod tests {
313+ use super :: * ;
314+ use crate :: test;
315+
316+ #[ test]
317+ fn test_remove_internal_dependencies_from_cargo_lockfile_workspace_build_scripts_deps_should_remove_internal_dependencies ( ) {
318+ let original_lockfile = test:: lockfile:: workspace_build_scripts_deps ( ) ;
319+
320+ let filtered_lockfile = remove_internal_dependencies_from_cargo_lockfile ( original_lockfile. clone ( ) ) ;
321+
322+ assert ! ( filtered_lockfile. packages. len( ) < original_lockfile. packages. len( ) ) ;
323+
324+ assert ! ( original_lockfile. packages. iter( ) . any( |pkg| pkg. name. as_str( ) == "child" ) ) ;
325+ assert ! ( !filtered_lockfile. packages. iter( ) . any( |pkg| pkg. name. as_str( ) == "child" ) ) ;
326+ }
327+ }
You can’t perform that action at this time.
0 commit comments