|
|
@ -31,11 +31,8 @@ let lang_of_com_style style =
|
|
|
|
else if style = comment_style_shell then "shell"
|
|
|
|
else if style = comment_style_shell then "shell"
|
|
|
|
else "??unknown??"
|
|
|
|
else "??unknown??"
|
|
|
|
|
|
|
|
|
|
|
|
(** If active, check copyright messages and exit. *)
|
|
|
|
|
|
|
|
let active = Config.from_env_variable "INFER_CHECK_COPYRIGHT"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(** If true, update the copyright message of the files. *)
|
|
|
|
(** If true, update the copyright message of the files. *)
|
|
|
|
let update_files = true
|
|
|
|
let update_files = ref false
|
|
|
|
|
|
|
|
|
|
|
|
let line_contains_copyright line =
|
|
|
|
let line_contains_copyright line =
|
|
|
|
string_contains "opyright " line
|
|
|
|
string_contains "opyright " line
|
|
|
@ -175,61 +172,56 @@ let file_should_have_copyright fname lines =
|
|
|
|
list_exists (Filename.check_suffix fname) extensions
|
|
|
|
list_exists (Filename.check_suffix fname) extensions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let get_files_from_git () =
|
|
|
|
let check_copyright fname = match read_file fname with
|
|
|
|
let tmpfile = Filename.temp_file "git_ls" "" in
|
|
|
|
| None -> ()
|
|
|
|
let _ = Sys.command ("git ls-files >" ^ tmpfile) in
|
|
|
|
| Some lines ->
|
|
|
|
let git_files = match read_file tmpfile with
|
|
|
|
match find_copyright_line lines 0 with
|
|
|
|
| Some git_files -> git_files
|
|
|
|
| None ->
|
|
|
|
| None -> [] in
|
|
|
|
if file_should_have_copyright fname lines
|
|
|
|
Sys.remove tmpfile;
|
|
|
|
then L.stderr "Copyright not found in %s@." fname
|
|
|
|
git_files
|
|
|
|
| Some n ->
|
|
|
|
|
|
|
|
let lines_arr = Array.of_list lines in
|
|
|
|
|
|
|
|
let line = lines_arr.(n) in
|
|
|
|
let check_copyright () =
|
|
|
|
let len = String.length line in
|
|
|
|
let check_file fname =
|
|
|
|
let (cstart, com_style) = find_comment_start_and_style lines_arr n in
|
|
|
|
match read_file fname with
|
|
|
|
let cend = find_comment_end lines_arr n com_style in
|
|
|
|
| None -> ()
|
|
|
|
if looks_like_copyright_message cstart cend lines_arr then
|
|
|
|
| Some lines ->
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
let mono = contains_monoidics cstart cend lines_arr in
|
|
|
|
match find_copyright_line lines 0 with
|
|
|
|
match get_fb_year cstart cend lines_arr with
|
|
|
|
| None ->
|
|
|
|
| None ->
|
|
|
|
if file_should_have_copyright fname lines
|
|
|
|
L.stderr "Can't find fb year: %s@." fname
|
|
|
|
then L.stderr "Copyright not found in %s@." fname
|
|
|
|
| Some fb_year ->
|
|
|
|
| Some n ->
|
|
|
|
let prefix = if com_style = comment_style_ocaml then " " else "" in
|
|
|
|
let lines_arr = Array.of_list lines in
|
|
|
|
if copyright_has_changed mono fb_year com_style prefix cstart cend lines_arr then
|
|
|
|
let line = lines_arr.(n) in
|
|
|
|
begin
|
|
|
|
let len = String.length line in
|
|
|
|
let range = cend - cstart in
|
|
|
|
let (cstart, com_style) = find_comment_start_and_style lines_arr n in
|
|
|
|
let lang = lang_of_com_style com_style in
|
|
|
|
let cend = find_comment_end lines_arr n com_style in
|
|
|
|
L.stdout "%s (start:%d n:%d end:%d len:%d range:%d lang:%s mono:%b year:%d)@."
|
|
|
|
if looks_like_copyright_message cstart cend lines_arr then
|
|
|
|
fname cstart n cend len range lang mono fb_year;
|
|
|
|
begin
|
|
|
|
for i = cstart to cend do
|
|
|
|
let mono = contains_monoidics cstart cend lines_arr in
|
|
|
|
L.stdout " %s@." lines_arr.(i)
|
|
|
|
match get_fb_year cstart cend lines_arr with
|
|
|
|
done;
|
|
|
|
| None ->
|
|
|
|
L.stdout "-----@.";
|
|
|
|
L.stderr "Can't find fb year: %s@." fname
|
|
|
|
L.stdout " @[<v>%a@]" (pp_copyright mono fb_year com_style) prefix;
|
|
|
|
| Some fb_year ->
|
|
|
|
L.flush_streams ();
|
|
|
|
let prefix = if com_style = comment_style_ocaml then " " else "" in
|
|
|
|
if !update_files then
|
|
|
|
if copyright_has_changed mono fb_year com_style prefix cstart cend lines_arr then
|
|
|
|
update_file fname mono fb_year com_style prefix cstart cend lines_arr
|
|
|
|
begin
|
|
|
|
end
|
|
|
|
let range = cend - cstart in
|
|
|
|
end
|
|
|
|
let lang = lang_of_com_style com_style in
|
|
|
|
else
|
|
|
|
L.stdout "%s (start:%d n:%d end:%d len:%d range:%d lang:%s mono:%b year:%d)@."
|
|
|
|
L.stderr "Copyright not recognized: %s@." fname
|
|
|
|
fname cstart n cend len range lang mono fb_year;
|
|
|
|
|
|
|
|
for i = cstart to cend do
|
|
|
|
let speclist = [
|
|
|
|
L.stdout " %s@." lines_arr.(i)
|
|
|
|
("-i", Arg.Set update_files, "Update copyright notice in-place");
|
|
|
|
done;
|
|
|
|
]
|
|
|
|
L.stdout "-----@.";
|
|
|
|
|
|
|
|
L.stdout " @[<v>%a@]" (pp_copyright mono fb_year com_style) prefix;
|
|
|
|
|
|
|
|
L.flush_streams ();
|
|
|
|
|
|
|
|
if update_files then
|
|
|
|
|
|
|
|
update_file fname mono fb_year com_style prefix cstart cend lines_arr
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
L.stderr "Copyright not recognized: %s@." fname
|
|
|
|
|
|
|
|
end in
|
|
|
|
|
|
|
|
list_iter check_file (get_files_from_git ());
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let check () =
|
|
|
|
let usage_msg = "checkCopyright [-i] file1 ..."
|
|
|
|
if active then check_copyright ()
|
|
|
|
|
|
|
|
|
|
|
|
let () =
|
|
|
|
|
|
|
|
let to_check = ref [] in
|
|
|
|
|
|
|
|
let add_file_to_check fname =
|
|
|
|
|
|
|
|
to_check := fname :: !to_check in
|
|
|
|
|
|
|
|
Arg.parse speclist add_file_to_check usage_msg;
|
|
|
|
|
|
|
|
list_iter check_copyright (list_rev !to_check);
|
|
|
|
|
|
|
|
exit 0
|