From 3221180315387d81bdb2e1c3f5a5cf5e4fdc1fe3 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 22 Jan 2025 00:26:32 +0100 Subject: [PATCH] Fixes to `"exec" use. --- .github/workflows/main.yml | 30 +++++++++---------- releasenotes.md | 1 + resources/testproject/project.json | 4 +-- resources/testproject/scripts/scriptme.c3 | 7 +++++ resources/testproject/{ => src}/bar.c3 | 0 resources/testproject/{ => src}/foo.c3 | 0 .../testproject/{ => src}/hello_world.c3 | 0 resources/testproject/{ => src}/zab.c3 | 0 src/compiler/compiler.c | 29 +++++++++++++++--- src/utils/file_utils.c | 1 + 10 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 resources/testproject/scripts/scriptme.c3 rename resources/testproject/{ => src}/bar.c3 (100%) rename resources/testproject/{ => src}/foo.c3 (100%) rename resources/testproject/{ => src}/hello_world.c3 (100%) rename resources/testproject/{ => src}/zab.c3 (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 89b0367e3..539cae6b3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,7 +51,7 @@ jobs: run: | call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 cd resources/testproject - ..\..\build\${{ matrix.build_type }}\c3c.exe -vvv --emit-llvm run hello_world_win32 + ..\..\build\${{ matrix.build_type }}\c3c.exe -vvv --emit-llvm run hello_world_win32 --trust=full dir build\llvm_ir ..\..\build\${{ matrix.build_type }}\c3c.exe clean dir build\llvm_ir @@ -61,7 +61,7 @@ jobs: run: | cd resources/testproject call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 - ..\..\build\${{ matrix.build_type }}\c3c.exe -vvv build hello_world_win32_lib + ..\..\build\${{ matrix.build_type }}\c3c.exe -vvv build hello_world_win32_lib --trust=full - name: Compile and run dynlib-test run: | @@ -153,7 +153,7 @@ jobs: - name: Build testproject run: | cd resources/testproject - ../../build/c3c run -vvv + ../../build/c3c run -vvv --trust=full - name: Vendor-fetch run: | @@ -162,7 +162,7 @@ jobs: - name: Build testproject lib run: | cd resources/testproject - ../../build/c3c build hello_world_lib --cc cc -vvv + ../../build/c3c build hello_world_lib --cc cc -vvv --trust=full - name: run compiler tests run: | @@ -209,12 +209,12 @@ jobs: - name: Build testproject run: | cd resources/testproject - ../../build/c3c run -vvv + ../../build/c3c run -vvv --trust=full - name: Build testproject lib run: | cd resources/testproject - ../../build/c3c build hello_world_lib -vvv + ../../build/c3c build hello_world_lib -vvv --trust=full - name: run compiler tests run: | @@ -349,7 +349,7 @@ jobs: - name: Build testproject run: | cd resources/testproject - ../../build/c3c run -vvv + ../../build/c3c run -vvv --trust=full - name: Test WASM run: | @@ -368,7 +368,7 @@ jobs: - name: Build testproject direct linker run: | cd resources/testproject - ../../build/c3c run -vvv --linker=builtin + ../../build/c3c run -vvv --linker=builtin --trust=full - name: Init a library & a project run: | @@ -491,12 +491,12 @@ jobs: - name: Build testproject run: | cd resources/testproject - ../../build/c3c run -vvv + ../../build/c3c run -vvv --trust=full - name: Build testproject direct linker run: | cd resources/testproject - ../../build/c3c run -vvv --linker=builtin + ../../build/c3c run -vvv --linker=builtin --trust=full - name: run compiler tests run: | @@ -583,7 +583,7 @@ jobs: - name: Build testproject run: | cd resources/testproject - ../../build/c3c run -vvv + ../../build/c3c run -vvv --trust=full - name: Test WASM run: | @@ -593,7 +593,7 @@ jobs: - name: Build testproject direct linker run: | cd resources/testproject - ../../build/c3c run -vvv --linker=builtin + ../../build/c3c run -vvv --linker=builtin --trust=full - name: Init a library & a project run: | @@ -670,17 +670,17 @@ jobs: - name: Build testproject run: | cd resources/testproject - ../../build/c3c run -vvv + ../../build/c3c run -vvv --trust=full - name: Build testproject direct linker run: | cd resources/testproject - ../../build/c3c run -vvv --linker=builtin + ../../build/c3c run -vvv --linker=builtin --trust=full - name: Build testproject lib run: | cd resources/testproject - ../../build/c3c build hello_world_lib -vvv + ../../build/c3c build hello_world_lib -vvv --trust=full - name: run compiler tests run: | diff --git a/releasenotes.md b/releasenotes.md index 72411a60e..a4885839b 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -19,6 +19,7 @@ - Fix `linux-crt` and `linux-crtbegin` not getting recognized as a project paramater - Fix dues to crash when converting a const vector to another vector #1864. - Filter `$exec` output from `\r`, which otherwise would cause a compiler assert #1867. +- Fixes to `"exec" use. ### Stdlib changes - Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter. diff --git a/resources/testproject/project.json b/resources/testproject/project.json index 6b75e902b..485b8f80b 100644 --- a/resources/testproject/project.json +++ b/resources/testproject/project.json @@ -9,13 +9,13 @@ ], // sources compiled "sources": [ - "./**" + "src" ], "dependency-search-paths": [ "./lib" ], "dependencies": ["clib", "clib2"], "features": ["ABCD"], - + "exec": ["scriptme.c3 myarg"], // c sources "targets": { "hello_world": { diff --git a/resources/testproject/scripts/scriptme.c3 b/resources/testproject/scripts/scriptme.c3 new file mode 100644 index 000000000..17b7e9f6f --- /dev/null +++ b/resources/testproject/scripts/scriptme.c3 @@ -0,0 +1,7 @@ +import std; +fn int main(String[] args) +{ + if (args.len == 1) return 1; + io::printn("Hello from script!"); + return 0; +} \ No newline at end of file diff --git a/resources/testproject/bar.c3 b/resources/testproject/src/bar.c3 similarity index 100% rename from resources/testproject/bar.c3 rename to resources/testproject/src/bar.c3 diff --git a/resources/testproject/foo.c3 b/resources/testproject/src/foo.c3 similarity index 100% rename from resources/testproject/foo.c3 rename to resources/testproject/src/foo.c3 diff --git a/resources/testproject/hello_world.c3 b/resources/testproject/src/hello_world.c3 similarity index 100% rename from resources/testproject/hello_world.c3 rename to resources/testproject/src/hello_world.c3 diff --git a/resources/testproject/zab.c3 b/resources/testproject/src/zab.c3 similarity index 100% rename from resources/testproject/zab.c3 rename to resources/testproject/src/zab.c3 diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 6d9798922..e4922df87 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -1124,15 +1124,36 @@ void execute_scripts(void) { StringSlice execs = slice_from_string(exec); StringSlice call = slice_next_token(&execs, ' '); + size_t out_len; + const char *out; if (call.len < 3 || call.ptr[call.len - 3] != '.' || call.ptr[call.len - 2] != 'c' || - call.ptr[call.len - 2] != '3') + call.ptr[call.len - 1] != '3') { - (void) execute_cmd(exec, false, NULL); - continue; + out = execute_cmd(exec, false, NULL); + if (compiler.build.silent) continue; + out_len = strlen(out); + goto PRINT_SCRIPT; } scratch_buffer_clear(); scratch_buffer_append_len(call.ptr, call.len); - (void) compile_and_invoke(scratch_buffer_copy(), execs.len ? execs.ptr : "", NULL); + File *script = compile_and_invoke(scratch_buffer_copy(), execs.len ? execs.ptr : "", NULL); + out = script->contents; + out_len = script->content_len; +PRINT_SCRIPT:; + if (!compiler.build.silent && script->content_len > 0) + { + if (out_len > 2048) + { + puts("Truncated script output --------------------------------->"); + out_len = 2048; + } + else + { + puts("Script output ------------------------------------------->"); + } + printf("%.*s\n", (int)out_len, out); + puts("---------------------------------------------------------<"); + } } dir_change(old_path); free(old_path); diff --git a/src/utils/file_utils.c b/src/utils/file_utils.c index ba3d81bc9..d3cf6dad4 100644 --- a/src/utils/file_utils.c +++ b/src/utils/file_utils.c @@ -217,6 +217,7 @@ bool file_touch(const char *path) size_t file_clean_buffer(char *buffer, const char *path, size_t file_size) { + if (file_size == 0) return 0; size_t offset = 0; // Simple UTF16 detection if (buffer[0] == (char)0xFF || buffer[1] == (char)0xFE)