finish dune-ification with tests and main binaries

Summary:
- move unit/clang/ to clang/unit/ and make it a dune library
- move unit/nullsafe/ to nullsafe/unit/ and make it a dune library
- make unit/ a dune library
- inline most of dune.common.in into dune.in and make more explicit
  rules for each binary as they don't depend on the same libraries
- move inferunit from unit/ to ./ like the other toplevel binaries

Reviewed By: skcho

Differential Revision: D21440822

fbshipit-source-id: 075c693e0
master
Jules Villard 5 years ago committed by Facebook GitHub Bot
parent 041ecc5b43
commit a515d1f4b0

3
.gitignore vendored

@ -167,7 +167,9 @@ infer/src/.project
/infer/src/clang/dune
/infer/src/integration/dune
/infer/src/java/dune
/infer/src/nullsafe/unit/dune
/infer/src/opensource/dune
/infer/src/unit/dune
.merlin
# generated when looking for dead code
@ -176,7 +178,6 @@ infer/src/.project
/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/*.ml
/infer/src/deadcode/*.mli
_opam

@ -76,7 +76,7 @@ GENERATED_FROM_AUTOCONF = dune.common ../dune-workspace base/Version.ml
.PHONY: dune-workspace
dune-workspace: ../dune-workspace
GENERATED_DUNES += dune al/dune clang/dune integration/dune java/dune opensource/dune
GENERATED_DUNES += dune al/dune clang/dune integration/dune java/dune opensource/dune unit/dune
SRC_BUILD_COMMON = $(GENERATED_FROM_AUTOCONF) $(GENERATED_DUNES) $(OCAML_SOURCES)
ifeq ($(BUILD_C_ANALYZERS),yes)
@ -244,10 +244,10 @@ $(GENERATED_DUNES): dune.common
dune: dune.in
al/dune: al/dune.in
clang/dune: clang/dune.in
deadcode/dune: deadcode/dune.in
integration/dune: integration/dune.in
java/dune: java/dune.in
opensource/dune: opensource/dune.in
unit/dune: unit/dune.in
.PHONY: clean
clean:

@ -18,6 +18,10 @@ module ClangQuotes = struct
let mk_arg_file _ _ _ = die ()
end
module ClangTests = struct
let tests = [OUnitTest.TestList []]
end
module ClangWrapper = struct
let exe ~prog:_ ~args:_ = ()
end

@ -18,6 +18,10 @@ module ClangQuotes : sig
val mk_arg_file : string -> style -> string list -> string
end
module ClangTests : sig
val tests : OUnit2.test list
end
module ClangWrapper : sig
val exe : prog:string -> args:string list -> unit
end

@ -17,7 +17,7 @@ let clang =
(:standard
-open Core -open IStdlib -open IStd -open OpenSource -open ATDGenerated
-open IBase -open IR -open Absint -open Checkers -open TestDeterminators))
(libraries core IStdlib ATDGenerated IBase IR Absint Checkers TestDeterminators)
(libraries oUnit core IStdlib ATDGenerated IBase IR Absint Checkers TestDeterminators)
(preprocess (pps ppx_compare))
)|}
(if clang then ":standard \\ ClangFrontendStubs" else "ClangFrontendStubs")

@ -0,0 +1,14 @@
; Copyright (c) Facebook, Inc. and its affiliates.
;
; This source code is licensed under the MIT license found in the
; LICENSE file in the root directory of this source tree.
(library
(name ClangUnitTests)
(public_name infer.ClangUnitTests)
(flags
(:standard -open Core -open IR -open IStdlib -open IStd -open ATDGenerated
-open IBase -open ClangFrontend -open ASTLanguage))
(libraries oUnit core IStdlib ATDGenerated IBase IR ClangFrontend ASTLanguage)
(preprocess (pps ppx_compare))
)

@ -50,8 +50,8 @@ endif
# Note that we run find under _build directory. Since we copy some
# sources from subfolders to src/ folder to avoid duplicates we use
# $(DEPTH_ONE) and iteration over main and library folders.
LIBRARY_FOLDERS = . ./IR ./absint ./al ./atd ./backend ./base ./biabduction ./bufferoverrun ./c_stubs ./checkers ./clang ./concurrency ./cost ./integration ./istd ./java ./labs ./nullsafe ./pulse ./quandary ./scripts ./test_determinator ./topl
INCLUDE_FOLDERS = -I IR -I absint -I al -I atd -I backend -I base -I biabduction -I bufferoverrun -I c_stubs -I checkers -I clang -I concurrency -I cost -I integration -I istd -I java -I labs -I nullsafe -I pulse -I quandary -I scripts -I test_determinator -I topl
LIBRARY_FOLDERS = . ./IR ./absint ./al ./atd ./backend ./base ./biabduction ./bufferoverrun ./c_stubs ./checkers ./clang ./clang/unit ./concurrency ./cost ./integration ./istd ./java ./labs ./nullsafe ./nullsafe/unit ./pulse ./quandary ./scripts ./test_determinator ./topl ./unit
INCLUDE_FOLDERS = -I IR -I absint -I al -I atd -I backend -I base -I biabduction -I bufferoverrun -I c_stubs -I checkers -I clang -I clang/unit -I concurrency -I cost -I integration -I istd -I java -I labs -I nullsafe -I nullsafe/unit -I pulse -I quandary -I scripts -I test_determinator -I topl -I unit
ml_src_files:=$(shell \
cd $(INFER_BUILD_DIR); \
@ -170,7 +170,7 @@ detect_dead_code:
# dune file for this directory
touch $(ALL_INFER_IN_ONE_FILE_ML) $(ALL_INFER_IN_ONE_FILE_ML:.ml=.mli)
# needed to get dune generated, and the generated code for the lexers and parsers in ../_build
$(MAKE) GENERATED_DUNES=deadcode/dune -C .. test
$(MAKE) -C .. test
$(MAKE) depend
# Need to be sequential to avoid getting a garbled file. Need to re-include .depend as it may
# have changed. For both of these reasons, run another `make`.
@ -192,6 +192,7 @@ detect_dead_code:
detect_dead_src_file:
function is_in_blacklist { \
if [ $$1 = infertop.ml ] \
|| [ $$1 = infertop.mli ] \
|| [ $$1 = deadcode/all_infer_in_one_file.ml ] \
|| [ $$1 = deadcode/all_infer_in_one_file.mli ] \
|| [[ $$1 =~ .*FrontendStubs.mli?$$ ]] \
@ -236,6 +237,6 @@ detect_dead_src_file:
.PHONY: clean
clean:
$(REMOVE) .depend *.ml *.mli dune $(ALL_ML_FILES) $(ALL_MLI_FILES) $(ALL_ML_FILES_COPIED) \
$(REMOVE) .depend *.ml *.mli $(ALL_ML_FILES) $(ALL_MLI_FILES) $(ALL_ML_FILES_COPIED) \
$(ALL_MLI_FILES_COPIED)

@ -0,0 +1,15 @@
; Copyright (c) Facebook, Inc. and its affiliates.
;
; This source code is licensed under the MIT license found in the
; LICENSE file in the root directory of this source tree.
(executable
(name all_infer_in_one_file)
(modes byte)
(flags (:standard -w +60))
(libraries javalib ANSITerminal async atdgen base base64 cmdliner core
mtime.clock.os ocamlgraph oUnit parmap re sawja sledge sqlite3 str unix xmlm
yojson zarith zip CStubs)
(modules All_infer_in_one_file)
(preprocess (pps ppx_compare ppx_enumerate ppx_fields_conv ppx_hash ppx_sexp_conv ppx_variants_conv -no-check))
)

@ -1,23 +0,0 @@
(* -*- tuareg -*- *)
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
(* NOTE: prepend dune.common to this file! *)
;;
Format.sprintf
{|
(executable
(name all_infer_in_one_file)
(modes byte)
(flags (:standard -w +60))
(libraries %s sledge)
(modules All_infer_in_one_file)
(preprocess (pps ppx_compare ppx_enumerate ppx_fields_conv ppx_hash ppx_sexp_conv ppx_variants_conv -no-check))
)
|}
(String.concat " " ("Absint" :: "IR" :: "CStubs" :: common_libraries))
|> Jbuild_plugin.V1.send

@ -18,54 +18,3 @@ let java = is_yes "@BUILD_JAVA_ANALYZERS@"
let facebook = is_yes "@IS_FACEBOOK_TREE@"
let extra_cflags = if is_empty "@EXTRA_CFLAGS@" then [] else ["@EXTRA_CFLAGS@"]
(*
* A known issue: At the moment of writing warning 14 (illegal backslash
* escape in string) does not manifest as an error, presumably due to
* peculiarities in communication between preprocessor and compiler.
* Still leave it for visibility and in hope that the issue will be
* fixed one day.
*)
let fatal_warnings =
"+3+5+6+8+10+11+12+14+18+19+20+21+23+26+29+27+28+32+33+34+35+37+38+39+50+52+57+60"
let warnings = fatal_warnings ^ "-4-9-40-41-42-45-48"
let ocamlc_flags =
[ "-g"
; "-short-paths"
; "-safe-string"
; "-principal"
; "-strict-formats"
; "-strict-sequence"
; "-bin-annot" ]
let lenient_flags = ocamlc_flags @ ["-w"; warnings] |> String.concat " "
let strict_flags =
ocamlc_flags @ ["-w"; warnings; "-warn-error"; fatal_warnings] |> String.concat " "
let common_libraries =
(if java then ["javalib"; "sawja"] else [])
@ [ "ANSITerminal"
; "async"
; "atdgen"
; "base"
; "base64"
; "cmdliner"
; "core"
; "mtime.clock.os"
; "ocamlgraph"
; "oUnit"
; "parmap"
; "re"
; "sqlite3"
; "str"
; "unix"
; "xmlm"
; "yojson"
; "zarith"
; "zip" ]

@ -7,13 +7,34 @@
*)
(* NOTE: prepend dune.common to this file! *)
let ( ^/ ) = Filename.concat
(*
* A known issue: At the moment of writing warning 14 (illegal backslash
* escape in string) does not manifest as an error, presumably due to
* peculiarities in communication between preprocessor and compiler.
* Still leave it for visibility and in hope that the issue will be
* fixed one day.
*)
let fatal_warnings =
"+3+5+6+8+10+11+12+14+18+19+20+21+23+26+29+27+28+32+33+34+35+37+38+39+50+52+57+60"
let warnings = fatal_warnings ^ "-4-9-40-41-42-45-48"
let ocamlc_flags =
[ "-g"
; "-short-paths"
; "-safe-string"
; "-principal"
; "-strict-formats"
; "-strict-sequence"
; "-bin-annot" ]
let source_dirs =
(if clang then ["unit" ^/ "clang"] else ["unit" ^/ "clang_stubs"]) @ ["unit"; "unit" ^/ "nullsafe"]
let lenient_flags = ocamlc_flags @ ["-w"; warnings] |> String.concat " "
let strict_flags =
ocamlc_flags @ ["-w"; warnings; "-warn-error"; fatal_warnings] |> String.concat " "
let infer_binaries = ["infer"; "inferunit"] @ if facebook then ["InferCreateTraceViewLinks"] else []
let env_stanza =
Format.sprintf
@ -31,115 +52,40 @@ let env_stanza =
lenient_flags lenient_flags strict_flags
let infer_cflags =
( [ "-open"
; "Core"
; "-open"
; "Biabduction"
; "-open"
; "BO"
; "-open"
; "Nullsafe"
; "-open"
; "Pulselib"
; "-open"
; "Checkers"
; "-open"
; "Costlib"
; "-open"
; "Quandary"
; "-open"
; "TOPLlib"
; "-open"
; "Concurrency"
; "-open"
; "Labs"
; "-open"
; "Absint"
; "-open"
; "OpenSource"
; "-open"
; "IStdlib"
; "-open"
; "IStd"
; "-open"
; "ATDGenerated"
; "-open"
; "IR"
; "-open"
; "IBase"
; "-open"
; "CStubs"
; "-open"
; "Backend"
; "-open"
; "JavaFrontend"
; "-open"
; "ClangFrontend"
; "-open"
; "ASTLanguage"
; "-open"
; "TestDeterminators"
; "-open"
; "Integration" ]
@ (if java then [] else ["-open"; "JavaFrontendStubs"])
@ if clang then [] else ["-open"; "ClangFrontendStubs"] )
|> String.concat " "
let main_lib_stanza =
Format.sprintf
{|
(library
(name InferModules)
(public_name infer)
(flags (:standard %s))
(libraries %s)
(modules :standard \ %s infertop)
(preprocess (pps ppx_compare ppx_fields_conv ppx_hash ppx_sexp_conv ppx_variants_conv -no-check))
)
|}
infer_cflags
(String.concat " "
(* we need JavaFrontend first to avoid clashes around base64 vs extlib *)
( ("JavaFrontend" :: common_libraries)
@ [ "IR"
; "CStubs"
; "Absint"
; "Biabduction"
; "Nullsafe"
; "BO"
; "Pulselib"
; "Checkers"
; "Costlib"
; "Quandary"
; "TOPLlib"
; "Concurrency"
; "Labs"
; "Backend"
; "ClangFrontend"
; "ASTLanguage"
; "TestDeterminators"
; "Integration" ] ))
(String.concat " " infer_binaries)
(** Put this *first* in (libraries) specifications to prevent a clash between extlib's and base64's
versions of Base64. Only Javalib depends on extlib so do it conditionally to avoid introducing a
new dependency in the clang-only build. *)
let extlib_if_java = if java then "extlib" else ""
let infer_exe_stanza =
Format.sprintf
{|
(executables
(names %s)
Printf.sprintf
{|(executable
(name infer)
(modes byte_complete exe)
(flags (:standard -open InferModules %s))
(libraries InferModules)
(modules %s)
(preprocess (pps ppx_compare ppx_fields_conv ppx_hash ppx_sexp_conv ppx_variants_conv -no-check))
(modules Infer)
(flags (:standard -open Core -open IStdlib -open IStd -open IBase -open IR -open Backend -open Integration -open Biabduction -open TestDeterminators -open ClangFrontend -open ASTLanguage %s))
(libraries %s core IStdlib IBase IR Backend Integration Biabduction TestDeterminators ClangFrontend ASTLanguage)
(preprocess (pps ppx_compare))
(promote (until-clean) (into ../bin))
)
|}
(String.concat " " infer_binaries)
infer_cflags
(String.concat " " infer_binaries)
)|}
(if clang then "" else "-open ClangFrontendStubs")
extlib_if_java
let inferunit_stanza =
Printf.sprintf
{|(executable
(name inferunit)
(modes byte_complete exe)
(modules Inferunit)
(flags (:standard -open Core -open IStdlib -open IStd -open IBase -open Backend -open Integration -open UnitTests -open NullsafeUnitTests -open ClangFrontend %s))
(libraries %s oUnit core IStdlib IBase Backend Integration UnitTests NullsafeUnitTests %s)
(preprocess (pps ppx_compare))
(promote (until-clean) (into ../bin))
)|}
(if clang then "-open ClangUnitTests" else "-open ClangFrontendStubs")
extlib_if_java
(if clang then "ClangUnitTests" else "")
let infertop_stanza =
@ -148,32 +94,34 @@ let infertop_stanza =
(executable
(name infertop)
(modes byte_complete)
(flags (:standard %s))
(libraries utop InferModules)
(link_flags (-linkall -warn-error -31))
(modules Infertop)
(preprocess (pps ppx_compare ppx_fields_conv ppx_hash ppx_sexp_conv ppx_variants_conv -no-check))
(flags (:standard -open Core -open IStdlib -open IStd))
(libraries %s utop Absint ASTLanguage ATDGenerated Backend IBase Biabduction BO Checkers Concurrency Costlib CStubs IR IStdlib Labs Nullsafe Pulselib Quandary Integration TestDeterminators TOPLlib UnitTests)
(link_flags (-linkall -warn-error -31))
(preprocess (pps ppx_compare))
(promote (until-clean) (into ../bin))
)
|}
infer_cflags
extlib_if_java
let flatten_sources_stanzas =
List.map
(fun source_dir ->
[ Printf.sprintf "(copy_files# %s/*.ml{,i,l})" source_dir
; (* menhir doesn't support '# 1 "<source file>"' directives at the start of the file inserted by
copy# actions *)
Printf.sprintf "(copy_files %s/*.mly)" source_dir ] )
source_dirs
|> List.concat
let inferCreateTraceViewLinks_stanza =
{|(executable
(name InferCreateTraceViewLinks)
(modes byte_complete exe)
(modules InferCreateTraceViewLinks)
(flags (:standard -open Core -open IStdlib -open IStd -open ATDGenerated -open IBase))
(libraries core async IStdlib ATDGenerated IBase)
(preprocess (pps ppx_compare))
(promote (until-clean) (into ../bin))
)|}
(** The build stanzas to be passed to dune *)
let stanzas =
env_stanza :: main_lib_stanza :: infer_exe_stanza :: infertop_stanza :: flatten_sources_stanzas
[env_stanza; infer_exe_stanza; inferunit_stanza; infertop_stanza]
@ if facebook then [inferCreateTraceViewLinks_stanza] else []
;;
String.concat "\n" stanzas |> Jbuild_plugin.V1.send
Jbuild_plugin.V1.send (String.concat "\n" stanzas)

@ -60,7 +60,6 @@ let setup () =
| Explore ->
ResultsDir.assert_results_dir "please run an infer analysis first" ) ;
db_start () ;
NullsafeInit.init () ;
if CLOpt.is_originator then ResultsDir.RunState.add_run_to_sequence () ;
()

@ -7,4 +7,4 @@
open! IStd
let tests = [OUnitTest.TestList []]
(** module for running an OCaml toplevel that embeds infer modules *)

@ -9,6 +9,9 @@ open! IStd
module L = Logging
module F = Format
(* make sure that this is initialized *)
let () = NullsafeInit.init ()
let callback1 ({IntraproceduralAnalysis.proc_desc= curr_pdesc; _} as analysis_data)
find_canonical_duplicate calls_this checks idenv annotated_signature linereader proc_loc :
bool * TypeState.t option =

@ -0,0 +1,14 @@
; Copyright (c) Facebook, Inc. and its affiliates.
;
; This source code is licensed under the MIT license found in the
; LICENSE file in the root directory of this source tree.
(library
(name NullsafeUnitTests)
(public_name infer.NullsafeUnitTests)
(flags
(:standard -open Core -open IR -open IStdlib -open IStd -open ATDGenerated
-open IBase -open Nullsafe))
(libraries oUnit core IStdlib ATDGenerated IBase IR Nullsafe)
(preprocess (pps ppx_compare))
)

@ -49,7 +49,7 @@ module PathCountTransferFunctions (CFG : ProcCfg.S) = struct
module CFG = CFG
module Domain = PathCountDomain
type analysis_data = unit ProcData.t
type analysis_data = unit
(* just propagate the current path count *)
let exec_instr astate _ _ _ = astate
@ -102,9 +102,7 @@ let tests =
, (* we expect the finally block to be visited *)
[invariant "1"] )
; invariant "1" ] ) ]
|> NormalTestInterpreter.create_tests
(fun summary -> {ProcData.summary; tenv= Tenv.create (); extras= ()})
~initial
|> NormalTestInterpreter.create_tests (fun _summary -> ()) ~initial
in
let exceptional_test_list =
[ ( "try1"
@ -129,8 +127,6 @@ let tests =
, (* could arrive here via (1, 2, 3), (1, 4), or (2, 4) *)
[invariant "3"] )
; invariant "3" ] ) ]
|> ExceptionalTestInterpreter.create_tests
(fun summary -> {ProcData.summary; tenv= Tenv.create (); extras= ()})
~initial
|> ExceptionalTestInterpreter.create_tests (fun _summary -> ()) ~initial
in
"analyzer_tests_suite" >::: normal_test_list @ exceptional_test_list

@ -0,0 +1,27 @@
(* -*- tuareg -*- *)
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
(* NOTE: prepend dune.common to this file! *)
let library =
Printf.sprintf
{|(library
(name UnitTests)
(public_name infer.UnitTests)
(flags
(:standard -open Core -open IR -open IStdlib -open IStd -open ATDGenerated
-open IBase -open Absint -open Backend -open CStubs -open ClangFrontend -open ASTLanguage %s
-open Checkers -open Quandary -open TestDeterminators -open Integration))
(libraries oUnit core IStdlib ATDGenerated IBase IR Absint Backend CStubs ClangFrontend
ASTLanguage Checkers Quandary TestDeterminators Integration)
(preprocess (pps ppx_compare))
)|}
(if clang then "-open ClangFrontend -open ASTLanguage" else "-open ClangFrontendStubs")
;;
Jbuild_plugin.V1.send library
Loading…
Cancel
Save