[copyrightor] turn checkCopyright into a standalone script

Summary:
Usage: `./scripts/checkCopyright [-i] file1 ...`.
master
Jules Villard 9 years ago
parent 85b0ef7266
commit 352b8edff9

1
.gitignore vendored

@ -65,6 +65,7 @@ buck-out/
/infer/lib/specs/cpp_models /infer/lib/specs/cpp_models
/infer/lib/specs/objc_models /infer/lib/specs/objc_models
/infer/lib/specs/clean_models /infer/lib/specs/clean_models
/scripts/checkCopyright
#atdgen stubs #atdgen stubs
/infer/src/backend/jsonbug_* /infer/src/backend/jsonbug_*

@ -6,9 +6,9 @@ MODELS = models
SRCDIR = src SRCDIR = src
.PHONY: clean clang java llvm models .PHONY: clean clang java llvm checkCopyright models
all: clang java llvm all: clang java llvm checkCopyright
java: java:
make -C $(SRCDIR) java make -C $(SRCDIR) java
@ -22,6 +22,9 @@ clang:
llvm: llvm:
make -C $(SRCDIR) llvm make -C $(SRCDIR) llvm
checkCopyright:
make -C $(SRCDIR) checkCopyright
clean: clean:
make -C $(SRCDIR) clean make -C $(SRCDIR) clean
make -C $(MODELS) clean make -C $(MODELS) clean

