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

Implement windows-powershell setting #1057

Merged
merged 18 commits into from
Jan 18, 2022
Merged

Conversation

michidk
Copy link
Contributor

@michidk michidk commented Dec 25, 2021

Implement the windows-powershell setting to fix #1050.

To be able to run the same justfile on Linux and Windows set shell is not enough because it would change the shell on every platform. To set PowerShell as the default shell when running just on Windows set windows-powershell to true.

set windows-powershell
hello-windows:
  Write-Host "Hello, world!"
hello-linux:
  echo 'Hello, world!'

@michidk michidk changed the title DRAFT: Add windows-powershell setting DRAFT: Implement windows-powershell setting Dec 25, 2021
@michidk michidk force-pushed the windows-powershell branch 2 times, most recently from e662240 to 2f5040c Compare January 1, 2022 14:23
@michidk
Copy link
Contributor Author

michidk commented Jan 1, 2022

Hey @casey I finished the implementation of windows-powershell. The core logic is here: https://github.com/michidk/just/blob/windows-powershell/src/settings.rs#L41
But quite a few integration tests like byte_order_mark::ignore_leading_byte_order_mark started failing after I implemented the shell selection logic (see GitHub actions).
I am not entirely sure what those tests do and what my code has do to with them failing, but I noticed in the test results that bash is used sometimes. Not sure if that's intended or some fallback in Linux?
If you have some time over the course of the next weeks, maybe you can have a look at it.

Happy new year!

@casey
Copy link
Owner

casey commented Jan 3, 2022

It's not a very satisfying answer, but I think if a whole bunch of tests start failing, the best thing to do is to uncomment/revert code until you they all pass/you get the previous behavior, and then start modifying it incrementally until you get failing tests.

@michidk michidk changed the title DRAFT: Implement windows-powershell setting Implement windows-powershell setting Jan 4, 2022
@casey
Copy link
Owner

casey commented Jan 5, 2022

#1061 reminded me of something: If there are arguments that make powershell less error prone, we should pass them by default. So, for example, if there's something like -u, which makes evaluating undefined variables an error, we should pass that.

@michidk
Copy link
Contributor Author

michidk commented Jan 7, 2022

#1061 reminded me of something: If there are arguments that make powershell less error prone, we should pass them by default. So, for example, if there's something like -u, which makes evaluating undefined variables an error, we should pass that.

I don't think there is such an argument. I think I will add the -NoLogo argument though. The argument list can be found here: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1

@michidk
Copy link
Contributor Author

michidk commented Jan 7, 2022

@casey I changed the version just-variable into an environment variable in the main justfile of this project itself because it would try to execute sed which is not available on Windows. Now I am able to execute most commands like just fmt.
Not sure if you agree with that change though, so please have a look at it and let me know what you think: michidk@1dc2502

@michidk michidk force-pushed the windows-powershell branch 2 times, most recently from 3e8a9a3 to 1804e99 Compare January 7, 2022 16:08
@casey
Copy link
Owner

casey commented Jan 7, 2022

I don't think the main justfile should be changed in this PR. In general, I try to keep PRs as small as possible, so they can be reviewed easily and merged quickly. Changing the main justfile to use Powershell would be a large change, since all the recipes would need to be rewritten to be compatible with Powershell, so it should be left out of this PR.

@michidk
Copy link
Contributor Author

michidk commented Jan 7, 2022

I don't think the main justfile should be changed in this PR. In general, I try to keep PRs as small as possible, so they can be reviewed easily and merged quickly. Changing the main justfile to use Powershell would be a large change, since all the recipes would need to be rewritten to be compatible with Powershell, so it should be left out of this PR.

I actually used this justfile for quite some time now. It works great - I never needed the parts that didn't work with PowerShell. But then I will keep it locally because I don't have the time to translate the whole justfile. Just as a sidenote: If variables would evaluate lazy (as soon as they are needed, and not before that) then the file in the current master would also work for most commands like just fmt.

@michidk michidk marked this pull request as ready for review January 7, 2022 18:46
@michidk
Copy link
Contributor Author

michidk commented Jan 7, 2022

I reverted the previous commit, so that the justfile now matches with the one from the current master again (meaning it's unchanged in this PR).

I would consider the PR as ready for review now. Thanks to @Shemnei who worked with me on this feature.

Copy link
Owner

@casey casey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this mostly looks good. Thanks for writing all the unit tests!

As for integration tests, there should be a new integration test dedicated to this feature, which I suggested in a comment, and none of the existing integration tests should change.

The reason being that when reviewing a PR like this, you really want to be sure that the feature works, and that nothing else changed. The easiest way to do this is to leave the existing tests alone, and write a new test that just covers the new feature.

README.adoc Outdated Show resolved Hide resolved
README.adoc Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/evaluator.rs Outdated Show resolved Hide resolved
src/settings.rs Outdated Show resolved Hide resolved
src/settings.rs Outdated Show resolved Hide resolved
src/settings.rs Outdated Show resolved Hide resolved
src/settings.rs Outdated Show resolved Hide resolved
src/settings.rs Outdated Show resolved Hide resolved
@michidk michidk force-pushed the windows-powershell branch 3 times, most recently from 41ba8a7 to 82bf657 Compare January 15, 2022 10:20
@michidk
Copy link
Contributor Author

michidk commented Jan 15, 2022

@casey Thanks for your review! I implemented all the changes.

@michidk michidk requested a review from casey January 15, 2022 11:26
Copy link
Owner

@casey casey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting there!

src/config.rs Outdated Show resolved Hide resolved
README.adoc Outdated Show resolved Hide resolved
src/justfile.rs Outdated Show resolved Hide resolved
src/settings.rs Outdated
@@ -1,11 +1,17 @@
use crate::common::*;

pub(crate) const DEFAULT_SHELL: &str = "sh";
pub(crate) const DEFAULT_SHELL_ARG: &[&str] = &["-cu"];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this conversation was accidentally marked as resolved. Since it's an array of strings, I would call it DEFAULT_SHELL_ARGS even if there's only one.

src/settings.rs Outdated Show resolved Hide resolved
tests/windows_powershell.rs Outdated Show resolved Hide resolved
src/settings.rs Outdated Show resolved Hide resolved
src/settings.rs Show resolved Hide resolved
src/settings.rs Outdated Show resolved Hide resolved
src/settings.rs Show resolved Hide resolved
@michidk
Copy link
Contributor Author

michidk commented Jan 18, 2022

Done!

src/settings.rs Outdated Show resolved Hide resolved
@casey casey enabled auto-merge (squash) January 18, 2022 18:53
src/settings.rs Outdated Show resolved Hide resolved
@casey casey disabled auto-merge January 18, 2022 18:56
@casey casey enabled auto-merge (squash) January 18, 2022 19:00
@casey casey merged commit 6cf95a7 into casey:master Jan 18, 2022
@casey
Copy link
Owner

casey commented Jan 18, 2022

Nice, merged! Thanks for sticking with it! This is a great feature, and long overdue.

@michidk
Copy link
Contributor Author

michidk commented Jan 19, 2022

Thanks for reviewing!

@michidk michidk deleted the windows-powershell branch January 19, 2022 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cross-platform justfiles & default shell
3 participants