diff --git a/.gitignore b/.gitignore index d19f7fdba..5c4dac4f2 100644 --- a/.gitignore +++ b/.gitignore @@ -98,6 +98,7 @@ buck-out/ /infer/models/cpp/out/ /infer/models/objc/out/ /infer/lib/specs/c_models +/infer/lib/specs/clang_models /infer/lib/specs/cpp_models /infer/lib/specs/objc_models /infer/lib/specs/clean_models diff --git a/Makefile b/Makefile index 81880abfc..95b68fa08 100644 --- a/Makefile +++ b/Makefile @@ -120,9 +120,6 @@ infer: src_build ifeq ($(BUILD_JAVA_ANALYZERS),yes) $(QUIET)$(MAKE) -C $(ANNOTATIONS_DIR) endif -# Delete existing specs so that they are not used during the analysis of models. Infer may -# segfault in some cases otherwise. - $(QUIET)$(MAKE) -C $(MODELS_DIR) clean_specs $(QUIET)$(MAKE) -C $(MODELS_DIR) all .PHONY: clang_setup diff --git a/infer/models/Makefile b/infer/models/Makefile index 514aedfc0..8d9e0d8be 100644 --- a/infer/models/Makefile +++ b/infer/models/Makefile @@ -13,6 +13,8 @@ CPP_MODELS_DIR = cpp JAVA_MODELS_DIR = java OBJC_MODELS_DIR = objc +CLANG_MODELS_FILE = $(SPECS_LIB_DIR)/clang_models + CLANG_SUBDIRS = $(C_MODELS_DIR) $(CPP_MODELS_DIR) ifneq (no, $(XCODE_SELECT)) CLANG_SUBDIRS += $(OBJC_MODELS_DIR) @@ -29,12 +31,29 @@ endif .PHONY: java clang clean clean_specs $(CLANG_SUBDIRS) clean_specs: - $(REMOVE) $(SPECS_LIB_DIR)/*.specs + $(REMOVE) $(SPECS_LIB_DIR)/*.specs $(C_MODELS_FILE) $(CPP_MODELS_FILE) $(OBJC_MODELS_FILE) $(CLANG_SUBDIRS): $(QUIET)$(MAKE) -C $@ install -clang: $(CLANG_SUBDIRS) +# The clang deps have changed, so the models need to be rebuilt. If infer itself has changed, we +# need to nuke the previous specs files in case the serialization has changed, otherwise we might +# encounter a segfault reading them. +$(CLANG_MODELS_FILE): $(CLANG_DEPS_NO_MODELS) + $(QUIET)$(MAKE) clean_specs +# Since [CLANG_DEPS_NO_MODELS] is newer than [CLANG_MODELS_FILE], it is also newer than the +# previously built clang models, so they will all be rebuilt by the subdirs' Makefiles. + $(QUIET)$(MAKE) $(CLANG_SUBDIRS) +# Maintain the invariant that [CLANG_MODELS_FILE] is newer than the clang models. + $(QUIET)touch $@ + +clang: $(CLANG_MODELS_FILE) +# Run the sub-makes unconditionally since they know more about when they need to be +# rebuilt. For instance, they need to be rebuilt when their source files change, which is not +# taken into account by the dependencies of the $(CLANG_MODELS_FILE) target. If we rebuilt +# $(CLANG_MODELS_FILE) already, then the command below will be a no-op (so we don't rebuild +# the models twice). + $(QUIET)$(MAKE) $(CLANG_SUBDIRS) java: $(QUIET)$(MAKE) -C $@ install