From fc6a6d09f921387dc15261bf548d15512993b714 Mon Sep 17 00:00:00 2001 From: "Vineel Kovvuri[MSFT]" Date: Fri, 9 Oct 2026 15:45:20 -0700 Subject: [PATCH] .sync: Forward command line arguments in make tasks Tasks in the five synced makefiles now pass command line arguments to the cargo command they run. A test or coverage run can be narrowed to one package, or given extra flags, without editing the makefile. More details are described in https://github.com/OpenDevicePartnership/patina/pull/1856 Signed-off-by: Vineel Kovvuri[MSFT] --- .../Makefile-patina-dxe-core-qemu.toml | 171 +++++++---------- .../rust/Makefiles/Makefile-patina-mtrr.toml | 107 ++++++++--- .../Makefiles/Makefile-patina-paging.toml | 87 ++++++--- .../Makefile-patina-readiness-tool.toml | 174 +++++++++++------ .sync/rust/Makefiles/Makefile-patina.toml | 177 ++++++++++-------- 5 files changed, 427 insertions(+), 289 deletions(-) diff --git a/.sync/rust/Makefiles/Makefile-patina-dxe-core-qemu.toml b/.sync/rust/Makefiles/Makefile-patina-dxe-core-qemu.toml index 51aca24..a5fe4ef 100644 --- a/.sync/rust/Makefiles/Makefile-patina-dxe-core-qemu.toml +++ b/.sync/rust/Makefiles/Makefile-patina-dxe-core-qemu.toml @@ -12,7 +12,10 @@ NO_STD_FLAGS = "--profile ${RUSTC_PROFILE} --timings" # Note: `--profile test` has been set here in the past. Cargo already defaults to test builds # with the test profile, so it is removed. cargo-llvm-cov will forward it to `cargo nextest run` # where `--profile` is used to incorrectly select a nextest config profile (not a Cargo build profile). -COV_FLAGS = { value = "--workspace --ignore-filename-regex .*test.*", condition = { env_not_set = ["COV_FLAGS"] } } +# `--workspace` is intentionally not part of this value. It is supplied separately by the +# `cov-workspace-flag` task, which omits it when the command line provides arguments, because +# `--workspace` overrides `-p`. +COV_FLAGS = { value = "--ignore-filename-regex .*test.*", condition = { env_not_set = ["COV_FLAGS"] } } RUSTDOCFLAGS = "-D warnings -D missing_docs" # Selects the nextest `ci` profile (defined in .config/nextest.toml) automatically when the `CI` # variable is set (e.g. GitHub Actions sets this for every job). @@ -111,48 +114,26 @@ for line in ${lines} end ''' -[tasks.individual-package-targets] -script_runner = "@duckscript" -script = ''' -args = get_env CARGO_MAKE_TASK_ARGS - -if is_empty ${args} - exit -end - -1 = array "" -2 = split ${args} , -3 = array_concat ${1} ${2} -joined_args = array_join ${3} " -p " -release ${1} -release ${2} -release ${3} - -joined_args = trim ${joined_args} -set_env INDIVIDUAL_PACKAGE_TARGETS ${joined_args} -release ${joined_args} -''' - [tasks.check_code_x64] description = "Checks rust code for x64 build errors with results." private = true command = "cargo" -args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features,x64", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",] +args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features,x64", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )",] [tasks.check_code_aarch64] description = "Checks rust code for aarch64 build errors with results." private = true command = "cargo" -args = ["check", "--target", "aarch64-unknown-uefi", "--features", "ci_features,aarch64", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",] +args = ["check", "--target", "aarch64-unknown-uefi", "--features", "ci_features,aarch64", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )",] [tasks.check_tests] description = "Checks rust test code for build errors with results." private = true command = "cargo" -args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS, )",] +args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)",] [tasks.check] -description = "Checks rust code for errors. Example `cargo make check`" +description = "Checks rust code for errors. Arguments are forwarded to `cargo check`/`cargo nextest`. Example `cargo make check` or `cargo make check -p qemu_dxe_core`" clear = true run_task = [{ name = ["check_code_x64", "check_code_aarch64", "check_tests"], parallel = true }] @@ -160,13 +141,13 @@ run_task = [{ name = ["check_code_x64", "check_code_aarch64", "check_tests"], pa description = "Checks rust code compiles without default features." private = true command = "cargo" -args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"] +args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.check-no-default-features-tests] description = "Checks rust test code compiles without default features." private = true command = "cargo" -args = ["nextest", "run", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"] +args = ["nextest", "run", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.check-no-default-features] description = "Checks rust code and tests compile without default features to catch feature-gate regressions." @@ -174,7 +155,7 @@ clear = true run_task = [{ name = ["check-no-default-features-code", "check-no-default-features-tests"], parallel = true }] [tasks.test] -description = "Runs tests via cargo-nextest. Example `cargo make test` or `cargo make test -p package_name -- --nocapture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." +description = "Runs tests via cargo-nextest. Arguments are forwarded to `cargo nextest run`. Example `cargo make test` or `cargo make test --no-capture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." clear = true dependencies = ["test-default", "test-ci-features"] @@ -191,8 +172,23 @@ condition = { env_set = ["CI"] } command = "cargo" args = ["nextest", "run", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +[tasks.cov-workspace-flag] +description = """Sets `COV_WORKSPACE` to `--workspace` only when no arguments were given on the +command line. `--workspace` overrides `-p`, so it is dropped whenever any argument is given +(for example `cargo make coverage -p qemu_dxe_core`).""" +private = true +script_runner = "@duckscript" +script = ''' +args = get_env CARGO_MAKE_TASK_ARGS +if is_empty ${args} + set_env COV_WORKSPACE "--workspace" +else + set_env COV_WORKSPACE "" +end +''' + [tasks.coverage-collect] -description = "Run tests and collect coverage data without generating reports." +description = "Run tests and collect coverage data without generating reports. Arguments are forwarded to `cargo llvm-cov nextest`." install_crate = false clear = true # `coverage_attribute` is deliberately excluded from the default allow-features in @@ -201,8 +197,8 @@ clear = true # Note: RUSTFLAGS replaces build.rustflags. env = { RUSTFLAGS = "-Z allow-features=c_variadic,allocator_api,coverage_attribute" } command = "cargo" -args = ["llvm-cov", "@@split(COV_FLAGS, )", "--no-report", "nextest"] -dependencies = ["individual-package-targets"] +args = ["llvm-cov", "@@split(COV_WORKSPACE, )", "@@split(COV_FLAGS, )", "--no-report", "nextest", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["cov-workspace-flag"] [tasks.coverage-lcov] description = "Generate an LCOV coverage report from collected data." @@ -219,7 +215,7 @@ command = "cargo" args = ["llvm-cov", "report", "--html", "--output-dir", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/coverage"] [tasks.coverage] -description = "Build and run all tests and calculate coverage (runs test once and generates LCOV and HTML reports). In CI, also runs a second pass with the `ci_features` feature enabled (outside of coverage collection) since only `cargo make coverage` is run in CI." +description = "Build and run all tests and calculate coverage (runs test once and generates LCOV and HTML reports). Arguments are forwarded to `cargo llvm-cov nextest`. Example `cargo make coverage -p qemu_dxe_core`. In CI, also runs a second pass with the `ci_features` feature enabled (outside of coverage collection) since only `cargo make coverage` is run in CI." dependencies = ["coverage-collect", "coverage-lcov", "coverage-html", "test-ci-features"] clear = true @@ -510,17 +506,19 @@ env = { CARGO_BIN_NAME = "qemu_armvirt_dxe_core", "RUSTC_PROFILE" = "release", C run_task = "patch" [tasks.doc] -description = "Builds all rust documentation in the workspace. Example `cargo make doc`" +description = "Builds all rust documentation in the workspace. Arguments are forwarded to `cargo doc`. Example `cargo make doc` or `cargo make doc -p qemu_dxe_core`" +clear = true command = "cargo" -args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--no-deps"] +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--no-deps"] [tasks.doc-open] -description = "Builds all rust documentation in the workspace and opens the documentation Example `cargo make doc-open`" +description = "Builds all rust documentation in the workspace and opens the documentation. Arguments are forwarded to `cargo doc`. Example `cargo make doc-open` or `cargo make doc-open -p qemu_dxe_core`" +clear = true command = "cargo" -args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--open"] +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--open"] [tasks.clippy] -description = "Run cargo clippy for the host target and both UEFI cross-compilation targets." +description = "Run cargo clippy for the host target and both UEFI cross-compilation targets. Arguments are forwarded to `cargo clippy`." clear = true run_task = [{ name = ["clippy-x64", "clippy-aarch64", "clippy-std"], parallel = true }] @@ -528,109 +526,82 @@ run_task = [{ name = ["clippy-x64", "clippy-aarch64", "clippy-std"], parallel = description = "Run cargo clippy for x86_64-unknown-uefi." private = true command = "cargo" -args = ["clippy", "--target", "x86_64-unknown-uefi", "--features", "ci_features,x64", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "--target", "x86_64-unknown-uefi", "--features", "ci_features,x64", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] [tasks.clippy-aarch64] description = "Run cargo clippy for aarch64-unknown-uefi." private = true command = "cargo" -args = ["clippy", "--target", "aarch64-unknown-uefi", "--features", "ci_features,aarch64", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "--target", "aarch64-unknown-uefi", "--features", "ci_features,aarch64", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] [tasks.clippy-std] description = "Run cargo clippy for the host target (library and tests only)." private = true command = "cargo" -args = ["clippy", "--tests", "--", "-D", "warnings"] +args = ["clippy", "--tests", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--", "-D", "warnings"] + +[tasks.fmt-all-flag] +description = """Sets `FMT_ALL` to `--all` only when no arguments were given on the command line. +`--all` overrides `-p`, so it is dropped whenever any argument is given (for example +`cargo make fmt -p qemu_dxe_core`).""" +private = true +script_runner = "@duckscript" +script = ''' +args = get_env CARGO_MAKE_TASK_ARGS +if is_empty ${args} + set_env FMT_ALL "--all" +else + set_env FMT_ALL "" +end +''' [tasks.fmt] -description = "Run cargo format." +description = "Run cargo format. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt` or `cargo make fmt -p qemu_dxe_core`" clear = true command = "cargo" -args = ["fmt", "--all"] +args = ["fmt", "@@split(FMT_ALL, )", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.fmt-check] -description = "Check cargo format without modifying files." +description = "Check cargo format without modifying files. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt-check` or `cargo make fmt-check -p qemu_dxe_core`" clear = true command = "cargo" -args = ["fmt", "--all", "--check"] +args = ["fmt", "@@split(FMT_ALL, )", "--check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.doc-test] -description = "Run documentation tests." +description = "Run documentation tests. Arguments are forwarded to `cargo test`." clear = true command = "cargo" -args = ["test", "--doc"] +args = ["test", "--doc", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.cspell] description = "Run cspell for spell checking." # npm install -g cspell@latest script = "cspell --quiet --no-progress --no-summary --dot --gitignore -e \"{.git/**,.github/**,.vscode/**}\" ." [tasks.deny] -description = "Run cargo deny." +description = "Run cargo deny. Arguments are forwarded to `cargo deny check`." install_crate = false clear = true command = "cargo" -args = ["deny", "check"] - -[tasks.bloat-q35-exec] -private = true -command = "cargo" -args = ["bloat", "--target", "x86_64-unknown-uefi", "--features", "x64", "--bin", "qemu_q35_dxe_core", "--profile", "${RUSTC_PROFILE}", "-Zbuild-std=core,compiler_builtins,alloc", "-Zbuild-std-features=compiler-builtins-mem", "-Zunstable-options", "@@split(CLEANED_ARGS, )"] +args = ["deny", "check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.bloat-q35] -description = "Run cargo bloat for q35 (x86_64-unknown-uefi). Examples: `cargo make bloat-q35 -- --crates`, `cargo make bloat-q35 -- --crates -n 40`." -script_runner = "@duckscript" -script = ''' -args = get_env CARGO_MAKE_TASK_ARGS - -# Clean up the args by replacing semicolons with spaces -if not is_empty ${args} - clean_args = replace ${args} ";;--" " --" - clean_args = replace ${clean_args} ";;" " " - clean_args = replace ${clean_args} ";" " " - # Remove leading/trailing whitespace and -- prefix - clean_args = trim ${clean_args} - clean_args = replace ${clean_args} "-- " "" - set_env CLEANED_ARGS ${clean_args} -else - set_env CLEANED_ARGS "" -end - -cm_run_task bloat-q35-exec -''' - -[tasks.bloat-armvirt-exec] -private = true +description = "Run cargo bloat for q35 (x86_64-unknown-uefi). Arguments are forwarded to `cargo bloat`. Examples: `cargo make bloat-q35 --crates`, `cargo make bloat-q35 --crates -n 40`." command = "cargo" -args = ["bloat", "--target", "aarch64-unknown-uefi", "--features", "aarch64", "--bin", "qemu_armvirt_dxe_core", "--profile", "${RUSTC_PROFILE}", "-Zbuild-std=core,compiler_builtins,alloc", "-Zbuild-std-features=compiler-builtins-mem", "-Zunstable-options", "@@split(CLEANED_ARGS, )"] +args = ["bloat", "--target", "x86_64-unknown-uefi", "--features", "x64", "--bin", "qemu_q35_dxe_core", "--profile", "${RUSTC_PROFILE}", "-Zbuild-std=core,compiler_builtins,alloc", "-Zbuild-std-features=compiler-builtins-mem", "-Zunstable-options", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.bloat-armvirt] -description = "Run cargo bloat for armvirt (aarch64-unknown-uefi). Examples: `cargo make bloat-armvirt -- --crates`, `cargo make bloat-armvirt -- --crates -n 40`." -script_runner = "@duckscript" -script = ''' -args = get_env CARGO_MAKE_TASK_ARGS - -# Clean up the args by replacing semicolons with spaces -if not is_empty ${args} - clean_args = replace ${args} ";;--" " --" - clean_args = replace ${clean_args} ";;" " " - clean_args = replace ${clean_args} ";" " " - # Remove leading/trailing whitespace and -- prefix - clean_args = trim ${clean_args} - clean_args = replace ${clean_args} "-- " "" - set_env CLEANED_ARGS ${clean_args} -else - set_env CLEANED_ARGS "" -end - -cm_run_task bloat-armvirt-exec -''' +description = "Run cargo bloat for armvirt (aarch64-unknown-uefi). Arguments are forwarded to `cargo bloat`. Examples: `cargo make bloat-armvirt --crates`, `cargo make bloat-armvirt --crates -n 40`." +command = "cargo" +args = ["bloat", "--target", "aarch64-unknown-uefi", "--features", "aarch64", "--bin", "qemu_armvirt_dxe_core", "--profile", "${RUSTC_PROFILE}", "-Zbuild-std=core,compiler_builtins,alloc", "-Zbuild-std-features=compiler-builtins-mem", "-Zunstable-options", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.all-preflight] private = true run_task = [{ name = ["fmt-check", "deny", "cspell"], parallel = true }] [tasks.all] -description = "Run all tasks for PR readiness." +description = "Run all tasks for PR readiness. This task takes no arguments; any arguments given are forwarded to every sub-task." env = { CARGO_INCREMENTAL = "0" } run_task = { name = [ "all-preflight", diff --git a/.sync/rust/Makefiles/Makefile-patina-mtrr.toml b/.sync/rust/Makefiles/Makefile-patina-mtrr.toml index a7ad540..76fa649 100644 --- a/.sync/rust/Makefiles/Makefile-patina-mtrr.toml +++ b/.sync/rust/Makefiles/Makefile-patina-mtrr.toml @@ -9,12 +9,13 @@ default_to_workspace = false [env] BUILD_FLAGS = "--profile ${RUSTC_PROFILE} --timings" -UEFI_CRATES = "-p patina_mtrr" -BUILD_CRATES = "-p patina_mtrr" # Note: `--profile test` has been set here in the past. Cargo already defaults to test builds # with the test profile, so it is removed. cargo-llvm-cov will forward it to `cargo nextest run` # where `--profile` is used to incorrectly select a nextest config profile (not a Cargo build profile). -COV_FLAGS = { value = "--workspace --ignore-filename-regex .*test.*", condition = { env_not_set = ["COV_FLAGS"] } } +# `--workspace` is intentionally not part of this value. It is supplied separately by the +# `cov-workspace-flag` task, which omits it when the command line provides arguments, because +# `--workspace` overrides `-p`. +COV_FLAGS = { value = "--ignore-filename-regex .*test.*", condition = { env_not_set = ["COV_FLAGS"] } } # Selects the nextest `ci` profile (defined in .config/nextest.toml) automatically when the `CI` # variable is set (e.g. GitHub Actions sets this for every job). # `NEXTEST_PROFILE` is read natively by `cargo nextest run` and by `cargo llvm-cov ... nextest`. @@ -113,53 +114,65 @@ end [tasks.build] description = """Builds a single rust package with the standard library. +Arguments are forwarded to `cargo build` unchanged, so any flag `cargo build` +accepts can be used. + Customizations: -p [development|release]: Builds in debug or release. Default: development Example: `cargo make build` `cargo make -p release build` + `cargo make build --features std` """ alias = "build-std" [tasks.build-std] description = """Builds patina_mtrr crate as std target. +Arguments are forwarded to `cargo build` unchanged, so any flag `cargo build` +accepts can be used. + Customizations: -p [development|release]: Builds in debug or release. Default: development Example: `cargo make build-std` + `cargo make build-std -p patina_mtrr` """ clear = true command = "cargo" -args = ["build", "--profile", "${RUSTC_PROFILE}", "--features", "std", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}", "@@split(BUILD_CRATES, )", "@@split(UEFI_CRATES, )"] +args = ["build", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--profile", "${RUSTC_PROFILE}", "--features", "std", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}"] [tasks.build-x64] description = """Builds patina_mtrr crate as UEFI target. +Arguments are forwarded to `cargo build` unchanged, so any flag `cargo build` +accepts can be used. + Example: `cargo make build-x64` `cargo make -p release build-x64` + `cargo make build-x64 --features ci_features` """ clear = true command = "cargo" -args = ["build", "--target", "x86_64-unknown-uefi", "@@split(BUILD_FLAGS, )", "@@split(UEFI_CRATES, )"] +args = ["build", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--target", "x86_64-unknown-uefi", "@@split(BUILD_FLAGS, )"] [tasks.check_code_x64] description = "Checks rust code for x64 build errors with results." private = true command = "cargo" -args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",] +args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )",] [tasks.check_tests] description = "Checks rust test code for build errors with results." private = true command = "cargo" -args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS, )",] +args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)",] [tasks.check] -description = "Checks rust code for errors. Example `cargo make check`" +description = "Checks rust code for errors. Arguments are forwarded to `cargo check`/`cargo nextest`. Example `cargo make check` or `cargo make check --features std`" clear = true run_task = [{ name = ["check_code_x64", "check_tests"], parallel = true }] @@ -167,16 +180,16 @@ run_task = [{ name = ["check_code_x64", "check_tests"], parallel = true }] description = "Checks rust code compiles without default features." private = true command = "cargo" -args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"] +args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.check-no-default-features-tests] description = "Checks rust test code compiles without default features." private = true command = "cargo" -args = ["nextest", "run", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"] +args = ["nextest", "run", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.check-no-default-features] -description = "Checks rust code and tests compile without default features to catch feature-gate regressions." +description = "Checks rust code and tests compile without default features to catch feature-gate regressions. Arguments are forwarded to `cargo check`/`cargo nextest`." clear = true run_task = [{ name = ["check-no-default-features-code", "check-no-default-features-tests"], parallel = true }] @@ -188,7 +201,7 @@ command = "cargo" args = ["llvm-cov", "clean", "--workspace"] [tasks.test] -description = "Runs tests via cargo-nextest. Example `cargo make test` or `cargo make test -- --nocapture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." +description = "Runs tests via cargo-nextest. Arguments are forwarded to `cargo nextest run`. Example `cargo make test` or `cargo make test -p patina_mtrr --no-capture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." clear = true dependencies = ["test-default", "test-ci-features"] @@ -205,8 +218,23 @@ condition = { env_set = ["CI"] } command = "cargo" args = ["nextest", "run", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +[tasks.cov-workspace-flag] +description = """Sets `COV_WORKSPACE` to `--workspace` only when no arguments were given on the +command line. `--workspace` overrides `-p`, so it is dropped whenever any argument is given +(for example `cargo make coverage -p patina_mtrr`).""" +private = true +script_runner = "@duckscript" +script = ''' +args = get_env CARGO_MAKE_TASK_ARGS +if is_empty ${args} + set_env COV_WORKSPACE "--workspace" +else + set_env COV_WORKSPACE "" +end +''' + [tasks.test-cov] -description = "Run tests and collect coverage data without generating reports." +description = "Run tests and collect coverage data without generating reports. Arguments are forwarded to `cargo llvm-cov nextest`." install_crate = false clear = true # `coverage_attribute` is deliberately excluded from the default allow-features in @@ -215,8 +243,8 @@ clear = true # Note: RUSTFLAGS replaces build.rustflags. env = { RUSTFLAGS = "-Z allow-features=c_variadic,allocator_api,coverage_attribute" } command = "cargo" -args = ["llvm-cov", "@@split(COV_FLAGS, )", "--no-report", "nextest"] -dependencies = ["llvm-cov-clean"] +args = ["llvm-cov", "@@split(COV_WORKSPACE, )", "@@split(COV_FLAGS, )", "--no-report", "nextest", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["cov-workspace-flag", "llvm-cov-clean"] [tasks.coverage-lcov] description = "Generate an LCOV coverage report from collected data." @@ -292,7 +320,7 @@ exec --fail-on-error cargo test --doc --target ${target} --workspace --features ''' [tasks.clippy] -description = "Run cargo clippy for the host target and both UEFI cross-compilation targets." +description = "Run cargo clippy for the host target and both UEFI cross-compilation targets. Arguments are forwarded to `cargo clippy`." clear = true run_task = [{ name = ["clippy-x64", "clippy-std"], parallel = true }] @@ -300,61 +328,78 @@ run_task = [{ name = ["clippy-x64", "clippy-std"], parallel = true }] description = "Run cargo clippy for x86_64-unknown-uefi." private = true command = "cargo" -args = ["clippy", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] [tasks.clippy-std] description = "Run cargo clippy for std." private = true command = "cargo" -args = ["clippy", "--all-targets", "--all-features", "--", "-D", "warnings"] +args = ["clippy", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--", "-D", "warnings"] [tasks.doc] env = { RUSTDOCFLAGS = "-D warnings"} -description = "Builds all rust documentation in the workspace. Example `cargo make doc`" +description = "Builds all rust documentation in the workspace. Arguments are forwarded to `cargo doc`. Example `cargo make doc` or `cargo make doc -p patina_mtrr`" command = "cargo" -args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--no-deps"] +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--no-deps"] [tasks.doc-open] env = { RUSTDOCFLAGS = "-D warnings"} -description = "Builds all rust documentation in the workspace and opens the documentation. Example `cargo make doc`" +description = "Builds all rust documentation in the workspace and opens the documentation. Arguments are forwarded to `cargo doc`. Example `cargo make doc-open` or `cargo make doc-open -p patina_mtrr`" command = "cargo" -args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--open"] +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--open"] + +[tasks.fmt-all-flag] +description = """Sets `FMT_ALL` to `--all` only when no arguments were given on the command line. +`--all` overrides `-p`, so it is dropped whenever any argument is given (for example +`cargo make fmt -p patina_mtrr`).""" +private = true +script_runner = "@duckscript" +script = ''' +args = get_env CARGO_MAKE_TASK_ARGS +if is_empty ${args} + set_env FMT_ALL "--all" +else + set_env FMT_ALL "" +end +''' [tasks.fmt] -description = "Run cargo format." +description = "Run cargo format. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt` or `cargo make fmt -p patina_mtrr`" clear = true command = "cargo" -args = ["fmt", "--all"] +args = ["fmt", "@@split(FMT_ALL, )", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.fmt-check] -description = "Check cargo format without modifying files." +description = "Check cargo format without modifying files. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt-check` or `cargo make fmt-check -p patina_mtrr`" clear = true command = "cargo" -args = ["fmt", "--all", "--check"] +args = ["fmt", "@@split(FMT_ALL, )", "--check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.doc-test] -description = "Run documentation tests." +description = "Run documentation tests. Arguments are forwarded to `cargo test`." clear = true command = "cargo" -args = ["test", "--doc"] +args = ["test", "--doc", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.cspell] description = "Run cspell for spell checking." # npm install -g cspell@latest script = "cspell --quiet --no-progress --no-summary --dot --gitignore -e \"{.git/**,.github/**,.vscode/**}\" ." [tasks.deny] -description = "Run cargo deny." +description = "Run cargo deny. Arguments are forwarded to `cargo deny check`." install_crate = false clear = true command = "cargo" -args = ["deny", "check"] +args = ["deny", "check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.all-preflight] private = true run_task = [{ name = ["fmt-check", "deny", "cspell"], parallel = true }] [tasks.all] -description = "Run all tasks for PR readiness." +description = "Run all tasks for PR readiness. This task takes no arguments; any arguments given are forwarded to every sub-task." env = { CARGO_INCREMENTAL = "0" } run_task = { name = [ "all-preflight", diff --git a/.sync/rust/Makefiles/Makefile-patina-paging.toml b/.sync/rust/Makefiles/Makefile-patina-paging.toml index 740e03f..ca53ea2 100644 --- a/.sync/rust/Makefiles/Makefile-patina-paging.toml +++ b/.sync/rust/Makefiles/Makefile-patina-paging.toml @@ -113,45 +113,57 @@ end [tasks.build-x64] description = """Builds patina_paging crate as UEFI target. +Arguments are forwarded to `cargo build` unchanged, so any flag `cargo build` +accepts can be used. Note that `-p` before the task name selects the cargo-make +profile, while `-p` after the task name is passed to cargo as the package +selector. + Example: `cargo make build-x64` `cargo make -p release build-x64` + `cargo make build-x64 --features supervisor` """ clear = true command = "cargo" -args = ["build", "--target", "x86_64-unknown-uefi", "@@split(BUILD_FLAGS, )", "@@split(UEFI_CRATES, )"] +args = ["build", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--target", "x86_64-unknown-uefi", "@@split(BUILD_FLAGS, )", "@@split(UEFI_CRATES, )"] [tasks.build-aarch64] description = """Builds patina_paging crate as UEFI target. +Arguments are forwarded to `cargo build` unchanged, so any flag `cargo build` +accepts can be used. Note that `-p` before the task name selects the cargo-make +profile, while `-p` after the task name is passed to cargo as the package +selector. + Example: `cargo make build-aarch64` `cargo make -p release build-aarch64` + `cargo make build-aarch64 --features supervisor` """ clear = true command = "cargo" -args = ["build", "--target", "aarch64-unknown-uefi", "@@split(BUILD_FLAGS, )", "@@split(UEFI_CRATES, )"] +args = ["build", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--target", "aarch64-unknown-uefi", "@@split(BUILD_FLAGS, )", "@@split(UEFI_CRATES, )"] [tasks.check_code_x64] description = "Checks rust code for x64 build errors with results." private = true command = "cargo" -args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",] +args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )",] [tasks.check_code_aarch64] description = "Checks rust code for aarch64 build errors with results." private = true command = "cargo" -args = ["check", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",] +args = ["check", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )",] [tasks.check_tests] description = "Checks rust test code for build errors with results." private = true command = "cargo" -args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS, )",] +args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)",] [tasks.check] -description = "Checks rust code for errors. Example `cargo make check`" +description = "Checks rust code for errors. Arguments are forwarded to `cargo check`/`cargo nextest`. Example `cargo make check` or `cargo make check --features supervisor`" clear = true run_task = [{ name = ["check_code_x64", "check_code_aarch64", "check_tests"], parallel = true }] @@ -159,13 +171,13 @@ run_task = [{ name = ["check_code_x64", "check_code_aarch64", "check_tests"], pa description = "Checks rust code compiles without default features." private = true command = "cargo" -args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"] +args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.check-no-default-features-tests] description = "Checks rust test code compiles without default features." private = true command = "cargo" -args = ["nextest", "run", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"] +args = ["nextest", "run", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.check-no-default-features] description = "Checks rust code and tests compile without default features to catch feature-gate regressions." @@ -180,7 +192,7 @@ command = "cargo" args = ["llvm-cov", "clean", "--workspace"] [tasks.test] -description = "Runs tests via cargo-nextest. Example `cargo make test` or `cargo make test -- --nocapture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." +description = "Runs tests via cargo-nextest. Arguments are forwarded to `cargo nextest run`. Example `cargo make test` or `cargo make test --no-capture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." clear = true dependencies = ["test-default", "test-ci-features"] @@ -198,7 +210,7 @@ command = "cargo" args = ["nextest", "run", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.test-cov] -description = "Run tests and collect coverage data without generating reports." +description = "Run tests and collect coverage data without generating reports. Arguments are forwarded to `cargo llvm-cov nextest`." install_crate = false clear = true # `coverage_attribute` is deliberately excluded from the default allow-features in @@ -207,7 +219,7 @@ clear = true # Note: RUSTFLAGS replaces build.rustflags. env = { RUSTFLAGS = "-Z allow-features=c_variadic,allocator_api,coverage_attribute" } command = "cargo" -args = ["llvm-cov", "@@split(COV_FLAGS, )", "--no-report", "nextest"] +args = ["llvm-cov", "@@split(COV_FLAGS, )", "--no-report", "nextest", "@@split(CARGO_MAKE_TASK_ARGS,;)"] dependencies = ["llvm-cov-clean"] [tasks.coverage-lcov] @@ -225,7 +237,7 @@ command = "cargo" args = ["llvm-cov", "report", "--html", "--output-dir", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/coverage"] [tasks.coverage] -description = "Build and run all tests and calculate coverage (runs test once and generates LCOV and HTML reports). In CI, also runs a second pass with the `ci_features` feature enabled (outside of coverage collection) since only `cargo make coverage` is run in CI." +description = "Build and run all tests and calculate coverage (runs test once and generates LCOV and HTML reports). Arguments are forwarded to `cargo llvm-cov nextest`. Example `cargo make coverage --lib`. In CI, also runs a second pass with the `ci_features` feature enabled (outside of coverage collection) since only `cargo make coverage` is run in CI." dependencies = ["test-cov", "coverage-lcov", "coverage-html", "test-ci-features"] clear = true @@ -284,7 +296,7 @@ exec --fail-on-error cargo test --doc --target ${target} --workspace ''' [tasks.clippy] -description = "Run cargo clippy for the host target and both UEFI cross-compilation targets." +description = "Run cargo clippy for the host target and both UEFI cross-compilation targets. Arguments are forwarded to `cargo clippy`." clear = true run_task = [{ name = ["clippy-x64", "clippy-aarch64", "clippy-std"], parallel = true }] @@ -292,67 +304,84 @@ run_task = [{ name = ["clippy-x64", "clippy-aarch64", "clippy-std"], parallel = description = "Run cargo clippy for x86_64-unknown-uefi." private = true command = "cargo" -args = ["clippy", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] [tasks.clippy-aarch64] description = "Run cargo clippy for aarch64-unknown-uefi." private = true command = "cargo" -args = ["clippy", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] [tasks.clippy-std] description = "Run cargo clippy for std." private = true command = "cargo" -args = ["clippy", "--all-targets", "--all-features", "--", "-D", "warnings"] +args = ["clippy", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--", "-D", "warnings"] [tasks.doc] env = { RUSTDOCFLAGS = "-D warnings"} -description = "Builds all rust documentation in the workspace. Example `cargo make doc`" +description = "Builds all rust documentation in the workspace. Arguments are forwarded to `cargo doc`. Example `cargo make doc` or `cargo make doc --all-features`" command = "cargo" -args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--no-deps"] +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--no-deps"] [tasks.doc-open] env = { RUSTDOCFLAGS = "-D warnings"} -description = "Builds all rust documentation in the workspace and opens the documentation Example `cargo make doc-open`" +description = "Builds all rust documentation in the workspace and opens the documentation. Arguments are forwarded to `cargo doc`. Example `cargo make doc-open`" command = "cargo" -args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--open"] +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--open"] + +[tasks.fmt-all-flag] +description = """Sets `FMT_ALL` to `--all` only when no arguments were given on the command line. +`--all` overrides `-p`, so it is dropped whenever any argument is given (for example +`cargo make fmt -p patina_paging`).""" +private = true +script_runner = "@duckscript" +script = ''' +args = get_env CARGO_MAKE_TASK_ARGS +if is_empty ${args} + set_env FMT_ALL "--all" +else + set_env FMT_ALL "" +end +''' [tasks.fmt] -description = "Run cargo format." +description = "Run cargo format. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt` or `cargo make fmt --check`" clear = true command = "cargo" -args = ["fmt", "--all"] +args = ["fmt", "@@split(FMT_ALL, )", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.fmt-check] -description = "Check cargo format without modifying files." +description = "Check cargo format without modifying files. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt-check`" clear = true command = "cargo" -args = ["fmt", "--all", "--check"] +args = ["fmt", "@@split(FMT_ALL, )", "--check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.doc-test] -description = "Run documentation tests." +description = "Run documentation tests. Arguments are forwarded to `cargo test`." clear = true command = "cargo" -args = ["test", "--doc"] +args = ["test", "--doc", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.cspell] description = "Run cspell for spell checking." # npm install -g cspell@latest script = "cspell --quiet --no-progress --no-summary --dot --gitignore -e \"{.git/**,.github/**,.vscode/**}\" ." [tasks.deny] -description = "Run cargo deny." +description = "Run cargo deny. Arguments are forwarded to `cargo deny check`." install_crate = false clear = true command = "cargo" -args = ["deny", "check"] +args = ["deny", "check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.all-preflight] private = true run_task = [{ name = ["fmt-check", "deny", "cspell"], parallel = true }] [tasks.all] -description = "Run all tasks for PR readiness." +description = "Run all tasks for PR readiness. This task takes no arguments; any arguments given are forwarded to every sub-task." env = { CARGO_INCREMENTAL = "0" } run_task = { name = [ "all-preflight", diff --git a/.sync/rust/Makefiles/Makefile-patina-readiness-tool.toml b/.sync/rust/Makefiles/Makefile-patina-readiness-tool.toml index 7d5731c..11b680f 100644 --- a/.sync/rust/Makefiles/Makefile-patina-readiness-tool.toml +++ b/.sync/rust/Makefiles/Makefile-patina-readiness-tool.toml @@ -16,10 +16,9 @@ X86_64_STD_LINUX_TARGET = "--target x86_64-unknown-linux-gnu" AARCH64_UEFI_TARGET = "--target aarch64-unknown-uefi" X86_64_UEFI_TARGET = "--target x86_64-unknown-uefi" -NO_STD_FLAGS = "--timings" -DXE_READINESS_PKG = "-p dxe_readiness_capture" -CAPTURE_BIN_FLAGS = "${NO_STD_FLAGS} ${DXE_READINESS_PKG}" -CAPTURE_UEFI_SHELL_FLAGS = "${DXE_READINESS_PKG} --features uefishell --bin uefishell_dxe_readiness_capture" +# Every cargo backed task forwards its arguments to the underlying cargo command with +# `@@split(CARGO_MAKE_TASK_ARGS,;)`. cargo-make joins task arguments into CARGO_MAKE_TASK_ARGS +# separated by a semicolon, so the separator must be `;` and not a space. # Selects the nextest `ci` profile (defined in .config/nextest.toml) automatically when the `CI` # variable is set (e.g. GitHub Actions sets this for every job). # `NEXTEST_PROFILE` is read natively by `cargo nextest run` and by `cargo llvm-cov ... nextest`. @@ -109,77 +108,77 @@ end # DXE Readiness Capture UEFI binaries to run from UEFI Shell. [tasks.build-x64-uefishell] -description = "Builds the DXE Readiness Capture UEFI binary to run in UEFI Shell." +description = "Builds the DXE Readiness Capture UEFI binary to run in UEFI Shell. Arguments are forwarded to `cargo build`." env = { RUSTFLAGS = "-C force-unwind-tables -C link-arg=/base:0x0 -C link-arg=/subsystem:efi_application -C link-arg=/PDBALTPATH:uefishell_dxe_readiness_capture.pdb" } command = "cargo" -args = [ "build", "@@split(CAPTURE_UEFI_SHELL_FLAGS, )", "@@split(X86_64_UEFI_TARGET, )", "${@}", ] +args = [ "build", "-p", "dxe_readiness_capture", "--features", "uefishell", "--bin", "uefishell_dxe_readiness_capture", "@@split(X86_64_UEFI_TARGET, )", "@@split(CARGO_MAKE_TASK_ARGS,;)", ] [tasks.build-aarch64-uefishell] -description = "Builds the DXE Readiness Capture UEFI binary to run in UEFI Shell." +description = "Builds the DXE Readiness Capture UEFI binary to run in UEFI Shell. Arguments are forwarded to `cargo build`." env = { RUSTFLAGS = "-C force-unwind-tables -C link-arg=/base:0x0 -C link-arg=/subsystem:efi_application -C link-arg=/PDBALTPATH:uefishell_dxe_readiness_capture.pdb" } command = "cargo" -args = [ "build", "@@split(CAPTURE_UEFI_SHELL_FLAGS, )", "@@split(AARCH64_UEFI_TARGET, )", "${@}", ] +args = [ "build", "-p", "dxe_readiness_capture", "--features", "uefishell", "--bin", "uefishell_dxe_readiness_capture", "@@split(AARCH64_UEFI_TARGET, )", "@@split(CARGO_MAKE_TASK_ARGS,;)", ] # Right now, both Intel Lunar Lake and Panther Lake can use the same binary. # They are available as separate commands, so they can implement different behavior # in the future if needed without impacting callers. [tasks.build-intel-common] -description = "Builds the Intel DXE Readiness Capture UEFI binary." +description = "Builds the Intel DXE Readiness Capture UEFI binary. Arguments are forwarded to `cargo build`." private = true env = { RUSTFLAGS = "-C force-unwind-tables -C link-arg=/base:0x0 -C link-arg=/subsystem:efi_boot_service_driver -C link-arg=/PDBALTPATH:intel_dxe_readiness_capture.pdb" } command = "cargo" -args = ["build", "@@split(CAPTURE_BIN_FLAGS, )", "@@split(X86_64_UEFI_TARGET, )", "--bin", "intel_dxe_readiness_capture", "${@}"] +args = ["build", "--timings", "-p", "dxe_readiness_capture", "@@split(X86_64_UEFI_TARGET, )", "--bin", "intel_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)"] # Builds EFI binaries for virtual platform (QEMU). [tasks.build-x64-uefi] -description = "Builds the x64 DXE Readiness Capture UEFI binary." +description = "Builds the x64 DXE Readiness Capture UEFI binary. Arguments are forwarded to `cargo build`." env = { RUSTFLAGS = "-C force-unwind-tables -C link-arg=/base:0x0 -C link-arg=/subsystem:efi_boot_service_driver -C link-arg=/PDBALTPATH:qemu_dxe_readiness_capture.pdb" } command = "cargo" -args = ["build", "@@split(CAPTURE_BIN_FLAGS, )", "@@split(X86_64_UEFI_TARGET, )", "--bin", "qemu_dxe_readiness_capture", "${@}"] +args = ["build", "--timings", "-p", "dxe_readiness_capture", "@@split(X86_64_UEFI_TARGET, )", "--bin", "qemu_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.build-aarch64-uefi] -description = "Builds the aarch64 DXE Readiness Capture UEFI binary." +description = "Builds the aarch64 DXE Readiness Capture UEFI binary. Arguments are forwarded to `cargo build`." env = { RUSTFLAGS = "-C force-unwind-tables -C link-arg=/base:0x0 -C link-arg=/subsystem:efi_boot_service_driver -C link-arg=/PDBALTPATH:qemu_dxe_readiness_capture.pdb" } command = "cargo" -args = ["build", "@@split(CAPTURE_BIN_FLAGS, )", "@@split(AARCH64_UEFI_TARGET, )", "--bin", "qemu_dxe_readiness_capture", "${@}"] +args = ["build", "--timings", "-p", "dxe_readiness_capture", "@@split(AARCH64_UEFI_TARGET, )", "--bin", "qemu_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.build-aarch64-arm-virt-uefi] -description = "Builds the aarch64 QEMU arm-virt DXE Readiness Capture UEFI binary." +description = "Builds the aarch64 QEMU arm-virt DXE Readiness Capture UEFI binary. Arguments are forwarded to `cargo build`." env = { RUSTFLAGS = "-C force-unwind-tables -C link-arg=/base:0x0 -C link-arg=/subsystem:efi_boot_service_driver -C link-arg=/PDBALTPATH:arm_virt_dxe_readiness_capture.pdb" } command = "cargo" -args = ["build", "@@split(CAPTURE_BIN_FLAGS, )", "@@split(AARCH64_UEFI_TARGET, )", "--bin", "arm_virt_dxe_readiness_capture", "${@}"] +args = ["build", "--timings", "-p", "dxe_readiness_capture", "@@split(AARCH64_UEFI_TARGET, )", "--bin", "arm_virt_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)"] # Builds Validation binary for the host platform. [tasks.build-validation-binary-windows-x64] -description = "Builds the Windows x64 DXE Readiness Validation binary." +description = "Builds the Windows x64 DXE Readiness Validation binary. Arguments are forwarded to `cargo build`." env = { RUSTFLAGS = "" } # Env variables are not cleaned up after execution, meaning that tasks following the executed task will inherit the variables set by the previous task. condition = { platforms = ["windows"]} command = "cargo" -args = [ "build", "-p", "dxe_readiness_validator", "@@split(X86_64_STD_WINDOWS_TARGET, )", "${@}", ] +args = [ "build", "-p", "dxe_readiness_validator", "@@split(X86_64_STD_WINDOWS_TARGET, )", "@@split(CARGO_MAKE_TASK_ARGS,;)", ] [tasks.build-validation-binary-windows-aarch64] -description = "Builds the Windows aarch64 DXE Readiness Validation binary." +description = "Builds the Windows aarch64 DXE Readiness Validation binary. Arguments are forwarded to `cargo build`." env = { RUSTFLAGS = "" } # Env variables are not cleaned up after execution, meaning that tasks following the executed task will inherit the variables set by the previous task. condition = { platforms = ["windows"]} command = "cargo" -args = [ "build", "-p", "dxe_readiness_validator", "@@split(AARCH64_STD_WINDOWS_TARGET, )", "${@}", ] +args = [ "build", "-p", "dxe_readiness_validator", "@@split(AARCH64_STD_WINDOWS_TARGET, )", "@@split(CARGO_MAKE_TASK_ARGS,;)", ] [tasks.build-validation-binary-linux-x64] -description = "Builds the Linux x64 DXE Readiness Validation binary." +description = "Builds the Linux x64 DXE Readiness Validation binary. Arguments are forwarded to `cargo build`." env = { RUSTFLAGS = "" } # Env variables are not cleaned up after execution, meaning that tasks following the executed task will inherit the variables set by the previous task. condition = { platforms = ["linux"], env = { CARGO_MAKE_RUST_TARGET_ARCH = "x86_64" }} command = "cargo" -args = [ "build", "-p", "dxe_readiness_validator", "@@split(X86_64_STD_LINUX_TARGET, )", "${@}", ] +args = [ "build", "-p", "dxe_readiness_validator", "@@split(X86_64_STD_LINUX_TARGET, )", "@@split(CARGO_MAKE_TASK_ARGS,;)", ] [tasks.build-validation-binary-linux-aarch64] -description = "Builds the Linux aarch64 DXE Readiness Validation binary." +description = "Builds the Linux aarch64 DXE Readiness Validation binary. Arguments are forwarded to `cargo build`." env = { RUSTFLAGS = "" } # Env variables are not cleaned up after execution, meaning that tasks following the executed task will inherit the variables set by the previous task. condition = { platforms = ["linux"], env = { CARGO_MAKE_RUST_TARGET_ARCH = "aarch64" }} command = "cargo" -args = [ "build", "-p", "dxe_readiness_validator", "@@split(AARCH64_STD_LINUX_TARGET, )", "${@}", ] +args = [ "build", "-p", "dxe_readiness_validator", "@@split(AARCH64_STD_LINUX_TARGET, )", "@@split(CARGO_MAKE_TASK_ARGS,;)", ] [tasks.build] -description = "Build all binaries." +description = "Build all binaries. Arguments are forwarded to each underlying `cargo build`. Example `cargo make build` or `cargo make build --release`" clear = true dependencies = [ "build-x64-uefishell", @@ -196,12 +195,12 @@ dependencies = [ # Run validator binary for all supported targets. [tasks.run-validator] -description = "Run the DXE Readiness Validation binary." +description = "Run the DXE Readiness Validation binary. Arguments are forwarded to `cargo run`." command = "cargo" -args = ["run", "-p", "dxe_readiness_validator", "${@}"] +args = ["run", "-p", "dxe_readiness_validator", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.run] -description = "Run validator binary." +description = "Run validator binary. Arguments are forwarded to `cargo run`. Example `cargo make run -- -f capture.json`" clear = true dependencies = ["run-validator"] @@ -212,8 +211,23 @@ install_crate = false command = "cargo" args = ["llvm-cov", "clean", "--workspace"] +[tasks.cov-workspace-flag] +description = """Sets `COV_WORKSPACE` to `--workspace` only when no arguments were given on the +command line. `--workspace` overrides `-p`, so it is dropped whenever any argument is given +(for example `cargo make coverage -p dxe_readiness_validator`).""" +private = true +script_runner = "@duckscript" +script = ''' +args = get_env CARGO_MAKE_TASK_ARGS +if is_empty ${args} + set_env COV_WORKSPACE "--workspace" +else + set_env COV_WORKSPACE "" +end +''' + [tasks.coverage-test] -description = "Run tests and collect coverage data without generating reports." +description = "Run tests and collect coverage data without generating reports. Arguments are forwarded to `cargo llvm-cov nextest`." install_crate = false clear = true # `coverage_attribute` is deliberately excluded from the default allow-features in @@ -225,14 +239,16 @@ command = "cargo" # Note: `--profile test` has been set here in the past. Cargo already defaults to test builds # with the test profile, so it is removed. cargo-llvm-cov will forward it to `cargo nextest run` # where `--profile` is used to incorrectly select a nextest config profile (not a Cargo build profile). -args = ["llvm-cov", "--ignore-filename-regex", ".*test.*", "--no-report", "nextest", "-p", "dxe_readiness_capture", "-p", "dxe_readiness_validator"] -dependencies = ["llvm-cov-clean"] +args = ["llvm-cov", "@@split(COV_WORKSPACE, )", "--ignore-filename-regex", ".*test.*", "--no-report", "nextest", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["cov-workspace-flag", "llvm-cov-clean"] [tasks.coverage-lcov] description = "Generate an LCOV coverage report from collected data." install_crate = false clear = true command = "cargo" +# Arguments are deliberately not forwarded here. `cargo llvm-cov report` rejects the package +# selectors that the parent `coverage` task forwards to `coverage-test`. args = ["llvm-cov", "report", "--lcov", "--output-path", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/lcov.info"] [tasks.coverage-html] @@ -240,15 +256,16 @@ description = "Generate an HTML coverage report from collected data." install_crate = false clear = true command = "cargo" +# Arguments are deliberately not forwarded here. See the note on `coverage-lcov`. args = ["llvm-cov", "report", "--html", "--output-dir", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/coverage"] [tasks.coverage] -description = "Build and run all tests and calculate coverage (runs test once and generates LCOV and HTML reports). In CI, also runs a second pass with the `ci_features` feature enabled (outside of coverage collection) since only `cargo make coverage` is run in CI." +description = "Build and run all tests and calculate coverage (runs test once and generates LCOV and HTML reports). Arguments are forwarded to `cargo llvm-cov nextest`. Example `cargo make coverage` or `cargo make coverage -p dxe_readiness_validator`. In CI, also runs a second pass with the `ci_features` feature enabled (outside of coverage collection) since only `cargo make coverage` is run in CI." dependencies = ["coverage-test", "coverage-lcov", "coverage-html", "test-ci-features"] clear = true [tasks.test] -description = "Runs tests via cargo-nextest. Example `cargo make test` or `cargo make test -p dxe_readiness_validator -- --nocapture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." +description = "Runs tests via cargo-nextest. Arguments are forwarded to `cargo nextest run`. Example `cargo make test` or `cargo make test -p dxe_readiness_validator --no-capture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." clear = true dependencies = ["test-default", "test-ci-features"] @@ -320,7 +337,7 @@ exec --fail-on-error cargo test --doc --target ${target} --workspace ''' [tasks.clippy] -description = "Run cargo clippy for the host target and both UEFI cross-compilation targets." +description = "Run cargo clippy for the host target and both UEFI cross-compilation targets. Arguments are forwarded to `cargo clippy`. The UEFI runs are pinned to `dxe_readiness_capture` and its per target binaries, so a `-p` of your own will conflict with them. Example `cargo make clippy` or `cargo make clippy --release`" clear = true run_task = [{ name = ["clippy-x64", "clippy-aarch64", "clippy-std"], parallel = true }] @@ -333,13 +350,13 @@ run_task = [{ name = ["clippy-x64-core", "clippy-x64-uefishell"] }] description = "Run cargo clippy for x86_64-unknown-uefi core binaries." private = true command = "cargo" -args = ["clippy", "@@split(DXE_READINESS_PKG, )", "--target", "x86_64-unknown-uefi", "--lib", "--bin", "intel_dxe_readiness_capture", "--bin", "qemu_dxe_readiness_capture", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "-p", "dxe_readiness_capture", "--target", "x86_64-unknown-uefi", "--lib", "--bin", "intel_dxe_readiness_capture", "--bin", "qemu_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--timings", "--", "-D", "warnings"] [tasks.clippy-x64-uefishell] description = "Run cargo clippy for x86_64-unknown-uefi uefishell binary." private = true command = "cargo" -args = ["clippy", "@@split(DXE_READINESS_PKG, )", "--target", "x86_64-unknown-uefi", "--features", "uefishell", "--bin", "uefishell_dxe_readiness_capture", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "-p", "dxe_readiness_capture", "--target", "x86_64-unknown-uefi", "--features", "uefishell", "--bin", "uefishell_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--timings", "--", "-D", "warnings"] [tasks.clippy-aarch64] description = "Run cargo clippy for aarch64-unknown-uefi." @@ -350,77 +367,128 @@ run_task = [{ name = ["clippy-aarch64-core", "clippy-aarch64-uefishell"] }] description = "Run cargo clippy for aarch64-unknown-uefi core binaries." private = true command = "cargo" -args = ["clippy", "@@split(DXE_READINESS_PKG, )", "--target", "aarch64-unknown-uefi", "--lib", "--bin", "qemu_dxe_readiness_capture", "--bin", "arm_virt_dxe_readiness_capture", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "-p", "dxe_readiness_capture", "--target", "aarch64-unknown-uefi", "--lib", "--bin", "qemu_dxe_readiness_capture", "--bin", "arm_virt_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--timings", "--", "-D", "warnings"] [tasks.clippy-aarch64-uefishell] description = "Run cargo clippy for aarch64-unknown-uefi uefishell binary." private = true command = "cargo" -args = ["clippy", "@@split(DXE_READINESS_PKG, )", "--target", "aarch64-unknown-uefi", "--features", "uefishell", "--bin", "uefishell_dxe_readiness_capture", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "-p", "dxe_readiness_capture", "--target", "aarch64-unknown-uefi", "--features", "uefishell", "--bin", "uefishell_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--timings", "--", "-D", "warnings"] [tasks.clippy-std] description = "Run cargo clippy for the host target (library and tests only)." private = true command = "cargo" -args = ["clippy", "--tests", "--", "-D", "warnings"] +args = ["clippy", "--tests", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--", "-D", "warnings"] +# The UEFI check tasks mirror the clippy tasks above. Only `dxe_readiness_capture` builds for the +# UEFI targets, and its binaries have to be named one by one, because `arm_virt_dxe_readiness_capture` +# is aarch64 only and `uefishell_dxe_readiness_capture` needs the `uefishell` feature. Checking the +# whole workspace for a UEFI target instead fails to compile the host only validator dependencies. [tasks.check_code_x64] description = "Checks rust code for x64 build errors with results." private = true +run_task = [{ name = ["check_code_x64_core", "check_code_x64_uefishell"] }] + +[tasks.check_code_x64_core] +description = "Checks x86_64-unknown-uefi core binaries for build errors." +private = true +command = "cargo" +args = ["check", "-p", "dxe_readiness_capture", "--target", "x86_64-unknown-uefi", "--features", "dxe_readiness_capture/ci_features", "--lib", "--bin", "intel_dxe_readiness_capture", "--bin", "qemu_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--timings",] + +[tasks.check_code_x64_uefishell] +description = "Checks the x86_64-unknown-uefi uefishell binary for build errors." +private = true command = "cargo" -args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",] +args = ["check", "-p", "dxe_readiness_capture", "--target", "x86_64-unknown-uefi", "--features", "uefishell", "--bin", "uefishell_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--timings",] [tasks.check_code_aarch64] description = "Checks rust code for aarch64 build errors with results." private = true +run_task = [{ name = ["check_code_aarch64_core", "check_code_aarch64_uefishell"] }] + +[tasks.check_code_aarch64_core] +description = "Checks aarch64-unknown-uefi core binaries for build errors." +private = true command = "cargo" -args = ["check", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",] +args = ["check", "-p", "dxe_readiness_capture", "--target", "aarch64-unknown-uefi", "--features", "dxe_readiness_capture/ci_features", "--lib", "--bin", "qemu_dxe_readiness_capture", "--bin", "arm_virt_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--timings",] + +[tasks.check_code_aarch64_uefishell] +description = "Checks the aarch64-unknown-uefi uefishell binary for build errors." +private = true +command = "cargo" +args = ["check", "-p", "dxe_readiness_capture", "--target", "aarch64-unknown-uefi", "--features", "uefishell", "--bin", "uefishell_dxe_readiness_capture", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--timings",] [tasks.check_tests] description = "Checks rust test code for build errors with results." private = true command = "cargo" -args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS, )",] +args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)",] [tasks.check] -description = "Checks rust code for errors. Example `cargo make check`" +description = "Checks rust code for errors. Arguments are forwarded to `cargo check`/`cargo nextest`. The UEFI checks are pinned to `dxe_readiness_capture` and its per target binaries, so a `-p` of your own will conflict with them. Example `cargo make check` or `cargo make check --release`" clear = true run_task = [{ name = ["check_code_x64", "check_code_aarch64", "check_tests"], parallel = true }] [tasks.doc] env = { RUSTDOCFLAGS = "-D warnings" } -description = "Builds all rust documentation in the workspace. Example `cargo make doc`" +description = "Builds all rust documentation in the workspace. Arguments are forwarded to `cargo doc`. Example `cargo make doc` or `cargo make doc -p dxe_readiness_validator`" +clear = true +command = "cargo" +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--no-deps"] + +[tasks.doc-open] +env = { RUSTDOCFLAGS = "-D warnings" } +description = "Builds all rust documentation in the workspace and opens the documentation. Arguments are forwarded to `cargo doc`. Example `cargo make doc-open` or `cargo make doc-open -p dxe_readiness_validator`" +clear = true command = "cargo" -args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--open", "--no-deps"] +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--no-deps", "--open"] + +[tasks.fmt-all-flag] +description = """Sets `FMT_ALL` to `--all` only when no arguments were given on the command line. +`--all` overrides `-p`, so it is dropped whenever any argument is given (for example +`cargo make fmt -p dxe_readiness_validator`).""" +private = true +script_runner = "@duckscript" +script = ''' +args = get_env CARGO_MAKE_TASK_ARGS +if is_empty ${args} + set_env FMT_ALL "--all" +else + set_env FMT_ALL "" +end +''' [tasks.fmt] -description = "Run cargo format." +description = "Run cargo format. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt` or `cargo make fmt -p dxe_readiness_validator`" clear = true command = "cargo" -args = ["fmt", "--all"] +args = ["fmt", "@@split(FMT_ALL, )", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.fmt-check] -description = "Check cargo format without modifying files." +description = "Check cargo format without modifying files. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt-check` or `cargo make fmt-check -p dxe_readiness_validator`" clear = true command = "cargo" -args = ["fmt", "--all", "--check"] +args = ["fmt", "@@split(FMT_ALL, )", "--check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.doc-test] -description = "Run documentation tests." +description = "Run documentation tests. Arguments are forwarded to `cargo test`." clear = true command = "cargo" -args = ["test", "--doc"] +args = ["test", "--doc", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.cspell] description = "Run cspell for spell checking." # npm install -g cspell@latest script = "cspell --quiet --no-progress --no-summary --dot --gitignore -e \"{.git/**,.github/**,.vscode/**,.azurepipelines/**,dxe_readiness_validator/src/tests/data/*.json}\" ." [tasks.deny] -description = "Run cargo deny." +description = "Run cargo deny. Arguments are forwarded to `cargo deny check`." install_crate = false clear = true command = "cargo" -args = ["deny", "check"] +args = ["deny", "check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.all-preflight] private = true diff --git a/.sync/rust/Makefiles/Makefile-patina.toml b/.sync/rust/Makefiles/Makefile-patina.toml index f87dda9..0b7b31d 100644 --- a/.sync/rust/Makefiles/Makefile-patina.toml +++ b/.sync/rust/Makefiles/Makefile-patina.toml @@ -13,7 +13,10 @@ STD_FLAGS = "--profile ${RUSTC_PROFILE} --features std" # Note: `--profile test` has been set here in the past. Cargo already defaults to test builds # with the test profile, so it is removed. cargo-llvm-cov will forward it to `cargo nextest run` # where `--profile` is used to incorrectly select a nextest config profile (not a Cargo build profile). -COV_FLAGS = { value = "--workspace --ignore-filename-regex .*test.*", condition = { env_not_set = ["COV_FLAGS"] } } +# `--workspace` is intentionally not part of this value. It is supplied separately by the +# `cov-workspace-flag` task, which omits it when the command line provides arguments, because +# `--workspace` overrides `-p`. +COV_FLAGS = { value = "--ignore-filename-regex .*test.*", condition = { env_not_set = ["COV_FLAGS"] } } RUSTDOCFLAGS = "-D warnings -D missing_docs" # Selects the nextest `ci` profile (defined in .config/nextest.toml) automatically when the `CI` # variable is set (e.g. GitHub Actions sets this for every job). @@ -108,31 +111,12 @@ for line in ${lines} end ''' -[tasks.individual-package-targets] -script_runner = "@duckscript" -script = ''' -args = get_env CARGO_MAKE_TASK_ARGS - -if is_empty ${args} - exit -end - -1 = array "" -2 = split ${args} , -3 = array_concat ${1} ${2} -joined_args = array_join ${3} " -p " -release ${1} -release ${2} -release ${3} - -joined_args = trim ${joined_args} -set_env INDIVIDUAL_PACKAGE_TARGETS ${joined_args} -release ${joined_args} -''' - [tasks.build] description = """Builds a single rust package with the standard library. +Arguments are forwarded to `cargo build` unchanged, so any flag `cargo build` +accepts can be used. + Customizations: -p [development|release]: Builds in debug or release. Default: development -e FEATURES=[feature,...]: Builds with the specified features. Default: none @@ -140,6 +124,7 @@ Customizations: Example: `cargo make build` `cargo make -p release build` + `cargo make build -p patina` `cargo make -e FEATURES=feature1,feature2 build` """ alias = "build-std" @@ -147,6 +132,9 @@ alias = "build-std" [tasks.build-std] description = """Builds crates in the repository with the standard library, and their examples. +Arguments are forwarded to `cargo build` unchanged, so any flag `cargo build` +accepts can be used. + Customizations: -p [development|release]: Builds in debug or release. Default: development -e FEATURES=[feature,...]: Builds with the specified features. Default: none @@ -154,15 +142,19 @@ Customizations: Example: `cargo make build-std` `cargo make -p release build-std` - `cargo make build-std ` + `cargo make build-std -p patina -p patina_dxe_core` """ clear = true command = "cargo" -args = ["build", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "@@split(STD_FLAGS, )", "--examples"] -dependencies = ["individual-package-targets", "build-lib"] +args = ["build", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(STD_FLAGS, )", "--examples"] +dependencies = ["build-lib"] [tasks.build-lib] description = """Builds crates in the repository with the standard library. + +Arguments are forwarded to `cargo build` unchanged, so any flag `cargo build` +accepts can be used. + Customizations: -p [development|release]: Builds in debug or release. Default: development -e FEATURES=[feature,...]: Builds with the specified features. Default: none @@ -170,42 +162,41 @@ Customizations: Example: `cargo make build-lib` `cargo make -p release build-lib` - `cargo make build-lib ` + `cargo make build-lib -p patina` """ clear = true command = "cargo" -args = ["build", "--all-features", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "@@split(STD_FLAGS, )"] -dependencies = ["individual-package-targets"] +args = ["build", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(STD_FLAGS, )"] [tasks.check_code_x64] description = "Checks rust code for x64 build errors with results." private = true command = "cargo" -args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",] +args = ["check", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )",] [tasks.check_code_aarch64] description = "Checks rust code for aarch64 build errors with results." private = true command = "cargo" -args = ["check", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS, )", "@@split(NO_STD_FLAGS, )",] +args = ["check", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )",] [tasks.check_tests] description = "Checks rust test code for build errors with results." private = true command = "cargo" -args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS, )"] +args = ["nextest", "run", "--no-run", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.check-no-default-features-code] description = "Checks rust code compiles without default features." private = true command = "cargo" -args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"] +args = ["check", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.check-no-default-features-tests] description = "Checks rust test code compiles without default features." private = true command = "cargo" -args = ["nextest", "run", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS, )"] +args = ["nextest", "run", "--no-run", "--no-default-features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.check-no-default-features] description = "Checks rust code and tests compile without default features to catch feature-gate regressions." @@ -213,16 +204,20 @@ clear = true run_task = [{ name = ["check-no-default-features-code", "check-no-default-features-tests"], parallel = true }] [tasks.check] -description = "Checks rust code for errors. Example `cargo make check`" +description = "Checks rust code for errors. Arguments are forwarded to `cargo check`/`cargo nextest`. Example `cargo make check` or `cargo make check -p patina`" clear = true run_task = [{ name = ["check_code_x64", "check_code_aarch64", "check_tests"], parallel = true }] [tasks.patina-test] -description = "Builds crates with Patina tests enabled. Example `cargo make patina-test`" +# The feature is selected as `patina_test/test-runner` rather than a bare `test-runner`. A bare +# feature name must be declared by every selected package, so `-p ` failed for every crate +# except `patina_test` itself. The `/` form only requires `patina_test` to be in +# the dependency graph of the selected packages, which is already true for any crate that writes +# `#[patina_test]` tests. +description = "Builds crates with Patina tests enabled. Arguments are forwarded to `cargo build`. Example `cargo make patina-test` or `cargo make patina-test -p patina_dxe_core`" clear = true command = "cargo" -args = ["build", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "@@split(STD_FLAGS, )", "--features", "test-runner"] -dependencies = ["individual-package-targets"] +args = ["build", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(STD_FLAGS, )", "--features", "patina_test/test-runner"] [tasks.generate-lockfile] description = "Generate Cargo.lock file." @@ -238,7 +233,7 @@ command = "cargo" args = ["llvm-cov", "clean", "--workspace"] [tasks.test] -description = "Runs tests via cargo-nextest. Example `cargo make test` or `cargo make test -p package_name -- --nocapture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." +description = "Runs tests via cargo-nextest. Arguments are forwarded to `cargo nextest run`. Example `cargo make test` or `cargo make test -p patina --no-capture`. In CI, also runs a second pass with the `ci_features` feature enabled to ensure tests do not depend on it being enabled." clear = true dependencies = ["test-default", "test-ci-features"] @@ -256,13 +251,28 @@ command = "cargo" args = ["nextest", "run", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.test-ignored] -description = "Runs ignored tests with native cargo test behavior. Example `cargo make test-ignored` or `cargo make test-ignored -p package_name" +description = "Runs ignored tests with native cargo test behavior. Arguments are forwarded to `cargo test`. Example `cargo make test-ignored` or `cargo make test-ignored -p patina`" clear = true command = "cargo" -args = ["test", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--lib", "--tests", "--examples", "--", "--ignored"] +args = ["test", "--lib", "--tests", "--examples", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--", "--ignored"] + +[tasks.cov-workspace-flag] +description = """Sets `COV_WORKSPACE` to `--workspace` only when no arguments were given on the +command line. `--workspace` overrides `-p`, so it is dropped whenever any argument is given +(for example `cargo make coverage -p patina`).""" +private = true +script_runner = "@duckscript" +script = ''' +args = get_env CARGO_MAKE_TASK_ARGS +if is_empty ${args} + set_env COV_WORKSPACE "--workspace" +else + set_env COV_WORKSPACE "" +end +''' [tasks.test-cov] -description = "Run tests and collect coverage data without generating reports." +description = "Run tests and collect coverage data without generating reports. Arguments are forwarded to `cargo llvm-cov nextest`." install_crate = false clear = true # `coverage_attribute` is deliberately excluded from the default allow-features in @@ -283,11 +293,11 @@ if eq ${target} "aarch64-pc-windows-msvc" end '''] command = "cargo" -args = ["llvm-cov", "@@split(COV_FLAGS, )", "--no-report", "nextest"] -dependencies = ["individual-package-targets", "llvm-cov-clean"] +args = ["llvm-cov", "@@split(COV_WORKSPACE, )", "@@split(COV_FLAGS, )", "--no-report", "nextest", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["cov-workspace-flag", "llvm-cov-clean"] [tasks.test-cov-fallback] -description = "Runs tests without coverage instrumentation on hosts where test-cov is skipped (currently just aarch64-pc-windows-msvc)." +description = "Runs tests without coverage instrumentation on hosts where test-cov is skipped (currently just aarch64-pc-windows-msvc). Arguments are forwarded to `cargo nextest run`." clear = true script_runner = "@duckscript" condition_script = [''' @@ -297,8 +307,7 @@ if not eq ${target} "aarch64-pc-windows-msvc" end '''] command = "cargo" -args = ["nextest", "run"] -dependencies = ["individual-package-targets"] +args = ["nextest", "run", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.test-asan] description = "Run tests with AddressSanitizer enabled. Example `cargo make test-asan`. Use `cargo make test-asan --print-dll-path` to print the ASan runtime DLL directory." @@ -393,23 +402,21 @@ command = "cargo" args = ["llvm-cov", "report", "--html", "--output-dir", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/coverage"] [tasks.coverage] -description = "Build and run all tests and calculate coverage (runs test once and generates LCOV and HTML reports). In CI, also runs a second pass with the `ci_features` feature enabled (outside of coverage collection) since only `cargo make coverage` is run in CI." +description = "Build and run all tests and calculate coverage (runs test once and generates LCOV and HTML reports). Arguments are forwarded to `cargo llvm-cov nextest`. Example `cargo make coverage -p patina`. In CI, also runs a second pass with the `ci_features` feature enabled (outside of coverage collection) since only `cargo make coverage` is run in CI." dependencies = ["test-cov", "test-cov-fallback", "coverage-lcov", "coverage-html", "test-ci-features"] clear = true [tasks.build-aarch64] -description = "Builds crates in the repository for AARCH64" +description = "Builds crates in the repository for AARCH64. Arguments are forwarded to `cargo build`. Example `cargo make build-aarch64 -p patina_dxe_core`" clear = true command = "cargo" -args = ["build", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--target", "aarch64-unknown-uefi", "@@split(NO_STD_FLAGS, )", ] -dependencies = ["individual-package-targets"] +args = ["build", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--target", "aarch64-unknown-uefi", "@@split(NO_STD_FLAGS, )", ] [tasks.build-x64] -description = "Builds crates in the repository for X64" +description = "Builds crates in the repository for X64. Arguments are forwarded to `cargo build`. Example `cargo make build-x64 -p patina_dxe_core`" clear = true command = "cargo" -args = ["build", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--target", "x86_64-unknown-uefi", "@@split(NO_STD_FLAGS, )", ] -dependencies = ["individual-package-targets"] +args = ["build", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--target", "x86_64-unknown-uefi", "@@split(NO_STD_FLAGS, )", ] script_runner = "@duckscript" condition_script = [''' target = get_env CARGO_MAKE_RUST_TARGET_TRIPLE @@ -420,18 +427,19 @@ end '''] [tasks.doc] -description = "Builds all rust documentation in the workspace. Example `cargo make doc`" +description = "Builds all rust documentation in the workspace. Arguments are forwarded to `cargo doc`. Example `cargo make doc` or `cargo make doc -p patina`" +clear = true command = "cargo" -args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--no-deps"] +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--no-deps"] [tasks.doc-open] -description = "Builds all rust documentation in the workspace and opens the documentation. Example `cargo make doc-open`" +description = "Builds all rust documentation in the workspace and opens the documentation. Arguments are forwarded to `cargo doc`. Example `cargo make doc-open` or `cargo make doc-open -p patina`" clear = true command = "cargo" -args = ["doc", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "--open"] +args = ["doc", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--open"] [tasks.clippy] -description = "Run cargo clippy for the host target and both UEFI cross-compilation targets." +description = "Run cargo clippy for the host target and both UEFI cross-compilation targets. Arguments are forwarded to `cargo clippy`." clear = true run_task = [{ name = ["clippy-x64", "clippy-aarch64", "clippy-std"], parallel = true }] @@ -439,37 +447,54 @@ run_task = [{ name = ["clippy-x64", "clippy-aarch64", "clippy-std"], parallel = description = "Run cargo clippy for x86_64-unknown-uefi." private = true command = "cargo" -args = ["clippy", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "--target", "x86_64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] [tasks.clippy-aarch64] description = "Run cargo clippy for aarch64-unknown-uefi." private = true command = "cargo" -args = ["clippy", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] +args = ["clippy", "--target", "aarch64-unknown-uefi", "--features", "ci_features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(NO_STD_FLAGS, )", "--", "-D", "warnings"] [tasks.clippy-std] description = "Run cargo clippy for std." private = true command = "cargo" -args = ["clippy", "--all-targets", "--all-features", "--", "-D", "warnings"] +args = ["clippy", "--all-targets", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "--", "-D", "warnings"] + +[tasks.fmt-all-flag] +description = """Sets `FMT_ALL` to `--all` only when no arguments were given on the command line. +`--all` overrides `-p`, so it is dropped whenever any argument is given (for example +`cargo make fmt -p patina`).""" +private = true +script_runner = "@duckscript" +script = ''' +args = get_env CARGO_MAKE_TASK_ARGS +if is_empty ${args} + set_env FMT_ALL "--all" +else + set_env FMT_ALL "" +end +''' [tasks.fmt] -description = "Run cargo format." +description = "Run cargo format. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt` or `cargo make fmt -p patina`" clear = true command = "cargo" -args = ["fmt", "--all"] +args = ["fmt", "@@split(FMT_ALL, )", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.fmt-check] -description = "Check cargo format without modifying files." +description = "Check cargo format without modifying files. Arguments are forwarded to `cargo fmt`. Example `cargo make fmt-check` or `cargo make fmt-check -p patina`" clear = true command = "cargo" -args = ["fmt", "--all", "--check"] +args = ["fmt", "@@split(FMT_ALL, )", "--check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] +dependencies = ["fmt-all-flag"] [tasks.doc-test] -description = "Run documentation tests." +description = "Run documentation tests. Arguments are forwarded to `cargo test`." clear = true command = "cargo" -args = ["test", "--doc"] +args = ["test", "--doc", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.clean-mdbook-deps] description = """Removes the `target/mdbook/` directory to clean up old rlibs.""" @@ -490,8 +515,8 @@ This is a prerequisite for `cargo make test-mdbook`.""" clear = true env = { RUSTC_PROFILE = "mdbook" } command = "cargo" -args = ["build", "--all-features", "@@split(INDIVIDUAL_PACKAGE_TARGETS, )", "@@split(STD_FLAGS, )"] -dependencies = ["clean-mdbook-deps", "individual-package-targets"] +args = ["build", "--all-features", "@@split(CARGO_MAKE_TASK_ARGS,;)", "@@split(STD_FLAGS, )"] +dependencies = ["clean-mdbook-deps"] [tasks.test-mdbook] description = """Builds the mdbook and runs all of its embedded doctests with @@ -537,25 +562,25 @@ description = "Run cspell for spell checking." # npm install -g cspell@latest script = "cspell --quiet --no-progress --no-summary --dot --gitignore -e \"{.git/**,.github/**,.vscode/**}\" ." [tasks.deny] -description = "Run cargo deny." +description = "Run cargo deny. Arguments are forwarded to `cargo deny check`." install_crate = false clear = true command = "cargo" -args = ["deny", "check"] +args = ["deny", "check", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.bench] -description = "Run cargo bench." +description = "Run cargo bench. Arguments are forwarded to `cargo bench`." clear = true command = "cargo" args = ["bench", "@@split(CARGO_MAKE_TASK_ARGS,;)"] [tasks.vet] -description = "Run cargo vet." +description = "Run cargo vet. Arguments are forwarded to `cargo vet`." install_crate = false clear = true dependencies = ["generate-lockfile"] command = "cargo" -args = ["vet", "--locked"] +args = ["vet", "--locked", "@@split(CARGO_MAKE_TASK_ARGS,;)"] ignore_errors = false [tasks.all-preflight] @@ -563,7 +588,7 @@ private = true run_task = [{ name = ["fmt-check", "deny", "cspell"], parallel = true }] [tasks.all] -description = "Run all tasks for PR readiness." +description = "Run all tasks for PR readiness. This task takes no arguments; any arguments given are forwarded to every sub-task." env = { CARGO_INCREMENTAL = "0" } run_task = { name = [ "all-preflight",