Skip to content
Snippets Groups Projects
Commit c21c71c6 authored by Patrick Baudin's avatar Patrick Baudin
Browse files

Merge branch 'bugfix/lint-tool/version-number' into 'master'

[LINT] fixes version number & adds default json value

See merge request frama-c/frama-c!4100
parents 86a171d6 5e5ca704
No related branches found
No related tags found
No related merge requests found
...@@ -79,5 +79,5 @@ That means there is an implicit overloadable JSON description: ...@@ -79,5 +79,5 @@ That means there is an implicit overloadable JSON description:
The option `-c <json-confi g-file>` allows to extend and/or overload the default configuration. The option `-c <json-confi g-file>` allows to extend and/or overload the default configuration.
When the `available_cmd` field is set to an empty string, that disable the check/update with the related tool.
An empty string can also be set to the field `check_cmd` (resp. `update_cmd`) when the related tool does not offer check (resp. update) command. An empty string can also be set to the field `check_cmd` (resp. `update_cmd`) when the related tool does not offer check (resp. update) command.
When the `available_cmd` is set to and empty string, the tool is considered available except if the fields `check_cmd` `update_cmd` are both set to an empty string.
...@@ -20,10 +20,17 @@ ...@@ -20,10 +20,17 @@
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; automatic versionning from opam file
(rule
(targets version.ml)
(deps frama-c-lint.opam)
(action (system "grep ^version frama-c-lint.opam | sed -e 's/version:/let version=/' > version.ml"))
)
(executable (executable
(public_name frama-c-lint) (public_name frama-c-lint)
(name lint) (name lint)
(modules lint UTF8) (modules lint version UTF8)
(preprocess (pps ppx_deriving_yojson)) (preprocess (pps ppx_deriving_yojson))
(libraries unix yojson ocp-indent.lexer ocp-indent.lib ocp-indent.dynlink) (libraries unix yojson ocp-indent.lexer ocp-indent.lib ocp-indent.dynlink)
) )
...@@ -10,6 +10,7 @@ C files, UTF8 for all text files, newline at EOF, no trailing whitespaces. ...@@ -10,6 +10,7 @@ C files, UTF8 for all text files, newline at EOF, no trailing whitespaces.
maintainer: "allan.blanchard@cea.fr" maintainer: "allan.blanchard@cea.fr"
authors: [ authors: [
"Allan Blanchard" "Allan Blanchard"
"Patrick Baudin"
] ]
homepage: "https://frama-c.com/" homepage: "https://frama-c.com/"
license: "LGPL-2.1-only" license: "LGPL-2.1-only"
......
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
(**************************************************************************) (**************************************************************************)
type tool_cmds = type tool_cmds =
{ kind: string ; { kind: (string [@default "Misc"]) ;
extensions: string list ; extensions: (string list [@default []]);
name: string ; name: string ;
available_cmd: string ; (* leaves it empty to set it as unavailable *) available_cmd: (string [@default ""]) ; (* leaves it empty to set it as unavailable *)
check_cmd: string ; (* leaves it empty if there is no check command *) check_cmd: (string [@default ""]) ; (* leaves it empty if there is no check command *)
update_cmd: string (* leaves it empty if there is no updating command *) update_cmd: (string [@default ""]) (* leaves it empty if there is no updating command *)
} }
[@@deriving yojson] [@@deriving yojson]
...@@ -327,15 +327,25 @@ let check_ml_indent ~update file = ...@@ -327,15 +327,25 @@ let check_ml_indent ~update file =
(* C/H *) (* C/H *)
(* returns true if the string command is empty *)
let cmd_result ~file cmd =
(cmd = "") || (0 = Sys.command (Format.sprintf "%s \"%s\"" cmd file))
let is_formatter_available ~file indent_formatter = let is_formatter_available ~file indent_formatter =
match indent_formatter.is_available with match indent_formatter.is_available with
| None -> | None ->
let is_available = let is_enabled =
let cmd = indent_formatter.tool_cmds.available_cmd in (indent_formatter.tool_cmds.update_cmd <> "") ||
(cmd <> "") && (0 = Sys.command cmd) in (indent_formatter.tool_cmds.check_cmd <> "")
indent_formatter.is_available <- Some is_available ; in
if not is_available then let is_available = is_enabled && (cmd_result ~file indent_formatter.tool_cmds.available_cmd) in
warn "%s is unavailable for checking indentation of some %s files (i.e. %s)@." indent_formatter.is_available <- Some is_available;
if not is_enabled then
(* [check_cmd] and [update_cmd] fields are empty *)
warn "%s is disabled for checking/updating indentation of some %s files (i.e. %s)@."
indent_formatter.tool_cmds.name indent_formatter.tool_cmds.kind file
else if not is_available then
warn "%s is unavailable for checking/updating indentation of some %s files (i.e. %s)@."
indent_formatter.tool_cmds.name indent_formatter.tool_cmds.kind file; indent_formatter.tool_cmds.name indent_formatter.tool_cmds.kind file;
is_available is_available
| Some is_available -> is_available | Some is_available -> is_available
...@@ -355,22 +365,20 @@ let check_indent ~indent_formatter ~update file = ...@@ -355,22 +365,20 @@ let check_indent ~indent_formatter ~update file =
in match tool with in match tool with
| Ocp_indent -> check_ml_indent ~update file | Ocp_indent -> check_ml_indent ~update file
| Tool indent_formatter -> | Tool indent_formatter ->
let do_cmd cmd =
(cmd = "") || (0 = Sys.command (Format.sprintf "%s \"%s\"" cmd file))
in
if not @@ is_formatter_available ~file indent_formatter then true if not @@ is_formatter_available ~file indent_formatter then true
else if not update then else if not update then
do_cmd indent_formatter.tool_cmds.check_cmd cmd_result ~file indent_formatter.tool_cmds.check_cmd
else else
do_cmd indent_formatter.tool_cmds.update_cmd cmd_result ~file indent_formatter.tool_cmds.update_cmd
(* Main checks *) (* Main checks *)
let check ~verbose ~update file params = let check ~count ~verbose ~update file params =
if verbose then if verbose then
Format.printf "Checking %s@." file ; Format.printf "Checking %s@." file ;
if Sys .is_directory file then () if Sys .is_directory file then ()
else begin else begin
incr count;
let in_chan = open_in file in let in_chan = open_in file in
let content = read_buffered in_chan in let content = read_buffered in_chan in
close_in in_chan ; close_in in_chan ;
...@@ -423,10 +431,8 @@ let check ~verbose ~update file params = ...@@ -423,10 +431,8 @@ let check ~verbose ~update file params =
let exec_name = Sys.argv.(0) let exec_name = Sys.argv.(0)
let version= "1.0"
let version () = let version () =
Format.printf "%s version %s@." (Filename.basename exec_name) version; Format.printf "%s version %s@." (Filename.basename exec_name) Version.version;
exit 0 exit 0
let update = ref false let update = ref false
...@@ -464,6 +470,8 @@ let () = ...@@ -464,6 +470,8 @@ let () =
updates_tbl external_formatters ; updates_tbl external_formatters ;
parse_config !config_file; parse_config !config_file;
collect @@ lines_from_in stdin ; collect @@ lines_from_in stdin ;
Hashtbl.iter (check ~verbose:!verbose ~update:!update) table ; let count = ref 0 in
Hashtbl.iter (check ~count ~verbose:!verbose ~update:!update) table ;
Format.printf "Lint %d file(s)@." !count;
if not !res then exit 1 if not !res then exit 1
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment