Skip to content

Commit 3b12445

Browse files
committed
do not require the -o option being set in commands of compilation database
1 parent 4709d78 commit 3b12445

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/util/compilationDatabase.ml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,20 @@ let load_and_preprocess ~all_cppflags filename =
6868
preprocess_command
6969
| None, Some arguments ->
7070
let arguments = List.map reroot arguments in
71-
begin match List.findi (fun i e -> e = "-o") arguments with
72-
| (o_i, _) ->
73-
begin match List.split_at o_i arguments with
74-
| (arguments_program :: arguments_init, _ :: o_file :: arguments_tl) ->
75-
let preprocess_arguments = all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: arguments_init @ "-o" :: preprocessed_file :: arguments_tl in
76-
Filename.quote_command arguments_program preprocess_arguments
77-
| _ ->
78-
failwith "CompilationDatabase.preprocess: no -o argument value found for " ^ file
79-
end
80-
| exception Not_found ->
81-
failwith "CompilationDatabase.preprocess: no -o argument found for " ^ file
71+
let preprocess_arguments =
72+
let suf =
73+
begin match List.findi (fun i e -> e = "-o") arguments with
74+
| (o_i, _) ->
75+
begin match List.drop o_i arguments with
76+
| (_ :: o_file :: arguments_tl) -> preprocessed_file :: arguments_tl
77+
| _ -> failwith ("CompilationDatabase.preprocess: no argument found for -o option for " ^ file)
78+
end
79+
| exception Not_found -> [preprocessed_file]
80+
end in
81+
all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: arguments @ "-o" :: suf in
82+
begin match arguments with
83+
| (arguments_program :: arguments) -> Filename.quote_command arguments_program preprocess_arguments
84+
| _ -> failwith "CompilationDatabase.preprocess: no program found for " ^ file
8285
end
8386
| Some _, Some _ ->
8487
failwith "CompilationDatabase.preprocess: both command and arguments specified for " ^ file
@@ -91,6 +94,6 @@ let load_and_preprocess ~all_cppflags filename =
9194
system ~cwd preprocess_command; (* command/arguments might have paths relative to directory *)
9295
Preprocessor.parse_makefile_deps deps_file;
9396
Some preprocessed_file
94-
in
97+
in
9598
parse_file filename
9699
|> BatList.filter_map preprocess

0 commit comments

Comments
 (0)