From a7f4aa79afb69bf329e545aebebe90acf93801e7 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Fri, 13 Jan 2017 05:15:19 -0800 Subject: [PATCH] [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 --- infer/src/Makefile | 9 ++++++--- infer/src/scripts/checkCopyright.ml | 10 ++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/infer/src/Makefile b/infer/src/Makefile index cd72cf29d..2f1a131a0 100644 --- a/infer/src/Makefile +++ b/infer/src/Makefile @@ -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 diff --git a/infer/src/scripts/checkCopyright.ml b/infer/src/scripts/checkCopyright.ml index 17e2b4288..689e70074 100644 --- a/infer/src/scripts/checkCopyright.ml +++ b/infer/src/scripts/checkCopyright.ml @@ -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