Skip to content

Commit f181380

Browse files
committed
Simplify changes to beam compiler shell communication handling
1 parent 0631852 commit f181380

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

compiler-cli/src/beam_compiler.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,26 @@ impl BeamCompiler {
6666
let mut buf = String::new();
6767
let mut accumulated_modules: Vec<String> = Vec::new();
6868
while let (Ok(_), Ok(None)) = (inner.stdout.read_line(&mut buf), inner.process.try_wait()) {
69-
let trimmed = buf.trim();
70-
71-
if trimmed.starts_with("gleam-compile") {
72-
match trimmed {
73-
"gleam-compile-result-ok" => {
74-
// Return Ok with the accumulated modules
75-
return Ok(accumulated_modules);
76-
}
77-
"gleam-compile-result-error" => {
78-
return Err(Error::ShellCommand {
79-
program: "escript".into(),
80-
err: None,
81-
});
82-
}
83-
_ => {}
69+
match buf.trim() {
70+
"gleam-compile-result-ok" => {
71+
// Return Ok with the accumulated modules
72+
return Ok(accumulated_modules);
8473
}
85-
} else if trimmed.starts_with("module:") {
86-
if let Some(module_content) = trimmed.strip_prefix("module:") {
87-
accumulated_modules.push(module_content.to_string());
74+
"gleam-compile-result-error" => {
75+
return Err(Error::ShellCommand {
76+
program: "escript".into(),
77+
err: None,
78+
})
8879
}
89-
} else {
90-
match stdio {
91-
Stdio::Inherit => {
92-
print!("{}", buf);
80+
s if s.starts_with("gleam-compile-module:") => {
81+
if let Some(module_content) = s.strip_prefix("gleam-compile-module:") {
82+
accumulated_modules.push(module_content.to_string());
9383
}
94-
Stdio::Null => {}
9584
}
85+
_ => match stdio {
86+
Stdio::Inherit => print!("{}", buf),
87+
Stdio::Null => {}
88+
},
9689
}
9790

9891
buf.clear()

compiler-cli/templates/gleam@@compile.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ compile_package_loop() ->
1616
case compile_package(Lib, Out, Modules) of
1717
{ok, ModuleNames} ->
1818
PrintModuleName = fun(ModuleName) ->
19-
io:put_chars("module:" ++ atom_to_list(ModuleName) ++ "\n")
19+
io:put_chars("gleam-compile-module:" ++ atom_to_list(ModuleName) ++ "\n")
2020
end,
2121
lists:map(PrintModuleName, ModuleNames),
2222
io:put_chars("gleam-compile-result-ok\n");

0 commit comments

Comments
 (0)