diff --git a/src/kernel_services/ast_queries/json_compilation_database.ml b/src/kernel_services/ast_queries/json_compilation_database.ml index 875c9431f78bec3d59d337b9d480b0dae38a28fc..eb529f3c23932565e139de9604c6d29b95bc7f10 100644 --- a/src/kernel_services/ast_queries/json_compilation_database.ml +++ b/src/kernel_services/ast_queries/json_compilation_database.ml @@ -240,11 +240,8 @@ let parse_entry jcdb_dir r = Flags.add path flags let compute_flags_from_file () = - let database = Kernel.JsonCompilationDatabase.get () in + let database = (Kernel.JsonCompilationDatabase.get () :> string) in let jcdb_dir, jcdb_path = - if not (Sys.file_exists database) then - Kernel.abort "invalid path for option %s: %s" - Kernel.JsonCompilationDatabase.option_name database; if Sys.is_directory database then database, Filename.concat database "compile_commands.json" else Filename.dirname database, database @@ -267,7 +264,7 @@ let compute_flags_from_file () = Flags.mark_as_computed () let get_flags f = - if Kernel.JsonCompilationDatabase.get () <> "" then begin + if not (Filepath.Normalized.is_unknown (Kernel.JsonCompilationDatabase.get ())) then begin if not (Flags.is_computed ()) then compute_flags_from_file (); try let flags = Flags.find f in diff --git a/src/kernel_services/plugin_entry_points/kernel.ml b/src/kernel_services/plugin_entry_points/kernel.ml index 0d5cfc8f14bd3213c0d186142b7ed97f41605dd9..cb516102daea7db1158e7f79d1ad3903063690a7 100644 --- a/src/kernel_services/plugin_entry_points/kernel.ml +++ b/src/kernel_services/plugin_entry_points/kernel.ml @@ -1110,12 +1110,12 @@ module C11 = let () = Parameter_customize.set_group parsing let () = Parameter_customize.do_not_reset_on_copy () module JsonCompilationDatabase = - String + P.Filepath (struct - let module_name = "JsonCompilationDatabase" let option_name = "-json-compilation-database" - let default = "" let arg_name = "path" + let file_kind = "directory or json" + let existence = Filepath.Must_exist let help = "when set, preprocessing of each file will include corresponding \ flags (e.g. -I, -D) from the JSON compilation database \ diff --git a/src/kernel_services/plugin_entry_points/kernel.mli b/src/kernel_services/plugin_entry_points/kernel.mli index c9dae9c7fd2a8eb422b6976f2bce1c8bf15cf982..fe86c933c173f75e5aa6e7c671bedded7da75809 100644 --- a/src/kernel_services/plugin_entry_points/kernel.mli +++ b/src/kernel_services/plugin_entry_points/kernel.mli @@ -465,7 +465,7 @@ module ImplicitFunctionDeclaration: Parameter_sig.String module C11: Parameter_sig.Bool (** Behavior of option "-c11" *) -module JsonCompilationDatabase: Parameter_sig.String +module JsonCompilationDatabase: Parameter_sig.Filepath (** Behavior of option "-json-compilation-database" *) (* ************************************************************************* *) diff --git a/tests/jcdb/compile_commands.json b/tests/jcdb/compile_commands.json index 52a0f039c5ba20d81bf77a3dd803b8579d285c75..0592cf2b0799160bb9d83ce1b7aa103c2fc15b7c 100644 --- a/tests/jcdb/compile_commands.json +++ b/tests/jcdb/compile_commands.json @@ -7,12 +7,12 @@ "command": "g++ -DDUPLICATE_FLAGS_THAT_WILL_BE_OVERWRITTEN", "file": "jcdb.c" }, - { "directory": ".", - "command": "/usr/bin/clang++ -D'MSG=\"a \\\" \\\"b\"' -D'SINGLE_DOUBLE(a)=\"a \\\"with spaces and tab \"' -DSOMEDEF=\"With spaces, quotes and \\-es.\" -D\"DOUBLE_SINGLE(a)=a \\\"macro with spaces and non-escaped \\\\'\\\"\" -DEMPTY='' -DEMPTY2= -DTEST=42 -D'MACRO_FOR_INCR(s)=s+1' -DTOUNDEF -UTOUNDEF", + { + "command": "testing entry without 'directory' key -DFLAG_TO_BE_FORGOTTEN", "file": "jcdb.c" }, - { - "command": "testing entry without 'directory' key", + { "directory": ".", + "command": "/usr/bin/clang++ -D'MSG=\"a \\\" \\\"b\"' -D'SINGLE_DOUBLE(a)=\"a \\\"with spaces and tab \"' -DSOMEDEF=\"With spaces, quotes and \\-es.\" -D\"DOUBLE_SINGLE(a)=a \\\"macro with spaces and non-escaped \\\\'\\\"\" -DEMPTY='' -DEMPTY2= -DTEST=42 -D'MACRO_FOR_INCR(s)=s+1' -DTOUNDEF -UTOUNDEF", "file": "jcdb.c" } ] diff --git a/tests/jcdb/jcdb.ml b/tests/jcdb/jcdb.ml index 4d0408048a1f47720c6605ccf9fdeb18669e8f57..d9163defa210d991acf8362bd59ac34d9f9c57ac 100644 --- a/tests/jcdb/jcdb.ml +++ b/tests/jcdb/jcdb.ml @@ -1,8 +1,8 @@ let print_json () = Kernel.feedback - "Value of -json-compilation-database in %s is %s" + "Value of -json-compilation-database in %s is %a" (Project.get_name (Project.current())) - (Kernel.JsonCompilationDatabase.get()) + Filepath.Normalized.pretty (Kernel.JsonCompilationDatabase.get()) let run () = print_json (); diff --git a/tests/jcdb/oracle/jcdb.0.res.oracle b/tests/jcdb/oracle/jcdb.0.res.oracle index 1a80090d55b0c602628524a47fa26ba90e0cf493..aca498a1f0268f3109f7298d7a4bf3fd11a6d37d 100644 --- a/tests/jcdb/oracle/jcdb.0.res.oracle +++ b/tests/jcdb/oracle/jcdb.0.res.oracle @@ -1,6 +1,6 @@ [kernel:pp:compilation-db] Warning: found duplicate flags for 'tests/jcdb/jcdb.c', replacing old flags. - Old flags no longer present: -D'MSG="a \" \"b"' -D'SINGLE_DOUBLE(a)="a \"with spaces and tab "' -DSOMEDEF="With spaces, quotes and \-es." -D"DOUBLE_SINGLE(a)=a \"macro with spaces and non-escaped \\'\"" -DEMPTY='' -DEMPTY2= -DTEST=42 -D'MACRO_FOR_INCR(s)=s+1' -DTOUNDEF -UTOUNDEF + Old flags no longer present: -DFLAG_TO_BE_FORGOTTEN New flags not previously present: -DDUPLICATE_FLAGS_THAT_WILL_BE_OVERWRITTEN (warn-once: no further messages from category 'pp:compilation-db' will be emitted) [kernel] Parsing tests/jcdb/jcdb.c (with preprocessing)