@ -37,6 +37,7 @@ GLOBAL_LIBS = unix str
BUILDDIR = ../_build-infer BUILDDIR = ../_build-infer
ANNOTDIR = $(ROOT)/infer/src/_build ANNOTDIR = $(ROOT)/infer/src/_build
BINDIR = $(ROOT)/infer/bin BINDIR = $(ROOT)/infer/bin
SCRIPTDIR = $(ROOT)/scripts
ifneq ($(wildcard $(BUILDDIR)/sanitize.sh),) ifneq ($(wildcard $(BUILDDIR)/sanitize.sh),)
SANITIZE_SCRIPT = $(BUILDDIR)/sanitize.sh SANITIZE_SCRIPT = $(BUILDDIR)/sanitize.sh
@ -111,6 +112,13 @@ LLVM_SOURCES = llvm
INFERLLVM_MAIN = $(LLVM_SOURCES)/lMain INFERLLVM_MAIN = $(LLVM_SOURCES)/lMain
INFERLLVM_BINARY = $(BINDIR)/InferLLVM INFERLLVM_BINARY = $(BINDIR)/InferLLVM
#### scripts declarations ####
SCRIPT_SOURCES = scripts
CHECKCOPYRIGHT_BINARY = $(SCRIPTDIR)/checkCopyright
CHECKCOPYRIGHT_MAIN = $(SCRIPT_SOURCES)/checkCopyright
#### End of declarations #### #### End of declarations ####
# Check whether .facebook file exists in a root directory. # Check whether .facebook file exists in a root directory.
@ -125,9 +133,9 @@ DEPENDENCIES = $(BACKEND_SOURCES) checkers facebook/checkers facebook/checkers/g
OCAMLBUILD = ocamlbuild -build-dir $(BUILDDIR) -j 0 $(addprefix -I , $(DEPENDENCIES)) $(GLOBAL_OPTIONS) $(ATDGEN_OPTIONS) $(JAVA_OPTIONS) OCAMLBUILD = ocamlbuild -build-dir $(BUILDDIR) -j 0 $(addprefix -I , $(DEPENDENCIES)) $(GLOBAL_OPTIONS) $(ATDGEN_OPTIONS) $(JAVA_OPTIONS)
.PHONY: all java clang llvm build_java build_clang build_llvm annotations init sanitize version clean .PHONY: all java clang llvm checkCopyright build_java build_clang build_llvm build_checkCopyright annotations init sanitize version clean
all: java clang llvm all: java clang llvm checkCopyright
java: build_java annotations $(INFERANALYZE_BINARY) $(INFERPRINT_BINARY) $(INFERJAVA_BINARY) java: build_java annotations $(INFERANALYZE_BINARY) $(INFERPRINT_BINARY) $(INFERJAVA_BINARY)
@ -135,6 +143,8 @@ clang: build_clang annotations $(INFERANALYZE_BINARY) $(INFERPRINT_BINARY) $(INF
llvm: build_llvm annotations $(INFERLLVM_BINARY) llvm: build_llvm annotations $(INFERLLVM_BINARY)
checkCopyright: build_checkCopyright annotations $(CHECKCOPYRIGHT_BINARY)
build_java: init $(INFERPRINT_ATDGEN_STUBS) build_java: init $(INFERPRINT_ATDGEN_STUBS)
$(OCAMLBUILD) $(TYPEPROP_MAIN).native $(INFERANALYZE_MAIN).native $(INFERPRINT_MAIN).native $(INFERJAVA_MAIN).native $(OCAMLBUILD) $(TYPEPROP_MAIN).native $(INFERANALYZE_MAIN).native $(INFERPRINT_MAIN).native $(INFERJAVA_MAIN).native
@ -144,11 +154,14 @@ build_clang: init $(INFERPRINT_ATDGEN_STUBS) check_clang_plugin $(CLANG_ATDGEN_S
build_llvm: build_llvm:
$(OCAMLBUILD) -use-menhir $(INFERLLVM_MAIN).native $(OCAMLBUILD) -use-menhir $(INFERLLVM_MAIN).native
build_checkCopyright:
$(OCAMLBUILD) -I $(SCRIPT_SOURCES) $(CHECKCOPYRIGHT_MAIN).native
annotations: annotations:
rsync -r --delete --exclude=*.ml* --exclude=*.o --exclude=*.cm* --exclude=*.native $(BUILDDIR)/* $(ANNOTDIR) rsync -r --delete --exclude=*.ml* --exclude=*.o --exclude=*.cm* --exclude=*.native $(BUILDDIR)/* $(ANNOTDIR)
check_clang_plugin: check_clang_plugin:
$(ROOT)/scripts/check_clang_plugin_version.sh $(CLANG_PLUGIN_ROOT) $(SCRIPTDIR)/check_clang_plugin_version.sh $(CLANG_PLUGIN_ROOT)
$(INFERPRINT_ATDGEN_STUBS): $(INFERPRINT_ATDGEN_STUB_ATD) $(INFERPRINT_ATDGEN_STUBS): $(INFERPRINT_ATDGEN_STUB_ATD)
atdgen -t $(INFERPRINT_ATDGEN_STUB_ATD) -o $(INFERPRINT_ATDGEN_STUB_BASE) atdgen -t $(INFERPRINT_ATDGEN_STUB_ATD) -o $(INFERPRINT_ATDGEN_STUB_BASE)
@ -214,7 +227,10 @@ $(INFERLLVM_BINARY): $(BUILDDIR)/$(INFERLLVM_MAIN).native
$(TYPEPROP_BINARY): $(BUILDDIR)/$(TYPEPROP_MAIN).native $(TYPEPROP_BINARY): $(BUILDDIR)/$(TYPEPROP_MAIN).native
$(COPY) $(BUILDDIR)/$(TYPEPROP_MAIN).native $(TYPEPROP_BINARY) $(COPY) $(BUILDDIR)/$(TYPEPROP_MAIN).native $(TYPEPROP_BINARY)
$(CHECKCOPYRIGHT_BINARY): $(BUILDDIR)/$(CHECKCOPYRIGHT_MAIN).native
$(COPY) $(BUILDDIR)/$(CHECKCOPYRIGHT_MAIN).native $(CHECKCOPYRIGHT_BINARY)
clean: $(BUILDDIR) clean: $(BUILDDIR)
$(OCAMLBUILD) -clean $(OCAMLBUILD) -clean
$(REMOVE_DIR) $(ANNOTDIR) $(REMOVE_DIR) $(ANNOTDIR)
$(REMOVE) $(TYPEPROP_BINARY) $(INFERANALYZE_BINARY) $(INFERPRINT_BINARY) $(INFERJAVA_BINARY) $(INFERCLANG_BINARY) $(INFERLLVM_BINARY) $(REMOVE) $(TYPEPROP_BINARY) $(INFERANALYZE_BINARY) $(INFERPRINT_BINARY) $(INFERJAVA_BINARY) $(INFERCLANG_BINARY) $(INFERLLVM_BINARY) $(CHECKCOPYRIGHT_BINARY)

@ -14,8 +14,6 @@ module L = Logging
module F = Format module F = Format
open Utils open Utils
let () = if CheckCopyright.active then CheckCopyright.check ()
(** {2 Programs and Types} *) (** {2 Programs and Types} *)
(** Type to represent one @Annotation. *) (** Type to represent one @Annotation. *)

@ -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
Loading…
Cancel
Save