Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/migrations/upgrade_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn upgrade_check(_options: &Options, options: &UpgradeCheck) -> anyhow::Resu
.context("tempfile failure")?
.into_temp_path();

let mut cmd = windows::ensure_wsl()?.edgedb();
let mut cmd = windows::ensure_wsl()?.cli_exe();
cmd.arg("migration").arg("upgrade-check");
cmd.args(&UpgradeCheck {
run_server_with_status: Some(windows::path_to_linux(&status_path)?.into()),
Expand Down
72 changes: 39 additions & 33 deletions src/portable/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static IS_IN_WSL: Lazy<bool> = Lazy::new(|| {
}
});

const USR_BIN_EXE: &str = const_format::concatcp!("/usr/bin/", BRANDING_CLI_CMD);

static WSL: OnceCell<Wsl> = OnceCell::new();

#[derive(Debug, thiserror::Error)]
Expand All @@ -83,8 +85,8 @@ struct WslInfo {
}

impl Wsl {
pub fn edgedb(&self) -> process::Native {
let mut pro = process::Native::new("edgedb", "edgedb", "wsl");
pub fn cli_exe(&self) -> process::Native {
let mut pro = process::Native::new(BRANDING_CLI_CMD, BRANDING_CLI_CMD, "wsl");
pro.arg("--user").arg("edgedb");
pro.arg("--distribution").arg(&self.distribution);
pro.arg("_EDGEDB_FROM_WINDOWS=1");
Expand All @@ -94,7 +96,7 @@ impl Wsl {
pair.push(log_env);
pro.arg(pair);
}
pro.arg("/usr/bin/edgedb");
pro.arg(USR_BIN_EXE);
pro.no_proxy();
pro
}
Expand Down Expand Up @@ -234,7 +236,7 @@ pub fn create_instance(
port: Some(port),
..options.clone()
};
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("create")
.args(&inner_options)
Expand All @@ -257,7 +259,7 @@ pub fn destroy(options: &destroy::Command, name: &str) -> anyhow::Result<()> {
..options.clone()
};
let status = wsl
.edgedb()
.cli_exe()
.arg("instance")
.arg("destroy")
.args(&options)
Expand Down Expand Up @@ -345,12 +347,12 @@ fn wsl_cli_version(distro: &str) -> anyhow::Result<ver::Semver> {
// Note: cannot capture output using wsl.launch

use const_format::concatcp;
let data = process::Native::new("check version", "edgedb", "wsl")
let data = process::Native::new("check version", BRANDING_CLI_CMD, "wsl")
.arg("--user")
.arg("edgedb")
.arg("--distribution")
.arg(distro)
.arg("/usr/bin/edgedb")
.arg(USR_BIN_EXE)
.arg("--version")
.get_stdout_text()?;
let version = data
Expand Down Expand Up @@ -543,7 +545,7 @@ fn get_wsl_distro(install: bool) -> anyhow::Result<Wsl> {
&wsl,
&distro,
&format!(
"cp {} /usr/bin/edgedb && chmod 755 /usr/bin/edgedb",
"cp {} {USR_BIN_EXE} && chmod 755 {USR_BIN_EXE}",
shell_escape::unix::escape(path_to_linux(&bin_path)?.into()),
),
)?;
Expand All @@ -554,7 +556,7 @@ fn get_wsl_distro(install: bool) -> anyhow::Result<Wsl> {
&wsl,
&distro,
&format!(
"mv {} /usr/bin/edgedb && chmod 755 /usr/bin/edgedb",
"mv {} {USR_BIN_EXE} && chmod 755 {USR_BIN_EXE}",
shell_escape::unix::escape(path_to_linux(&cache_path)?.into()),
),
)?;
Expand Down Expand Up @@ -656,7 +658,7 @@ pub fn create_service(info: &InstanceInfo) -> anyhow::Result<()> {
}

fn create_and_start(wsl: &Wsl, name: &str) -> anyhow::Result<()> {
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("start")
.arg("-I")
Expand All @@ -666,9 +668,9 @@ fn create_and_start(wsl: &Wsl, name: &str) -> anyhow::Result<()> {
service_file(name)?,
format!(
"wsl \
--distribution {} --user edgedb \
/usr/bin/edgedb instance start -I {}",
&wsl.distribution, &name
--distribution {} --user edgedb \
{USR_BIN_EXE} instance start -I {name}",
&wsl.distribution,
),
)?;
Ok(())
Expand All @@ -680,7 +682,7 @@ pub fn stop_and_disable(_name: &str) -> anyhow::Result<bool> {

pub fn server_cmd(instance: &str, _is_shutdown_supported: bool) -> anyhow::Result<process::Native> {
let wsl = try_get_wsl()?;
let mut pro = wsl.edgedb();
let mut pro = wsl.cli_exe();
pro.arg("instance")
.arg("start")
.arg("--foreground")
Expand All @@ -692,7 +694,7 @@ pub fn server_cmd(instance: &str, _is_shutdown_supported: bool) -> anyhow::Resul
cmd.arg("--user").arg("edgedb");
cmd.arg("--distribution").arg(&wsl.distribution);
cmd.arg("_EDGEDB_FROM_WINDOWS=1");
cmd.arg("/usr/bin/edgedb");
cmd.arg(USR_BIN_EXE);
cmd.arg("instance").arg("stop").arg("-I").arg(&instance);
cmd
});
Expand All @@ -701,7 +703,7 @@ pub fn server_cmd(instance: &str, _is_shutdown_supported: bool) -> anyhow::Resul

pub fn daemon_start(instance: &str) -> anyhow::Result<()> {
let wsl = try_get_wsl()?;
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("start")
.arg("-I")
Expand Down Expand Up @@ -739,7 +741,7 @@ pub fn is_wrapped() -> bool {

pub fn install(options: &server::install::Command) -> anyhow::Result<()> {
ensure_wsl()?
.edgedb()
.cli_exe()
.arg("server")
.arg("install")
.args(options)
Expand All @@ -749,7 +751,7 @@ pub fn install(options: &server::install::Command) -> anyhow::Result<()> {

pub fn uninstall(options: &server::uninstall::Command) -> anyhow::Result<()> {
if let Some(wsl) = get_wsl()? {
wsl.edgedb()
wsl.cli_exe()
.arg("server")
.arg("uninstall")
.args(options)
Expand All @@ -765,7 +767,7 @@ pub fn uninstall(options: &server::uninstall::Command) -> anyhow::Result<()> {

pub fn list_versions(options: &server::list_versions::Command) -> anyhow::Result<()> {
if let Some(wsl) = get_wsl()? {
wsl.edgedb()
wsl.cli_exe()
.arg("server")
.arg("list-versions")
.args(options)
Expand All @@ -783,7 +785,11 @@ pub fn list_versions(options: &server::list_versions::Command) -> anyhow::Result

pub fn info(options: &server::info::Command) -> anyhow::Result<()> {
if let Some(wsl) = get_wsl()? {
wsl.edgedb().arg("server").arg("info").args(options).run()?;
wsl.cli_exe()
.arg("server")
.arg("info")
.args(options)
.run()?;
} else {
anyhow::bail!(
"WSL distribution is not installed, \
Expand All @@ -798,7 +804,7 @@ pub fn reset_password(
name: &str,
) -> anyhow::Result<()> {
if let Some(wsl) = get_wsl()? {
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("reset-password")
.args(options)
Expand All @@ -816,7 +822,7 @@ pub fn reset_password(
pub fn start(options: &control::Start, name: &str) -> anyhow::Result<()> {
if let Some(wsl) = get_wsl()? {
if options.foreground {
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("start")
.args(options)
Expand All @@ -839,7 +845,7 @@ pub fn stop(options: &control::Stop, name: &str) -> anyhow::Result<()> {
fs::remove_file(&service_file)
.map_err(|e| log::warn!("error removing {service_file:?}: {e:#}"))
.ok();
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("stop")
.args(options)
Expand All @@ -855,7 +861,7 @@ pub fn stop(options: &control::Stop, name: &str) -> anyhow::Result<()> {

pub fn restart(options: &control::Restart) -> anyhow::Result<()> {
if let Some(wsl) = get_wsl()? {
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("restart")
.args(options)
Expand All @@ -871,7 +877,7 @@ pub fn restart(options: &control::Restart) -> anyhow::Result<()> {

pub fn logs(options: &control::Logs) -> anyhow::Result<()> {
if let Some(wsl) = get_wsl()? {
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("logs")
.args(options)
Expand All @@ -888,7 +894,7 @@ pub fn logs(options: &control::Logs) -> anyhow::Result<()> {
pub fn status(options: &status::Status) -> anyhow::Result<()> {
if options.service {
if let Some(wsl) = get_wsl()? {
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("status")
.args(options)
Expand All @@ -907,7 +913,7 @@ pub fn status(options: &status::Status) -> anyhow::Result<()> {
};
if let Some(wsl) = get_wsl()? {
let status = wsl
.edgedb()
.cli_exe()
.arg("instance")
.arg("status")
.args(&inner_opts)
Expand All @@ -932,7 +938,7 @@ fn list_local(options: &status::List) -> anyhow::Result<Vec<status::JsonStatus>>
..options.clone()
};
if let Some(wsl) = get_wsl()? {
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("list")
.args(&inner_opts)
Expand All @@ -948,7 +954,7 @@ fn list_local(options: &status::List) -> anyhow::Result<Vec<status::JsonStatus>>
};
let local: Vec<status::JsonStatus> = if let Some(wsl) = get_wsl()? {
let text = wsl
.edgedb()
.cli_exe()
.arg("instance")
.arg("list")
.args(&inner_opts)
Expand Down Expand Up @@ -1030,7 +1036,7 @@ pub fn list(options: &status::List, opts: &crate::Options) -> anyhow::Result<()>

pub fn upgrade(options: &instance::upgrade::Command, name: &str) -> anyhow::Result<()> {
let wsl = try_get_wsl()?;
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("upgrade")
.args(options)
Expand All @@ -1042,7 +1048,7 @@ pub fn upgrade(options: &instance::upgrade::Command, name: &str) -> anyhow::Resu

pub fn revert(options: &instance::revert::Command, name: &str) -> anyhow::Result<()> {
let wsl = try_get_wsl()?;
wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("revert")
.args(options)
Expand Down Expand Up @@ -1107,7 +1113,7 @@ pub fn extension_install(
..cmd.clone()
};

wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("install")
.args(&options)
Expand All @@ -1126,7 +1132,7 @@ pub fn extension_uninstall(
..cmd.clone()
};

wsl.edgedb()
wsl.cli_exe()
.arg("instance")
.arg("uninstall")
.args(&options)
Expand Down
1 change: 1 addition & 0 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl Native {
self
}

#[allow(dead_code)]
pub fn quiet(&mut self) -> &mut Self {
self.quiet = true;
self
Expand Down
9 changes: 5 additions & 4 deletions src/watch/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ pub async fn run_script(
script: &str,
current_dir: &path::Path,
) -> Result<std::process::ExitStatus, anyhow::Error> {
let marker = marker.to_string();

let status = if !cfg!(windows) {
let marker = marker.to_string();
process::Native::new("", marker, "/bin/sh")
.arg("-c")
.arg(script)
.current_dir(current_dir)
.run_for_status()
.await?
} else {
let wsl = windows::try_get_wsl()?;
wsl.sh(current_dir)
.arg("-c")
process::Native::new("", marker, "cmd.exe")
.arg("/c")
.arg(script)
.current_dir(current_dir)
.run_for_status()
.await?
};
Expand Down
1 change: 0 additions & 1 deletion tests/portable_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ fn project_link_and_init() {
}

#[test]
#[cfg(not(target_os = "windows"))]
fn hooks() {
use std::{fs, path};

Expand Down