diff --git a/core/binary.mk b/core/binary.mk index 23a8169d9..c454e4a33 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -1742,7 +1742,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),) @@ -1781,6 +1781,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 9f173fd51..1bd57518d 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)))