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.
This commit is contained in:
Casey Rodarmor 2020-06-27 16:38:56 -07:00 committed by GitHub
parent 863fb53885
commit 5533073f56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 11 deletions

View File

@ -5,7 +5,7 @@ on:
branches: branches:
- master - master
tags: tags:
- v*.*.* - '*'
pull_request: pull_request:
branches: branches:
- master - master
@ -30,9 +30,12 @@ jobs:
runs-on: ${{matrix.os}} runs-on: ${{matrix.os}}
env:
RUSTFLAGS: "-D warnings"
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v2
- name: Cache cargo registry - name: Cache cargo registry
uses: actions/cache@v1 uses: actions/cache@v1
@ -99,16 +102,16 @@ jobs:
- name: Package - name: Package
id: 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 }} run: ./bin/package ${{github.ref}} ${{matrix.os}} ${{ matrix.target }}
shell: bash shell: bash
- name: Publish - name: Publish
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v') if: startsWith(github.ref, 'refs/tags/')
with: with:
draft: false draft: false
files: ${{ steps.package.outputs.archive }} files: ${{ steps.package.outputs.archive }}
prerelease: false prerelease: true
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -694,6 +694,25 @@ Yo from a shell script!
Hello from ruby! 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 === 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. 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.

View File

@ -53,19 +53,28 @@ impl PlatformInterface for Platform {
command: &str, command: &str,
argument: Option<&str>, argument: Option<&str>,
) -> Result<Command, OutputError> { ) -> Result<Command, OutputError> {
// Translate path to the interpreter from unix style to windows style // 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"); let mut cygpath = Command::new("cygpath");
cygpath.current_dir(working_directory); cygpath.current_dir(working_directory);
cygpath.arg("--windows"); cygpath.arg("--windows");
cygpath.arg(command); 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); cmd.current_dir(working_directory);
if let Some(argument) = argument { if let Some(argument) = argument {
cmd.arg(argument); cmd.arg(argument);
} }
cmd.arg(path); cmd.arg(path);
Ok(cmd) Ok(cmd)
} }

View File

@ -2635,3 +2635,15 @@ test! {
status: 127, status: 127,
shell: false, shell: false,
} }
#[cfg(windows)]
test! {
name: windows_interpreter_path_no_base,
justfile: r#"
foo:
#!powershell
exit 0
"#,
args: (),
}