From 5533073f565102419fe581934c9fb23a477dcc69 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 27 Jun 2020 16:38:56 -0700 Subject: [PATCH] Only use `cygpath` on shebang if it contains `/` (#652) On Windows, skip conversion if a shebang path does not include `/`. In this case it is not a Unix path, and does not need to be converted to a Windows path before running. --- .github/workflows/{main.yaml => build.yaml} | 13 ++++++++----- README.adoc | 19 +++++++++++++++++++ src/platform.rs | 21 +++++++++++++++------ tests/integration.rs | 12 ++++++++++++ 4 files changed, 54 insertions(+), 11 deletions(-) rename .github/workflows/{main.yaml => build.yaml} (92%) diff --git a/.github/workflows/main.yaml b/.github/workflows/build.yaml similarity index 92% rename from .github/workflows/main.yaml rename to .github/workflows/build.yaml index 98c11fe..5afbfbb 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/build.yaml @@ -5,7 +5,7 @@ on: branches: - master tags: - - v*.*.* + - '*' pull_request: branches: - master @@ -30,9 +30,12 @@ jobs: runs-on: ${{matrix.os}} + env: + RUSTFLAGS: "-D warnings" + steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Cache cargo registry uses: actions/cache@v1 @@ -99,16 +102,16 @@ jobs: - name: Package id: package - if: startsWith(github.ref, 'refs/tags/v') + if: startsWith(github.ref, 'refs/tags/') run: ./bin/package ${{github.ref}} ${{matrix.os}} ${{ matrix.target }} shell: bash - name: Publish uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/v') + if: startsWith(github.ref, 'refs/tags/') with: draft: false files: ${{ steps.package.outputs.archive }} - prerelease: false + prerelease: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.adoc b/README.adoc index 2650c5d..02014ef 100644 --- a/README.adoc +++ b/README.adoc @@ -694,6 +694,25 @@ Yo from a shell script! Hello from ruby! ``` +==== Shebang Recipe Execution on Windows + +On Windows, shebang interpreter paths containing a `/` are translated from Unix-style +paths to Windows-style paths using `cygpath`, a utility that ships with http://www.cygwin.com[Cygwin]. + +For example, to execute this recipe on Windows: + +```make +echo: + #!/bin/sh + + echo "Hello!" +``` + +The interpreter path `/bin/sh` will be translated to a Windows-style path using +`cygpath` before being executed. + +If the interpreter path does not contain a `/` it will be executed without being translated. This is useful if `cygpath` is not available, or you wish to use a Windows style path to the interpreter. + === Multi-line Constructs Recipes without an initial shebang are evaluated and run line-by-line, which means that multi-line constructs probably won't do what you want. diff --git a/src/platform.rs b/src/platform.rs index d90e126..ac00b85 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -53,19 +53,28 @@ impl PlatformInterface for Platform { command: &str, argument: Option<&str>, ) -> Result { - // Translate path to the interpreter from unix style to windows style - let mut cygpath = Command::new("cygpath"); - cygpath.current_dir(working_directory); - cygpath.arg("--windows"); - cygpath.arg(command); + // If the path contains forward slashes… + let command = if command.contains('/') { + // …translate path to the interpreter from unix style to windows style. + let mut cygpath = Command::new("cygpath"); + cygpath.current_dir(working_directory); + cygpath.arg("--windows"); + cygpath.arg(command); - let mut cmd = Command::new(output(cygpath)?); + Cow::Owned(output(cygpath)?) + } else { + // …otherwise use it as-is. + Cow::Borrowed(command) + }; + + let mut cmd = Command::new(command.as_ref()); cmd.current_dir(working_directory); if let Some(argument) = argument { cmd.arg(argument); } + cmd.arg(path); Ok(cmd) } diff --git a/tests/integration.rs b/tests/integration.rs index 1ebd70a..6eccdbd 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -2635,3 +2635,15 @@ test! { status: 127, shell: false, } + +#[cfg(windows)] +test! { + name: windows_interpreter_path_no_base, + justfile: r#" + foo: + #!powershell + + exit 0 + "#, + args: (), +}