Merge pull request #38 from birth-software/more-fixes-and-improvements
More fixes and improvements for the build program
This commit is contained in:
commit
b9b3151c61
@ -1,6 +1,7 @@
|
|||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
|
|
||||||
#define build_dir "build"
|
#define build_dir "build"
|
||||||
|
#define nest_dir "nest"
|
||||||
|
|
||||||
typedef enum OptimizationMode : u8
|
typedef enum OptimizationMode : u8
|
||||||
{
|
{
|
||||||
@ -282,9 +283,10 @@ fn void run_tests(Arena* arena, TestOptions const * const test_options, char** e
|
|||||||
print("===========================\n\n");
|
print("===========================\n\n");
|
||||||
|
|
||||||
String compiler_path = arena_join_string(arena, ((Slice(String)) array_to_slice(((String[]){
|
String compiler_path = arena_join_string(arena, ((Slice(String)) array_to_slice(((String[]){
|
||||||
strlit(build_dir "/"),
|
strlit(build_dir "/" "nest"),
|
||||||
strlit("nest"),
|
strlit("_"),
|
||||||
optimization_string,
|
optimization_string,
|
||||||
|
strlit("_"),
|
||||||
linkage_string,
|
linkage_string,
|
||||||
}))));
|
}))));
|
||||||
compile_options.out_path = string_to_c(compiler_path);
|
compile_options.out_path = string_to_c(compiler_path);
|
||||||
@ -299,6 +301,8 @@ fn void run_tests(Arena* arena, TestOptions const * const test_options, char** e
|
|||||||
{
|
{
|
||||||
String test_path = test_options->test_paths.pointer[test_i];
|
String test_path = test_options->test_paths.pointer[test_i];
|
||||||
char* test_path_c = string_to_c(test_path);
|
char* test_path_c = string_to_c(test_path);
|
||||||
|
auto test_dir = string_no_extension(test_path);
|
||||||
|
auto test_name = string_base(test_dir);
|
||||||
|
|
||||||
for (u32 engine_i = 0; engine_i < test_options->execution_engines.length; engine_i += 1)
|
for (u32 engine_i = 0; engine_i < test_options->execution_engines.length; engine_i += 1)
|
||||||
{
|
{
|
||||||
@ -323,12 +327,17 @@ fn void run_tests(Arena* arena, TestOptions const * const test_options, char** e
|
|||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
run_command((CStringSlice) array_to_slice(arguments), envp);
|
run_command((CStringSlice) array_to_slice(arguments), envp);
|
||||||
|
|
||||||
if (execution_engine != EXECUTION_ENGINE_INTERPRETER)
|
if (execution_engine != EXECUTION_ENGINE_INTERPRETER)
|
||||||
{
|
{
|
||||||
|
String out_program = arena_join_string(arena, ((Slice(String)) array_to_slice(((String[]){
|
||||||
|
strlit(nest_dir "/"),
|
||||||
|
test_name,
|
||||||
|
}))));
|
||||||
char* run_arguments[] = {
|
char* run_arguments[] = {
|
||||||
compile_options.out_path,
|
string_to_c(out_program),
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
run_command((CStringSlice) array_to_slice(run_arguments), envp);
|
run_command((CStringSlice) array_to_slice(run_arguments), envp);
|
||||||
@ -350,6 +359,7 @@ int main(int argc, char* argv[], char** envp)
|
|||||||
ExecutionEngine preferred_execution_engine = EXECUTION_ENGINE_COUNT;
|
ExecutionEngine preferred_execution_engine = EXECUTION_ENGINE_COUNT;
|
||||||
Command command = COMMAND_COUNT;
|
Command command = COMMAND_COUNT;
|
||||||
u8 test_every_config = 0;
|
u8 test_every_config = 0;
|
||||||
|
String source_file_path = {};
|
||||||
|
|
||||||
for (int i = 1; i < argc; i += 1)
|
for (int i = 1; i < argc; i += 1)
|
||||||
{
|
{
|
||||||
@ -377,6 +387,20 @@ int main(int argc, char* argv[], char** envp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc > 2)
|
||||||
|
{
|
||||||
|
auto* c_argument = argv[2];
|
||||||
|
auto argument = cstr(c_argument);
|
||||||
|
auto expected_start = strlit("tests/");
|
||||||
|
if (expected_start.length < argument.length)
|
||||||
|
{
|
||||||
|
if (strncmp(c_argument, "tests/", sizeof("tests/") - 1) == 0)
|
||||||
|
{
|
||||||
|
source_file_path = argument;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (command == COMMAND_COUNT)
|
if (command == COMMAND_COUNT)
|
||||||
{
|
{
|
||||||
print("Expected a command\n");
|
print("Expected a command\n");
|
||||||
@ -391,15 +415,20 @@ int main(int argc, char* argv[], char** envp)
|
|||||||
switch (command)
|
switch (command)
|
||||||
{
|
{
|
||||||
case COMMAND_DEBUG:
|
case COMMAND_DEBUG:
|
||||||
|
if (!source_file_path.pointer)
|
||||||
|
{
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
|
||||||
compile_and_run(&(CompileOptions) {
|
compile_and_run(&(CompileOptions) {
|
||||||
.in_path = compiler_source_path,
|
.in_path = compiler_source_path,
|
||||||
.out_path = build_dir "/" "nest",
|
.out_path = build_dir "/" "nest_O0_static",
|
||||||
.compiler = default_compiler,
|
.compiler = default_compiler,
|
||||||
.debug_info = 1,
|
.debug_info = 1,
|
||||||
.error_on_warning = 0,
|
.error_on_warning = 0,
|
||||||
.optimization_mode = O0,
|
.optimization_mode = O0,
|
||||||
.linkage = LINKAGE_STATIC,
|
.linkage = LINKAGE_STATIC,
|
||||||
}, envp, EXECUTION_ENGINE_INTERPRETER, 1, "tests/first.nat");
|
}, envp, EXECUTION_ENGINE_INTERPRETER, 1, string_to_c(source_file_path));
|
||||||
break;
|
break;
|
||||||
case COMMAND_RUN_TESTS:
|
case COMMAND_RUN_TESTS:
|
||||||
{
|
{
|
||||||
@ -408,13 +437,24 @@ int main(int argc, char* argv[], char** envp)
|
|||||||
static_assert(array_length(all_linkages) == LINKAGE_COUNT);
|
static_assert(array_length(all_linkages) == LINKAGE_COUNT);
|
||||||
OptimizationMode all_optimization_modes[] = { O0, O1, O2, O3, Os, Oz };
|
OptimizationMode all_optimization_modes[] = { O0, O1, O2, O3, Os, Oz };
|
||||||
static_assert(array_length(all_optimization_modes) == OPTIMIZATION_COUNT);
|
static_assert(array_length(all_optimization_modes) == OPTIMIZATION_COUNT);
|
||||||
String all_test_paths[] = {
|
String every_single_test[] = {
|
||||||
strlit("tests/first.nat"),
|
strlit("tests/first.nat"),
|
||||||
|
strlit("tests/add_sub.nat"),
|
||||||
|
strlit("tests/mul.nat"),
|
||||||
|
strlit("tests/div.nat"),
|
||||||
|
strlit("tests/and.nat"),
|
||||||
|
strlit("tests/or.nat"),
|
||||||
|
strlit("tests/xor.nat"),
|
||||||
|
strlit("tests/return_var.nat"),
|
||||||
|
strlit("tests/return_mod_scope.nat"),
|
||||||
|
strlit("tests/shift_left.nat"),
|
||||||
|
strlit("tests/shift_right.nat"),
|
||||||
|
strlit("tests/thousand_simple_functions.nat"),
|
||||||
|
strlit("tests/simple_arg.nat"),
|
||||||
};
|
};
|
||||||
ExecutionEngine all_execution_engines[] = { EXECUTION_ENGINE_INTERPRETER, EXECUTION_ENGINE_C };
|
ExecutionEngine all_execution_engines[] = { EXECUTION_ENGINE_INTERPRETER, EXECUTION_ENGINE_C };
|
||||||
static_assert(array_length(all_execution_engines) == EXECUTION_ENGINE_COUNT);
|
static_assert(array_length(all_execution_engines) == EXECUTION_ENGINE_COUNT);
|
||||||
|
|
||||||
Slice(String) test_selection = (Slice(String)) array_to_slice(all_test_paths);
|
|
||||||
Slice(Linkage) linkage_selection;
|
Slice(Linkage) linkage_selection;
|
||||||
Slice(OptimizationMode) optimization_selection;
|
Slice(OptimizationMode) optimization_selection;
|
||||||
Slice(ExecutionEngine) execution_engine_selection;
|
Slice(ExecutionEngine) execution_engine_selection;
|
||||||
@ -436,6 +476,16 @@ int main(int argc, char* argv[], char** envp)
|
|||||||
execution_engine_selection = (Slice(ExecutionEngine)) { .pointer = &preferred_execution_engine, .length = 1 };
|
execution_engine_selection = (Slice(ExecutionEngine)) { .pointer = &preferred_execution_engine, .length = 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Slice(String) test_selection;
|
||||||
|
if (source_file_path.pointer)
|
||||||
|
{
|
||||||
|
test_selection = (Slice(String)) { .pointer = &source_file_path, .length = 1 };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
test_selection = (Slice(String)) array_to_slice(every_single_test);
|
||||||
|
}
|
||||||
|
|
||||||
run_tests(arena, &(TestOptions) {
|
run_tests(arena, &(TestOptions) {
|
||||||
.linkages = linkage_selection,
|
.linkages = linkage_selection,
|
||||||
.optimization_modes = optimization_selection,
|
.optimization_modes = optimization_selection,
|
||||||
|
@ -1377,19 +1377,28 @@ fn void run_command(CStringSlice arguments, char* envp[])
|
|||||||
int status = 0;
|
int status = 0;
|
||||||
int options = 0;
|
int options = 0;
|
||||||
pid_t result = syscall_waitpid(pid, &status, options);
|
pid_t result = syscall_waitpid(pid, &status, options);
|
||||||
|
int success = 0;
|
||||||
if (result == pid)
|
if (result == pid)
|
||||||
{
|
{
|
||||||
WIFEXITED(status);
|
if (WIFEXITED(status))
|
||||||
auto exit_code = WEXITSTATUS(status);
|
|
||||||
if (exit_code != 0)
|
|
||||||
{
|
{
|
||||||
trap();
|
auto exit_code = WEXITSTATUS(status);
|
||||||
|
if (exit_code == 0)
|
||||||
|
{
|
||||||
|
success = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trap();
|
trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
print("Program failed to run!\n");
|
||||||
|
fail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4906,18 +4906,6 @@ void entry_point(int argc, const char* argv[])
|
|||||||
(char*)c_source_path.pointer,
|
(char*)c_source_path.pointer,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
print("Argument count: {u32}\n", (u32)array_length(command));
|
|
||||||
|
|
||||||
for (u32 i = 0; i < array_length(command); i += 1)
|
|
||||||
{
|
|
||||||
auto* arg = command[i];
|
|
||||||
if (arg)
|
|
||||||
{
|
|
||||||
print("{cstr} ", arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print("\n");
|
|
||||||
|
|
||||||
run_command((CStringSlice) array_to_slice(command), envp);
|
run_command((CStringSlice) array_to_slice(command), envp);
|
||||||
} break;
|
} break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user