From b818a7713175d882a7f8b345cee59bd19b0d1d47 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Thu, 25 Jan 2024 02:16:30 +0100 Subject: check if -define is actually used --- src/main.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index a3e87fb6a..eac1b7ed9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -822,9 +822,9 @@ gb_internal bool parse_build_flags(Array args) { } case BuildFlag_ShowDefineables: { GB_ASSERT(value.kind == ExactValue_Invalid); - build_context.show_defineables = true; - break; - } + build_context.show_defineables = true; + break; + } case BuildFlag_ExportDefineables: { GB_ASSERT(value.kind == ExactValue_String); @@ -1577,6 +1577,28 @@ gb_internal void timings_export_all(Timings *t, Checker *c, bool timings_are_fin gb_printf("Done.\n"); } +gb_internal void check_defines(BuildContext *bc, Checker *c) { + for (auto const &entry : bc->defined_values) { + String name = make_string_c(entry.key); + ExactValue value = entry.value; + GB_ASSERT(value.kind != ExactValue_Invalid); + + bool found = false; + for_array(i, c->info.defineables) { + Defineable *def = &c->info.defineables[i]; + if (def->name == name) { + found = true; + break; + } + } + + if (!found) { + warning(nullptr, "given -define:%s is unused in the project", name); + error_line("\tSuggestion: use the -show-defineables flag for an overview of the possible defines\n"); + } + } +} + gb_internal void temp_alloc_defineable_strings(Checker *c) { for_array(i, c->info.defineables) { Defineable *def = &c->info.defineables[i]; @@ -2059,11 +2081,11 @@ gb_internal void print_show_help(String const arg0, String const &command) { print_usage_line(0, ""); print_usage_line(1, "-show-defineables"); - print_usage_line(2, "Shows an overview of all the #config usages in the project."); + print_usage_line(2, "Shows an overview of all the #config/#defined usages in the project."); print_usage_line(0, ""); print_usage_line(1, "-export-defineables:"); - print_usage_line(2, "Exports an overview of all the #config usages in CSV format to the given file path."); + print_usage_line(2, "Exports an overview of all the #config/#defined usages in CSV format to the given file path."); print_usage_line(2, "Example: -export-defineables:defineables.csv"); print_usage_line(0, ""); } @@ -3063,6 +3085,7 @@ int main(int arg_count, char const **arg_ptr) { defer (destroy_checker(checker)); check_parsed_files(checker); + check_defines(&build_context, checker); if (any_errors()) { print_all_errors(); return 1; -- cgit v1.2.3