A1: macOS readiness: setup guide, cargo xtask mac-report, unix/macOS fixes
- docs/macos.md: step-by-step setup for a fresh Apple Silicon Mac (Xcode CLT, Homebrew, git, PHP, Composer, Node 22, pnpm, rustup, clone from Forgejo), the machine report, Gatekeeper notes, macOS differences and what Windows cannot check. - cargo xtask mac-report: versions, the gate steps, the bundled-UI desktop build and a self-check over the control channel (project, file, Phpactor, hover, git.status, terminal, screenshot, quit); every step times out and runs in a lutra_proc group; one report.md to send back. - Fixes: macOS native menu (system menus only; Cmd+W stays buffer.close, Cmd+Q runs app.quit), xcap screenshot region in points on macOS (Retina), login shell (-l, /bin/zsh fallback) and LANG for the terminal on macOS, PHP lookup in Homebrew/MacPorts dirs for Finder starts, case-insensitive LSP path mapping on macOS, rendezvous file mode re-set to 0600, CLI-started desktop in its own process group. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
da58c83158
commit
1bf69ded55
18 changed files with 1795 additions and 36 deletions
|
|
@ -191,7 +191,9 @@ pub fn write(dir: &Path, instance: &Instance) -> io::Result<()> {
|
|||
}
|
||||
|
||||
/// Creates `path` readable and writable by the owner only and writes
|
||||
/// `bytes` to it.
|
||||
/// `bytes` to it. On Unix the mode is set again after opening, because
|
||||
/// `mode(0o600)` only applies when the file is created, and a stale
|
||||
/// temporary file (same process id after a crash) keeps its old mode.
|
||||
///
|
||||
/// # Errors
|
||||
/// If the file cannot be created or written.
|
||||
|
|
@ -204,6 +206,11 @@ fn write_private(path: &Path, bytes: &[u8]) -> io::Result<()> {
|
|||
options.mode(0o600);
|
||||
}
|
||||
let mut file = options.open(path)?;
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
file.set_permissions(fs::Permissions::from_mode(0o600))?;
|
||||
}
|
||||
file.write_all(bytes)?;
|
||||
file.sync_all()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,8 +291,8 @@ pub fn locations(state: &State, root: &Path, value: &Value) -> Vec<NavLocation>
|
|||
}
|
||||
|
||||
/// `path` (absolute, from the server) relative to the project, or `None`
|
||||
/// outside it. Windows paths compare without regard to case, as the file
|
||||
/// system does, and `..` never escapes. A path that resolves through a
|
||||
/// outside it. Windows and macOS paths compare without regard to case, as
|
||||
/// their default file systems (NTFS, APFS) do, and `..` never escapes. A path that resolves through a
|
||||
/// symbolic link to a place outside the project counts as outside.
|
||||
pub fn project_relative(state: &State, root: &Path, path: &Path) -> Option<PathBuf> {
|
||||
let rel = match state
|
||||
|
|
@ -301,7 +301,7 @@ pub fn project_relative(state: &State, root: &Path, path: &Path) -> Option<PathB
|
|||
.and_then(|w| w.project.relative(path))
|
||||
{
|
||||
Some(rel) => rel,
|
||||
None => windows_relative(root, path)?,
|
||||
None => case_insensitive_relative(root, path)?,
|
||||
};
|
||||
if rel.components().any(|c| !matches!(c, Component::Normal(_))) {
|
||||
return None;
|
||||
|
|
@ -316,9 +316,10 @@ pub fn project_relative(state: &State, root: &Path, path: &Path) -> Option<PathB
|
|||
Some(rel)
|
||||
}
|
||||
|
||||
/// The case-insensitive fallback of [`project_relative`] on Windows.
|
||||
fn windows_relative(root: &Path, path: &Path) -> Option<PathBuf> {
|
||||
if !cfg!(windows) {
|
||||
/// The case-insensitive fallback of [`project_relative`] on Windows and
|
||||
/// macOS.
|
||||
fn case_insensitive_relative(root: &Path, path: &Path) -> Option<PathBuf> {
|
||||
if !cfg!(any(windows, target_os = "macos")) {
|
||||
return None;
|
||||
}
|
||||
let root_text = root.to_str()?.trim_end_matches(['\\', '/']);
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ impl Command for Create {
|
|||
label: "New Terminal",
|
||||
menu_path: None,
|
||||
default_shortcut: None,
|
||||
params: "{ cwd? (project-relative or absolute directory, default the project root), shell? (program name or path; default pwsh, then powershell, then cmd on Windows, $SHELL or /bin/sh elsewhere), cols, rows (1..=1000) }; returns { terminalId }, then events terminalOutput { terminalId, data } and terminalExited { terminalId, code }; at most 16 terminals",
|
||||
params: "{ cwd? (project-relative or absolute directory, default the project root), shell? (program name or path; default pwsh, then powershell, then cmd on Windows, the login shell $SHELL -l (else /bin/zsh) on macOS, $SHELL or /bin/sh elsewhere), cols, rows (1..=1000) }; returns { terminalId }, then events terminalOutput { terminalId, data } and terminalExited { terminalId, code }; at most 16 terminals",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -971,13 +971,14 @@ fn clear_diagnostics(state: &mut State) {
|
|||
}
|
||||
}
|
||||
|
||||
/// `path` relative to `root`; `None` outside it. Windows paths compare
|
||||
/// without regard to case, as the file system does.
|
||||
/// `path` relative to `root`; `None` outside it. Windows and macOS paths
|
||||
/// compare without regard to case, as their default file systems (NTFS,
|
||||
/// APFS) do.
|
||||
fn relative(root: &Path, path: &Path) -> Option<PathBuf> {
|
||||
if let Ok(rel) = path.strip_prefix(root) {
|
||||
return Some(rel.to_path_buf());
|
||||
}
|
||||
if !cfg!(windows) {
|
||||
if !cfg!(any(windows, target_os = "macos")) {
|
||||
return None;
|
||||
}
|
||||
let root_text = root.to_str()?.trim_end_matches(['\\', '/']);
|
||||
|
|
@ -1119,6 +1120,13 @@ mod tests {
|
|||
Some(PathBuf::from("b.php"))
|
||||
);
|
||||
}
|
||||
if cfg!(target_os = "macos") {
|
||||
assert_eq!(
|
||||
relative(&root, Path::new("/WORK/Demo/b.php")),
|
||||
Some(PathBuf::from("b.php"))
|
||||
);
|
||||
assert_eq!(relative(&root, Path::new("/WORK/Demo2/b.php")), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -106,13 +106,13 @@ impl PhpError {
|
|||
}
|
||||
|
||||
/// Finds PHP and checks it: the `setting` (`php.executable`; empty means
|
||||
/// look in `PATH`), resolved with [`locate`], then `php -v` with
|
||||
/// [`PROBE_TIMEOUT`].
|
||||
/// look in `PATH`, see [`search_path`]), resolved with [`locate`], then
|
||||
/// `php -v` with [`PROBE_TIMEOUT`].
|
||||
///
|
||||
/// # Errors
|
||||
/// [`PhpError`] saying what is missing or wrong.
|
||||
pub fn detect(setting: &str) -> Result<Php, PhpError> {
|
||||
let path = locate(setting, std::env::var_os("PATH"))?;
|
||||
let path = locate(setting, search_path(std::env::var_os("PATH")))?;
|
||||
let output = run_version(&path, PROBE_TIMEOUT)?;
|
||||
let version =
|
||||
parse_version(&output).ok_or_else(|| PhpError::NoVersion { path: path.clone() })?;
|
||||
|
|
@ -122,6 +122,41 @@ pub fn detect(setting: &str) -> Result<Php, PhpError> {
|
|||
Ok(Php { path, version })
|
||||
}
|
||||
|
||||
/// Package manager folders searched after `PATH` on macOS: Homebrew on
|
||||
/// Apple Silicon, Homebrew on Intel and MacPorts.
|
||||
pub const MACOS_EXTRA_DIRS: [&str; 3] = ["/opt/homebrew/bin", "/usr/local/bin", "/opt/local/bin"];
|
||||
|
||||
/// The directories PHP is looked up in: `path_env`, and on macOS
|
||||
/// [`MACOS_EXTRA_DIRS`] after it. An app started from the Finder or Dock
|
||||
/// inherits only the system `PATH` (`/usr/bin:/bin:/usr/sbin:/sbin`), which
|
||||
/// has no PHP since macOS 12, so Homebrew's PHP would not be found although
|
||||
/// it works in Terminal.
|
||||
pub fn search_path(path_env: Option<OsString>) -> Option<OsString> {
|
||||
if !cfg!(target_os = "macos") {
|
||||
return path_env;
|
||||
}
|
||||
with_extra_dirs(path_env, &MACOS_EXTRA_DIRS)
|
||||
}
|
||||
|
||||
/// `path_env` with `extra` appended, skipping folders it lists already.
|
||||
/// `None` only if both are empty; a `PATH` that cannot be joined again
|
||||
/// (an entry with the separator in it) is returned unchanged.
|
||||
fn with_extra_dirs(path_env: Option<OsString>, extra: &[&str]) -> Option<OsString> {
|
||||
let mut dirs: Vec<PathBuf> = path_env
|
||||
.as_ref()
|
||||
.map(|p| std::env::split_paths(p).collect())
|
||||
.unwrap_or_default();
|
||||
for dir in extra {
|
||||
if !dirs.iter().any(|d| d == Path::new(dir)) {
|
||||
dirs.push(PathBuf::from(dir));
|
||||
}
|
||||
}
|
||||
if dirs.is_empty() {
|
||||
return path_env;
|
||||
}
|
||||
std::env::join_paths(dirs).ok().or(path_env)
|
||||
}
|
||||
|
||||
/// Resolves the PHP executable.
|
||||
///
|
||||
/// - `setting` is the `php.executable` value, trimmed. A value with a path
|
||||
|
|
@ -338,6 +373,23 @@ mod tests {
|
|||
assert_eq!(locate(given.to_str().unwrap(), None).unwrap(), given);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extra_dirs_come_after_path_once() {
|
||||
let path = std::env::join_paths(["/usr/bin", "/opt/homebrew/bin"]).unwrap();
|
||||
let joined = with_extra_dirs(Some(path), &["/opt/homebrew/bin", "/opt/local/bin"]);
|
||||
let dirs: Vec<PathBuf> = std::env::split_paths(&joined.unwrap()).collect();
|
||||
assert_eq!(
|
||||
dirs,
|
||||
["/usr/bin", "/opt/homebrew/bin", "/opt/local/bin"].map(PathBuf::from)
|
||||
);
|
||||
let only_extra = with_extra_dirs(None, &["/opt/local/bin"]).unwrap();
|
||||
assert_eq!(only_extra, OsString::from("/opt/local/bin"));
|
||||
assert_eq!(with_extra_dirs(None, &[]), None);
|
||||
if !cfg!(target_os = "macos") {
|
||||
assert_eq!(search_path(Some("x".into())), Some("x".into()));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_program_that_is_not_php_fails_cleanly() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
|
|
|||
|
|
@ -160,6 +160,22 @@ fn pty_size(cols: u16, rows: u16) -> Result<PtySize, TerminalError> {
|
|||
})
|
||||
}
|
||||
|
||||
/// Whether the shell needs `LANG=en_US.UTF-8`: on macOS only, when neither
|
||||
/// Lutra's environment nor `extra` sets `LANG`, `LC_ALL` or `LC_CTYPE`.
|
||||
/// An app started from the Finder or Dock gets no locale, and without one
|
||||
/// zsh and most tools treat non-ASCII text (umlauts in file names and
|
||||
/// output) as unknown bytes; Terminal.app sets `LANG` the same way.
|
||||
fn needs_utf8_locale(extra: &[(OsString, OsString)]) -> bool {
|
||||
const LOCALE_VARS: [&str; 3] = ["LANG", "LC_ALL", "LC_CTYPE"];
|
||||
cfg!(target_os = "macos")
|
||||
&& LOCALE_VARS
|
||||
.iter()
|
||||
.all(|name| std::env::var_os(name).is_none_or(|v| v.is_empty()))
|
||||
&& !extra
|
||||
.iter()
|
||||
.any(|(key, _)| LOCALE_VARS.iter().any(|name| key == name))
|
||||
}
|
||||
|
||||
/// A spawn error from any displayable cause.
|
||||
fn spawn_error(e: impl std::fmt::Display) -> TerminalError {
|
||||
TerminalError::Spawn(e.to_string())
|
||||
|
|
@ -188,6 +204,9 @@ impl Session {
|
|||
cmd.env("TERM", "xterm-256color");
|
||||
cmd.env("COLORTERM", "truecolor");
|
||||
cmd.env("TERM_PROGRAM", "Lutra");
|
||||
if needs_utf8_locale(&options.env) {
|
||||
cmd.env("LANG", "en_US.UTF-8");
|
||||
}
|
||||
for (key, value) in &options.env {
|
||||
cmd.env(key, value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,13 @@ impl Shell {
|
|||
/// - **Windows:** `pwsh.exe` (PowerShell 7) from `PATH`, else
|
||||
/// `powershell.exe` (Windows PowerShell), else `%COMSPEC%`, else
|
||||
/// `cmd.exe`. PowerShell starts with `-NoLogo`.
|
||||
/// - **Unix:** `$SHELL`, else `/bin/sh`.
|
||||
/// - **macOS:** `$SHELL`, else `/bin/zsh` (the default login shell since
|
||||
/// macOS 10.15), else `/bin/sh`, started as a login shell (`-l`) the way
|
||||
/// Terminal.app does. A login shell reads `~/.zprofile`, where Homebrew
|
||||
/// puts `/opt/homebrew/bin` on the `PATH`; without it, PHP and Composer
|
||||
/// from Homebrew are missing in a Lutra started from the Finder or Dock,
|
||||
/// which inherits only the system `PATH`.
|
||||
/// - **Other Unix:** `$SHELL`, else `/bin/sh`.
|
||||
pub fn default_shell() -> Shell {
|
||||
if cfg!(windows) {
|
||||
for name in ["pwsh.exe", "powershell.exe"] {
|
||||
|
|
@ -46,6 +52,15 @@ pub fn default_shell() -> Shell {
|
|||
let shell = std::env::var_os("SHELL")
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(PathBuf::from);
|
||||
if cfg!(target_os = "macos") {
|
||||
let program = shell
|
||||
.or_else(|| Some(PathBuf::from("/bin/zsh")).filter(|p| p.is_file()))
|
||||
.unwrap_or_else(|| PathBuf::from("/bin/sh"));
|
||||
return Shell {
|
||||
program,
|
||||
args: vec![OsString::from("-l")],
|
||||
};
|
||||
}
|
||||
Shell::new(shell.unwrap_or_else(|| PathBuf::from("/bin/sh")))
|
||||
}
|
||||
|
||||
|
|
@ -101,6 +116,12 @@ mod tests {
|
|||
assert!(found, "{shell:?}");
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn macos_starts_a_login_shell() {
|
||||
assert_eq!(default_shell().args, vec![OsString::from("-l")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finds_programs_in_path() {
|
||||
let name = if cfg!(windows) { "cmd" } else { "sh" };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue