Skip to content

Commit

Permalink
Merge pull request #1 from svasista-ms/replace-plugin
Browse files Browse the repository at this point in the history
Replace directory substitution plugin with condition_script_runner_args
  • Loading branch information
svasista-ms authored Sep 2, 2024
2 parents 5788223 + 727431c commit 1628330
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
29 changes: 5 additions & 24 deletions crates/wdk-build/rust-driver-makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,6 @@ if not is_empty ${script_output}
end
'''

# This plugin replaces the embedded `CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY` in the rust-script doc comment with its evaluated value. See https://github.com/sagiegurari/cargo-make/issues/1081 for more context.
[plugins.impl.rust-condition-script-cargo_make_current_task_initial_makefile_directory-substitution]
script = '''
# Parse task json into variables
taskjson = json_parse ${task.as_json}
# Convert backslashes to forward slashes
rust-driver-toolchain-path = replace ${taskjson.env.CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY} "\\" "/"
# Replace the ${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY} variable in the condition_script with the rust-driver-toolchain-path
taskjson.condition_script = replace ${taskjson.condition_script} "\${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}" "${rust-driver-toolchain-path}"
# Unset the private flag since it breaks cm_plugin_run_custom_task: https://github.com/sagiegurari/cargo-make/issues/1084
unset taskjson.private
# Reencode variables into json
taskjson = json_encode taskjson
# Run the invoking task, with the modified condition_script
cm_plugin_run_custom_task ${taskjson}
'''

# This plugin adds support for cargo-make's emulated workspace feature to work on emulated workspace members which are Cargo workspaces themselves.
# Since Cargo workspaces are not detected in cargo-make emulated workspace members, the task is rerun in a forked subprocess with the CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER env var unset to allow cargo-make's workspace detection to run.
[plugins.impl.nested-cargo-workspace-in-cargo-make-emulated-workspace-support]
Expand Down Expand Up @@ -237,13 +215,16 @@ std::fs::copy(&source_file, &destination_file).expect(&format!(
[tasks.generate-driver-binary-file]
private = true
dependencies = ["setup-wdk-config-env-vars", "build"]
plugin = "rust-condition-script-cargo_make_current_task_initial_makefile_directory-substitution"
condition_script_runner_args = [
"--base-path",
"${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}",
]
condition_script = '''
#!@rust
//! ```cargo
//! [dependencies]
//! wdk-build = { path = "${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}", version = "0.2.0" }
//! wdk-build = { path = ".", version = "0.2.0" }
//! ```
#![allow(unused_doc_comments)]
Expand Down
7 changes: 5 additions & 2 deletions crates/wdk-build/rust-driver-sample-makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ wdk_build::cargo_make::forward_printed_env_vars(

[tasks.infverif]
dependencies = ["wdk-samples-setup", "stampinf"]
plugin = "rust-condition-script-cargo_make_current_task_initial_makefile_directory-substitution"
condition_script_runner_args = [
"--base-path",
"${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}",
]
condition_script = '''
#!@rust
//! ```cargo
//! [dependencies]
//! wdk-build = { path = "${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}", version = "0.2.0" }
//! wdk-build = { path = ".", version = "0.2.0" }
//! ```
#![allow(unused_doc_comments)]
Expand Down

0 comments on commit 1628330

Please # to comment.