From be5dd2023ed0afbd5284d4c4f7a221fe6a788f5a Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Sun, 26 Aug 2018 20:37:49 -0700 Subject: [PATCH] Filter out unknown arguments with clang-tidy.sh. * Call clang-tidy.sh defined in PATH_TO_CLANG_TIDY_SHELL. * Add dependency to clang-tidy and clang-tidy.sh. Bug: 110538415 Test: build with WITH_TIDY=1 Change-Id: I90175ea1489272d8d4fc0f9ba4e5bbfdc7399d82 --- core/binary.mk | 11 ++++++++++- core/clang/tidy.mk | 13 ------------- core/definitions.mk | 26 ++++++++++++-------------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/core/binary.mk b/core/binary.mk index a28561c1a..5b73e527d 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -1737,7 +1737,7 @@ ifneq (,$(filter 1 true,$(my_tidy_enabled))) # Disable clang-tidy if clang is disabled. my_tidy_enabled := false else - tidy_only: $(cpp_objects) $(c_objects) + tidy_only: $(cpp_objects) $(c_objects) $(gen_c_objects) $(gen_cpp_objects) # Set up global default checks my_tidy_checks := $(WITH_TIDY_CHECKS) ifeq ($(my_tidy_checks),) @@ -1776,6 +1776,15 @@ endif my_tidy_checks := $(subst $(space),,$(my_tidy_checks)) +# Add dependency of clang-tidy and clang-tidy.sh +ifneq ($(my_tidy_checks),) + my_clang_tidy_programs := $(PATH_TO_CLANG_TIDY) $(PATH_TO_CLANG_TIDY_SHELL) + $(cpp_objects): $(intermediates)/%.o: $(my_clang_tidy_programs) + $(c_objects): $(intermediates)/%.o: $(my_clang_tidy_programs) + $(gen_cpp_objects): $(intermediates)/%.o: $(my_clang_tidy_programs) + $(gen_c_objects): $(intermediates)/%.o: $(my_clang_tidy_programs) +endif + # Move -l* entries from ldflags to ldlibs, and everything else to ldflags my_ldlib_flags := $(my_ldflags) $(my_ldlibs) my_ldlibs := $(filter -l%,$(my_ldlib_flags)) diff --git a/core/clang/tidy.mk b/core/clang/tidy.mk index 36c6931b7..868f7bc88 100644 --- a/core/clang/tidy.mk +++ b/core/clang/tidy.mk @@ -14,19 +14,6 @@ # limitations under the License. # -# clang-tidy doesn't recognize every flag that clang does. This is unlikely to -# be a complete list, but we can populate this with the ones we know to avoid -# issues with clang-diagnostic-unused-command-line-argument. -# b/111885396: -flto affected header include directory; -# -fsanitize and -fwhole-program-vtables need -flto. -CLANG_TIDY_UNKNOWN_CFLAGS := \ - -Wa,% \ - -flto \ - -flto=% \ - -fsanitize=% \ - -fsanitize-% \ - -fwhole-program-vtables \ - # Returns 2nd word of $(1) if $(2) has prefix of the 1st word of $(1). define find_default_local_tidy_check2 $(if $(filter $(word 1,$(1))%,$(2)/),$(word 2,$(1))) diff --git a/core/definitions.mk b/core/definitions.mk index 4d2f5e698..c2b3a9eb8 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -105,8 +105,6 @@ ALL_VINTF_MANIFEST_FRAGMENTS_LIST:= # All tests that should be skipped in presubmit check. ALL_DISABLED_PRESUBMIT_TESTS := -sanitize_tidy_cflags = $(filter-out $(CLANG_TIDY_UNKNOWN_CFLAGS),$1) - ########################################################### ## Debugging; prints a variable list to stdout ########################################################### @@ -1252,10 +1250,16 @@ define transform-cpp-to-o-compiler-args $(PRIVATE_CPPFLAGS_NO_OVERRIDE) endef +# PATH_TO_CLANG_TIDY_SHELL is defined in build/soong +define call-clang-tidy +CLANG_TIDY=$(PATH_TO_CLANG_TIDY) \ + $(PATH_TO_CLANG_TIDY_SHELL) \ + $(PRIVATE_TIDY_FLAGS) \ + -checks=$(PRIVATE_TIDY_CHECKS) +endef + define clang-tidy-cpp -$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \ - -checks=$(PRIVATE_TIDY_CHECKS) \ - $< -- $(call sanitize_tidy_cflags,$(transform-cpp-to-o-compiler-args)) +$(hide) $(call-clang-tidy) $< -- $(transform-cpp-to-o-compiler-args) endef ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY))) @@ -1301,9 +1305,7 @@ $(call transform-c-or-s-to-o-compiler-args, \ endef define clang-tidy-c -$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \ - -checks=$(PRIVATE_TIDY_CHECKS) \ - $< -- $(call sanitize_tidy_cflags,$(transform-c-to-o-compiler-args)) +$(hide) $(call-clang-tidy) $< -- $(transform-c-to-o-compiler-args) endef ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY))) @@ -1371,9 +1373,7 @@ define transform-host-cpp-to-o-compiler-args endef define clang-tidy-host-cpp -$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \ - -checks=$(PRIVATE_TIDY_CHECKS) \ - $< -- $(call sanitize_tidy_cflags,$(transform-host-cpp-to-o-compiler-args)) +$(hide) $(call-clang-tidy) $< -- $(transform-host-cpp-to-o-compiler-args) endef ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY))) @@ -1423,9 +1423,7 @@ define transform-host-c-to-o-compiler-args endef define clang-tidy-host-c -$(hide) $(PATH_TO_CLANG_TIDY) $(PRIVATE_TIDY_FLAGS) \ - -checks=$(PRIVATE_TIDY_CHECKS) \ - $< -- $(call sanitize_tidy_cflags,$(transform-host-c-to-o-compiler-args)) +$(hide) $(call-clang-tidy) $< -- $(transform-host-c-to-o-compiler-args) endef ifneq (,$(filter 1 true,$(WITH_TIDY_ONLY)))