2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2017-04-21 22:20:13 -07:00
|
|
|
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) struct Platform;
|
2017-04-21 22:20:13 -07:00
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
impl PlatformInterface for Platform {
|
2018-12-08 14:29:41 -08:00
|
|
|
fn make_shebang_command(
|
|
|
|
path: &Path,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
working_directory: &Path,
|
2021-05-17 20:44:12 -07:00
|
|
|
_shebang: Shebang,
|
2019-07-13 01:55:06 -07:00
|
|
|
) -> Result<Command, OutputError> {
|
2017-04-21 22:20:13 -07:00
|
|
|
// shebang scripts can be executed directly on unix
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
let mut cmd = Command::new(path);
|
|
|
|
|
|
|
|
cmd.current_dir(working_directory);
|
|
|
|
|
|
|
|
Ok(cmd)
|
2017-04-21 22:20:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn set_execute_permission(path: &Path) -> Result<(), io::Error> {
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
|
|
|
|
// get current permissions
|
|
|
|
let mut permissions = fs::metadata(&path)?.permissions();
|
|
|
|
|
|
|
|
// set the execute bit
|
|
|
|
let current_mode = permissions.mode();
|
|
|
|
permissions.set_mode(current_mode | 0o100);
|
|
|
|
|
|
|
|
// set the new permissions
|
|
|
|
fs::set_permissions(&path, permissions)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signal_from_exit_status(exit_status: process::ExitStatus) -> Option<i32> {
|
|
|
|
use std::os::unix::process::ExitStatusExt;
|
|
|
|
exit_status.signal()
|
|
|
|
}
|
2018-06-19 10:04:03 -07:00
|
|
|
|
2021-02-15 01:18:31 -08:00
|
|
|
fn convert_native_path(_working_directory: &Path, path: &Path) -> Result<String, String> {
|
2018-12-08 14:29:41 -08:00
|
|
|
path
|
|
|
|
.to_str()
|
|
|
|
.map(str::to_string)
|
|
|
|
.ok_or_else(|| String::from("Error getting current directory: unicode decode error"))
|
2018-06-19 10:04:03 -07:00
|
|
|
}
|
2017-04-21 22:20:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
impl PlatformInterface for Platform {
|
2018-12-08 14:29:41 -08:00
|
|
|
fn make_shebang_command(
|
|
|
|
path: &Path,
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
working_directory: &Path,
|
2021-05-17 20:44:12 -07:00
|
|
|
shebang: Shebang,
|
2019-07-13 01:55:06 -07:00
|
|
|
) -> Result<Command, OutputError> {
|
2021-04-05 21:28:37 -07:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2020-06-27 16:38:56 -07:00
|
|
|
// If the path contains forward slashes…
|
2021-05-17 20:44:12 -07:00
|
|
|
let command = if shebang.interpreter.contains('/') {
|
2020-06-27 16:38:56 -07:00
|
|
|
// …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");
|
2021-05-17 20:44:12 -07:00
|
|
|
cygpath.arg(shebang.interpreter);
|
2020-06-27 16:38:56 -07:00
|
|
|
|
|
|
|
Cow::Owned(output(cygpath)?)
|
|
|
|
} else {
|
|
|
|
// …otherwise use it as-is.
|
2021-05-17 20:44:12 -07:00
|
|
|
Cow::Borrowed(shebang.interpreter)
|
2020-06-27 16:38:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut cmd = Command::new(command.as_ref());
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
|
|
|
|
cmd.current_dir(working_directory);
|
|
|
|
|
2021-05-17 20:44:12 -07:00
|
|
|
if let Some(argument) = shebang.argument {
|
2017-04-21 22:20:13 -07:00
|
|
|
cmd.arg(argument);
|
|
|
|
}
|
2020-06-27 16:38:56 -07:00
|
|
|
|
2017-04-21 22:20:13 -07:00
|
|
|
cmd.arg(path);
|
2017-04-23 16:09:34 -07:00
|
|
|
Ok(cmd)
|
2017-04-21 22:20:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn set_execute_permission(_path: &Path) -> Result<(), io::Error> {
|
2020-02-14 04:49:25 -08:00
|
|
|
// it is not necessary to set an execute permission on a script on windows, so
|
|
|
|
// this is a nop
|
2017-04-21 22:20:13 -07:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signal_from_exit_status(_exit_status: process::ExitStatus) -> Option<i32> {
|
2020-02-14 04:49:25 -08:00
|
|
|
// The rust standard library does not expose a way to extract a signal from a
|
|
|
|
// windows process exit status, so just return None
|
2017-04-21 22:20:13 -07:00
|
|
|
None
|
|
|
|
}
|
2018-06-19 10:04:03 -07:00
|
|
|
|
2021-02-15 01:18:31 -08:00
|
|
|
fn convert_native_path(working_directory: &Path, path: &Path) -> Result<String, String> {
|
2018-06-19 10:04:03 -07:00
|
|
|
// Translate path from windows style to unix style
|
|
|
|
let mut cygpath = Command::new("cygpath");
|
Gargantuan refactor (#522)
- Instead of changing the current directory with `env::set_current_dir`
to be implicitly inherited by subprocesses, we now use
`Command::current_dir` to set it explicitly. This feels much better,
since we aren't dependent on the implicit state of the process's
current directory.
- Subcommand execution is much improved.
- Added a ton of tests for config parsing, config execution, working
dir, and search dir.
- Error messages are improved. Many more will be colored.
- The Config is now onwed, instead of borrowing from the arguments and
the `clap::ArgMatches` object. This is a huge ergonomic improvement,
especially in tests, and I don't think anyone will notice.
- `--edit` now uses `$VISUAL`, `$EDITOR`, or `vim`, in that order,
matching git, which I think is what most people will expect.
- Added a cute `tmptree!{}` macro, for creating temporary directories
populated with directories and files for tests.
- Admitted that grammer is LL(k) and I don't know what `k` is.
2019-11-09 21:43:20 -08:00
|
|
|
cygpath.current_dir(working_directory);
|
2018-06-19 10:04:03 -07:00
|
|
|
cygpath.arg("--unix");
|
|
|
|
cygpath.arg(path);
|
2020-01-28 18:02:58 -08:00
|
|
|
|
|
|
|
match output(cygpath) {
|
|
|
|
Ok(shell_path) => Ok(shell_path),
|
|
|
|
Err(_) => path
|
|
|
|
.to_str()
|
|
|
|
.map(str::to_string)
|
|
|
|
.ok_or_else(|| String::from("Error getting current directory: unicode decode error")),
|
|
|
|
}
|
2018-06-19 10:04:03 -07:00
|
|
|
}
|
2017-04-21 22:20:13 -07:00
|
|
|
}
|