Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a46753c authored by Chih-Hung Hsieh's avatar Chih-Hung Hsieh
Browse files

No clang-tidy by default for external and vendor

* Most tidy-external-* and tidy-vendor-* rules
  are no longer generated. But external/bcc,
  external/android-clat, and some vendor/...
  projects still have tidy- rules because they
  have explicitly set tidy:true in .bp files.
* Some hardware/* directories are third-party
  projects and also disabled by default.

Bug: 244631413
Test: presubmit; make tidy-soong_subset
Change-Id: I17f625e6270de81a111d9cd382fbc39f34edf924
parent 0228d279
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -164,19 +164,21 @@ const tidyExternalVendor = "${config.TidyExternalVendorChecks}"
const tidyDefaultNoAnalyzer = "${config.TidyDefaultGlobalChecks},-clang-analyzer-*"

// This is a map of local path prefixes to the set of default clang-tidy checks
// to be used.
// to be used.  This is like android.IsThirdPartyPath, but with more patterns.
// The last matched local_path_prefix should be the most specific to be used.
var DefaultLocalTidyChecks = []PathBasedTidyCheck{
	{"external/", tidyExternalVendor},
	{"external/google", tidyDefault},
	{"external/webrtc", tidyDefault},
	{"external/googletest/", tidyExternalVendor},
	{"frameworks/compile/mclinker/", tidyExternalVendor},
	{"hardware/qcom", tidyExternalVendor},
	{"hardware/", tidyExternalVendor},
	{"hardware/google/", tidyDefault},
	{"hardware/interfaces/", tidyDefault},
	{"hardware/ril/", tidyDefault},
	{"hardware/libhardware", tidyDefault}, // all 'hardware/libhardware*'
	{"vendor/", tidyExternalVendor},
	{"vendor/google", tidyDefault},
	{"vendor/google", tidyDefault}, // all 'vendor/google*'
	{"vendor/google/external/", tidyExternalVendor},
	{"vendor/google_arc/libs/org.chromium.arc.mojom", tidyExternalVendor},
	{"vendor/google_devices", tidyExternalVendor},
	{"vendor/google_devices/", tidyExternalVendor}, // many have vendor code
}

var reversedDefaultLocalTidyChecks = reverseTidyChecks(DefaultLocalTidyChecks)
@@ -199,6 +201,13 @@ func TidyChecksForDir(dir string) string {
	return tidyDefault
}

func NoClangTidyForDir(dir string) bool {
	// This function depends on TidyChecksForDir, which selects tidyExternalVendor
	// checks for external/vendor projects. For those projects we disable clang-tidy
	// by default, unless some modules enable clang-tidy with tidy:true.
	return TidyChecksForDir(dir) == tidyExternalVendor
}

// Returns a globally disabled tidy checks, overriding locally selected checks.
func TidyGlobalNoChecks() string {
	if len(globalNoCheckList) > 0 {
+5 −1
Original line number Diff line number Diff line
@@ -76,7 +76,11 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
	if tidy.Properties.Tidy != nil && !*tidy.Properties.Tidy {
		return flags
	}

	// Some projects like external/* and vendor/* have clang-tidy disabled by default.
	// They can enable clang-tidy explicitly with the "tidy:true" property.
	if config.NoClangTidyForDir(ctx.ModuleDir()) && !proptools.Bool(tidy.Properties.Tidy) {
		return flags
	}
	// If not explicitly disabled, set flags.Tidy to generate .tidy rules.
	// Note that libraries and binaries will depend on .tidy files ONLY if
	// the global WITH_TIDY or module 'tidy' property is true.