From 4709d784a6d7a8cdb167501ef61394e2889f315c Mon Sep 17 00:00:00 2001 From: stilscher <66023521+stilscher@users.noreply.github.com> Date: Tue, 14 Dec 2021 18:42:45 +0100 Subject: [PATCH 1/8] fix makefile generation --- src/incremental/makefileUtil.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/incremental/makefileUtil.ml b/src/incremental/makefileUtil.ml index 5752691405..b3e1b5e29c 100644 --- a/src/incremental/makefileUtil.ml +++ b/src/incremental/makefileUtil.ml @@ -61,7 +61,8 @@ let run_cilly (path: string) ~all_cppflags = remove_comb_files path; (* Combine source files with make using cilly as compiler *) let gcc_path = GobConfig.get_string "exp.gcc_path" in - let (exit_code, output) = exec_command ~path ("make CC=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\" CFLAGS+=" ^ String.join " " (List.map Filename.quote all_cppflags) ^ " " ^ + let cflags = if List.length all_cppflags > 0 then " CFLAGS+=" ^ Filename.quote (String.join " " all_cppflags) else "" in + let (exit_code, output) = exec_command ~path ("make CC=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\"" ^cflags ^ " " ^ "LD=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\"") in print_string output; (* fail if make failed *) @@ -80,9 +81,9 @@ let generate_and_combine makefile ~all_cppflags = let generate_makefile_with (name, command, file) = if Sys.file_exists file then ( print_endline ("Trying to run " ^ name ^ " to generate Makefile"); let exit_code, output = exec_command ~path command in - print_endline (command ^ GobUnix.string_of_process_status exit_code ^ ". Output: " ^ output); + print_endline (command ^ " " ^ GobUnix.string_of_process_status exit_code ^ ". Output: " ^ output); if not (Sys.file_exists makefile) then raise MakefileNotGenerated - ); raise MakefileNotGenerated in + ) else raise MakefileNotGenerated in try generate_makefile_with configure with MakefileNotGenerated -> try generate_makefile_with autogen From 3b124456ca42980d2f638c3a714392f234bfaead Mon Sep 17 00:00:00 2001 From: stilscher <66023521+stilscher@users.noreply.github.com> Date: Tue, 25 Jan 2022 17:32:20 +0100 Subject: [PATCH 2/8] do not require the -o option being set in commands of compilation database --- src/util/compilationDatabase.ml | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/util/compilationDatabase.ml b/src/util/compilationDatabase.ml index 54a46e2bf8..d8bd87c5e3 100644 --- a/src/util/compilationDatabase.ml +++ b/src/util/compilationDatabase.ml @@ -68,17 +68,20 @@ let load_and_preprocess ~all_cppflags filename = preprocess_command | None, Some arguments -> let arguments = List.map reroot arguments in - begin match List.findi (fun i e -> e = "-o") arguments with - | (o_i, _) -> - begin match List.split_at o_i arguments with - | (arguments_program :: arguments_init, _ :: o_file :: arguments_tl) -> - let preprocess_arguments = all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: arguments_init @ "-o" :: preprocessed_file :: arguments_tl in - Filename.quote_command arguments_program preprocess_arguments - | _ -> - failwith "CompilationDatabase.preprocess: no -o argument value found for " ^ file - end - | exception Not_found -> - failwith "CompilationDatabase.preprocess: no -o argument found for " ^ file + let preprocess_arguments = + let suf = + begin match List.findi (fun i e -> e = "-o") arguments with + | (o_i, _) -> + begin match List.drop o_i arguments with + | (_ :: o_file :: arguments_tl) -> preprocessed_file :: arguments_tl + | _ -> failwith ("CompilationDatabase.preprocess: no argument found for -o option for " ^ file) + end + | exception Not_found -> [preprocessed_file] + end in + all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: arguments @ "-o" :: suf in + begin match arguments with + | (arguments_program :: arguments) -> Filename.quote_command arguments_program preprocess_arguments + | _ -> failwith "CompilationDatabase.preprocess: no program found for " ^ file end | Some _, Some _ -> failwith "CompilationDatabase.preprocess: both command and arguments specified for " ^ file @@ -91,6 +94,6 @@ let load_and_preprocess ~all_cppflags filename = system ~cwd preprocess_command; (* command/arguments might have paths relative to directory *) Preprocessor.parse_makefile_deps deps_file; Some preprocessed_file - in + in parse_file filename |> BatList.filter_map preprocess From 99c8d22f95e64c0330ebf8814d4068afe0c403f6 Mon Sep 17 00:00:00 2001 From: stilscher <66023521+stilscher@users.noreply.github.com> Date: Wed, 2 Feb 2022 17:56:06 +0100 Subject: [PATCH 3/8] correct length of list checking --- src/incremental/makefileUtil.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/incremental/makefileUtil.ml b/src/incremental/makefileUtil.ml index b3e1b5e29c..deb952b923 100644 --- a/src/incremental/makefileUtil.ml +++ b/src/incremental/makefileUtil.ml @@ -61,7 +61,7 @@ let run_cilly (path: string) ~all_cppflags = remove_comb_files path; (* Combine source files with make using cilly as compiler *) let gcc_path = GobConfig.get_string "exp.gcc_path" in - let cflags = if List.length all_cppflags > 0 then " CFLAGS+=" ^ Filename.quote (String.join " " all_cppflags) else "" in + let cflags = if all_cppflags = [] then " CFLAGS+=" ^ Filename.quote (String.join " " all_cppflags) else "" in let (exit_code, output) = exec_command ~path ("make CC=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\"" ^cflags ^ " " ^ "LD=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\"") in print_string output; From dfda27094b4a958e6ee9b9fd014eb5253cf24adc Mon Sep 17 00:00:00 2001 From: stilscher <66023521+stilscher@users.noreply.github.com> Date: Mon, 7 Feb 2022 16:51:53 +0100 Subject: [PATCH 4/8] fix duplicate arguments --- src/util/compilationDatabase.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/compilationDatabase.ml b/src/util/compilationDatabase.ml index d8bd87c5e3..6ffdf31872 100644 --- a/src/util/compilationDatabase.ml +++ b/src/util/compilationDatabase.ml @@ -72,13 +72,13 @@ let load_and_preprocess ~all_cppflags filename = let suf = begin match List.findi (fun i e -> e = "-o") arguments with | (o_i, _) -> - begin match List.drop o_i arguments with - | (_ :: o_file :: arguments_tl) -> preprocessed_file :: arguments_tl + begin match List.split_at o_i arguments with + | (arguments_init, o_file :: arguments_tl) -> arguments_init @ preprocessed_file :: arguments_tl | _ -> failwith ("CompilationDatabase.preprocess: no argument found for -o option for " ^ file) end - | exception Not_found -> [preprocessed_file] + | exception Not_found -> arguments @ "-o" :: [preprocessed_file] end in - all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: arguments @ "-o" :: suf in + all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: suf in begin match arguments with | (arguments_program :: arguments) -> Filename.quote_command arguments_program preprocess_arguments | _ -> failwith "CompilationDatabase.preprocess: no program found for " ^ file From 615f4a80a7b05fa22e5912c093bfc18c009dfca7 Mon Sep 17 00:00:00 2001 From: stilscher <66023521+stilscher@users.noreply.github.com> Date: Mon, 7 Feb 2022 17:52:52 +0100 Subject: [PATCH 5/8] add -o handling also for command case --- src/util/compilationDatabase.ml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/util/compilationDatabase.ml b/src/util/compilationDatabase.ml index 6ffdf31872..fcd0bcfe7c 100644 --- a/src/util/compilationDatabase.ml +++ b/src/util/compilationDatabase.ml @@ -61,11 +61,14 @@ let load_and_preprocess ~all_cppflags filename = (* TODO: extract o_file *) let command = reroot command in let preprocess_command = Str.replace_first command_program_regexp ("\\1 " ^ String.join " " (List.map Filename.quote all_cppflags) ^ " -E -MMD -MT " ^ file) command in - let preprocess_command = Str.replace_first command_o_regexp ("-o " ^ preprocessed_file) preprocess_command in if preprocess_command = command then (* easier way to check if match was found (and replaced) *) - failwith "CompilationDatabase.preprocess: no -o argument found for " ^ file + failwith "CompilationDatabase.preprocess: no program found for " ^ file else - preprocess_command + let preprocess_command_o = Str.replace_first command_o_regexp ("-o " ^ preprocessed_file) preprocess_command in + if preprocess_command_o = preprocess_command then (* easier way to check if match was found (and replaced) *) + preprocess_command ^ " -o " ^ preprocessed_file + else + preprocess_command_o | None, Some arguments -> let arguments = List.map reroot arguments in let preprocess_arguments = From 384b25cac4ea8e42872a65894b9191984b05f7c1 Mon Sep 17 00:00:00 2001 From: stilscher <66023521+stilscher@users.noreply.github.com> Date: Tue, 8 Feb 2022 14:31:34 +0100 Subject: [PATCH 6/8] fix preprocess command composition --- src/util/compilationDatabase.ml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/util/compilationDatabase.ml b/src/util/compilationDatabase.ml index fcd0bcfe7c..f293656662 100644 --- a/src/util/compilationDatabase.ml +++ b/src/util/compilationDatabase.ml @@ -70,22 +70,23 @@ let load_and_preprocess ~all_cppflags filename = else preprocess_command_o | None, Some arguments -> - let arguments = List.map reroot arguments in + let arguments_program, arguments = + begin match List.map reroot arguments with + | arguments_program::arguments -> arguments_program, arguments + | _ -> failwith ("CompilationDatabase.preprocess: no program found for " ^ file) + end in let preprocess_arguments = let suf = begin match List.findi (fun i e -> e = "-o") arguments with | (o_i, _) -> begin match List.split_at o_i arguments with - | (arguments_init, o_file :: arguments_tl) -> arguments_init @ preprocessed_file :: arguments_tl + | (arguments_init, _ :: o_file :: arguments_tl) -> arguments_init @ "-o" :: preprocessed_file :: arguments_tl | _ -> failwith ("CompilationDatabase.preprocess: no argument found for -o option for " ^ file) end | exception Not_found -> arguments @ "-o" :: [preprocessed_file] end in all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: suf in - begin match arguments with - | (arguments_program :: arguments) -> Filename.quote_command arguments_program preprocess_arguments - | _ -> failwith "CompilationDatabase.preprocess: no program found for " ^ file - end + Filename.quote_command arguments_program preprocess_arguments | Some _, Some _ -> failwith "CompilationDatabase.preprocess: both command and arguments specified for " ^ file | None, None -> From 75cfe4cdab68c598dc1711d4e184e03f1653b482 Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Thu, 17 Feb 2022 16:31:09 +0200 Subject: [PATCH 7/8] Fix all_cppflags special case in MakefileUtil --- src/incremental/makefileUtil.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/incremental/makefileUtil.ml b/src/incremental/makefileUtil.ml index deb952b923..d8e9bcb693 100644 --- a/src/incremental/makefileUtil.ml +++ b/src/incremental/makefileUtil.ml @@ -61,7 +61,7 @@ let run_cilly (path: string) ~all_cppflags = remove_comb_files path; (* Combine source files with make using cilly as compiler *) let gcc_path = GobConfig.get_string "exp.gcc_path" in - let cflags = if all_cppflags = [] then " CFLAGS+=" ^ Filename.quote (String.join " " all_cppflags) else "" in + let cflags = if all_cppflags = [] then "" else " CFLAGS+=" ^ Filename.quote (String.join " " all_cppflags) in let (exit_code, output) = exec_command ~path ("make CC=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\"" ^cflags ^ " " ^ "LD=\"cilly --gcc=" ^ gcc_path ^ " --merge --keepmerged\"") in print_string output; From c44bcd60ab7b97a1c8b95f9f816ae1f7aac435ff Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Thu, 17 Feb 2022 16:42:39 +0200 Subject: [PATCH 8/8] Reformat compilation database arguments case --- src/util/compilationDatabase.ml | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/util/compilationDatabase.ml b/src/util/compilationDatabase.ml index 44a6019ca5..1d845e08ef 100644 --- a/src/util/compilationDatabase.ml +++ b/src/util/compilationDatabase.ml @@ -70,21 +70,20 @@ let load_and_preprocess ~all_cppflags filename = preprocess_command_o | None, Some arguments -> let arguments_program, arguments = - begin match List.map reroot arguments with - | arguments_program::arguments -> arguments_program, arguments - | _ -> failwith ("CompilationDatabase.preprocess: no program found for " ^ file) - end in + match List.map reroot arguments with + | arguments_program :: arguments -> arguments_program, arguments + | _ -> failwith ("CompilationDatabase.preprocess: no program found for " ^ file) + in let preprocess_arguments = - let suf = - begin match List.findi (fun i e -> e = "-o") arguments with - | (o_i, _) -> - begin match List.split_at o_i arguments with - | (arguments_init, _ :: o_file :: arguments_tl) -> arguments_init @ "-o" :: preprocessed_file :: arguments_tl - | _ -> failwith ("CompilationDatabase.preprocess: no argument found for -o option for " ^ file) - end - | exception Not_found -> arguments @ "-o" :: [preprocessed_file] - end in - all_cppflags @ "-E" :: suf in + match List.findi (fun i e -> e = "-o") arguments with + | (o_i, _) -> + begin match List.split_at o_i arguments with + | (arguments_init, _ :: o_file :: arguments_tl) -> arguments_init @ "-o" :: preprocessed_file :: arguments_tl + | _ -> failwith ("CompilationDatabase.preprocess: no argument found for -o option for " ^ file) + end + | exception Not_found -> arguments @ "-o" :: [preprocessed_file] + in + let preprocess_arguments = all_cppflags @ "-E" :: preprocess_arguments in Filename.quote_command arguments_program preprocess_arguments | Some _, Some _ -> failwith "CompilationDatabase.preprocess: both command and arguments specified for " ^ file