From c1a21a2dfe91e11184606805818aad27eea8c221 Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Thu, 7 Nov 2019 13:39:30 +0800 Subject: [PATCH 1/4] Also replace paths in [build-dependencies] --- scripts/node-template-release/src/main.rs | 56 ++++++++++++----------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/scripts/node-template-release/src/main.rs b/scripts/node-template-release/src/main.rs index e1db5af649748..807278d3161dd 100644 --- a/scripts/node-template-release/src/main.rs +++ b/scripts/node-template-release/src/main.rs @@ -88,33 +88,35 @@ fn replace_path_dependencies_with_git(cargo_toml_path: &Path, commit_id: &str, c // remove `Cargo.toml` cargo_toml_path.pop(); - let mut dependencies: toml::value::Table = match cargo_toml - .remove("dependencies") - .and_then(|v| v.try_into().ok()) { - Some(deps) => deps, - None => return, - }; - - let deps_rewritten = dependencies - .iter() - .filter_map(|(k, v)| v.clone().try_into::().ok().map(move |v| (k, v))) - .filter(|t| t.1.contains_key("path")) - .filter(|t| { - // if the path does not exists, we need to add this as git dependency - t.1.get("path").unwrap().as_str().map(|path| !cargo_toml_path.join(path).exists()).unwrap_or(false) - }) - .map(|(k, mut v)| { - // remove `path` and add `git` and `rev` - v.remove("path"); - v.insert("git".into(), SUBSTRATE_GIT_URL.into()); - v.insert("rev".into(), commit_id.into()); - - (k.clone(), v.into()) - }).collect::>(); - - dependencies.extend(deps_rewritten.into_iter()); - - cargo_toml.insert("dependencies".into(), dependencies.into()); + for table in vec!["dependencies", "build-dependencies"] { + let mut dependencies: toml::value::Table = match cargo_toml + .remove(table) + .and_then(|v| v.try_into().ok()) { + Some(deps) => deps, + None => return, + }; + + let deps_rewritten = dependencies + .iter() + .filter_map(|(k, v)| v.clone().try_into::().ok().map(move |v| (k, v))) + .filter(|t| t.1.contains_key("path")) + .filter(|t| { + // if the path does not exists, we need to add this as git dependency + t.1.get("path").unwrap().as_str().map(|path| !cargo_toml_path.join(path).exists()).unwrap_or(false) + }) + .map(|(k, mut v)| { + // remove `path` and add `git` and `rev` + v.remove("path"); + v.insert("git".into(), SUBSTRATE_GIT_URL.into()); + v.insert("rev".into(), commit_id.into()); + + (k.clone(), v.into()) + }).collect::>(); + + dependencies.extend(deps_rewritten.into_iter()); + + cargo_toml.insert(table.into(), dependencies.into()); + } } /// Update the top level (workspace) `Cargo.toml` file. From 92745c6cb89e4613a64dceb894d6afbff5808324 Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Thu, 7 Nov 2019 17:40:29 +0800 Subject: [PATCH 2/4] Update scripts/node-template-release/src/main.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Bastian Köcher --- scripts/node-template-release/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/node-template-release/src/main.rs b/scripts/node-template-release/src/main.rs index 807278d3161dd..8ccfc66ebbb1e 100644 --- a/scripts/node-template-release/src/main.rs +++ b/scripts/node-template-release/src/main.rs @@ -93,7 +93,7 @@ fn replace_path_dependencies_with_git(cargo_toml_path: &Path, commit_id: &str, c .remove(table) .and_then(|v| v.try_into().ok()) { Some(deps) => deps, - None => return, + None => continue, }; let deps_rewritten = dependencies From e704fbcb4c59d5fea0d06c62594ce51a4c922110 Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Thu, 7 Nov 2019 17:52:22 +0800 Subject: [PATCH 3/4] Slightly reduce memory usage --- scripts/node-template-release/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/node-template-release/src/main.rs b/scripts/node-template-release/src/main.rs index 8ccfc66ebbb1e..db42b155e65e7 100644 --- a/scripts/node-template-release/src/main.rs +++ b/scripts/node-template-release/src/main.rs @@ -88,7 +88,7 @@ fn replace_path_dependencies_with_git(cargo_toml_path: &Path, commit_id: &str, c // remove `Cargo.toml` cargo_toml_path.pop(); - for table in vec!["dependencies", "build-dependencies"] { + for &table in &["dependencies", "build-dependencies"] { let mut dependencies: toml::value::Table = match cargo_toml .remove(table) .and_then(|v| v.try_into().ok()) { From bb8c1457b314f22695d625054653041cfc430a8c Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Thu, 7 Nov 2019 17:56:59 +0800 Subject: [PATCH 4/4] Update scripts/node-template-release/src/main.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Bastian Köcher --- scripts/node-template-release/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/node-template-release/src/main.rs b/scripts/node-template-release/src/main.rs index db42b155e65e7..7fde9c8684720 100644 --- a/scripts/node-template-release/src/main.rs +++ b/scripts/node-template-release/src/main.rs @@ -88,7 +88,7 @@ fn replace_path_dependencies_with_git(cargo_toml_path: &Path, commit_id: &str, c // remove `Cargo.toml` cargo_toml_path.pop(); - for &table in &["dependencies", "build-dependencies"] { + for table in &["dependencies", "build-dependencies"] { let mut dependencies: toml::value::Table = match cargo_toml .remove(table) .and_then(|v| v.try_into().ok()) {