From 4319b08e7736c3ff0f2d16aa8dc6e588123d5737 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Thu, 13 Oct 2016 11:54:01 -0700 Subject: [PATCH] [make] Add target to generate interface file Summary: This diff adds a make target to generate interface files from implementation files. These generated interface files can then be used as a starting point for documenting and restricting the exposed module interface. For example, to generate an interface for JavaTaintAnalysis.ml, execute: ``` make -C infer/src M=quandary/JavaTaintAnalysis mli ``` Note that this relies on `ocamlc -i`, which for reason currently produces syntactically ill-formed files. Reviewed By: sblackshear, jvillard Differential Revision: D3998175 fbshipit-source-id: f653737 --- Makefile | 2 +- infer/src/Makefile | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 5e068c40b..9a797de65 100644 --- a/Makefile +++ b/Makefile @@ -190,7 +190,7 @@ inferTraceBugs_test: infer check_missing_mli: @bash -c '\ - for x in `find infer/src -name "*.ml"`; do \ + for x in `find infer/src -name "*.ml" -or -name "*.re"`; do \ test -f "$$x"i || echo Missing "$$x"i; done' inferScriptMode_test: toplevel diff --git a/infer/src/Makefile b/infer/src/Makefile index 3ba0b3528..208180b70 100644 --- a/infer/src/Makefile +++ b/infer/src/Makefile @@ -215,6 +215,21 @@ test_build: init $(STACKTREE_ATDGEN_STUBS) $(INFERPRINT_ATDGEN_STUBS) $(CLANG_AT -cflags -warn-error,$(OCAML_FATAL_WARNINGS) \ $(INFER_ALL_TARGETS:.native=.byte) +# to generate interface file.mli from implementation file.ml execute: +# make M=file mli +mli: + ocamlfind ocamlc -package atdgen,extlib,oUnit,str,unix,yojson,zip $(addprefix -I ../_build/infer/,$(DEPENDENCIES)) -i $(M).ml > $(M).mli + +rei: + ocamlfind ocamlc -package atdgen,extlib,oUnit,str,unix,yojson,zip $(addprefix -I ../_build/infer/,$(DEPENDENCIES)) -i -pp refmt -impl $(M).re > $(M).rei + +# convert to reason +%.re : %.ml + refmt -assume-explicit-arity -heuristics-file unary.txt -parse ml -print re $< > $*.re + +%.rei : %.mli + refmt -assume-explicit-arity -heuristics-file unary.txt -parse ml -print re $< > $*.rei + roots:=Infer InferAnalyze InferClang CMain JMain InferPrint BuckCompilationDatabase clusters:=base clang java IR @@ -346,10 +361,3 @@ endif $(REMOVE) $(INFER_CLANG_FCP_MIRRORED_FILES) $(REMOVE) mod_dep.dot $(REMOVE) mod_dep.pdf - -# convert to reason -%.re : %.ml - refmt -assume-explicit-arity -heuristics-file unary.txt -parse ml -print re $< > $*.re - -%.rei : %.mli - refmt -assume-explicit-arity -heuristics-file unary.txt -parse ml -print re $< > $*.rei