Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize handling of .d files: Accept .d files with multiple targets, eat -MF arguments to preprocessor #557

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/util/compilationDatabase.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ let load_and_preprocess ~all_cppflags filename =
| (o_i, _) ->
begin match List.split_at o_i arguments with
| (arguments_program :: arguments_init, _ :: o_file :: arguments_tl) ->
let arguments_init = match List.findi (fun i e -> e = "-MF") arguments_init with
| (mf_i,_) -> List.remove_at mf_i (List.remove_at mf_i arguments_init)
| exception Not_found -> arguments_init
in
let preprocess_arguments = all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: arguments_init @ "-o" :: preprocessed_file :: arguments_tl in
Filename.quote_command arguments_program preprocess_arguments
| _ ->
Expand Down
6 changes: 4 additions & 2 deletions src/util/makefileParser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
%token NEWLINE
%token EOF

%type <string * string list> deps
%type <(string list * string list) list> deps

%start deps

%%

deps:
| IDENTIFIER COLON identifier_list NEWLINE EOF { ($1, $3) }
| identifier_nonempty_list COLON identifier_list NEWLINE deps { ($1, $3) :: $5 }
| NEWLINE identifier_nonempty_list COLON identifier_list NEWLINE deps { ($2, $4) :: $6 }
| EOF { [] }
;

identifier_list:
Expand Down
10 changes: 7 additions & 3 deletions src/util/preprocessor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ let dependencies: (string, string list) Hashtbl.t = Hashtbl.create 3
let parse_makefile_deps makefile =
BatFile.with_file_in makefile (fun input ->
let lexbuf = Lexing.from_channel input in
let (rule, deps) = MakefileParser.deps MakefileLexer.token lexbuf in
let deps = List.remove deps rule in
Hashtbl.replace dependencies rule deps
let rules = MakefileParser.deps MakefileLexer.token lexbuf in
List.iter (fun (rule, deps) ->
List.iter (fun r ->
let deps = List.remove deps r in
Hashtbl.replace dependencies r deps
) rule
) rules
)