@@ -24,7 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
24
24
. expect ( "requires 'add' or 'update' mode argument" ) ;
25
25
26
26
let script_root = PathBuf :: from ( env:: var ( "CARGO_MANIFEST_DIR" ) ?) ;
27
- let repo_root = script_root. join ( "../../.. " ) . canonicalize ( ) ?;
27
+ let repo_root = script_root. join ( "../.." ) . canonicalize ( ) ?;
28
28
29
29
// find all Cargo.toml files in the repo_root directory
30
30
let exclude_dirs = vec ! [
@@ -38,13 +38,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
38
38
39
39
for mut toml_file in toml_files {
40
40
let should_add = add_mode && !toml_file. is_publish_disabled ;
41
-
42
- update_package_versions ( toml_file. document . as_table_mut ( ) , & package_versions, should_add) ;
41
+ println ! ( "Processing {}" , toml_file . path . display ( ) ) ;
42
+ update_package_versions ( toml_file. document . as_table_mut ( ) , & package_versions, None , should_add) ;
43
43
44
44
// if the toml file has a workspace table, update the workspace table
45
45
if let Some ( workspace) = toml_file. document . get_mut ( "workspace" ) {
46
46
if let Some ( table) = workspace. as_table_mut ( ) {
47
- update_package_versions ( table, & package_versions, should_add) ;
47
+ update_package_versions ( table, & package_versions, Some ( "workspace" ) , should_add) ;
48
48
}
49
49
}
50
50
@@ -57,6 +57,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
57
57
}
58
58
59
59
fn load_cargo_toml_files ( repo_root : & PathBuf , exclude_dirs : & Vec < PathBuf > ) -> Result < Vec < TomlInfo > , Box < dyn Error > > {
60
+ println ! ( "Loading Cargo.toml files in {}" , repo_root. display( ) ) ;
60
61
let mut toml_paths = Vec :: new ( ) ;
61
62
find_cargo_toml_files ( repo_root, exclude_dirs, & mut toml_paths) ?;
62
63
@@ -109,7 +110,7 @@ fn get_package_versions(toml_files: &Vec<TomlInfo>) -> Vec<(String, String, bool
109
110
package_versions
110
111
}
111
112
112
- fn update_package_versions ( toml : & mut Table , package_versions : & Vec < ( String , String , bool ) > , add : bool ) {
113
+ fn update_package_versions ( toml : & mut Table , package_versions : & Vec < ( String , String , bool ) > , prefix : Option < & str > , add : bool ) {
113
114
// for each dependency table, for each package in package_versions
114
115
// if the package is in the dependency table
115
116
// if the dependency has both path and version properties, update the version property
@@ -121,16 +122,26 @@ fn update_package_versions(toml: &mut Table, package_versions: &Vec<(String, Str
121
122
let dependency_tables = get_dependency_tables ( toml) ;
122
123
123
124
for ( table_name, table) in dependency_tables {
125
+ let table_display_name = if prefix. is_some ( ) {
126
+ format ! ( "{}.{}" , prefix. unwrap( ) , table_name)
127
+ } else {
128
+ table_name. clone ( )
129
+ } ;
124
130
for ( package, version, is_publish_disabled) in package_versions {
125
131
if let Some ( dependency) = table. get_mut ( package) {
126
132
// azure_idenentity will only be a transitive dev-dependency
127
133
let should_add = add && table_name != "dev-dependencies" && !is_publish_disabled && package != "azure_identity" ;
128
134
129
- let has_path_property = dependency. get ( "path" ) . is_some ( ) ;
130
- let has_version_property = dependency. get ( "version" ) . is_some ( ) ;
131
-
132
- if has_path_property && ( has_version_property || should_add) {
133
- dependency[ "version" ] = value ( version) ;
135
+ if dependency. get ( "path" ) . is_some ( ) {
136
+ if let Some ( current_version) = dependency. get ( "version" ) {
137
+ if current_version. as_str ( ) != Some ( version) {
138
+ dependency[ "version" ] = value ( version) ;
139
+ println ! ( " Updating {table_display_name}.{package} to {version}" ) ;
140
+ }
141
+ } else if should_add {
142
+ dependency[ "version" ] = value ( version) ;
143
+ println ! ( " Adding {table_display_name}.{package} version {version}" ) ;
144
+ }
134
145
}
135
146
}
136
147
}
0 commit comments