From f16648a365a48de5049ed28944d7a04b57dc0cbe Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 20 Oct 2021 22:46:53 -0500 Subject: [PATCH] Regression: Example bzip fakefile fails. Empty strings end up getting passed to the programs, such as gcc. The program gcc will throw an error claiming it cannot find file (displaying an empty sting for the filename). This empty string doesn't show up in verbose, so the whole reason for failure is confusing because nothing is being displayed. Fix this by not appending empty strings to the arguments. At some point I added additional checks when loading the build settings file. Because the fake make process uses the same function, it ends up failing because unrequired settings are now required. Add a new variable "checks" to designate to perform these requirement checks or not. The fake make process will then be setup to not perform these requirement checks. In a recent commit, I added support for indexer_arguments. It turns out I did more than necessary because this will already get loaded via the build settings loading code. Remove the extra unnecessary processing of the indexer_arguments setting as it is already being processed later on. The "compiler" and "indexer" should also be looked into. Cleanup a print function. Add a missing newline print at the end of the "print" operation. Update the example fakefiles. Add missing settings to the example build settings. --- level_3/fake/c/private-build.c | 93 ++++++++++++++++++++-- level_3/fake/c/private-build.h | 5 +- level_3/fake/c/private-make.c | 49 ++---------- level_3/fake/data/build/fakefile-example-bzip2 | 4 +- level_3/fake/data/build/settings-example-bzip2 | 1 + .../fake/data/build/settings-example-bzip2recover | 1 + 6 files changed, 99 insertions(+), 54 deletions(-) diff --git a/level_3/fake/c/private-build.c b/level_3/fake/c/private-build.c index 68f4ce1..86fa951 100644 --- a/level_3/fake/c/private-build.c +++ b/level_3/fake/c/private-build.c @@ -48,6 +48,8 @@ extern "C" { for (uint8_t i = 0; i < 2; ++i) { + if (!lengths[i]) continue; + *status = fll_execute_arguments_add(values[i], lengths[i], arguments); if (F_status_is_error(*status)) break; } // for @@ -98,117 +100,183 @@ extern "C" { f_array_length_t i = 0; for (i = 0; i < data_build.setting.build_libraries.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.build_libraries.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.build_libraries.array[i].string, data_build.setting.build_libraries.array[i].used, arguments); } // for if (is_shared) { for (i = 0; i < data_build.setting.build_libraries_shared.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.build_libraries_shared.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.build_libraries_shared.array[i].string, data_build.setting.build_libraries_shared.array[i].used, arguments); } // for } else { for (i = 0; i < data_build.setting.build_libraries_static.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.build_libraries_static.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.build_libraries_static.array[i].string, data_build.setting.build_libraries_static.array[i].used, arguments); } // for } for (i = 0; i < data_build.setting.flags.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.flags.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.flags.array[i].string, data_build.setting.flags.array[i].used, arguments); } // for if (is_shared) { for (i = 0; i < data_build.setting.flags_shared.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.flags_shared.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.flags_shared.array[i].string, data_build.setting.flags_shared.array[i].used, arguments); } // for } else { for (i = 0; i < data_build.setting.flags_static.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.flags_static.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.flags_static.array[i].string, data_build.setting.flags_static.array[i].used, arguments); } // for } if (is_library) { for (i = 0; i < data_build.setting.flags_library.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.flags_library.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.flags_library.array[i].string, data_build.setting.flags_library.array[i].used, arguments); } // for if (is_shared) { for (i = 0; i < data_build.setting.flags_library_shared.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.flags_library_shared.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.flags_library_shared.array[i].string, data_build.setting.flags_library_shared.array[i].used, arguments); } // for } else { for (i = 0; i < data_build.setting.flags_library_static.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.flags_library_static.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.flags_library_static.array[i].string, data_build.setting.flags_library_static.array[i].used, arguments); } // for } } else { for (i = 0; i < data_build.setting.flags_program.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.flags_program.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.flags_program.array[i].string, data_build.setting.flags_program.array[i].used, arguments); } // for if (is_shared) { for (i = 0; i < data_build.setting.flags_program_shared.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.flags_program_shared.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.flags_program_shared.array[i].string, data_build.setting.flags_program_shared.array[i].used, arguments); } // for } else { for (i = 0; i < data_build.setting.flags_program_static.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.flags_program_static.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.flags_program_static.array[i].string, data_build.setting.flags_program_static.array[i].used, arguments); } // for } } for (i = 0; i < data_build.setting.defines.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.defines.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.defines.array[i].string, data_build.setting.defines.array[i].used, arguments); } // for if (is_shared) { for (i = 0; i < data_build.setting.defines_shared.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.defines_shared.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.defines_shared.array[i].string, data_build.setting.defines_shared.array[i].used, arguments); } // for } else { for (i = 0; i < data_build.setting.defines_static.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.defines_static.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.defines_static.array[i].string, data_build.setting.defines_static.array[i].used, arguments); } // for } if (is_library) { for (i = 0; i < data_build.setting.defines_library.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.defines_library.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.defines_library.array[i].string, data_build.setting.defines_library.array[i].used, arguments); } // for if (is_shared) { for (i = 0; i < data_build.setting.defines_library_shared.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.defines_library_shared.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.defines_library_shared.array[i].string, data_build.setting.defines_library_shared.array[i].used, arguments); } // for } else { for (i = 0; i < data_build.setting.defines_library_static.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.defines_library_static.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.defines_library_static.array[i].string, data_build.setting.defines_library_static.array[i].used, arguments); } // for } } else { for (i = 0; i < data_build.setting.defines_program.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.defines_program.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.defines_program.array[i].string, data_build.setting.defines_program.array[i].used, arguments); } // for if (is_shared) { for (i = 0; i < data_build.setting.defines_program_shared.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.defines_program_shared.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.defines_program_shared.array[i].string, data_build.setting.defines_program_shared.array[i].used, arguments); } // for } else { for (i = 0; i < data_build.setting.defines_program_static.used && F_status_is_error_not(*status); ++i) { + + if (!data_build.setting.defines_program_static.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.defines_program_static.array[i].string, data_build.setting.defines_program_static.array[i].used, arguments); } // for } } for (i = 0; i < main.define.used && F_status_is_error_not(*status); ++i) { + + if (!main.define.array[i].used) continue; + *status = fll_execute_arguments_add(main.define.array[i].string, main.define.array[i].used, arguments); } // for } @@ -874,6 +942,8 @@ extern "C" { for (j = 0; j < sources[i]->used; ++j) { + if (!sources[i]->array[j].used) continue; + source_length = path_sources->used + sources[i]->array[j].used; char source[source_length + 1]; @@ -1147,6 +1217,8 @@ extern "C" { for (uint8_t i = 0; i < 4; ++i) { + if (!lengths[i]) continue; + *status = fll_execute_arguments_add(values[i], lengths[i], &arguments); if (F_status_is_error(*status)) break; } // for @@ -1339,6 +1411,8 @@ extern "C" { for (; i < data_build.setting.build_indexer_arguments.used; ++i) { + if (!data_build.setting.build_indexer_arguments.array[i].used) continue; + *status = fll_execute_arguments_add(data_build.setting.build_indexer_arguments.array[i].string, data_build.setting.build_indexer_arguments.array[i].used, &arguments); if (F_status_is_error(*status)) break; } // for @@ -1593,7 +1667,7 @@ extern "C" { fll_error_print(main.error, F_status_set_fine(*status), "fl_fss_apply_delimit", F_true); } else { - fake_build_load_setting_process(main, setting_file.used ? path_file : main.file_data_build_settings.string, buffer, objects, contents, setting, status); + fake_build_load_setting_process(main, F_true, setting_file.used ? path_file : main.file_data_build_settings.string, buffer, objects, contents, setting, status); } } @@ -1646,7 +1720,7 @@ extern "C" { #endif // _di_fake_build_load_setting_ #ifndef _di_fake_build_load_setting_process_ - void fake_build_load_setting_process(const fake_main_t main, const f_string_t path_file, const f_string_static_t buffer, const f_fss_objects_t objects, const f_fss_contents_t contents, fake_build_setting_t *setting, f_status_t *status) { + void fake_build_load_setting_process(const fake_main_t main, const bool checks, const f_string_t path_file, const f_string_static_t buffer, const f_fss_objects_t objects, const f_fss_contents_t contents, fake_build_setting_t *setting, f_status_t *status) { if (F_status_is_error(*status) && buffer.used) return; @@ -2101,8 +2175,7 @@ extern "C" { if (main.error.verbosity != f_console_verbosity_quiet) { funlockfile(main.error.to.stream); - // @todo update FSS functions to return which setting index the problem happened on. - fl_print_format("%c%[%SA setting in the build setting file '%]", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, main.error.context); + fl_print_format("%c%[%SA setting in the file '%]", main.error.to.stream, f_string_eol_s[0], main.error.context, main.error.prefix, main.error.context); fl_print_format("%[%S%]", main.error.to.stream, main.error.notable, path_file, main.error.notable); fl_print_format("%[' is too long.%]%c", main.error.to.stream, main.error.context, main.error.context, f_string_eol_s[0]); @@ -2550,7 +2623,7 @@ extern "C" { } // for if (F_status_is_error_not(*status)) { - if (!setting->version_file) { + if (checks && !setting->version_file) { setting->version_file = fake_build_version_type_micro; if (main.warning.verbosity == f_console_verbosity_verbose) { @@ -2568,7 +2641,7 @@ extern "C" { } } - if (!setting->version_target) { + if (checks && !setting->version_target) { setting->version_target = fake_build_version_type_major; if (main.warning.verbosity == f_console_verbosity_verbose) { @@ -2652,7 +2725,7 @@ extern "C" { } } } - else { + else if (checks) { prefix[i]->used = 0; for (j = 0; j < 2; ++j) { @@ -3192,6 +3265,8 @@ extern "C" { for (uint8_t k = 0; k < 5; ++k) { + if (!lengths[k]) continue; + *status = fll_execute_arguments_add(values[k], lengths[k], &arguments); if (F_status_is_error(*status)) break; } // for @@ -3440,6 +3515,8 @@ extern "C" { for (uint8_t i = 0; i < 2; ++i) { + if (!lengths[i]) continue; + *status = fll_execute_arguments_add(values[i], lengths[i], &arguments); if (F_status_is_error(*status)) break; } // for @@ -3585,6 +3662,8 @@ extern "C" { for (uint8_t i = 0; i < 4; ++i) { + if (!lengths[i]) continue; + *status = fll_execute_arguments_add(values[i], lengths[i], &arguments); if (F_status_is_error(*status)) break; } // for diff --git a/level_3/fake/c/private-build.h b/level_3/fake/c/private-build.h index 2e5df0a..c8f8025 100644 --- a/level_3/fake/c/private-build.h +++ b/level_3/fake/c/private-build.h @@ -265,6 +265,9 @@ extern "C" { * * @param main * The main data. + * @param checks + * If TRUE, perform certain "required" sanity checks. + * If FALSE, do not perform certain "required" sanity checks (intended for a fakefile rather than a build settings file). * @param path_file * The path to the buffer. * @param buffer @@ -285,7 +288,7 @@ extern "C" { * Status codes (with error bit) are returned on any problem. */ #ifndef _di_fake_build_load_setting_process_ - extern void fake_build_load_setting_process(const fake_main_t main, const f_string_t path_file, const f_string_static_t buffer, const f_fss_objects_t objects, const f_fss_contents_t contents, fake_build_setting_t *setting, f_status_t *status) F_attribute_visibility_internal_d; + extern void fake_build_load_setting_process(const fake_main_t main, const bool checks, const f_string_t path_file, const f_string_static_t buffer, const f_fss_objects_t objects, const f_fss_contents_t contents, fake_build_setting_t *setting, f_status_t *status) F_attribute_visibility_internal_d; #endif // _di_fake_build_load_setting_process_ /** diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index e54f416..6433a2c 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -582,48 +582,6 @@ extern "C" { } } } - else if (fl_string_dynamic_partial_compare_string(fake_make_setting_indexer_arguments_s, data_make->buffer, fake_make_setting_indexer_arguments_s_length, settings.objects.array[i]) == F_equal_to) { - f_array_length_t j = 0; - - // clear all existing indexer arguments. - for (; j < data_make->setting_build.build_indexer_arguments.used; ++j) { - data_make->setting_build.build_indexer_arguments.array[j].used = 0; - } // for - - data_make->setting_build.build_indexer_arguments.used = 0; - - if (settings.contents.array[i].used > data_make->setting_build.build_indexer_arguments.size) { - *status = f_string_dynamics_increase_by(F_memory_default_allocation_small_d, &data_make->setting_build.build_indexer_arguments); - - if (F_status_is_error(*status)) { - fll_error_print(main.error, F_status_set_fine(*status), "f_string_dynamic_terminate_after", F_true); - break; - } - } - - for (j = 0; j < settings.contents.array[i].used; ++j) { - - *status = f_string_dynamic_partial_append_nulless(data_make->buffer, settings.contents.array[i].array[j], &data_make->setting_build.build_indexer_arguments.array[data_make->setting_build.build_indexer_arguments.used]); - - if (F_status_is_error(*status)) { - fll_error_print(main.error, F_status_set_fine(*status), "f_string_dynamic_partial_append_nulless", F_true); - break; - } - - *status = f_string_dynamic_terminate_after(&data_make->setting_build.build_indexer_arguments.array[data_make->setting_build.build_indexer_arguments.used]); - - if (F_status_is_error(*status)) { - fll_error_print(main.error, F_status_set_fine(*status), "f_string_dynamic_terminate_after", F_true); - break; - } - - ++data_make->setting_build.build_indexer_arguments.used; - } // for - - if (F_status_is_error(*status)) break; - - *status = F_none; - } else if (fl_string_dynamic_partial_compare_string(fake_make_setting_load_build_s, data_make->buffer, fake_make_setting_load_build_s_length, settings.objects.array[i]) == F_equal_to) { if (unmatched_load) { if (settings.contents.array[i].used) { @@ -720,7 +678,7 @@ extern "C" { return; } - // if either compiler or linker is specified, each will replace any existing build_compiler or build_indexer, respectively. + // if either compiler or indexer is specified, each will replace any existing build_compiler or build_indexer, respectively. if (range_compiler) { data_make->setting_build.build_compiler.used = 0; *status = f_string_dynamic_partial_append(data_make->buffer, *range_compiler, &data_make->setting_build.build_compiler); @@ -744,7 +702,9 @@ extern "C" { *status = F_status_set_error(F_signal); } else { - fake_build_load_setting_process(main, main.file_data_build_fakefile.string, data_make->buffer, settings.objects, settings.contents, &data_make->setting_build, status); + + // load the fakefile "settings" as if they are build "settings". + fake_build_load_setting_process(main, F_false, main.file_data_build_fakefile.string, data_make->buffer, settings.objects, settings.contents, &data_make->setting_build, status); } if (F_status_is_error_not(*status) && settings.objects.used) { @@ -3779,6 +3739,7 @@ extern "C" { } // for f_print_character(f_string_space_s[0], main->output.to.stream); + f_print_character(f_string_eol_s[0], main->output.to.stream); funlockfile(main->output.to.stream); diff --git a/level_3/fake/data/build/fakefile-example-bzip2 b/level_3/fake/data/build/fakefile-example-bzip2 index 558b937..35d51b1 100644 --- a/level_3/fake/data/build/fakefile-example-bzip2 +++ b/level_3/fake/data/build/fakefile-example-bzip2 @@ -35,5 +35,5 @@ bzip2recover: scripts: print print copying bzip2 scripts. - touch directory build/ build/program/ build/program/scripts/ - copy bzdiff bzgrep build/program/scripts/ + touch directory build build/programs build/programs/scripts + copy bzdiff bzgrep build/programs/scripts diff --git a/level_3/fake/data/build/settings-example-bzip2 b/level_3/fake/data/build/settings-example-bzip2 index 611aac0..5af88ff 100644 --- a/level_3/fake/data/build/settings-example-bzip2 +++ b/level_3/fake/data/build/settings-example-bzip2 @@ -14,6 +14,7 @@ project_name bzip2 version_major 1 version_minor 0 version_micro 8 +version_file micro version_target major build_compiler gcc diff --git a/level_3/fake/data/build/settings-example-bzip2recover b/level_3/fake/data/build/settings-example-bzip2recover index 18a8acf..da70061 100644 --- a/level_3/fake/data/build/settings-example-bzip2recover +++ b/level_3/fake/data/build/settings-example-bzip2recover @@ -14,6 +14,7 @@ project_name bzip2recover version_major 1 version_minor 0 version_micro 8 +version_file micro version_target major build_compiler gcc -- 1.8.3.1