Allow configuring cygpath with --cygpath and $JUST_CYGPATH (#2804)
Some checks failed
CI / lint (push) Has been cancelled
CI / msrv (push) Has been cancelled
CI / pages (push) Has been cancelled
CI / test (macos-latest) (push) Has been cancelled
CI / test (ubuntu-latest) (push) Has been cancelled
CI / test (windows-latest) (push) Has been cancelled

This commit is contained in:
hyrious 2025-07-06 11:24:32 +08:00 committed by GitHub
parent 33936f4918
commit 014491d667
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 35 additions and 13 deletions

View file

@ -17,6 +17,7 @@ pub(crate) struct Config {
pub(crate) check: bool,
pub(crate) color: Color,
pub(crate) command_color: Option<ansi_term::Color>,
pub(crate) cygpath: PathBuf,
pub(crate) dotenv_filename: Option<String>,
pub(crate) dotenv_path: Option<PathBuf>,
pub(crate) dry_run: bool,
@ -96,6 +97,7 @@ mod arg {
pub(crate) const CLEAR_SHELL_ARGS: &str = "CLEAR-SHELL-ARGS";
pub(crate) const COLOR: &str = "COLOR";
pub(crate) const COMMAND_COLOR: &str = "COMMAND-COLOR";
pub(crate) const CYGPATH: &str = "CYGPATH";
pub(crate) const DOTENV_FILENAME: &str = "DOTENV-FILENAME";
pub(crate) const DOTENV_PATH: &str = "DOTENV-PATH";
pub(crate) const DRY_RUN: &str = "DRY-RUN";
@ -200,6 +202,15 @@ impl Config {
.value_parser(clap::value_parser!(CommandColor))
.help("Echo recipe lines in <COMMAND-COLOR>"),
)
.arg(
Arg::new(arg::CYGPATH)
.long("cygpath")
.env("JUST_CYGPATH")
.action(ArgAction::Set)
.value_parser(value_parser!(PathBuf))
.default_value("cygpath")
.help("Use binary at <CYGPATH> to convert between unix and Windows paths."),
)
.arg(
Arg::new(arg::DOTENV_FILENAME)
.long("dotenv-filename")
@ -772,6 +783,7 @@ impl Config {
.get_one::<CommandColor>(arg::COMMAND_COLOR)
.copied()
.map(CommandColor::into),
cygpath: matches.get_one::<PathBuf>(arg::CYGPATH).unwrap().clone(),
dotenv_filename: matches
.get_one::<String>(arg::DOTENV_FILENAME)
.map(Into::into),

View file

@ -8,6 +8,7 @@ pub(crate) enum Executor<'a> {
impl Executor<'_> {
pub(crate) fn command<'src>(
&self,
config: &Config,
path: &Path,
recipe: &'src str,
working_directory: Option<&Path>,
@ -36,12 +37,12 @@ impl Executor<'_> {
})?;
// create command to run script
Platform::make_shebang_command(path, working_directory, *shebang).map_err(|output_error| {
Error::Cygpath {
Platform::make_shebang_command(config, path, *shebang, working_directory).map_err(
|output_error| Error::Cygpath {
recipe,
output_error,
}
})
},
)
}
}
}

View file

@ -333,6 +333,7 @@ fn file_stem(_context: Context, path: &str) -> FunctionResult {
fn invocation_directory(context: Context) -> FunctionResult {
Platform::convert_native_path(
context.evaluator.context.config,
&context.evaluator.context.search.working_directory,
&context.evaluator.context.config.invocation_directory,
)

View file

@ -2,9 +2,10 @@ use super::*;
impl PlatformInterface for Platform {
fn make_shebang_command(
_config: &Config,
path: &Path,
working_directory: Option<&Path>,
_shebang: Shebang,
working_directory: Option<&Path>,
) -> Result<Command, OutputError> {
// shebang scripts can be executed directly on unix
let mut command = Command::new(path);
@ -35,7 +36,11 @@ impl PlatformInterface for Platform {
exit_status.signal()
}
fn convert_native_path(_working_directory: &Path, path: &Path) -> FunctionResult {
fn convert_native_path(
_config: &Config,
_working_directory: &Path,
path: &Path,
) -> FunctionResult {
path
.to_str()
.map(str::to_string)

View file

@ -2,16 +2,17 @@ use super::*;
impl PlatformInterface for Platform {
fn make_shebang_command(
config: &Config,
path: &Path,
working_directory: Option<&Path>,
shebang: Shebang,
working_directory: Option<&Path>,
) -> Result<Command, OutputError> {
use std::borrow::Cow;
// If the path contains forward slashes…
let command = if shebang.interpreter.contains('/') {
// …translate path to the interpreter from unix style to windows style.
let mut cygpath = Command::new("cygpath");
let mut cygpath = Command::new(&config.cygpath);
if let Some(working_directory) = working_directory {
cygpath.current_dir(working_directory);
@ -56,9 +57,9 @@ impl PlatformInterface for Platform {
None
}
fn convert_native_path(working_directory: &Path, path: &Path) -> FunctionResult {
fn convert_native_path(config: &Config, working_directory: &Path, path: &Path) -> FunctionResult {
// Translate path from windows style to unix style
let mut cygpath = Command::new("cygpath");
let mut cygpath = Command::new(&config.cygpath);
cygpath
.current_dir(working_directory)

View file

@ -2,7 +2,7 @@ use super::*;
pub(crate) trait PlatformInterface {
/// translate path from "native" path to path interpreter expects
fn convert_native_path(working_directory: &Path, path: &Path) -> FunctionResult;
fn convert_native_path(config: &Config, working_directory: &Path, path: &Path) -> FunctionResult;
/// install handler, may only be called once
fn install_signal_handler<T: Fn(Signal) + Send + 'static>(handler: T) -> RunResult<'static>;
@ -10,9 +10,10 @@ pub(crate) trait PlatformInterface {
/// construct command equivalent to running script at `path` with shebang
/// line `shebang`
fn make_shebang_command(
config: &Config,
path: &Path,
working_directory: Option<&Path>,
shebang: Shebang,
working_directory: Option<&Path>,
) -> Result<Command, OutputError>;
/// set the execute permission on file pointed to by `path`

View file

@ -416,6 +416,7 @@ impl<'src, D> Recipe<'src, D> {
})?;
let mut command = executor.command(
config,
&path,
self.name(),
self.working_directory(context).as_deref(),

View file

@ -12,7 +12,7 @@ fn convert_native_path(path: &Path) -> String {
#[cfg(windows)]
fn convert_native_path(path: &Path) -> String {
// Translate path from windows style to unix style
let mut cygpath = Command::new("cygpath");
let mut cygpath = Command::new(env::var_os("JUST_CYGPATH").unwrap_or("cygpath".into()));
cygpath.arg("--unix");
cygpath.arg(path);