Commit 6e91fa95 authored by Valentin Perrelle's avatar Valentin Perrelle Committed by Andre Maroneze
Browse files

[kernel] add an option to dump the current configuration into a Json object

parent 3d327d85
......@@ -627,6 +627,7 @@ KERNEL_CMO=\
src/kernel_services/ast_transformations/clone.cmo \
src/kernel_services/ast_transformations/filter.cmo \
src/kernel_services/ast_transformations/inline.cmo \
src/kernel_internals/runtime/dump_config.cmo \
src/kernel_internals/runtime/special_hooks.cmo \
src/kernel_internals/runtime/messages.cmo
......
......@@ -367,6 +367,8 @@ src/kernel_internals/parsing/logic_preprocess.mli: CEA_INRIA_LGPL
src/kernel_internals/parsing/logic_preprocess.mll: CEA_INRIA_LGPL
src/kernel_internals/runtime/README.md: .ignore
src/kernel_internals/runtime/boot.ml: CEA_LGPL
src/kernel_internals/runtime/dump_config.ml: CEA_LGPL
src/kernel_internals/runtime/dump_config.mli: CEA_LGPL
src/kernel_internals/runtime/fc_config.ml.in: CEA_LGPL
src/kernel_internals/runtime/fc_config.mli: CEA_LGPL
src/kernel_internals/runtime/frama_c_config.ml.in: CEA_LGPL
......
(**************************************************************************)
(* *)
(* This file is part of Frama-C. *)
(* *)
(* Copyright (C) 2007-2020 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
(* you can redistribute it and/or modify it under the terms of the GNU *)
(* Lesser General Public License as published by the Free Software *)
(* Foundation, version 2.1. *)
(* *)
(* It is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
(* GNU Lesser General Public License for more details. *)
(* *)
(* See the GNU Lesser General Public License version 2.1 *)
(* for more details (enclosed in the file licenses/LGPLv2.1). *)
(* *)
(**************************************************************************)
let dump_to_stdout () =
let string s = `String s in
let list f l = `List (List.map f l) in
let json = `Assoc [
"version", `String Fc_config.version ;
"codename", `String Fc_config.codename ;
"version_and_codename", `String Fc_config.version_and_codename ;
"major_version", `Int Fc_config.major_version ;
"minor_version", `Int Fc_config.minor_version ;
"is_gui", `Bool !Fc_config.is_gui ;
"ocamlc", `String Fc_config.ocamlc ;
"ocamlopt", `String Fc_config.ocamlopt ;
"ocaml_wflags", `String Fc_config.ocaml_wflags ;
"datadir", `String Fc_config.datadir ;
"datadirs", list string Fc_config.datadirs ;
"framac_libc", `String Fc_config.framac_libc ;
"libdir", `String Fc_config.libdir ;
"plugin_dir", list string Fc_config.plugin_dir ;
"plugin_path", `String Fc_config.plugin_path ;
"compilation_unit_names", list string Fc_config.compilation_unit_names ;
"library_names", list string Fc_config.library_names ;
"preprocessor", `String Fc_config.preprocessor ;
"using_default_cpp", `Bool Fc_config.using_default_cpp ;
"preprocessor_is_gnu_like", `Bool Fc_config.preprocessor_is_gnu_like ;
"preprocessor_supported_arch_options",
list string Fc_config.preprocessor_supported_arch_options ;
"preprocessor_keep_comments", `Bool Fc_config.preprocessor_keep_comments ;
"dot", (match Fc_config.dot with Some cmd -> `String cmd | None -> `Null) ;
"current_machdep", `String (Kernel.Machdep.get ()) ;
"machdeps", list string (File.list_available_machdeps ())
]
in
Yojson.Basic.pretty_to_channel stdout json
let () =
let action () =
if Kernel.DumpConfig.get () then begin
dump_to_stdout ();
raise Cmdline.Exit
end else
Cmdline.nop
in
Cmdline.run_after_exiting_stage action
(**************************************************************************)
(* *)
(* This file is part of Frama-C. *)
(* *)
(* Copyright (C) 2007-2020 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
(* you can redistribute it and/or modify it under the terms of the GNU *)
(* Lesser General Public License as published by the Free Software *)
(* Foundation, version 2.1. *)
(* *)
(* It is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
(* GNU Lesser General Public License for more details. *)
(* *)
(* See the GNU Lesser General Public License version 2.1 *)
(* for more details (enclosed in the file licenses/LGPLv2.1). *)
(* *)
(**************************************************************************)
val dump_to_stdout : unit -> unit
(** Dumps a Json object describing the Frama-C configuration *)
......@@ -396,6 +396,9 @@ let get_machdep () =
with Not_found -> (* Should not happen given the checks above *)
Kernel.fatal "Machdep %s not registered" m
let list_available_machdeps () =
Machdeps.fold (fun m _ acc -> m :: acc) (List.map fst default_machdeps)
let pretty_machdep ?fmt ?machdep () =
let machine = match machdep with None -> get_machdep () | Some m -> m in
match fmt with
......
......@@ -69,6 +69,12 @@ val machdep_macro: string -> string
@since Magnesium-20151001 (exported in the API)
*)
val list_available_machdeps: unit -> string list
(** [list_available_machdeps ()] gives the list of the names of available
machdeps, starting with the ones added with new_machdep and ending with
the list of default machdeps.
@since Frama-C+dev *)
type code_transformation_category
(** type of registered code transformations
@since Neon-20140301
......
......@@ -418,6 +418,17 @@ let () =
if not (DumpDependencies.is_default ()) then
State_dependency_graph.dump (DumpDependencies.get ()))
let () = Parameter_customize.set_group help
let () = Parameter_customize.set_cmdline_stage Cmdline.Exiting
module DumpConfig =
False
(struct
let module_name = "DumpConfig"
let option_name = "-dump-config"
let help = "dump several information about frama-configuration inside \
JSON object"
end)
let () = Parameter_customize.set_group help
let () = Parameter_customize.set_cmdline_stage Cmdline.Exiting
let () = Parameter_customize.do_not_journalize ()
......
......@@ -238,6 +238,10 @@ module PrintPluginPath: Parameter_sig.Bool
module AutocompleteHelp: Parameter_sig.String_set
(** Behavior of option "-autocomplete" *)
module DumpConfig: Parameter_sig.Bool
(** Behavior of option "-dump-config"
@since Frama-C+dev *)
(* ************************************************************************* *)
(** {2 Output Messages} *)
(* ************************************************************************* *)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment