[lint] fix copyright linter

Summary:
1. One call to `Core.Std.String.slice` was wrong and caused the program to crash, and
2. The crash was silently ignored because the error code of uncaught OCaml
   exceptions was the same as `CheckCopyright.copyright_malformed_exit_code` (=2)

Address both issues. Also build CheckCopyright with debug options.

Reviewed By: jberdine

Differential Revision: D4410306

fbshipit-source-id: d73b086
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent c10126d0fd
commit a7f4aa79af

@ -309,9 +309,12 @@ toplevel: $(INFER_BUILD_DIR)/toplevel.cmo
.PHONY: checkCopyright
checkCopyright: $(CHECKCOPYRIGHT_BIN)
$(CHECKCOPYRIGHT_BIN): $(BUILD_DIR) $(CHECKCOPYRIGHT_MAIN).ml
rebuild -quiet -r -j $(NCPU) -build-dir $(BUILD_DIR)/checkCopyright -pkgs core,str -tag thread -use-ocamlfind $(CHECKCOPYRIGHT_MAIN).native
$(INSTALL_PROGRAM) $(BUILD_DIR)/checkCopyright/$(CHECKCOPYRIGHT_MAIN).native $(CHECKCOPYRIGHT_BIN)
$(CHECKCOPYRIGHT_BIN): $(BUILD_DIR) $(CHECKCOPYRIGHT_MAIN).ml Makefile
rebuild -quiet -r -j $(NCPU) -build-dir $(BUILD_DIR)/checkCopyright \
-cflags -g,-safe-string -lflags -g \
-pkgs core,str -tag thread -use-ocamlfind $(CHECKCOPYRIGHT_MAIN).native
$(INSTALL_PROGRAM) \
$(BUILD_DIR)/checkCopyright/$(CHECKCOPYRIGHT_MAIN).native $(CHECKCOPYRIGHT_BIN)
define gen_atdgen_rules
# generate files using atdgen

@ -12,7 +12,7 @@ open! Core.Std
module F = Format
let copyright_modified_exit_code = 1
let copyright_malformed_exit_code = 2
let copyright_malformed_exit_code = 3 (* error code 2 is for OCaml uncaught exceptions *)
type comment_style =
| Line of string (** line comments, eg "#" for shell *)
@ -202,12 +202,6 @@ let com_style_of_lang = [
let file_should_have_copyright fname =
List.Assoc.mem com_style_of_lang ~equal:Filename.check_suffix fname
let get_filename_extension fname =
try
let len_without_ext = String.length (Filename.chop_extension fname) in
String.slice fname len_without_ext (String.length fname - len_without_ext)
with Not_found -> ""
let output_diff fname lines_arr cstart n cend len mono fb_year com_style prefix =
let range = cend - cstart in
let lang = lang_of_com_style com_style in
@ -228,7 +222,7 @@ let check_copyright fname =
if file_should_have_copyright fname then
begin
let year = 1900 + (Unix.localtime (Unix.time ())).Unix.tm_year in
let ext = get_filename_extension fname in
let ext = "." ^ Option.value (snd (Filename.split_extension fname)) ~default:"" in
let com_style = List.Assoc.find_exn com_style_of_lang ~equal:String.equal ext in
let prefix = prefix_of_comment_style com_style in
let start = default_start_line_of_com_style com_style in

Loading…
Cancel
Save