Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Also replace paths in [build-dependencies] #4039

Merged
merged 4 commits into from
Nov 7, 2019
Merged
Changes from 1 commit
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
56 changes: 29 additions & 27 deletions scripts/node-template-release/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<toml::value::Table>().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::<HashMap<_, _>>();

dependencies.extend(deps_rewritten.into_iter());

cargo_toml.insert("dependencies".into(), dependencies.into());
for table in vec!["dependencies", "build-dependencies"] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for table in vec!["dependencies", "build-dependencies"] {
for table in &["dependencies", "build-dependencies"] {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an extra & is needed before table if we do so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Please revert this.

let mut dependencies: toml::value::Table = match cargo_toml
.remove(table)
.and_then(|v| v.try_into().ok()) {
Some(deps) => deps,
None => return,
en marked this conversation as resolved.
Show resolved Hide resolved
};

let deps_rewritten = dependencies
.iter()
.filter_map(|(k, v)| v.clone().try_into::<toml::value::Table>().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::<HashMap<_, _>>();

dependencies.extend(deps_rewritten.into_iter());

cargo_toml.insert(table.into(), dependencies.into());
}
}

/// Update the top level (workspace) `Cargo.toml` file.
Expand Down