diff --git a/tools/lint/README.md b/tools/lint/README.md index b5ab4cfe03061fe8370eb9f4cc9a59bd2f25c2b9..5f88f8eb9b9ab0a3b27a8fb8b82d39d77231c4c3 100644 --- a/tools/lint/README.md +++ b/tools/lint/README.md @@ -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. -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. +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. diff --git a/tools/lint/dune b/tools/lint/dune index cff48d122fdfd851d113eb40f14a7f5b1bc38f09..8e5852b25acd82545c769b2ffdce491b7f82e9c2 100644 --- a/tools/lint/dune +++ b/tools/lint/dune @@ -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 (public_name frama-c-lint) (name lint) - (modules lint UTF8) + (modules lint version UTF8) (preprocess (pps ppx_deriving_yojson)) (libraries unix yojson ocp-indent.lexer ocp-indent.lib ocp-indent.dynlink) ) diff --git a/tools/lint/frama-c-lint.opam b/tools/lint/frama-c-lint.opam index d7c1d0324a45a9fc6d1733f46d7654b865ca3233..1965b30ff49e4c3289e1f4e69eda47bdec0fe2cc 100644 --- a/tools/lint/frama-c-lint.opam +++ b/tools/lint/frama-c-lint.opam @@ -10,6 +10,7 @@ C files, UTF8 for all text files, newline at EOF, no trailing whitespaces. maintainer: "allan.blanchard@cea.fr" authors: [ "Allan Blanchard" + "Patrick Baudin" ] homepage: "https://frama-c.com/" license: "LGPL-2.1-only" diff --git a/tools/lint/lint.ml b/tools/lint/lint.ml index e08be5eb7821545c3530ad9ad365b7a1300c489f..37e26caba6b8786785e2ad289c0c5a95a4c99642 100644 --- a/tools/lint/lint.ml +++ b/tools/lint/lint.ml @@ -21,12 +21,12 @@ (**************************************************************************) type tool_cmds = - { kind: string ; - extensions: string list ; + { kind: (string [@default "Misc"]) ; + extensions: (string list [@default []]); name: string ; - available_cmd: string ; (* leaves it empty to set it as unavailable *) - check_cmd: string ; (* leaves it empty if there is no check command *) - update_cmd: string (* leaves it empty if there is no updating command *) + available_cmd: (string [@default ""]) ; (* leaves it empty to set it as unavailable *) + check_cmd: (string [@default ""]) ; (* leaves it empty if there is no check command *) + update_cmd: (string [@default ""]) (* leaves it empty if there is no updating command *) } [@@deriving yojson] @@ -327,15 +327,25 @@ let check_ml_indent ~update file = (* 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 = match indent_formatter.is_available with | None -> - let is_available = - let cmd = indent_formatter.tool_cmds.available_cmd in - (cmd <> "") && (0 = Sys.command cmd) in - indent_formatter.is_available <- Some is_available ; - if not is_available then - warn "%s is unavailable for checking indentation of some %s files (i.e. %s)@." + let is_enabled = + (indent_formatter.tool_cmds.update_cmd <> "") || + (indent_formatter.tool_cmds.check_cmd <> "") + in + let is_available = is_enabled && (cmd_result ~file indent_formatter.tool_cmds.available_cmd) in + 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; is_available | Some is_available -> is_available @@ -355,22 +365,20 @@ let check_indent ~indent_formatter ~update file = in match tool with | Ocp_indent -> check_ml_indent ~update file | 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 else if not update then - do_cmd indent_formatter.tool_cmds.check_cmd + cmd_result ~file indent_formatter.tool_cmds.check_cmd else - do_cmd indent_formatter.tool_cmds.update_cmd + cmd_result ~file indent_formatter.tool_cmds.update_cmd (* Main checks *) -let check ~verbose ~update file params = +let check ~count ~verbose ~update file params = if verbose then Format.printf "Checking %s@." file ; if Sys .is_directory file then () else begin + incr count; let in_chan = open_in file in let content = read_buffered in_chan in close_in in_chan ; @@ -423,10 +431,8 @@ let check ~verbose ~update file params = let exec_name = Sys.argv.(0) -let version= "1.0" - 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 let update = ref false @@ -464,6 +470,8 @@ let () = updates_tbl external_formatters ; parse_config !config_file; 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 end