diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 312bd695be8..33d75e903d7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 78b35b9839f..2d41d9ea065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,10 @@ an empty README. ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) +- The build tool now deletes `escript` file after compilation, which is + unnecessary once the build is completed. + ([Andrey Kozhev](https://github.com/ankddev)) + ### Language server - The language server now allows extracting the start of a pipeline into a diff --git a/compiler-cli/src/beam_compiler.rs b/compiler-cli/src/beam_compiler.rs index 79ef4e49de5..f6d58b25161 100644 --- a/compiler-cli/src/beam_compiler.rs +++ b/compiler-cli/src/beam_compiler.rs @@ -66,6 +66,11 @@ impl BeamCompiler { let mut buf = String::new(); let mut accumulated_modules: Vec = 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 @@ -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, @@ -103,9 +108,7 @@ impl BeamCompiler { io: &IO, out: &Utf8Path, ) -> Result { - 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)?; diff --git a/compiler-core/src/paths.rs b/compiler-core/src/paths.rs index ad66dbecb48..d74024b1ed0 100644 --- a/compiler-core/src/paths.rs +++ b/compiler-core/src/paths.rs @@ -133,6 +133,10 @@ impl ProjectPaths { } } +pub fn compilation_escript_path(out: &Utf8Path) -> Utf8PathBuf { + out.join(ARTEFACT_DIRECTORY_NAME).join("gleam@@compile.erl") +} + pub fn global_package_cache_package_tarball(checksum: &Base16Checksum) -> Utf8PathBuf { global_packages_cache().join(format!("{}.tar", checksum.to_string())) } diff --git a/test/delete_escript_after_compilation/.gitignore b/test/delete_escript_after_compilation/.gitignore new file mode 100644 index 00000000000..796b96d1c40 --- /dev/null +++ b/test/delete_escript_after_compilation/.gitignore @@ -0,0 +1 @@ +/build diff --git a/test/delete_escript_after_compilation/gleam.toml b/test/delete_escript_after_compilation/gleam.toml new file mode 100644 index 00000000000..d5f7adc95ed --- /dev/null +++ b/test/delete_escript_after_compilation/gleam.toml @@ -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"] diff --git a/test/delete_escript_after_compilation/manifest.toml b/test/delete_escript_after_compilation/manifest.toml new file mode 100644 index 00000000000..c5d779a3f81 --- /dev/null +++ b/test/delete_escript_after_compilation/manifest.toml @@ -0,0 +1,7 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ +] + +[requirements] diff --git a/test/delete_escript_after_compilation/src/delete_escript_after_compilation.gleam b/test/delete_escript_after_compilation/src/delete_escript_after_compilation.gleam new file mode 100644 index 00000000000..86ee73c178c --- /dev/null +++ b/test/delete_escript_after_compilation/src/delete_escript_after_compilation.gleam @@ -0,0 +1,3 @@ +pub fn something() { + "Just a thing to export" +} diff --git a/test/delete_escript_after_compilation/test.sh b/test/delete_escript_after_compilation/test.sh new file mode 100755 index 00000000000..58c14b8258c --- /dev/null +++ b/test/delete_escript_after_compilation/test.sh @@ -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