Skip to content

Commit c2eae21

Browse files
committed
Include both shell and ps1 entrypoint scripts with gleam export erlang-shipment #4360
1 parent 9f44f6a commit c2eae21

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

compiler-cli/src/export.rs

+30-19
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ use gleam_core::{
66
paths::ProjectPaths,
77
};
88

9-
#[cfg(target_os = "windows")]
10-
static ENTRYPOINT_FILENAME: &str = "entrypoint.ps1";
11-
#[cfg(not(target_os = "windows"))]
12-
static ENTRYPOINT_FILENAME: &str = "entrypoint.sh";
9+
static ENTRYPOINT_FILENAME_POWERSHELL: &str = "entrypoint.ps1";
10+
static ENTRYPOINT_FILENAME_BOURNE_SHELL: &str = "entrypoint.sh";
1311

14-
#[cfg(target_os = "windows")]
15-
static ENTRYPOINT_TEMPLATE: &str = include_str!("../templates/erlang-shipment-entrypoint.ps1");
16-
#[cfg(not(target_os = "windows"))]
17-
static ENTRYPOINT_TEMPLATE: &str = include_str!("../templates/erlang-shipment-entrypoint.sh");
12+
static ENTRYPOINT_TEMPLATE_POWERSHELL: &str =
13+
include_str!("../templates/erlang-shipment-entrypoint.ps1");
14+
static ENTRYPOINT_TEMPLATE_BOURNE_SHELL: &str =
15+
include_str!("../templates/erlang-shipment-entrypoint.sh");
1816

1917
// TODO: start in embedded mode
2018
// TODO: test
@@ -78,23 +76,36 @@ pub(crate) fn erlang_shipment(paths: &ProjectPaths) -> Result<()> {
7876
}
7977
}
8078

81-
// Write entrypoint script
82-
let entrypoint = out.join(ENTRYPOINT_FILENAME);
83-
let text =
84-
ENTRYPOINT_TEMPLATE.replace("$PACKAGE_NAME_FROM_GLEAM", &built.root_package.config.name);
85-
crate::fs::write(&entrypoint, &text)?;
86-
crate::fs::make_executable(&entrypoint)?;
79+
for (entrypoint_filename, entrypoint_template_path) in [
80+
(
81+
ENTRYPOINT_FILENAME_POWERSHELL,
82+
ENTRYPOINT_TEMPLATE_POWERSHELL,
83+
),
84+
(
85+
ENTRYPOINT_FILENAME_BOURNE_SHELL,
86+
ENTRYPOINT_TEMPLATE_BOURNE_SHELL,
87+
),
88+
] {
89+
// Write entrypoint script
90+
let entrypoint = out.join(entrypoint_filename);
91+
let text = entrypoint_template_path
92+
.replace("$PACKAGE_NAME_FROM_GLEAM", &built.root_package.config.name);
93+
crate::fs::write(&entrypoint, &text)?;
94+
crate::fs::make_executable(&entrypoint)?;
95+
}
8796

8897
crate::cli::print_exported(&built.root_package.config.name);
8998

9099
println!(
91100
"
92-
Your Erlang shipment has been generated to {out}.
93-
94-
It can be copied to a compatible server with Erlang installed and run with
95-
the {ENTRYPOINT_FILENAME} script.
101+
Your Erlang shipment has been generated to {out}."
102+
);
96103

97-
{entrypoint}
104+
println!(
105+
"
106+
It can be copied to a compatible server with Erlang installed and run with one of the following scripts:
107+
- {ENTRYPOINT_FILENAME_POWERSHELL} (PowerShell script)
108+
- {ENTRYPOINT_FILENAME_BOURNE_SHELL} (Bourne Shell script)
98109
",
99110
);
100111

0 commit comments

Comments
 (0)