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

Commit d3b4830

Browse files
ericjmillerEric Millerbkchrgavofyorkemostov
authored
#9386: copy rustfmt.toml to node-template (#9461)
* copying rustfmt from root to node-template build. Also, running rustfmt on this. * Update .maintain/node-template-release/src/main.rs Co-authored-by: Bastian Köcher <[email protected]> * Add some important events to batch & staking to ensure ease of analysis (#9462) * Add some important events to batch & staking to ensure ease of analysis * Update frame/staking/src/pallet/mod.rs Co-authored-by: Zeke Mostov <[email protected]> * Update lib.rs * fix test Co-authored-by: Zeke Mostov <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]> * Move client consensus parts out of primitives and into client/consensus/api (#9319) * moved client code out of primitives * bump ci * Fixup from merge. * Removed unused deps thanks to review feedback * Removing unneeded deps * updating lock file * note about rustfmt * fixed typo to bump ci * Move lonely CacheKeyId to parent * cargo fmt * updating import style * Update docs/STYLE_GUIDE.md Co-authored-by: André Silva <[email protected]> Co-authored-by: André Silva <[email protected]> * Refactor Benchmarks for Less Wasm Memory Usage (#9373) * extract repeat out of benchmark * remove r * unused * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * use linked map to keep order * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Delete pallet_balances.rs * Delete out * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * steps and repeat to tuple (current_*, total_*) * idea for list command * fmt * use benchmark list in cli * handle steps in cli * move log update to cli * fmt * remove old todo * line width * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * benchmark metadata function * don't need this warm up * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * fix warnings * fix node-template * fix * fmt * line width * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * improve docs * improve cli * fix format * fix bug? * Revert "fix bug?" This reverts commit 8051bf1. * skip frame-metadata * extract repeat out of benchmark * remove r * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * use linked map to keep order * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Delete pallet_balances.rs * Delete out * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * steps and repeat to tuple (current_*, total_*) * idea for list command * fmt * use benchmark list in cli * handle steps in cli * move log update to cli * remove old todo * line width * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * benchmark metadata function * don't need this warm up * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * fix warnings * fix node-template * fix * fmt * line width * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * improve docs * improve cli * fix format * fix bug? * Revert "fix bug?" This reverts commit 8051bf1. * skip frame-metadata * Update .gitlab-ci.yml * fix import * Update .gitlab-ci.yml Co-authored-by: Parity Benchmarking Bot <[email protected]> * Warp sync part I (#9227) * Started warp sync * BABE & GRANDPA recovery * Warp sync protocol * Sync warp proofs first * Added basic documentation * Apply suggestions from code review Co-authored-by: André Silva <[email protected]> * Style changes * Apply suggestions from code review Co-authored-by: André Silva <[email protected]> * fmt * Apply suggestions from code review Co-authored-by: André Silva <[email protected]> * Fixed chage trie pruning wrt missing blocks * Restore parent finalization * fmt * fmt * Revert pwasm-utils bump * Change error type & check API version * Apply suggestions from code review Co-authored-by: Bastian Köcher <[email protected]> * Build fix * Fixed target block check * Formatting Co-authored-by: André Silva <[email protected]> Co-authored-by: Bastian Köcher <[email protected]> * Add rustfmt skip to default frame benchmarking template (#9473) This was missed in the introduction pr of rustfmt. There we only had updated the Substrate local template. * CI: stop publishing to crates.io until unleash is fixed (#9474) * CI: stop publishing to crates.io until unleash is fixed; allow restarting k8s runners * CI: fix CI if ci-release tag is pushed Co-authored-by: Eric Miller <[email protected]> Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Gavin Wood <[email protected]> Co-authored-by: Zeke Mostov <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: Squirrel <[email protected]> Co-authored-by: André Silva <[email protected]> Co-authored-by: Parity Benchmarking Bot <[email protected]> Co-authored-by: Arkadiy Paronyan <[email protected]> Co-authored-by: Denis Pisarev <[email protected]>
1 parent be72e5d commit d3b4830

File tree

1 file changed

+73
-46
lines changed
  • .maintain/node-template-release/src

1 file changed

+73
-46
lines changed

.maintain/node-template-release/src/main.rs

Lines changed: 73 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use structopt::StructOpt;
22

33
use std::{
4-
path::{PathBuf, Path}, collections::HashMap, fs::{File, OpenOptions, self}, io::{Read, Write},
5-
process::Command
4+
collections::HashMap,
5+
fs::{self, File, OpenOptions},
6+
io::{Read, Write},
7+
path::{Path, PathBuf},
8+
process::Command,
69
};
710

811
use glob;
@@ -40,11 +43,9 @@ fn find_cargo_tomls(path: PathBuf) -> Vec<PathBuf> {
4043
let glob = glob::glob(&path).expect("Generates globbing pattern");
4144

4245
let mut result = Vec::new();
43-
glob.into_iter().for_each(|file| {
44-
match file {
45-
Ok(file) => result.push(file),
46-
Err(e) => println!("{:?}", e),
47-
}
46+
glob.into_iter().for_each(|file| match file {
47+
Ok(file) => result.push(file),
48+
Err(e) => println!("{:?}", e),
4849
});
4950

5051
if result.is_empty() {
@@ -78,30 +79,44 @@ fn get_git_commit_id(path: &Path) -> String {
7879
/// Parse the given `Cargo.toml` into a `HashMap`
7980
fn parse_cargo_toml(file: &Path) -> CargoToml {
8081
let mut content = String::new();
81-
File::open(file).expect("Cargo.toml exists").read_to_string(&mut content).expect("Reads file");
82+
File::open(file)
83+
.expect("Cargo.toml exists")
84+
.read_to_string(&mut content)
85+
.expect("Reads file");
8286
toml::from_str(&content).expect("Cargo.toml is a valid toml file")
8387
}
8488

8589
/// Replaces all substrate path dependencies with a git dependency.
86-
fn replace_path_dependencies_with_git(cargo_toml_path: &Path, commit_id: &str, cargo_toml: &mut CargoToml) {
90+
fn replace_path_dependencies_with_git(
91+
cargo_toml_path: &Path,
92+
commit_id: &str,
93+
cargo_toml: &mut CargoToml,
94+
) {
8795
let mut cargo_toml_path = cargo_toml_path.to_path_buf();
8896
// remove `Cargo.toml`
8997
cargo_toml_path.pop();
9098

9199
for &table in &["dependencies", "build-dependencies", "dev-dependencies"] {
92-
let mut dependencies: toml::value::Table = match cargo_toml
93-
.remove(table)
94-
.and_then(|v| v.try_into().ok()) {
95-
Some(deps) => deps,
96-
None => continue,
97-
};
100+
let mut dependencies: toml::value::Table =
101+
match cargo_toml.remove(table).and_then(|v| v.try_into().ok()) {
102+
Some(deps) => deps,
103+
None => continue,
104+
};
98105

99106
let deps_rewritten = dependencies
100107
.iter()
101-
.filter_map(|(k, v)| v.clone().try_into::<toml::value::Table>().ok().map(move |v| (k, v)))
102-
.filter(|t| t.1.contains_key("path") && {
103-
// if the path does not exists, we need to add this as git dependency
104-
t.1.get("path").unwrap().as_str().map(|path| !cargo_toml_path.join(path).exists()).unwrap_or(false)
108+
.filter_map(|(k, v)| {
109+
v.clone().try_into::<toml::value::Table>().ok().map(move |v| (k, v))
110+
})
111+
.filter(|t| {
112+
t.1.contains_key("path") && {
113+
// if the path does not exists, we need to add this as git dependency
114+
t.1.get("path")
115+
.unwrap()
116+
.as_str()
117+
.map(|path| !cargo_toml_path.join(path).exists())
118+
.unwrap_or(false)
119+
}
105120
})
106121
.map(|(k, mut v)| {
107122
// remove `path` and add `git` and `rev`
@@ -110,7 +125,8 @@ fn replace_path_dependencies_with_git(cargo_toml_path: &Path, commit_id: &str, c
110125
v.insert("rev".into(), commit_id.into());
111126

112127
(k.clone(), v.into())
113-
}).collect::<HashMap<_, _>>();
128+
})
129+
.collect::<HashMap<_, _>>();
114130

115131
dependencies.extend(deps_rewritten.into_iter());
116132

@@ -135,8 +151,9 @@ fn update_top_level_cargo_toml(
135151

136152
cargo_toml.insert("profile".into(), profile.into());
137153

138-
let members = workspace_members.iter()
139-
.map(|p|
154+
let members = workspace_members
155+
.iter()
156+
.map(|p| {
140157
p.strip_prefix(node_template_path)
141158
.expect("Workspace member is a child of the node template path!")
142159
.parent()
@@ -145,7 +162,7 @@ fn update_top_level_cargo_toml(
145162
.expect("The given path ends with `Cargo.toml` as file name!")
146163
.display()
147164
.to_string()
148-
)
165+
})
149166
.collect::<Vec<_>>();
150167

151168
let mut members_section = toml::value::Table::new();
@@ -163,24 +180,20 @@ fn write_cargo_toml(path: &Path, cargo_toml: CargoToml) {
163180
/// Build and test the generated node-template
164181
fn build_and_test(path: &Path, cargo_tomls: &[PathBuf]) {
165182
// Build node
166-
assert!(
167-
Command::new("cargo")
168-
.args(&["build", "--all"])
169-
.current_dir(path)
170-
.status()
171-
.expect("Compiles node")
172-
.success()
173-
);
183+
assert!(Command::new("cargo")
184+
.args(&["build", "--all"])
185+
.current_dir(path)
186+
.status()
187+
.expect("Compiles node")
188+
.success());
174189

175190
// Test node
176-
assert!(
177-
Command::new("cargo")
178-
.args(&["test", "--all"])
179-
.current_dir(path)
180-
.status()
181-
.expect("Tests node")
182-
.success()
183-
);
191+
assert!(Command::new("cargo")
192+
.args(&["test", "--all"])
193+
.current_dir(path)
194+
.status()
195+
.expect("Tests node")
196+
.success());
184197

185198
// Remove all `target` directories
186199
for toml in cargo_tomls {
@@ -189,7 +202,8 @@ fn build_and_test(path: &Path, cargo_tomls: &[PathBuf]) {
189202
target_path = target_path.join("target");
190203

191204
if target_path.exists() {
192-
fs::remove_dir_all(&target_path).expect(&format!("Removes `{}`", target_path.display()));
205+
fs::remove_dir_all(&target_path)
206+
.expect(&format!("Removes `{}`", target_path.display()));
193207
}
194208
}
195209
}
@@ -219,7 +233,10 @@ fn main() {
219233
// Check if top level Cargo.toml exists. If not, create one in the destination
220234
if !cargo_tomls.contains(&top_level_cargo_toml_path) {
221235
// create the top_level_cargo_toml
222-
OpenOptions::new().create(true).write(true).open(top_level_cargo_toml_path.clone())
236+
OpenOptions::new()
237+
.create(true)
238+
.write(true)
239+
.open(top_level_cargo_toml_path.clone())
223240
.expect("Create root level `Cargo.toml` failed.");
224241

225242
// push into our data structure
@@ -233,20 +250,30 @@ fn main() {
233250
// Check if this is the top level `Cargo.toml`, as this requires some special treatments.
234251
if top_level_cargo_toml_path == *t {
235252
// All workspace member `Cargo.toml` file paths.
236-
let workspace_members = cargo_tomls.iter()
237-
.filter(|p| **p != top_level_cargo_toml_path)
238-
.collect();
253+
let workspace_members =
254+
cargo_tomls.iter().filter(|p| **p != top_level_cargo_toml_path).collect();
239255

240256
update_top_level_cargo_toml(&mut cargo_toml, workspace_members, &node_template_path);
241257
}
242258

243259
write_cargo_toml(&t, cargo_toml);
244260
});
245261

262+
// adding root rustfmt to node template build path
263+
let node_template_rustfmt_toml_path = node_template_path.join("rustfmt.toml");
264+
let root_rustfmt_toml =
265+
&options.node_template.join("../../rustfmt.toml");
266+
if root_rustfmt_toml.exists() {
267+
fs::copy(&root_rustfmt_toml, &node_template_rustfmt_toml_path)
268+
.expect("Copying rustfmt.toml.");
269+
}
270+
246271
build_and_test(&node_template_path, &cargo_tomls);
247272

248-
let output = GzEncoder::new(File::create(&options.output)
249-
.expect("Creates output file"), Compression::default());
273+
let output = GzEncoder::new(
274+
File::create(&options.output).expect("Creates output file"),
275+
Compression::default(),
276+
);
250277
let mut tar = tar::Builder::new(output);
251278
tar.append_dir_all("substrate-node-template", node_template_path)
252279
.expect("Writes substrate-node-template archive");

0 commit comments

Comments
 (0)