From c2eae21a36f9848a90bdc3add3c0649bb77657f4 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Sun, 16 Mar 2025 23:06:39 +0100 Subject: [PATCH 1/4] Include both shell and ps1 entrypoint scripts with gleam export erlang-shipment #4360 --- compiler-cli/src/export.rs | 49 +++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/compiler-cli/src/export.rs b/compiler-cli/src/export.rs index 60e9429c58e..0669cecbf76 100644 --- a/compiler-cli/src/export.rs +++ b/compiler-cli/src/export.rs @@ -6,15 +6,13 @@ use gleam_core::{ paths::ProjectPaths, }; -#[cfg(target_os = "windows")] -static ENTRYPOINT_FILENAME: &str = "entrypoint.ps1"; -#[cfg(not(target_os = "windows"))] -static ENTRYPOINT_FILENAME: &str = "entrypoint.sh"; +static ENTRYPOINT_FILENAME_POWERSHELL: &str = "entrypoint.ps1"; +static ENTRYPOINT_FILENAME_BOURNE_SHELL: &str = "entrypoint.sh"; -#[cfg(target_os = "windows")] -static ENTRYPOINT_TEMPLATE: &str = include_str!("../templates/erlang-shipment-entrypoint.ps1"); -#[cfg(not(target_os = "windows"))] -static ENTRYPOINT_TEMPLATE: &str = include_str!("../templates/erlang-shipment-entrypoint.sh"); +static ENTRYPOINT_TEMPLATE_POWERSHELL: &str = + include_str!("../templates/erlang-shipment-entrypoint.ps1"); +static ENTRYPOINT_TEMPLATE_BOURNE_SHELL: &str = + include_str!("../templates/erlang-shipment-entrypoint.sh"); // TODO: start in embedded mode // TODO: test @@ -78,23 +76,36 @@ pub(crate) fn erlang_shipment(paths: &ProjectPaths) -> Result<()> { } } - // Write entrypoint script - let entrypoint = out.join(ENTRYPOINT_FILENAME); - let text = - ENTRYPOINT_TEMPLATE.replace("$PACKAGE_NAME_FROM_GLEAM", &built.root_package.config.name); - crate::fs::write(&entrypoint, &text)?; - crate::fs::make_executable(&entrypoint)?; + for (entrypoint_filename, entrypoint_template_path) in [ + ( + ENTRYPOINT_FILENAME_POWERSHELL, + ENTRYPOINT_TEMPLATE_POWERSHELL, + ), + ( + ENTRYPOINT_FILENAME_BOURNE_SHELL, + ENTRYPOINT_TEMPLATE_BOURNE_SHELL, + ), + ] { + // Write entrypoint script + let entrypoint = out.join(entrypoint_filename); + let text = entrypoint_template_path + .replace("$PACKAGE_NAME_FROM_GLEAM", &built.root_package.config.name); + crate::fs::write(&entrypoint, &text)?; + crate::fs::make_executable(&entrypoint)?; + } crate::cli::print_exported(&built.root_package.config.name); println!( " -Your Erlang shipment has been generated to {out}. - -It can be copied to a compatible server with Erlang installed and run with -the {ENTRYPOINT_FILENAME} script. +Your Erlang shipment has been generated to {out}." + ); - {entrypoint} + println!( + " +It can be copied to a compatible server with Erlang installed and run with one of the following scripts: + - {ENTRYPOINT_FILENAME_POWERSHELL} (PowerShell script) + - {ENTRYPOINT_FILENAME_BOURNE_SHELL} (Bourne Shell script) ", ); From c45c680f048b76f71252603976f2065c1f14e583 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 17 Mar 2025 17:40:14 +0100 Subject: [PATCH 2/4] Use a function instead of a loop. "Bourne Shell" -> "POSIX Shell". --- compiler-cli/src/export.rs | 55 +++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/compiler-cli/src/export.rs b/compiler-cli/src/export.rs index 0669cecbf76..30521a6f04a 100644 --- a/compiler-cli/src/export.rs +++ b/compiler-cli/src/export.rs @@ -7,11 +7,11 @@ use gleam_core::{ }; static ENTRYPOINT_FILENAME_POWERSHELL: &str = "entrypoint.ps1"; -static ENTRYPOINT_FILENAME_BOURNE_SHELL: &str = "entrypoint.sh"; +static ENTRYPOINT_FILENAME_POSIX_SHELL: &str = "entrypoint.sh"; static ENTRYPOINT_TEMPLATE_POWERSHELL: &str = include_str!("../templates/erlang-shipment-entrypoint.ps1"); -static ENTRYPOINT_TEMPLATE_BOURNE_SHELL: &str = +static ENTRYPOINT_TEMPLATE_POSIX_SHELL: &str = include_str!("../templates/erlang-shipment-entrypoint.sh"); // TODO: start in embedded mode @@ -76,42 +76,47 @@ pub(crate) fn erlang_shipment(paths: &ProjectPaths) -> Result<()> { } } - for (entrypoint_filename, entrypoint_template_path) in [ - ( - ENTRYPOINT_FILENAME_POWERSHELL, - ENTRYPOINT_TEMPLATE_POWERSHELL, - ), - ( - ENTRYPOINT_FILENAME_BOURNE_SHELL, - ENTRYPOINT_TEMPLATE_BOURNE_SHELL, - ), - ] { - // Write entrypoint script - let entrypoint = out.join(entrypoint_filename); - let text = entrypoint_template_path - .replace("$PACKAGE_NAME_FROM_GLEAM", &built.root_package.config.name); - crate::fs::write(&entrypoint, &text)?; - crate::fs::make_executable(&entrypoint)?; - } + // PowerShell entry point script. + write_entrypoint_script( + &out.join(ENTRYPOINT_FILENAME_POWERSHELL), + ENTRYPOINT_TEMPLATE_POWERSHELL, + &built.root_package.config.name, + )?; + + // POSIX Shell entry point script. + write_entrypoint_script( + &out.join(ENTRYPOINT_FILENAME_POSIX_SHELL), + ENTRYPOINT_TEMPLATE_POSIX_SHELL, + &built.root_package.config.name, + )?; crate::cli::print_exported(&built.root_package.config.name); println!( " -Your Erlang shipment has been generated to {out}." - ); +Your Erlang shipment has been generated to {out}. - println!( - " -It can be copied to a compatible server with Erlang installed and run with one of the following scripts: +It can be copied to a compatible server with Erlang installed and run with one of the following +scripts: - {ENTRYPOINT_FILENAME_POWERSHELL} (PowerShell script) - - {ENTRYPOINT_FILENAME_BOURNE_SHELL} (Bourne Shell script) + - {ENTRYPOINT_FILENAME_POSIX_SHELL} (POSIX Shell script) ", ); Ok(()) } +fn write_entrypoint_script( + entrypoint_output_path: &Utf8PathBuf, + entrypoint_template_path: &str, + package_name: &str, +) -> Result<(), gleam_core::Error> { + let text = entrypoint_template_path.replace("$PACKAGE_NAME_FROM_GLEAM", package_name); + crate::fs::write(entrypoint_output_path, &text)?; + crate::fs::make_executable(entrypoint_output_path)?; + Ok(()) +} + pub fn hex_tarball(paths: &ProjectPaths) -> Result<()> { let mut config = crate::config::root_config(paths)?; let data: Vec = crate::publish::build_hex_tarball(paths, &mut config)?; From 882bfa85a07d995234d10685250b9f331b7820ec Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 17 Mar 2025 17:48:05 +0100 Subject: [PATCH 3/4] Wrap output string (80 columns). --- compiler-cli/src/export.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler-cli/src/export.rs b/compiler-cli/src/export.rs index 30521a6f04a..dc29f25b24e 100644 --- a/compiler-cli/src/export.rs +++ b/compiler-cli/src/export.rs @@ -96,8 +96,8 @@ pub(crate) fn erlang_shipment(paths: &ProjectPaths) -> Result<()> { " Your Erlang shipment has been generated to {out}. -It can be copied to a compatible server with Erlang installed and run with one of the following -scripts: +It can be copied to a compatible server with Erlang installed and run with +one of the following scripts: - {ENTRYPOINT_FILENAME_POWERSHELL} (PowerShell script) - {ENTRYPOINT_FILENAME_POSIX_SHELL} (POSIX Shell script) ", From f6322ff1fe9ef7bb02883d0c38328119bcf0b52f Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 17 Mar 2025 18:30:19 +0100 Subject: [PATCH 4/4] Update changelog about 'gleam export erlang-shipment' --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db39aeec975..e61753b2917 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,11 @@ - Include a type annotation for the `main` function generated by `gleam new`. ([Drew Olson](https://github.com/drewolson)) +- Two entry point scripts are now always generated by `gleam export erlang-shipment`: + - `entrypoint.sh` for UNIX Shell + - `entrypoint.ps1` for PowerShell + ([Greg Burri](https://github.com/ummon)) + ### Language server - The language server now allows renaming of functions and constants across