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

Environment variable issue on windows #62

Closed
Cokemonkey11 opened this issue Jan 21, 2018 · 8 comments
Closed

Environment variable issue on windows #62

Cokemonkey11 opened this issue Jan 21, 2018 · 8 comments
Assignees
Labels

Comments

@Cokemonkey11
Copy link

The following won't work as expected on bash nor msys2:

[config]
skip_core_tasks = true

[tasks.default]
script = [
    "echo \"var: ${CARGO_MAKE_CRATE_VERSION}\""
]

Emits:

$ cargo make
[cargo-make] INFO - cargo-make 0.9.4
[cargo-make] INFO - Using Build File: Makefile.toml
[cargo-make] INFO - Task: default
[cargo-make] INFO - Setting Up Env.
[cargo-make] INFO - Running Task: empty
[cargo-make] INFO - Running Task: default

C:\workspace2\gen>cd C:\workspace2\gen

C:\workspace2\gen>echo "var: ${CARGO_MAKE_CRATE_VERSION}"
"var: ${CARGO_MAKE_CRATE_VERSION}"
[cargo-make] INFO - Running Task: empty
[cargo-make] INFO - Build Done  in 0 seconds.
@sagiegurari
Copy link
Owner

Windows use the %var% syntax.
In order to use bash syntax on windows you must tell which runner to use.
You should do that on platform override task in order not to impact linux/mac execution.
For example:

[tasks.default.windows]
# if we want to keep rest of task definition just define the runner for windows
# and rest will be taken from original task
script_runner = "bash" 

Another option is to use the cross platform shell runner that can convert only very basic scripts from shell to batch if task is executed on windows. See docs

[tasks.shell]
script_runner = "@shell"
script = [
'''
rm ./myfile.txt
'''
]

@sagiegurari
Copy link
Owner

@Cokemonkey11 does it resolve your issue or do you need any changes?

@sagiegurari sagiegurari self-assigned this Jan 26, 2018
@Cokemonkey11
Copy link
Author

Hi,

Sorry for the huge delay.

My concern then is that when executing in a bash enviroment on a windows host (for example with MSYS2), the script runner choses windows style script.

I think this is also a design smell. I think script_runner should always default to unix-style shell.

How is this being detected, by the way?

@sagiegurari
Copy link
Owner

I have to disagree, I think it should default based on the OS default shell and let the user change that manually, which you can.
That is why I have

  • OS task overrides
  • Ability to define what runner you want
  • @shell runner
    So you have complete freedom, but default should be based on OS.

Its been done using normal rust cfg! macro and implemented in the run_script crate (https://github.com/sagiegurari/run_script)
So if no runner is provided it defaults to something like:

if cfg!(windows) {
  "cmd.exe"
} else {
  "sh"
}

@Cokemonkey11
Copy link
Author

I think your response is of the form "run_script doesn't do the right thing here"

Fundamentally, I'm running in a shell environment, and my OS has quite little to do with that.

That doesn't mean the onus is on you to change it though

@sagiegurari
Copy link
Owner

Don't think run_script doesn't do the right thing. I wrote it, so it actually does what I wanted it to :)
Right now, I think everything works by design which to me makes sense to use the OS native capabilities per OS and cargo-make gives you the ability to change that if you wish.
I do not see some actionable item here for cargo-make itself unless you feel something can be done better and give me some suggestions.

@sagiegurari
Copy link
Owner

closing due to no feedback

@Cokemonkey11
Copy link
Author

Sorry, didn't mean to blank you. No feedback at this time. My view is that, given that script can do pretty naughty things if using the wrong runner, the rust way would be to panic/fail/stop if there's a mismatch between the script runner and the actual environment/platform.

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

No branches or pull requests

2 participants