Skip to content

Commit

Permalink
[build] Replace custom make cmds w/ dune promotion and byte_complete
Browse files Browse the repository at this point in the history
Summary:
Main changes are:

1. Dune can promote targets into the source tree as a part of build. This
allows us to **remove custom promotion/installation logic in src/Makefile**.

2. Dune promotion only works for path within workspace. This required
**moving dune-workspace one folder up**: from infer/infer/src to infer/infer.
But this is not bad, since it makes it possible to migrate tests under dune at some point.

3. `checkCopyright` now also promoted into `infer/infer/bin` instead of
`infer/scripts` partly for consistency and partly because of the
dune-workspace location.

4. `byte` mode was replaced with `byte_complete`. The latter takes
similar amount of time to build compared to `byte`, but produces
standalone binaries that don't require InferCStubs to be
installed. This allowed to remove `dune_exec_shim` and custom logic
around `dune build InferCStubs.install` when dealing with byte
targets.

All in all, `infer/src/Makefile` is not about 2/3 its previous size
with less custom logic in Makefiles/scripts and more encoded in dune
build files.

Reviewed By: jvillard

Differential Revision: D20303902

fbshipit-source-id: 9e4c65bd0
  • Loading branch information
artempyanykh authored and facebook-github-bot committed Mar 11, 2020
1 parent 9fc048b commit 786a725
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 199 deletions.
19 changes: 2 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,6 @@ buck-out/
.buckd/

