Add ODIN_BUILD_PROJECT_NAME and //+build-project-name

This allows for condition inclusion of files, similar to `+build` or `ODIN_BUILD`, but relies on the directory name of the project to be the same as specified

Example:

    odin build foo/bar/baz

    ODIN_BUILD_PROJECT_NAME == "baz"

    //+build_project_name baz
This commit is contained in:
gingerBill
2022-09-08 16:35:25 +01:00
parent 39728b8bfb
commit 81e3b64ecd
3 changed files with 58 additions and 1 deletions
+7
View File
@@ -225,6 +225,7 @@ struct BuildContext {
String ODIN_VENDOR; // compiler vendor
String ODIN_VERSION; // compiler version
String ODIN_ROOT; // Odin ROOT
String ODIN_BUILD_PROJECT_NAME; // Odin main/initial package's directory name
bool ODIN_DEBUG; // Odin in debug mode
bool ODIN_DISABLE_ASSERT; // Whether the default 'assert' et al is disabled in code or not
bool ODIN_DEFAULT_TO_NIL_ALLOCATOR; // Whether the default allocator is a "nil" allocator or not (i.e. it does nothing)
@@ -1537,6 +1538,12 @@ bool init_build_paths(String init_filename) {
enable_target_feature({}, bc->target_features_string);
}
{
String build_project_name = last_path_element(bc->build_paths[BuildPath_Main_Package].basename);
GB_ASSERT(build_project_name.len > 0);
bc->ODIN_BUILD_PROJECT_NAME = build_project_name;
}
return true;
}