Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,11 @@ jobs:
run: make test
working-directory: ./test/hextarball

- name: test/running_modules
- name: Test deletion of escript compile file after compilation
run: ./test.sh
working-directory: ./test/delete_escript_after_compilation

- name: Test running modules
run: make test-all
working-directory: ./test/running_modules

Expand Down
11 changes: 7 additions & 4 deletions compiler-cli/src/beam_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ impl BeamCompiler {
let mut buf = String::new();
let mut accumulated_modules: Vec<String> = Vec::new();
while let (Ok(_), Ok(None)) = (inner.stdout.read_line(&mut buf), inner.process.try_wait()) {
let escript_path = paths::compilation_escript_path(out);

// Delete escript file, which is unnecessary after compilation
io.delete_file(&escript_path)?;

match buf.trim() {
"gleam-compile-result-ok" => {
// Return Ok with the accumulated modules
Expand All @@ -91,7 +96,7 @@ impl BeamCompiler {
buf.clear()
}

// if we get here, stdout got closed before we got an "ok" or "err".
// If we get here, stdout got closed before we got an "ok" or "err".
Err(Error::ShellCommand {
program: "escript".into(),
reason: ShellCommandFailureReason::Unknown,
Expand All @@ -103,9 +108,7 @@ impl BeamCompiler {
io: &IO,
out: &Utf8Path,
) -> Result<BeamCompilerInner, Error> {
let escript_path = out
.join(paths::ARTEFACT_DIRECTORY_NAME)
.join("gleam@@compile.erl");
let escript_path = paths::compilation_escript_path(out);

let escript_source = std::include_str!("../templates/gleam@@compile.erl");
io.write(&escript_path, escript_source)?;
Expand Down
4 changes: 4 additions & 0 deletions compiler-core/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ impl ProjectPaths {
}
}

pub fn compilation_escript_path(out: &Utf8Path) -> Utf8PathBuf {
out.join(ARTEFACT_DIRECTORY_NAME).join("gleam@@compile.erl")
}

Comment on lines +136 to +139
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lpil I've moved this function to paths module. I've thought about placing it under ProjectPaths, but BeamCompiler and its callers don't receive ProjectPaths, they receive just out, so this would require some refactoring. What are your thoughts?

pub fn global_package_cache_package_tarball(checksum: &Base16Checksum) -> Utf8PathBuf {
global_packages_cache().join(format!("{}.tar", checksum.to_string()))
}
Expand Down
1 change: 1 addition & 0 deletions test/delete_escript_after_compilation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
10 changes: 10 additions & 0 deletions test/delete_escript_after_compilation/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# TODO: migrate to Rust shell commands, possibly ./compiler-cli/src/fs/tests.rs
test:
# clean build directory && build the project
cargo run clean && cargo run build

# fail if file exists
@if find build -name "gleam@@compile.erl" | grep -q .; then \
echo "Error: gleam@@compile.erl file(s) still exist after build"; \
exit 1; \
fi
4 changes: 4 additions & 0 deletions test/delete_escript_after_compilation/gleam.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "delete_escript_after_compilation"
version = "1.0.0"
description = "Test project to delete escript compile file after compilation"
licences = ["Apache-2.0"]
7 changes: 7 additions & 0 deletions test/delete_escript_after_compilation/manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Gleam
# You typically do not need to edit this file

packages = [
]

[requirements]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn something() {
"Just a thing to export"
}
26 changes: 26 additions & 0 deletions test/delete_escript_after_compilation/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

set -eu

GLEAM_COMMAND=${GLEAM_COMMAND:-"cargo run --quiet --"}

g() {
echo "Running: $GLEAM_COMMAND $@"
$GLEAM_COMMAND "$@"
}

echo Resetting the build directory to get to a known state
rm -rf build

echo Building the project
g build

echo Searching for leftover gleam@@compile.erl files
if find build -name "gleam@@compile.erl" | grep -q .; then
echo "ERROR: gleam@@compile.erl file(s) still exist after build"
exit 1
fi

echo
echo None found! Success!
echo
Loading