Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Cargo-Make global environment variables are not available in plugin context #978

Closed
wmmc88 opened this issue Oct 30, 2023 · 5 comments
Assignees

Comments

@wmmc88
Copy link
Contributor

wmmc88 commented Oct 30, 2023

Describe The Bug

I've found that there are inconsistencies in what global cargo make environment variables are available in task context vs. in plugin context.

To Reproduce

Makefile.toml:

[plugins.impl.env-plugin]
script = '''
a = get_env CARGO_MAKE_CARGO_HOME
echo ${a}

a = get_env CARGO_MAKE_CRATE_CUSTOM_TRIPLE_TARGET_DIRECTORY
echo ${a}

a = get_env CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY
echo ${a}

a = get_env CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE
echo ${a}
'''

[tasks.env-args-plugin]
plugin = "env-plugin"

[tasks.env-args-task]
script = '''
#!@duckscript

a = get_env CARGO_MAKE_CARGO_HOME
echo ${a}

a = get_env CARGO_MAKE_CRATE_CUSTOM_TRIPLE_TARGET_DIRECTORY
echo ${a}

a = get_env CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY
echo ${a}

a = get_env CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE
echo ${a}
'''

Output:

🪟 Windows 11 Enterprise(10.0.23565) (pwsh) cargo-make-ws-bug\crate-1 on  plugin-env-vars [!] is 📦 v0.1.0 via 🦀 v1.73.0 
at 06:29:03 PM ❯ cargo make --no-workspace env-args-task  
[cargo-make] INFO - cargo make 0.37.3
[cargo-make] INFO - Calling cargo metadata to extract project info
[cargo-make] INFO - Cargo metadata done
[cargo-make] INFO - Project: crate-1
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: env-args-task
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Running Task: env-args-task
D:\.tools\.cargo 
D:\git-repos\github\cargo-make-ws-bug\crate-1\target\aarch64-pc-windows-msvc
D:\git-repos\github\cargo-make-ws-bug\crate-1
D:\git-repos\github\cargo-make-ws-bug\crate-1\Makefile.toml
[cargo-make] INFO - Build Done in 1.58 seconds.

🪟 Windows 11 Enterprise(10.0.23565) (pwsh) cargo-make-ws-bug\crate-1 on  plugin-env-vars [!] is 📦 v0.1.0 via 🦀 v1.73.0 took 2s
at 06:29:24 PM ❯ cargo make --no-workspace env-args-plugin
[cargo-make] INFO - cargo make 0.37.3
[cargo-make] INFO - Calling cargo metadata to extract project info
[cargo-make] INFO - Cargo metadata done
[cargo-make] INFO - Project: crate-1
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: env-args-plugin
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
D:\.tools\.cargo
D:\git-repos\github\cargo-make-ws-bug\crate-1\target\aarch64-pc-windows-msvc


[cargo-make] INFO - Build Done in 1.48 seconds.

As you can see in the above output, CARGO_MAKE_CARGO_HOME and CARGO_MAKE_CRATE_CUSTOM_TRIPLE_TARGET_DIRECTORY resolve properly, but CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY and CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE fail to resolve when run from a plugin. I couldn't find any documentation calling out this behaviour, so I think this is a bug.

@wmmc88
Copy link
Contributor Author

wmmc88 commented Oct 30, 2023

But i did notice that for the two failing variables, the plugin script could be changed to:

taskjson = json_parse ${task.as_json}

a = set ${taskjson.env.CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE_DIRECTORY}
echo ${a}

a = set ${taskjson.env.CARGO_MAKE_CURRENT_TASK_INITIAL_MAKEFILE}
echo ${a}

and then it resolves properly. But this doesn't work for all global cargomake env vars. If this is not a bug in behaviour, could you document which environment variables are not accessible from plugin contexts?

@sagiegurari
Copy link
Owner

CARGO_MAKE_CURRENT_TASK_XXX will never be available for the plugin itself.
they (as you saw) defined in the task env block and get set when the task is invoked.
but a plugin takes over task execution and nothing in the task is invoked (env, command, conditions, etc...) and its up to the plugin to decide what to do.

@wmmc88
Copy link
Contributor Author

wmmc88 commented Oct 30, 2023

Ah. So its only CARGO_MAKE_CURRENT_TASK_XXX vars that will behave like this? I think this should probably be called out somewhere in the plugin docs

@sagiegurari
Copy link
Owner

I'll add. thanks for the feedback.

@sagiegurari
Copy link
Owner

docs updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants