Skip to content

Commit

Permalink
workaround upstream cargo-make not expanding condition_script_runner_…
Browse files Browse the repository at this point in the history
…args
  • Loading branch information
wmmc88 committed Aug 15, 2024
1 parent 3338382 commit 2d199bc
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions crates/wdk-build/rust-driver-makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ 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.
#
# This plugin also includes functionality from `rust-condition-script-cargo_make_current_task_initial_makefile_directory-substitution` since `https://github.com/sagiegurari/cargo-make/pull/1132` has not merged yet.
[plugins.impl.nested-cargo-workspace-in-cargo-make-emulated-workspace-support]
script = '''
# If current flow is executing in a Cargo workspace, which is a member of a cargo-make emulated workspace
Expand All @@ -132,7 +134,25 @@ if ${CARGO_MAKE_WORKSPACE_EMULATION} and ${CARGO_MAKE_CRATE_IS_WORKSPACE}
cm_plugin_run_custom_task "{\"run_task\":{\"name\":\"${task.name}\",\"fork\":true}}"
else
cm_plugin_run_task
# FIXME: modifying the taskjson here is not needed after upstream fix is merged: https://github.com/sagiegurari/cargo-make/pull/1132
# 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}
end
'''

Expand Down Expand Up @@ -540,16 +560,12 @@ dependencies = [
dependencies = ["build"]
# Only run package-driver flow if the current package is marked as a driver
plugin = "nested-cargo-workspace-in-cargo-make-emulated-workspace-support"
condition_script_runner_args = [
"--base-path",
"${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}",
]
condition_script = '''
#!@rust
//! ```cargo
//! [dependencies]
//! wdk-build = { path = ".", version = "0.2.0" }
//! wdk-build = { path = "${CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}", version = "0.2.0" }
//! anyhow = "1"
//! ```
#![allow(unused_doc_comments)]
Expand Down

0 comments on commit 2d199bc

Please sign in to comment.