From: Kevin Day <thekevinday@gmail.com>
Date: Sat, 5 Sep 2020 20:24:12 +0000 (-0500)
Subject: Update: featureless make fakefile build section operation should allow a custom file... 
X-Git-Tag: 0.5.0~21
X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=574632d1406be58c1ae304de713d1e4c08b1b40b;p=fll

Update: featureless make fakefile build section operation should allow a custom file name.

The documentation mentions this to some extent.
Actually implement this and update the documentation.
---

diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c
index 6263cc0..289e9fc 100644
--- a/level_3/fake/c/fake.c
+++ b/level_3/fake/c/fake.c
@@ -283,7 +283,9 @@ extern "C" {
           }
 
           if (F_status_is_not_error(status)) {
-            status = fake_build_operate(*data);
+            f_string_static_t stub = f_string_static_t_initialize;
+
+            status = fake_build_operate(*data, stub);
           }
         }
         else if (operations[i] == fake_operation_clean) {
diff --git a/level_3/fake/c/private-build.c b/level_3/fake/c/private-build.c
index e31ab31..52e485b 100644
--- a/level_3/fake/c/private-build.c
+++ b/level_3/fake/c/private-build.c
@@ -1168,16 +1168,29 @@ extern "C" {
 #endif // _di_fake_build_load_environment_
 
 #ifndef _di_fake_build_load_setting_
-  void fake_build_load_setting(const fake_data_t data, fake_build_setting_t *setting, f_status_t *status) {
+  void fake_build_load_setting(const fake_data_t data, const f_string_static_t setting_file, fake_build_setting_t *setting, f_status_t *status) {
     if (F_status_is_error(*status)) return;
 
+    char path_file[data.path_data_build.used + setting_file.used + 1];
+
     {
       f_string_dynamic_t buffer = f_string_dynamic_t_initialize;
 
       f_fss_objects_t objects = f_fss_objects_t_initialize;
       f_fss_contents_t contents = f_fss_contents_t_initialize;
 
-      *status = fake_file_buffer(data, data.file_data_build_settings.string, &buffer);
+      if (setting_file.used) {
+        memcpy(path_file, data.path_data_build.string, data.path_data_build.used);
+        memcpy(path_file + data.path_data_build.used, setting_file.string, setting_file.used);
+
+        path_file[data.path_data_build.used + setting_file.used] = 0;
+
+        *status = fake_file_buffer(data, path_file, &buffer);
+      }
+      else {
+        *status = fake_file_buffer(data, data.file_data_build_settings.string, &buffer);
+      }
+
       if (F_status_is_error(*status)) return;
 
       f_string_range_t range = f_macro_string_range_initialize(buffer.used);
@@ -1187,7 +1200,7 @@ extern "C" {
         fake_print_error_fss(data, *status, "fll_fss_extended_read", data.file_data_build_settings.string, range, F_true);
       }
 
-      fake_build_load_setting_process(data, data.file_data_build_settings.string, buffer, objects, contents, setting, status);
+      fake_build_load_setting_process(data, setting_file.used ? path_file : data.file_data_build_settings.string, buffer, objects, contents, setting, status);
 
       f_macro_string_dynamic_t_delete_simple(buffer);
       f_macro_fss_objects_t_delete_simple(objects);
@@ -1212,7 +1225,7 @@ extern "C" {
           fl_color_print(f_type_error, data.context.error, data.context.reset, "ERROR: The setting '");
           fl_color_print(f_type_error, data.context.notable, data.context.reset, "%s", names[i]);
           fl_color_print(f_type_error, data.context.error, data.context.reset, "' is required but is not specified in the settings file '");
-          fl_color_print(f_type_error, data.context.notable, data.context.reset, "%s", data.file_data_build_settings.string);
+          fl_color_print(f_type_error, data.context.notable, data.context.reset, "%s", setting_file.used ? path_file : data.file_data_build_settings.string);
           fl_color_print_line(f_type_error, data.context.error, data.context.reset, "'.");
 
           failed = F_true;
@@ -2249,7 +2262,7 @@ extern "C" {
 #endif // _di_fake_build_objects_static_
 
 #ifndef _di_fake_build_operate_
-  f_return_status fake_build_operate(const fake_data_t data) {
+  f_return_status fake_build_operate(const fake_data_t data, const f_string_static_t setting_file) {
     if (data.verbosity != fake_verbosity_quiet) {
       printf("%c", f_string_eol[0]);
       fl_color_print_line(f_type_output, data.context.important, data.context.reset, "Building project.");
@@ -2263,7 +2276,7 @@ extern "C" {
 
     f_macro_mode_t_set_default_umask(mode, data.umask);
 
-    fake_build_load_setting(data, &data_build.setting, &status);
+    fake_build_load_setting(data, setting_file, &data_build.setting, &status);
 
     fake_build_load_stage(data, &stage, &status);
 
diff --git a/level_3/fake/c/private-build.h b/level_3/fake/c/private-build.h
index ac33349..3787fe8 100644
--- a/level_3/fake/c/private-build.h
+++ b/level_3/fake/c/private-build.h
@@ -574,6 +574,9 @@ extern "C" {
  *
  * @param data
  *   The program data.
+ * @param setting_file
+ *   The name of the settings file to use.
+ *   If setting_file.used is 0, then the default or program parameter supplied file is used.
  * @param setting
  *   All build related setting data from the build setting file are loaded into this.
  *   These setting will have any specified mode property applied.
@@ -586,7 +589,7 @@ extern "C" {
  *   Status codes (with error bit) are returned on any problem.
  */
 #ifndef _di_fake_build_load_setting_
-  extern void fake_build_load_setting(const fake_data_t data, fake_build_setting_t *setting, f_status_t *status) f_gcc_attribute_visibility_internal;
+  extern void fake_build_load_setting(const fake_data_t data, const f_string_static_t setting_file, fake_build_setting_t *setting, f_status_t *status) f_gcc_attribute_visibility_internal;
 #endif // _di_fake_build_load_setting_
 
 /**
@@ -709,6 +712,9 @@ extern "C" {
  *
  * @param data
  *   The program data.
+ * @param setting_file
+ *   The name of the settings file to use.
+ *   If setting_file.used is 0, then the default or program parameter supplied file is used.
  *
  * @return
  *   F_none on success.
@@ -716,7 +722,7 @@ extern "C" {
  *   Status codes (with error bit) are returned on any problem.
  */
 #ifndef _di_fake_build_operate_
-  extern f_return_status fake_build_operate(const fake_data_t data) f_gcc_attribute_visibility_internal;
+  extern f_return_status fake_build_operate(const fake_data_t data, const f_string_static_t setting_file) f_gcc_attribute_visibility_internal;
 #endif // _di_fake_build_operate_
 
 /**
diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c
index a9f97a8..ce2f91e 100644
--- a/level_3/fake/c/private-make.c
+++ b/level_3/fake/c/private-make.c
@@ -560,7 +560,9 @@ extern "C" {
       }
 
       if (data_make->setting_make.load_build) {
-        fake_build_load_setting(data, &data_make->setting_build, status);
+        f_string_static_t stub = f_string_static_t_initialize;
+
+        fake_build_load_setting(data, stub, &data_make->setting_build, status);
 
         if (F_status_is_error(*status)) {
           fake_print_error(data, *status, "fake_build_load_setting", F_true);
@@ -1738,7 +1740,9 @@ extern "C" {
     }
 
     if (operation == fake_make_operation_type_build) {
-      *status = fake_build_operate(data);
+      f_string_static_t stub = f_string_static_t_initialize;
+
+      *status = fake_build_operate(data, arguments.used ? arguments.array[0] : stub);
 
       fake_make_operate_process_return(data, 0, data_make, status);
       return;
@@ -3103,27 +3107,34 @@ extern "C" {
       }
       else if (arguments.used) {
         if (arguments.array[0].used) {
-          f_status_t status_file = f_file_is(arguments.array[0].string, f_file_type_regular);
+          char path_file[data.path_data_build.used + arguments.array[0].used + 1];
+
+          memcpy(path_file, data.path_data_build.string, data.path_data_build.used);
+          memcpy(path_file + data.path_data_build.used, arguments.array[0].string, arguments.array[0].used);
+
+          path_file[data.path_data_build.used + arguments.array[0].used] = 0;
+
+          f_status_t status_file = f_file_is(path_file, f_file_type_regular);
 
           if (status_file == F_file_found_not) {
             if (data.verbosity != fake_verbosity_quiet && data_make->print.to) {
               printf("%c", f_string_eol[0]);
               fl_color_print(data_make->print.to, data_make->print.context, data.context.reset, "%s: Failed to find file '", data_make->print.prefix);
-              fl_color_print(data_make->print.to, data.context.notable, data.context.reset, "%s", arguments.array[0].string);
+              fl_color_print(data_make->print.to, data.context.notable, data.context.reset, "%s", path_file);
               fl_color_print_line(data_make->print.to, data_make->print.context, data.context.reset, "'.");
             }
 
             *status = F_status_set_error(status_file);
           }
           else if (F_status_is_error(status_file)) {
-            fake_print_message_file(data, *status, "f_file_is", data.file_data_build_fakefile.string, "find", F_true, F_true, data_make->print);
+            fake_print_message_file(data, *status, "f_file_is", path_file, "find", F_true, F_true, data_make->print);
             *status = status_file;
           }
           else if (!status_file) {
             if (data.verbosity != fake_verbosity_quiet && data_make->print.to) {
               printf("%c", f_string_eol[0]);
               fl_color_print(data_make->print.to, data_make->print.context, data.context.reset, "%s: The file '", data_make->print.prefix);
-              fl_color_print(data_make->print.to, data.context.notable, data.context.reset, "%s", arguments.array[0].string);
+              fl_color_print(data_make->print.to, data.context.notable, data.context.reset, "%s", path_file);
               fl_color_print_line(data_make->print.to, data_make->print.context, data.context.reset, "' must be a regular file.");
             }
 
diff --git a/level_3/fake/documents/fakefile.txt b/level_3/fake/documents/fakefile.txt
index 451c0c1..839bcee 100644
--- a/level_3/fake/documents/fakefile.txt
+++ b/level_3/fake/documents/fakefile.txt
@@ -75,7 +75,8 @@ Fakefile Documentation:
       Run the fake build operation as if "fake build" was run instead of "fake make".
       Command line arguments are automatically passed to the fake build operation.
 
-      Accepts an optional Content that is a path to a build settings file to use instead of the default.
+      Accepts an optional Content that is a file name to a build settings file to use instead of the default.
+      This file name is relative to the data build directory (which can be changed by -D/--data parameter).
 
     - break\:
       Perform an exit from the current make operation.
diff --git a/level_3/fake/specifications/fakefile.txt b/level_3/fake/specifications/fakefile.txt
index 92591d4..e28b929 100644
--- a/level_3/fake/specifications/fakefile.txt
+++ b/level_3/fake/specifications/fakefile.txt
@@ -46,7 +46,7 @@ Fakefile Specification:
   The Section Operation Objects are\:
   - archive: One or more Content.
   - break: Zero or One Content. If specified, First content must be one of "success" or "failure".
-  - build: Zero or One Content. First Content represents path to the settings file, relative to the project root.
+  - build: Zero or One Content. First Content represents file name of the settings file to use.
   - clean: Zero Content.
   - compile: One or more Content as parameters to compiler.
   - define: Two or more Content.