Split out code to generate test rules for C build
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/43b5f7e5 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/43b5f7e5 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/43b5f7e5 Branch: refs/heads/perl_build_with_make Commit: 43b5f7e52263023ed84e0b2528d0a42e72f64ce8 Parents: 60589a8 Author: Nick Wellnhofer <[email protected]> Authored: Sat Nov 8 17:23:44 2014 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Sat Nov 8 18:20:00 2014 +0100 ---------------------------------------------------------------------- common/charmonizer.main | 149 +++++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 69 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/43b5f7e5/common/charmonizer.main ---------------------------------------------------------------------- diff --git a/common/charmonizer.main b/common/charmonizer.main index 0b2de5a..5a85216 100644 --- a/common/charmonizer.main +++ b/common/charmonizer.main @@ -94,6 +94,9 @@ static void lucy_MakeFile_write_c_cfc_rules(lucy_MakeFile *self); static void +lucy_MakeFile_write_c_test_rules(lucy_MakeFile *self); + +static void S_c_file_callback(const char *dir, char *file, void *context); static void @@ -323,13 +326,9 @@ lucy_MakeFile_write(lucy_MakeFile *self) { SourceFileContext sfc; const char *dir_sep = chaz_OS_dir_sep(); - const char *exe_ext = chaz_OS_exe_ext(); const char *obj_ext = chaz_CC_obj_ext(); const char *math_lib = chaz_Floats_math_library(); - char *test_lucy_exe = chaz_Util_join("", "t", dir_sep, "test_lucy", - exe_ext, NULL); - chaz_MakeVar *var; chaz_MakeRule *rule; chaz_MakeRule *clean_rule; @@ -337,9 +336,7 @@ lucy_MakeFile_write(lucy_MakeFile *self) { chaz_CFlags *extra_cflags = chaz_CC_get_extra_cflags(); chaz_CFlags *makefile_cflags; chaz_CFlags *link_flags; - chaz_CFlags *test_cflags; - char *test_command; char *scratch; int i; @@ -450,59 +447,7 @@ lucy_MakeFile_write(lucy_MakeFile *self) { chaz_CFlags_destroy(link_flags); chaz_MakeFile_add_static_lib(self->makefile, self->static_lib, "$(LUCY_OBJS)"); - test_cflags = chaz_CC_new_cflags(); - chaz_CFlags_enable_optimization(test_cflags); - chaz_CFlags_add_include_dir(test_cflags, self->autogen_inc_dir); - chaz_CFlags_add_library(test_cflags, self->shared_lib); - if (self->cfish_lib_dir) { - chaz_CFlags_add_library_path(link_flags, self->cfish_lib_dir); - } - chaz_CFlags_add_external_library(test_cflags, self->cfish_lib_name); - scratch = chaz_Util_join(dir_sep, "t", "test_lucy.c", NULL); - rule = chaz_MakeFile_add_compiled_exe(self->makefile, test_lucy_exe, scratch, - test_cflags); - free(scratch); - chaz_MakeRule_add_prereq(rule, self->shared_lib_filename); - chaz_CFlags_destroy(test_cflags); - - rule = chaz_MakeFile_add_rule(self->makefile, "test", test_lucy_exe); - if (strcmp(chaz_OS_shared_lib_ext(), ".so") == 0) { - if (self->cfish_lib_dir) { - test_command - = chaz_Util_join("", "LD_LIBRARY_PATH=.:", self->cfish_lib_dir, - ":$$LD_LIBRARY_PATH ", test_lucy_exe, NULL); - } - else { - test_command - = chaz_Util_join(" ", "LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH", - test_lucy_exe, NULL); - } - } - else { - test_command = chaz_Util_strdup(test_lucy_exe); - } - chaz_MakeRule_add_command(rule, test_command); - - if (chaz_CLI_defined(self->cli, "enable-coverage")) { - rule = chaz_MakeFile_add_rule(self->makefile, "coverage", test_lucy_exe); - chaz_MakeRule_add_command(rule, - "lcov" - " --zerocounters" - " --directory $(BASE_DIR)"); - chaz_MakeRule_add_command(rule, test_command); - chaz_MakeRule_add_command(rule, - "lcov" - " --capture" - " --directory $(BASE_DIR)" - " --base-directory ." - " --rc lcov_branch_coverage=1" - " --output-file lucy.info"); - chaz_MakeRule_add_command(rule, - "genhtml" - " --branch-coverage" - " --output-directory coverage" - " lucy.info"); - } + lucy_MakeFile_write_c_test_rules(self); clean_rule = chaz_MakeFile_clean_rule(self->makefile); @@ -523,17 +468,7 @@ lucy_MakeFile_write(lucy_MakeFile *self) { chaz_MakeRule_add_recursive_rm_command(clean_rule, "autogen"); - if (chaz_CLI_defined(cli, "enable-coverage")) { - chaz_MakeRule_add_rm_command(clean_rule, "lucy.info"); - chaz_MakeRule_add_recursive_rm_command(clean_rule, "coverage"); - } - - chaz_MakeFile_distclean_rule(self->makefile); - chaz_MakeFile_write(self->makefile); - - free(test_lucy_exe); - free(test_command); } static void @@ -570,6 +505,82 @@ lucy_MakeFile_write_c_cfc_rules(lucy_MakeFile *self) { } static void +lucy_MakeFile_write_c_test_rules(lucy_MakeFile *self) { + const char *dir_sep = chaz_OS_dir_sep(); + const char *exe_ext = chaz_OS_exe_ext(); + + chaz_CFlags *test_cflags; + chaz_MakeRule *rule; + + char *test_lucy_exe; + char *test_lucy_c; + char *test_command; + + test_lucy_exe = chaz_Util_join("", "t", dir_sep, "test_lucy", exe_ext, + NULL); + test_lucy_c = chaz_Util_join(dir_sep, "t", "test_lucy.c", NULL); + test_cflags = chaz_CC_new_cflags(); + chaz_CFlags_enable_optimization(test_cflags); + chaz_CFlags_add_include_dir(test_cflags, self->autogen_inc_dir); + chaz_CFlags_add_library(test_cflags, self->shared_lib); + if (self->cfish_lib_dir) { + chaz_CFlags_add_library_path(test_cflags, self->cfish_lib_dir); + } + chaz_CFlags_add_external_library(test_cflags, self->cfish_lib_name); + rule = chaz_MakeFile_add_compiled_exe(self->makefile, test_lucy_exe, + test_lucy_c, test_cflags); + chaz_MakeRule_add_prereq(rule, self->shared_lib_filename); + chaz_CFlags_destroy(test_cflags); + + rule = chaz_MakeFile_add_rule(self->makefile, "test", test_lucy_exe); + if (strcmp(chaz_OS_shared_lib_ext(), ".so") == 0) { + if (self->cfish_lib_dir) { + test_command + = chaz_Util_join("", "LD_LIBRARY_PATH=.:", self->cfish_lib_dir, + ":$$LD_LIBRARY_PATH ", test_lucy_exe, NULL); + } + else { + test_command + = chaz_Util_join(" ", "LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH", + test_lucy_exe, NULL); + } + } + else { + test_command = chaz_Util_strdup(test_lucy_exe); + } + chaz_MakeRule_add_command(rule, test_command); + + if (chaz_CLI_defined(self->cli, "enable-coverage")) { + rule = chaz_MakeFile_add_rule(self->makefile, "coverage", test_lucy_exe); + chaz_MakeRule_add_command(rule, + "lcov" + " --zerocounters" + " --directory $(BASE_DIR)"); + chaz_MakeRule_add_command(rule, test_command); + chaz_MakeRule_add_command(rule, + "lcov" + " --capture" + " --directory $(BASE_DIR)" + " --base-directory ." + " --rc lcov_branch_coverage=1" + " --output-file lucy.info"); + chaz_MakeRule_add_command(rule, + "genhtml" + " --branch-coverage" + " --output-directory coverage" + " lucy.info"); + + rule = chaz_MakeFile_clean_rule(self->makefile); + chaz_MakeRule_add_rm_command(rule, "lucy.info"); + chaz_MakeRule_add_recursive_rm_command(rule, "coverage"); + } + + free(test_lucy_exe); + free(test_lucy_c); + free(test_command); +} + +static void S_c_file_callback(const char *dir, char *file, void *context) { SourceFileContext *sfc = (SourceFileContext*)context; const char *dir_sep = chaz_OS_dir_sep();
