mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add "prepare" target in project.json #1577
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
- `string::new_struct_to_str` and `io::struct_to_format` to dump struct data.
|
||||
- `io::print` will now print structs.
|
||||
- Improve error message when using `void` aliases as variable storage type.
|
||||
- Add a target type: "prepare" which doesn't compile anything (but may run `exec`)
|
||||
|
||||
### Fixes
|
||||
- `Unsupported int[*] $x = { 1, 2, 3, 4 }` #1489.
|
||||
|
||||
@@ -374,23 +374,27 @@ typedef enum
|
||||
TARGET_TYPE_OBJECT_FILES,
|
||||
TARGET_TYPE_BENCHMARK,
|
||||
TARGET_TYPE_TEST,
|
||||
TARGET_TYPE_PREPARE,
|
||||
} TargetType;
|
||||
|
||||
static const char *targets[6] = {
|
||||
static const char *targets[7] = {
|
||||
[TARGET_TYPE_EXECUTABLE] = "executable",
|
||||
[TARGET_TYPE_STATIC_LIB] = "static-lib",
|
||||
[TARGET_TYPE_DYNAMIC_LIB] = "dynamic-lib",
|
||||
[TARGET_TYPE_BENCHMARK] = "benchmark",
|
||||
[TARGET_TYPE_TEST] = "test",
|
||||
[TARGET_TYPE_OBJECT_FILES] = "object-files"
|
||||
[TARGET_TYPE_OBJECT_FILES] = "object-files",
|
||||
[TARGET_TYPE_PREPARE] = "prepare",
|
||||
};
|
||||
static const char *target_desc[6] = {
|
||||
static const char *target_desc[7] = {
|
||||
[TARGET_TYPE_EXECUTABLE] = "Executable",
|
||||
[TARGET_TYPE_STATIC_LIB] = "Static library",
|
||||
[TARGET_TYPE_DYNAMIC_LIB] = "Dynamic library",
|
||||
[TARGET_TYPE_BENCHMARK] = "benchmark suite",
|
||||
[TARGET_TYPE_TEST] = "test suite",
|
||||
[TARGET_TYPE_OBJECT_FILES] = "object files"
|
||||
[TARGET_TYPE_OBJECT_FILES] = "object files",
|
||||
[TARGET_TYPE_PREPARE] = "prepare"
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ const char* project_target_keys[][2] = {
|
||||
{"target", "Compile for a particular architecture + OS target."},
|
||||
{"testfn", "Override the test function."},
|
||||
{"trap-on-wrap", "Make signed and unsigned integer overflow generate a panic rather than wrapping."},
|
||||
{"type", "Type of output, one of 'executable', 'static-lib', 'dynamic-lib', 'benchmark', 'test', 'object-files'." },
|
||||
{"type", "Type of output, one of 'executable', 'static-lib', 'dynamic-lib', 'benchmark', 'test', 'object-files' and 'prepare'." },
|
||||
{"use-stdlib", "Include the standard library (default: true)."},
|
||||
{"vendor", "Vendor specific extensions, ignored by c3c."},
|
||||
{"version", "Version using semantic versioning."},
|
||||
|
||||
@@ -283,13 +283,11 @@ void fetch_project(BuildOptions* options)
|
||||
const char** deps_dirs = get_project_dependency_directories();
|
||||
int num_lib = vec_size(deps_dirs);
|
||||
if (num_lib > 0) options->vendor_download_path = deps_dirs[0];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const char** libdirs = get_project_dependency_directories();
|
||||
const char** deps = get_project_dependencies();
|
||||
const char **libdirs = get_project_dependency_directories();
|
||||
const char **deps = get_project_dependencies();
|
||||
const char *filename;
|
||||
JSONObject *project_json = read_project(&filename);
|
||||
|
||||
@@ -306,23 +304,21 @@ void fetch_project(BuildOptions* options)
|
||||
error_exit("Invalid data in target '%s'", key);
|
||||
}
|
||||
|
||||
const char** target_deps = get_optional_string_array(filename, key, target, "dependencies");
|
||||
const char **target_deps = get_optional_string_array(filename, key, target, "dependencies");
|
||||
|
||||
FOREACH(const char*, dep, target_deps) {
|
||||
FOREACH(const char*, dep, target_deps)
|
||||
{
|
||||
vec_add(deps, dep);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// dependency check tree
|
||||
while (vec_size(deps) > 0)
|
||||
{
|
||||
|
||||
FOREACH(const char*, dir, libdirs)
|
||||
{
|
||||
|
||||
const char* dep = deps[vec_size(deps)-1];
|
||||
const char *dep = VECLAST(deps);
|
||||
if (file_exists(file_append_path(dir, str_printf("%s.c3l", dep))))
|
||||
{
|
||||
vec_pop(deps);
|
||||
@@ -332,7 +328,7 @@ void fetch_project(BuildOptions* options)
|
||||
printf("Fetching missing library '%s'...", dep);
|
||||
fflush(stdout);
|
||||
|
||||
const char* error = vendor_fetch_single(dep, options->vendor_download_path);
|
||||
const char *error = vendor_fetch_single(dep, options->vendor_download_path);
|
||||
|
||||
if (!error)
|
||||
{
|
||||
|
||||
@@ -506,6 +506,8 @@ void compiler_compile(void)
|
||||
break;
|
||||
case TARGET_TYPE_OBJECT_FILES:
|
||||
break;
|
||||
case TARGET_TYPE_PREPARE:
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE
|
||||
}
|
||||
@@ -843,6 +845,17 @@ void compile_clean(BuildOptions *options)
|
||||
void compile_file_list(BuildOptions *options)
|
||||
{
|
||||
init_build_target(&compiler.build, options);
|
||||
if (compiler.build.type == TARGET_TYPE_PREPARE)
|
||||
{
|
||||
if (options->command != COMMAND_BUILD)
|
||||
{
|
||||
error_exit("The target is a 'prepare' target, and only 'build' can be used with it.");
|
||||
}
|
||||
printf("] Running prepare target '%s'.\n", options->target_select);
|
||||
execute_scripts();
|
||||
printf("] Completed.\n.");
|
||||
return;
|
||||
}
|
||||
if (options->command == COMMAND_CLEAN_RUN)
|
||||
{
|
||||
clean_obj_files();
|
||||
@@ -1116,7 +1129,7 @@ static int jump_buffer_size()
|
||||
UNREACHABLE
|
||||
}
|
||||
|
||||
static void execute_scripts(void)
|
||||
void execute_scripts(void)
|
||||
{
|
||||
if (!vec_size(compiler.build.exec)) return;
|
||||
if (compiler.build.trust_level < TRUST_FULL)
|
||||
|
||||
@@ -10,6 +10,7 @@ void compile();
|
||||
void compile_target(BuildOptions *options);
|
||||
void compile_file_list(BuildOptions *options);
|
||||
void compile_clean(BuildOptions *options);
|
||||
void execute_scripts(void);
|
||||
void init_build_target(BuildTarget *build_target, BuildOptions *build_options);
|
||||
void init_default_build_target(BuildTarget *target, BuildOptions *options);
|
||||
void symtab_init(uint32_t max_size);
|
||||
|
||||
Reference in New Issue
Block a user