[infer] Find dead signature (.mli file)

Reviewed By: ezgicicek

Differential Revision: D20036524

fbshipit-source-id: c39150e04
master
Sungkeun Cho 5 years ago committed by Facebook Github Bot
parent a66f6cd736
commit 50e5bfd32f

2
.gitignore vendored

@ -185,6 +185,8 @@ infer/src/.project
/infer/src/deadcode/.depend /infer/src/deadcode/.depend
/infer/src/deadcode/all_ml_files /infer/src/deadcode/all_ml_files
/infer/src/deadcode/all_ml_files_copied /infer/src/deadcode/all_ml_files_copied
/infer/src/deadcode/all_mli_files
/infer/src/deadcode/all_mli_files_copied
/infer/src/deadcode/dune /infer/src/deadcode/dune
/infer/src/deadcode/*.ml /infer/src/deadcode/*.ml
/infer/src/deadcode/*.mli /infer/src/deadcode/*.mli

@ -32,7 +32,9 @@ INFER_BUILD_DIR = ../_build/test
ALL_INFER_IN_ONE_FILE_ML = all_infer_in_one_file.ml ALL_INFER_IN_ONE_FILE_ML = all_infer_in_one_file.ml
ALL_ML_FILES = all_ml_files ALL_ML_FILES = all_ml_files
ALL_MLI_FILES = all_mli_files
ALL_ML_FILES_COPIED = all_ml_files_copied ALL_ML_FILES_COPIED = all_ml_files_copied
ALL_MLI_FILES_COPIED = all_mli_files_copied
default: detect_dead_code default: detect_dead_code
@ -103,6 +105,7 @@ depend:
echo '[@warning "-60"] ' >> $(ALL_INFER_IN_ONE_FILE_ML);\ echo '[@warning "-60"] ' >> $(ALL_INFER_IN_ONE_FILE_ML);\
fi fi
$(QUIET)echo >> $(ALL_INFER_IN_ONE_FILE_ML) $(QUIET)echo >> $(ALL_INFER_IN_ONE_FILE_ML)
$(QUIET)echo "$*.mli" >> $(ALL_MLI_FILES_COPIED)
$(QUIET)echo "$*.ml" >> $(ALL_ML_FILES_COPIED) $(QUIET)echo "$*.ml" >> $(ALL_ML_FILES_COPIED)
$(ml_src_files_without_mli:.ml=.cmx): $(ml_src_files_without_mli:.ml=.cmx):
@ -158,11 +161,12 @@ detect_dead_code:
# have changed. For both of these reasons, run another `make`. # have changed. For both of these reasons, run another `make`.
# Create a temp file so that the build doesn't break if this step gets interrupted. # Create a temp file so that the build doesn't break if this step gets interrupted.
tmp_file=$$(mktemp -t all_infer_in_one_file_XXXXX.ml); \ tmp_file=$$(mktemp -t all_infer_in_one_file_XXXXX.ml); \
tmp_file_copied=$$(mktemp -t all_ml_files_copied); \ tmp_file_copied=$$(mktemp -t all_ml_files_copied_XXXXX); \
$(MAKE) -j 1 ALL_INFER_IN_ONE_FILE_ML="$$tmp_file" ALL_ML_FILES_COPIED="$$tmp_file_copied" flatten_infer; \ $(MAKE) -j 1 ALL_INFER_IN_ONE_FILE_ML="$$tmp_file" ALL_ML_FILES_COPIED="$$tmp_file_copied" flatten_infer; \
mv "$$tmp_file" $(ALL_INFER_IN_ONE_FILE_ML); \ mv "$$tmp_file" $(ALL_INFER_IN_ONE_FILE_ML); \
sort -u "$$tmp_file_copied" > $(ALL_ML_FILES_COPIED) sort -u "$$tmp_file_copied" > $(ALL_ML_FILES_COPIED); \
$(MAKE) -j 1 detect_dead_ml_file rm "$$tmp_file_copied"
$(MAKE) -j 1 detect_dead_src_file
# build and get dead code warnings; clean in case of errors so as not to leave rubbish around # build and get dead code warnings; clean in case of errors so as not to leave rubbish around
if ! dune build $(INFER_BUILD_DIR)/deadcode/all_infer_in_one_file.bc; then \ if ! dune build $(INFER_BUILD_DIR)/deadcode/all_infer_in_one_file.bc; then \
$(MAKE) clean; \ $(MAKE) clean; \
@ -172,11 +176,12 @@ detect_dead_code:
# accident and I don't know enough dune to be positive that it won't happen # accident and I don't know enough dune to be positive that it won't happen
$(MAKE) clean $(MAKE) clean
.PHONY: detect_dead_ml_file .PHONY: detect_dead_src_file
detect_dead_ml_file: detect_dead_src_file:
function is_in_blacklist { \ function is_in_blacklist { \
if [ "$$1" = "infertop.ml" ] \ if [ "$$1" = "infertop.ml" ] \
|| [ "$$1" = "deadcode/all_infer_in_one_file.ml" ] \ || [ "$$1" = "deadcode/all_infer_in_one_file.ml" ] \
|| [ "$$1" = "deadcode/all_infer_in_one_file.mli" ] \
|| [[ "$$1" =~ ^"labs/" ]] \ || [[ "$$1" =~ ^"labs/" ]] \
|| [[ "$$1" =~ ^"llvm/" ]] \ || [[ "$$1" =~ ^"llvm/" ]] \
|| [[ "$$1" =~ ^"opensource/" ]]; then \ || [[ "$$1" =~ ^"opensource/" ]]; then \
@ -185,23 +190,47 @@ detect_dead_ml_file:
exit 1; \ exit 1; \
fi; \ fi; \
}; \ }; \
tmp_file=$$(mktemp -t all_ml_files); \ \
tmp_file=$$(mktemp -t all_ml_files_XXXXX); \
for i in $(ml_src_files) $(ml_src_files_without_mli); do \ for i in $(ml_src_files) $(ml_src_files_without_mli); do \
(is_in_blacklist "$$i") || (echo "$$i" >> "$$tmp_file"); \ (is_in_blacklist "$$i") || (echo "$$i" >> "$$tmp_file"); \
done; \ done; \
sort -u "$$tmp_file" > $(ALL_ML_FILES); \ sort -u "$$tmp_file" > $(ALL_ML_FILES); \
tmp_file=$$(mktemp -t all_ml_files_copied); \ rm "$$tmp_file"; \
\
tmp_file=$$(mktemp -t all_mli_files_XXXXX); \
for i in $(mli_src_files); do \
(is_in_blacklist "$$i") || (echo "$$i" >> "$$tmp_file"); \
done; \
sort -u "$$tmp_file" > $(ALL_MLI_FILES); \
rm "$$tmp_file"; \
\
tmp_file=$$(mktemp -t all_ml_files_copied_XXXXX); \
for i in $$(cat $(ALL_ML_FILES_COPIED)); do \ for i in $$(cat $(ALL_ML_FILES_COPIED)); do \
(is_in_blacklist "$$i") || (echo "$$i" >> "$$tmp_file"); \ (is_in_blacklist "$$i") || (echo "$$i" >> "$$tmp_file"); \
done; \ done; \
sort -u "$$tmp_file" > $(ALL_ML_FILES_COPIED) sort -u "$$tmp_file" > $(ALL_ML_FILES_COPIED); \
rm "$$tmp_file"; \
\
tmp_file=$$(mktemp -t all_mli_files_copied_XXXXX); \
for i in $$(cat $(ALL_MLI_FILES_COPIED)); do \
(is_in_blacklist "$$i") || (echo "$$i" >> "$$tmp_file"); \
done; \
sort -u "$$tmp_file" > $(ALL_MLI_FILES_COPIED); \
rm "$$tmp_file"; \
if ! diff $(ALL_ML_FILES) $(ALL_ML_FILES_COPIED) 1>&2; then \ if ! diff $(ALL_ML_FILES) $(ALL_ML_FILES_COPIED) 1>&2; then \
$(MAKE) clean; \ $(MAKE) clean; \
exit 1; \ exit 1; \
fi fi
if ! diff $(ALL_MLI_FILES) $(ALL_MLI_FILES_COPIED) 1>&2; then \
$(MAKE) clean; \
exit 1; \
fi
.PHONY: clean .PHONY: clean
clean: clean:
$(REMOVE) .depend *.ml *.mli dune $(ALL_ML_FILES) $(ALL_ML_FILES_COPIED) $(REMOVE) .depend *.ml *.mli dune $(ALL_ML_FILES) $(ALL_MLI_FILES) $(ALL_ML_FILES_COPIED) \
$(ALL_MLI_FILES_COPIED)

Loading…
Cancel
Save