Skip to content

Commit 9a52443

Browse files
committed
Merge dev audit Into dev check
1 parent 54c86c3 commit 9a52443

8 files changed

Lines changed: 207 additions & 242 deletions

File tree

host/dev/src/client/check.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::env;
22
use std::process::Command;
3-
use std::time::Duration;
3+
use std::time::Instant;
44

55
use anyhow::Result;
66
use clap::{Args, ValueEnum};
@@ -24,6 +24,7 @@ pub enum Tool {
2424
#[default]
2525
Clippy,
2626
CargoJsSys,
27+
RustSec,
2728
Tombi,
2829
}
2930

@@ -50,7 +51,7 @@ impl Check {
5051

5152
pub fn execute(self, verbose: bool) -> Result<()> {
5253
let tools = Tool::from_tools(self.tools)?;
53-
let mut duration = Duration::ZERO;
54+
let start = Instant::now();
5455

5556
for tool in tools {
5657
match tool {
@@ -65,7 +66,7 @@ impl Check {
6566
CargoCommand {
6667
title: "Check Tests",
6768
sub_command: "clippy",
68-
args: &["--tests", "--benches", "--", "-D", "warnings"],
69+
args: &["--tests", "--benches", "--examples", "--", "-D", "warnings"],
6970
envs: &[],
7071
},
7172
CargoCommand {
@@ -75,7 +76,7 @@ impl Check {
7576
envs: &[("RUSTDOCFLAGS", "-D warnings")],
7677
},
7778
];
78-
duration += metadata::run(self.args.clone(), &commands, verbose)?;
79+
metadata::run(self.args.clone(), &commands, verbose)?;
7980
}
8081
Tool::CargoJsSys => {
8182
let tools_installed =
@@ -88,26 +89,31 @@ impl Check {
8889
command::run("Build `cargo-js-sys`", command, verbose)?;
8990
}
9091

91-
duration += Self::cargo_js_sys("js-sys", tools_installed, verbose)?;
92-
duration += Self::cargo_js_sys("web-sys", tools_installed, verbose)?;
92+
Self::cargo_js_sys("js-sys", tools_installed, verbose)?;
93+
Self::cargo_js_sys("web-sys", tools_installed, verbose)?;
94+
}
95+
Tool::RustSec => {
96+
let mut command = Command::new("cargo");
97+
command.current_dir("../client").arg("audit");
98+
command::run("RustSec", command, verbose)?;
9399
}
94100
Tool::Tombi => {
95101
let mut command = Command::new("tombi");
96102
command
97103
.current_dir("../client")
98104
.args(["lint", "--error-on-warnings", "."]);
99-
duration += command::run("Tombi Lint", command, verbose)?;
105+
command::run("Tombi Lint", command, verbose)?;
100106
}
101107
}
102108
}
103109

104110
println!("-------------------------");
105-
println!("Total Time: {:.2}s", duration.as_secs_f32());
111+
println!("Total Time: {:.2}s", start.elapsed().as_secs_f32());
106112

107113
Ok(())
108114
}
109115

110-
fn cargo_js_sys(pkg: &str, tools_installed: bool, verbose: bool) -> Result<Duration> {
116+
fn cargo_js_sys(pkg: &str, tools_installed: bool, verbose: bool) -> Result<()> {
111117
let mut command = if tools_installed {
112118
Command::new("cargo-js-sys")
113119
} else {
@@ -125,6 +131,8 @@ impl Check {
125131
command.arg("-v");
126132
}
127133

128-
command::run(&format!("Check `cargo-js-sys` - `{pkg}`"), command, verbose)
134+
command::run(&format!("Check `cargo-js-sys` - `{pkg}`"), command, verbose)?;
135+
136+
Ok(())
129137
}
130138
}

host/dev/src/client/fmt.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use std::process::Command;
2+
use std::time::Instant;
3+
4+
use anyhow::Result;
5+
use clap::Args;
6+
7+
use crate::{FmtTool, FmtTools, command};
8+
9+
#[derive(Args)]
10+
pub struct Fmt {
11+
#[arg(long, value_delimiter = ',', default_value = FmtTools::default_arg())]
12+
tools: Vec<FmtTools>,
13+
}
14+
15+
impl Default for Fmt {
16+
fn default() -> Self {
17+
Self {
18+
tools: vec![FmtTools::default()],
19+
}
20+
}
21+
}
22+
23+
impl Fmt {
24+
pub fn new(tools: Vec<FmtTools>) -> Self {
25+
Self { tools }
26+
}
27+
28+
pub fn execute(self, verbose: bool) -> Result<()> {
29+
let tools = FmtTool::from_tools(self.tools)?;
30+
let start = Instant::now();
31+
32+
for tool in tools {
33+
match tool {
34+
FmtTool::Rustfmt => {
35+
let mut command = Command::new("cargo");
36+
command.current_dir("../client").args(["+nightly", "fmt"]);
37+
command::run("Rustfmt", command, verbose)?;
38+
}
39+
FmtTool::Tombi => {
40+
let mut command = Command::new("tombi");
41+
command.current_dir("../client").args(["format", "."]);
42+
command::run("Tombi Format", command, verbose)?;
43+
}
44+
FmtTool::Prettier => {
45+
let mut command = Command::new("prettier");
46+
command.current_dir("..").args(["client", "-w"]);
47+
command::run("Prettier", command, verbose)?;
48+
}
49+
}
50+
}
51+
52+
println!("-------------------------");
53+
println!("Total Time: {:.2}s", start.elapsed().as_secs_f32());
54+
55+
Ok(())
56+
}
57+
}

host/dev/src/client/mod.rs

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
mod check;
2+
mod fmt;
23
mod metadata;
34
mod permutation;
45
mod process;
56
mod test;
67
mod util;
78

8-
use std::fmt;
99
use std::fmt::{Display, Formatter};
10-
use std::process::Command;
11-
use std::time::Duration;
1210

1311
use anyhow::Result;
1412
use clap::{Args, Subcommand, ValueEnum};
1513
use strum::EnumIter;
1614

1715
use self::check::{Check, Tools};
16+
use self::fmt::Fmt;
1817
use self::permutation::Toolchain;
1918
use self::test::Test;
2019
use self::util::ToolchainParser;
21-
use crate::command::{self, CargoCommand};
22-
use crate::{FmtTool, FmtTools};
20+
use crate::FmtTools;
21+
use crate::command::CargoCommand;
2322

2423
#[derive(Subcommand)]
2524
pub enum Client {
@@ -31,17 +30,13 @@ pub enum Client {
3130
#[command(flatten)]
3231
test: Test,
3332
},
34-
Fmt {
35-
#[arg(long, value_delimiter = ',', default_value = FmtTools::default_arg())]
36-
tools: Vec<FmtTools>,
37-
},
33+
Fmt(Fmt),
3834
Build {
3935
#[command(flatten)]
4036
args: ClientArgs,
4137
},
4238
Check(Check),
4339
Test(Test),
44-
Audit,
4540
}
4641

4742
#[derive(Args, Clone)]
@@ -56,9 +51,7 @@ pub struct ClientArgs {
5651

5752
impl Client {
5853
pub fn fmt() -> Self {
59-
Self::Fmt {
60-
tools: vec![FmtTools::default()],
61-
}
54+
Self::Fmt(Fmt::default())
6255
}
6356

6457
pub fn build(all: bool) -> Self {
@@ -96,7 +89,7 @@ impl Client {
9689
check_tools,
9790
test,
9891
} => {
99-
Self::Fmt { tools: fmt_tools }.execute(verbose)?;
92+
Self::Fmt(Fmt::new(fmt_tools)).execute(verbose)?;
10093
println!("-------------------------");
10194
println!();
10295
Self::Build {
@@ -112,35 +105,7 @@ impl Client {
112105

113106
Ok(())
114107
}
115-
Self::Fmt { tools } => {
116-
let tools = FmtTool::from_tools(tools)?;
117-
let mut duration = Duration::ZERO;
118-
119-
for tool in tools {
120-
match tool {
121-
FmtTool::Rustfmt => {
122-
let mut command = Command::new("cargo");
123-
command.current_dir("../client").args(["+nightly", "fmt"]);
124-
duration += command::run("Rustfmt", command, verbose)?;
125-
}
126-
FmtTool::Tombi => {
127-
let mut command = Command::new("tombi");
128-
command.current_dir("../client").args(["format", "."]);
129-
duration += command::run("Tombi Format", command, verbose)?;
130-
}
131-
FmtTool::Prettier => {
132-
let mut command = Command::new("prettier");
133-
command.current_dir("..").args(["client", "-w"]);
134-
duration += command::run("Prettier", command, verbose)?;
135-
}
136-
}
137-
}
138-
139-
println!("-------------------------");
140-
println!("Total Time: {:.2}s", duration.as_secs_f32());
141-
142-
Ok(())
143-
}
108+
Self::Fmt(fmt) => fmt.execute(verbose),
144109
Self::Build { args } => {
145110
let command = CargoCommand {
146111
title: "Build",
@@ -157,16 +122,6 @@ impl Client {
157122
}
158123
Self::Check(check) => check.execute(verbose),
159124
Self::Test(test) => test.execute(verbose),
160-
Self::Audit => {
161-
let mut command = Command::new("cargo");
162-
command.current_dir("../client").arg("audit");
163-
let duration = command::run("RustSec", command, verbose)?;
164-
165-
println!("-------------------------");
166-
println!("Total Time: {:.2}s", duration.as_secs_f32());
167-
168-
Ok(())
169-
}
170125
}
171126
}
172127
}
@@ -249,7 +204,7 @@ impl Target {
249204
}
250205

251206
impl Display for Target {
252-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
207+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
253208
match self {
254209
Self::Wasm32 => f.write_str("Wasm32"),
255210
Self::Wasm64 => f.write_str("Wasm64"),
@@ -274,7 +229,7 @@ impl TargetFeature {
274229
}
275230

276231
impl Display for TargetFeature {
277-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
232+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
278233
match self {
279234
Self::Default => Ok(()),
280235
Self::Atomics => f.write_str("Atomics"),

host/dev/src/host/audit.rs

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)