From 8c54a2f1ed74b366b50bc7019340df7230f749b1 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Thu, 11 Jul 2024 02:59:30 +0000 Subject: [PATCH] fix(tasks/ast_codegen): run `cargo fmt` synchronously (#4181) relates #4152 This is my wild guess, because it works in my other script https://github.com/oxc-project/oxc-browserslist/blob/143685deb1dec9ffce3bc3ba4d9abf7d3fe300ad/xtask/src/main.rs#L21 --- .github/workflows/ci.yml | 8 +------- tasks/ast_codegen/src/fmt.rs | 13 +++---------- tasks/ast_codegen/src/main.rs | 2 +- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71333597d57eb..51cbec9c31390 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -330,12 +330,6 @@ jobs: - name: Check AST Changes if: steps.filter.outputs.src == 'true' run: | - cargo run -p oxc_ast_codegen -- --no-fmt - # FIXME: - # remove the following command and `--no-fmt` flag - # for some reason in the CI `cargo fmt` in the `oxc_ast_codegen` doesn't produce formatted code, - # Even though it is running succesfully and produces no errors. - # It also prints the right results for `cargo fmt --version` so it can find the right binary for sure. - cargo fmt + cargo run -p oxc_ast_codegen echo 'AST changes must be commited to the repo.' git diff --exit-code diff --git a/tasks/ast_codegen/src/fmt.rs b/tasks/ast_codegen/src/fmt.rs index 8d2de9ba228fa..ce4cae8a2e20d 100644 --- a/tasks/ast_codegen/src/fmt.rs +++ b/tasks/ast_codegen/src/fmt.rs @@ -59,14 +59,7 @@ pub fn pprint(input: &TokenStream) -> String { result } -/// Runs cargo fmt in the `root` path. -pub fn cargo_fmt(root: &str) -> std::io::Result<()> { - let mut cmd = Command::new("cargo"); - cmd.arg("fmt") - .stdin(Stdio::inherit()) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .current_dir(root); - cmd.spawn()?; - Ok(()) +/// Runs cargo fmt. +pub fn cargo_fmt() { + Command::new("cargo").arg("fmt").status().unwrap(); } diff --git a/tasks/ast_codegen/src/main.rs b/tasks/ast_codegen/src/main.rs index a5802b586c4b6..5c996ea719d0c 100644 --- a/tasks/ast_codegen/src/main.rs +++ b/tasks/ast_codegen/src/main.rs @@ -245,7 +245,7 @@ fn main() -> std::result::Result<(), Box> { } if !cli_options.no_fmt { - cargo_fmt(".")?; + cargo_fmt(); } if let CliOptions { schema: Some(schema_path), dry_run: false, .. } = cli_options {