#other
/infer/bin/infer
/infer/bin/infer.bc
/infer/bin/infer.exe
/infer/bin/infer-analyze
/infer/bin/infer-capture
/infer/bin/infer-compile
/infer/bin/infer-explore
/infer/bin/infer-report
/infer/bin/infer-reportdiff
/infer/bin/infer-run
/infer/bin/InferCreateTraceViewLinks
/infer/bin/InferUnit
/infer/bin/infertop.bc
/infer/bin/llvm_sil
/infer/man/man1/*.1
/infer/man/man1/*.1.gz

Expand All @@ -142,7 +128,6 @@ buck-out/
/infer/lib/specs/cpp_models
/infer/lib/specs/objc_models
/infer/lib/specs/clean_models
/scripts/checkCopyright
/infer/etc/clang_ast.dict
/infer/src/toplevel.mlpack

Expand Down Expand Up @@ -174,10 +159,10 @@ infer/src/.project
/infer/annotations/target

# dune
/infer/src/_build
/infer/_build
/infer/dune-workspace
/infer/src/dune.common
/infer/src/dune
/infer/src/dune-workspace
.merlin

# generated when looking for dead code
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ make devsetup
if you're unsure of a module name.

```console
$ ledit ocamldebug infer/bin/infer.bc
$ ledit ocamldebug infer/bin/infer.bc.exe
(ocd) break @ InferModules__InferAnalyze 100
Breakpoint 1 at 9409684: file backend/InferAnalyze.ml, line 99, characters 18-78
```
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ clang_plugin_test_replace: clang_setup
ocaml_unit_test: test_build
$(QUIET)$(REMOVE_DIR) infer-out-unit-tests
$(QUIET)$(call silent_on_success,Running OCaml unit tests,\
INFER_ARGS=--results-dir^infer-out-unit-tests \
$(SCRIPT_DIR)/dune_exec_shim.sh $(BUILD_DIR)/default/inferunit.bc)
INFER_ARGS=--results-dir^infer-out-unit-tests $(INFERUNIT_BIN))

define silence_make
$(1) 2> >(grep -v 'warning: \(ignoring old\|overriding\) \(commands\|recipe\) for target')
Expand Down Expand Up @@ -593,9 +592,6 @@ ifeq (,$(findstring s,$(MAKEFLAGS)))
$(QUIET)echo "$(TERM_INFO)ALL TESTS PASSED$(TERM_RESET)"
endif

.PHONY: quick-test
quick-test: test_build ocaml_unit_test

.PHONY: test-replace
test-replace: $(BUILD_SYSTEMS_TESTS:%=build_%_replace) $(DIRECT_TESTS:%=direct_%_replace) \
clang_plugin_test_replace
Expand Down
7 changes: 4 additions & 3 deletions Makefile.config
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ JAVA_BUILTINS_DIR = $(MODELS_DIR)/java/builtins
JAVA_MODELS_DIR = $(MODELS_DIR)/java/src
SRC_DIR = $(INFER_DIR)/src

BUILD_DIR = $(SRC_DIR)/_build
BUILD_DIR = $(INFER_DIR)/_build

JAVA_LIB_DIR = $(LIB_DIR)/java
SPECS_LIB_DIR = $(LIB_DIR)/specs
Expand All @@ -62,8 +62,9 @@ INFER_COMMANDS = \
infer-reportdiff \
infer-run \

INFERTOP_BIN = $(BIN_DIR)/infertop.bc
INFERUNIT_BIN = $(BIN_DIR)/InferUnit
INFERTOP_BIN = $(BIN_DIR)/infertop.bc.exe
INFERUNIT_BIN = $(BIN_DIR)/inferunit.bc.exe
CHECKCOPYRIGHT_BIN = $(BIN_DIR)/checkCopyright

INFER_CREATE_TRACEVIEW_LINKS = InferCreateTraceViewLinks
INFER_CREATE_TRACEVIEW_LINKS_BIN = $(BIN_DIR)/$(INFER_CREATE_TRACEVIEW_LINKS)
Expand Down
6 changes: 6 additions & 0 deletions infer/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# .gitignore to keep the directory for dune to promote binaries into
###################################

# Filter everything except the .gitignore
*
!.gitignore
11 changes: 0 additions & 11 deletions infer/bin/infer.byte

This file was deleted.

File renamed without changes.
157 changes: 52 additions & 105 deletions infer/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ include $(ROOT_DIR)/Makefile.config

#### Global declarations ####

# override this for faster builds (but slower infer)
# Override this for faster builds (but slower infer)
BUILD_MODE ?= opt
BUILD_ROOT = _build
# paths to BUILD_DIR are relative because that's how dune likes it
INFER_BUILD_DIR = $(BUILD_ROOT)/default

DUNE_BUILD = dune build --profile=$(BUILD_MODE) --build-dir=$(BUILD_ROOT)
DUNE_BUILD = dune build --profile=$(BUILD_MODE)

ETC_DIR = $(INFER_DIR)/etc

#### Backend declarations ####

INFER_MAIN = infer

#### Checkers declarations ####
INFERTOP_MAIN = infertop
INFERUNIT_MAIN = inferunit
INFER_CREATE_TRACEVIEW_LINKS_MODULE = InferCreateTraceViewLinks
INFER_CREATE_TRACEVIEW_LINKS_MAIN = $(INFER_CREATE_TRACEVIEW_LINKS_MODULE)
CHECKCOPYRIGHT_MAIN = checkCopyright

INFER_ATDGEN_STUB_BASES = atd/jsonbug atd/runstate atd/java_method_decl atd/perf_profiler atd/java_profiler_samples atd/clang_profiler_samples
INFER_ATDGEN_TYPES = j t
Expand All @@ -31,15 +29,8 @@ INFER_ATDGEN_SUFFIXES = $(foreach atd_t,$(INFER_ATDGEN_TYPES),_$(atd_t).ml _$(at
INFER_ATDGEN_STUBS = $(foreach base,$(INFER_ATDGEN_STUB_BASES),\
$(addprefix $(base),$(INFER_ATDGEN_SUFFIXES)))

#### InferCreateTraceViewLinks declarations ####

FACEBOOK_DIR = facebook
INFER_CREATE_TRACEVIEW_LINKS_MODULE = InferCreateTraceViewLinks
INFER_CREATE_TRACEVIEW_LINKS_MAIN = $(INFER_CREATE_TRACEVIEW_LINKS_MODULE)

### InferUnit declarations ###

INFERUNIT_MAIN = inferunit

#### Clang declarations ####

Expand All @@ -65,21 +56,14 @@ CLANG_PLUGIN_MIRRORED_FILES = $(addprefix $(CLANG_PLUGIN_MIRROR)/, $(notdir $(FC

CLANG_BINIOU_DICT = $(ETC_DIR)/clang_ast.dict

#### scripts declarations ####

CHECKCOPYRIGHT_BIN = $(SCRIPT_DIR)/checkCopyright
CHECKCOPYRIGHT_MAIN = checkCopyright

#### End of declarations ####

ifeq ($(ENABLE_OCAMLOPT_CUSTOM_CC),yes)
EXTRA_CFLAGS += -cc,$(CC)
endif

# list of ocamlbuild targets common to all build targets -- native version
INFER_CONFIG_TARGETS = $(INFER_BUILD_DIR)/$(INFER_MAIN).exe
INFER_CONFIG_TARGETS = $(INFER_MAIN).exe
ifeq ($(IS_FACEBOOK_TREE),yes)
INFER_CONFIG_TARGETS += $(INFER_BUILD_DIR)/$(INFER_CREATE_TRACEVIEW_LINKS_MAIN).exe
INFER_CONFIG_TARGETS += $(INFER_CREATE_TRACEVIEW_LINKS_MAIN).exe
endif

OCAML_GENERATED_SOURCES = \
Expand All @@ -96,7 +80,10 @@ OCAML_SOURCES = \
.PHONY: all
all: infer

GENERATED_FROM_AUTOCONF = dune.common dune-workspace base/Version.ml
GENERATED_FROM_AUTOCONF = dune.common ../dune-workspace base/Version.ml

.PHONY: dune-workspace
dune-workspace: ../dune-workspace

GENERATED_DUNES += dune

Expand All @@ -108,25 +95,12 @@ endif
.PHONY: src_build_common
src_build_common: $(SRC_BUILD_COMMON)

# Single out infer.exe as the source of truth for make, knowing that in fact several
# targets are produced by the build.
# The target is marked as .PHONY because if you build with one profile `make
# BUILD_MODE=dev` and then try with another profile `make BUILD_MODE=opt`, make won't
# trigger a rebuild since it has only partial view on the dependencies.
.PHONY: $(INFER_BUILD_DIR)/$(INFER_MAIN).exe
$(INFER_BUILD_DIR)/$(INFER_MAIN).exe: $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
$(QUIET)$(DUNE_BUILD) $(INFER_CONFIG_TARGETS)
# let make know that the target is up-to-date even if ocamlbuild cached it
$(QUIET)touch $@

.PHONY: test
test: BUILD_MODE = test
test: $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
# needed for dune to "install" the relevant dynamic libraries for the C stubs
$(QUIET)cd c_stubs; $(DUNE_BUILD) InferCStubs.install
$(QUIET)$(DUNE_BUILD) \
$(patsubst $(INFER_BUILD_DIR)/%.exe,%.bc, $(INFER_CONFIG_TARGETS)) \
scripts/checkCopyright.bc $(INFERUNIT_MAIN).bc infertop.bc
$(patsubst %.exe, %.bc.exe, $(INFER_CONFIG_TARGETS)) \
scripts/$(CHECKCOPYRIGHT_MAIN).bc.exe $(INFERUNIT_MAIN).bc.exe $(INFERTOP_MAIN).bc.exe

.PHONY: doc
doc: $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
Expand All @@ -136,57 +110,54 @@ doc: $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
check: src_build_common
$(DUNE_BUILD) @check

#### Aliases for building binaries ####

INFER_BIN_ALIASES = $(foreach alias,$(INFER_COMMANDS),$(BIN_DIR)/$(alias))
# Single out infer[.bc].exe as the source of truth for make, knowing that in fact several
# targets are produced by the build.
# The targets below are marked as .PHONY because if you build with one profile `make
# BUILD_MODE=dev` and then try with another profile `make BUILD_MODE=opt`, make won't
# trigger a rebuild since it has only partial view on the dependencies.

$(INFER_BIN_ALIASES): Makefile $(BIN_DIR)/$(INFER_MAIN)
$(REMOVE) $@
$(QUIET)cd $(@D) && $(LN_S) -f infer $(@F)
$(QUIET)touch $@
.PHONY: $(INFER_BIN).exe
$(INFER_BIN).exe: $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
$(QUIET)$(DUNE_BUILD) $(INFER_CONFIG_TARGETS)

$(INFER_BIN).exe: $(INFER_BUILD_DIR)/$(INFER_MAIN).exe
$(QUIET)$(MKDIR_P) $(BIN_DIR)
ifeq ($(WINDOWS_BUILD),yes)
# http://cygwin.1069669.n5.nabble.com/cp-utility-bug-when-dest-name-exe-file-exist-tp57955p58001.html
$(REMOVE) $(INFER_BIN) $(INFER_BIN).exe
endif
$(INSTALL_PROGRAM) -C $(INFER_BUILD_DIR)/$(INFER_MAIN).exe $(INFER_BIN).exe
ifeq ($(IS_FACEBOOK_TREE),yes)
$(INSTALL_PROGRAM) -C $(INFER_BUILD_DIR)/$(INFER_CREATE_TRACEVIEW_LINKS_MAIN).exe \
$(INFER_CREATE_TRACEVIEW_LINKS_BIN)
endif
.PHONY: $(INFER_BIN).bc.exe
$(INFER_BIN).bc.exe: $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
$(QUIET)$(DUNE_BUILD) $(patsubst %.exe, %.bc.exe, $(INFER_CONFIG_TARGETS))

.PHONY: $(INFERTOP_BIN) toplevel
$(INFERTOP_BIN): $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
$(DUNE_BUILD) $(INFERTOP_MAIN).bc.exe
toplevel: $(INFERTOP_BIN)

.PHONY: $(CHECKCOPYRIGHT_BIN) checkCopyright
$(CHECKCOPYRIGHT_BIN): $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
$(DUNE_BUILD) scripts/$(CHECKCOPYRIGHT_MAIN)
checkCopyright: $(CHECKCOPYRIGHT_BIN)

.PHONY: infer
infer: $(INFER_BIN).exe
$(INSTALL_PROGRAM) -C $(INFER_BIN).exe $(INFER_BIN)
$(MAKE) $(INFER_BIN_ALIASES)

.PHONY: $(INFER_BUILD_DIR)/$(INFER_MAIN).bc
$(INFER_BUILD_DIR)/$(INFER_MAIN).bc: $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
$(DUNE_BUILD) $(INFER_CONFIG_TARGETS:.exe=.bc)
$(QUIET)touch $@

.PHONY: $(INFER_BIN).bc
$(INFER_BIN).bc: $(INFER_BUILD_DIR)/$(INFER_MAIN).bc
$(QUIET)$(MKDIR_P) $(BIN_DIR)
ifeq ($(WINDOWS_BUILD),yes)
# http://cygwin.1069669.n5.nabble.com/cp-utility-bug-when-dest-name-exe-file-exist-tp57955p58001.html
$(REMOVE) $(INFER_BIN) $(INFER_BIN).exe
endif
$(INSTALL_PROGRAM) -C $(INFER_BUILD_DIR)/$(INFER_MAIN).bc $(INFER_BIN).bc
ifeq ($(IS_FACEBOOK_TREE),yes)
$(INSTALL_PROGRAM) -C $(INFER_BUILD_DIR)/$(INFER_CREATE_TRACEVIEW_LINKS_MAIN).bc \
$(INFER_CREATE_TRACEVIEW_LINKS_BIN)
$(INSTALL_PROGRAM) -C $(INFER_CREATE_TRACEVIEW_LINKS_BIN).exe $(INFER_CREATE_TRACEVIEW_LINKS_BIN)
endif
# needed for dune to "install" the relevant dynamic libraries for the C stubs
cd c_stubs; $(DUNE_BUILD) InferCStubs.install
$(MAKE) $(INFER_BIN_ALIASES)

.PHONY: byte
byte: $(INFER_BIN).bc
$(INSTALL_PROGRAM) -C $(INFER_BIN).byte $(INFER_BIN)
byte: $(INFER_BIN).bc.exe
$(INSTALL_PROGRAM) -C $(INFER_BIN).bc.exe $(INFER_BIN)
ifeq ($(IS_FACEBOOK_TREE),yes)
$(INSTALL_PROGRAM) -C $(INFER_CREATE_TRACEVIEW_LINKS_BIN).bc.exe $(INFER_CREATE_TRACEVIEW_LINKS_BIN)
endif
$(MAKE) $(INFER_BIN_ALIASES)

INFER_BIN_ALIASES = $(foreach alias,$(INFER_COMMANDS),$(BIN_DIR)/$(alias))
$(INFER_BIN_ALIASES): Makefile $(BIN_DIR)/$(INFER_MAIN)
$(REMOVE) $@
$(QUIET)cd $(@D) && $(LN_S) -f infer $(@F)
$(QUIET)touch $@

roots:=Infer
ifeq ($(IS_FACEBOOK_TREE),yes)
roots += $(INFER_CREATE_TRACEVIEW_LINKS_MODULE)
Expand All @@ -212,28 +183,6 @@ mod_dep.pdf: mod_dep.dot
dsort:
$(QUIET)ocamldep.opt -sort $(inc_flags) $(ml_src_files)

.PHONY: $(INFER_BUILD_DIR)/infertop.bc
$(INFER_BUILD_DIR)/infertop.bc: $(SRC_DIR)/infertop.ml $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
$(DUNE_BUILD) $@
# needed for dune to "install" the relevant dynamic libraries for the C stubs
cd c_stubs; $(DUNE_BUILD) InferCStubs.install
$(QUIET)touch $@

$(INFERTOP_BIN): $(INFER_BUILD_DIR)/infertop.bc
$(QUIET)$(INSTALL_PROGRAM) -C $< $@
$(QUIET)touch $@

.PHONY: toplevel
toplevel: $(INFERTOP_BIN)

.PHONY: checkCopyright
checkCopyright: $(CHECKCOPYRIGHT_BIN)

.PHONY: $(CHECKCOPYRIGHT_BIN)
$(CHECKCOPYRIGHT_BIN): $(SRC_BUILD_COMMON) $(MAKEFILE_LIST)
$(DUNE_BUILD) $(INFER_BUILD_DIR)/scripts/$(CHECKCOPYRIGHT_MAIN).exe
$(INSTALL_PROGRAM) -C $(INFER_BUILD_DIR)/scripts/$(CHECKCOPYRIGHT_MAIN).exe $(CHECKCOPYRIGHT_BIN)

define gen_atdgen_rules
# generate files using atdgen
# parameters:
Expand Down Expand Up @@ -300,7 +249,7 @@ $(GENERATED_FROM_AUTOCONF): $(MAKEFILE_LIST)
cat "$$TMPFILE" > $@; \
$(REMOVE) "$$TMPFILE"
dune.common: dune.common.in
dune-workspace: dune-workspace.in
../dune-workspace: ../dune-workspace.in
base/Version.ml: base/Version.ml.in

$(GENERATED_DUNES): dune.common
Expand All @@ -314,20 +263,18 @@ clean:
$(MAKE) -C deadcode clean
$(REMOVE) $(INFER_TARGET)
$(REMOVE) toplevel.mlpack
$(REMOVE_DIR) $(BUILD_DIR)
$(REMOVE) $(ETC_DIR)/clang_ast.dict
$(REMOVE) $(GENERATED_FROM_AUTOCONF)
$(REMOVE) $(GENERATED_DUNES)
$(REMOVE) base/Version.ml.tmp.* dune.tmp.* dune-workspace.tmp.*
# be a bit more aggressive than needed with what we remove here so that stale binaries that
# only existed in previous versions get removed as well
$(REMOVE) $(BIN_DIR)/Infer* $(BIN_DIR)/infer-* $(INFER_BIN){,.bc,.exe} $(INFER_BIN_ALIASES) \
$(INFERUNIT_BIN) $(CHECKCOPYRIGHT_BIN)
$(REMOVE) $(INFER_BIN) $(INFER_BIN_ALIASES) $(INFER_CREATE_TRACEVIEW_LINKS_BIN)
$(REMOVE) $(BIN_DIR)/llvm_sil
$(REMOVE) $(INFER_CREATE_TRACEVIEW_LINKS_BIN)
$(REMOVE) atd/*_{j,t,v}.ml{,i} atd/clang_ast_*
$(REMOVE) mod_dep.dot
$(REMOVE) mod_dep.pdf
cd .. && dune clean

.PHONY: fmt
fmt:
Expand Down
21 changes: 7 additions & 14 deletions infer/src/c_stubs/dune
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
(* -*- 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.
*)
; 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.

;;
Format.sprintf
{|
(library
(name InferCStubs)
(public_name InferCStubs)
(foreign_stubs (language c) (names fnv64_hash))
)
|}
|> Jbuild_plugin.V1.send
(foreign_stubs
(language c)
(names fnv64_hash)))
Loading

0 comments on commit 786a725

Please sign in to comment.