Fixes to `"exec" use.

This commit is contained in:
Christoffer Lerno
2025-01-22 00:26:32 +01:00
parent c326c525be
commit 3221180315
10 changed files with 51 additions and 21 deletions

View File

@@ -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: |

View File

@@ -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.

View File

@@ -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": {

View File

@@ -0,0 +1,7 @@
import std;
fn int main(String[] args)
{
if (args.len == 1) return 1;
io::printn("Hello from script!");
return 0;
}

View File

@@ -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);

View File

@@ -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)