summaryrefslogtreecommitdiff
path: root/rust/config/clippy.go
diff options
context:
space:
mode:
author Matthew Maurer <mmaurer@google.com> 2020-06-26 20:33:37 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2020-06-26 20:33:37 +0000
commit85a08fc454dc8e5f9adda57d92f496e203f792d4 (patch)
tree130759b176239ba7554493fb475c14fc4250118a /rust/config/clippy.go
parenta8bfdbd1317cc9150cff633af66820c43c5bedfd (diff)
parent92f703b0848531b4b7212897e443e052cfa68779 (diff)
Merge "Add clippy-driver build rule"
Diffstat (limited to 'rust/config/clippy.go')
-rw-r--r--rust/config/clippy.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/rust/config/clippy.go b/rust/config/clippy.go
new file mode 100644
index 000000000..c199ff269
--- /dev/null
+++ b/rust/config/clippy.go
@@ -0,0 +1,80 @@
+// Copyright 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package config
+
+import (
+ "strings"
+
+ "android/soong/android"
+)
+
+var (
+ defaultLints = []string{
+ "-D missing-docs",
+ "-D clippy::missing-safety-doc",
+ }
+ defaultVendorLints = []string{
+ "",
+ }
+)
+
+func init() {
+ // Default Rust lints. These apply to all Google-authored modules.
+ pctx.VariableFunc("ClippyDefaultLints", func(ctx android.PackageVarContext) string {
+ if override := ctx.Config().Getenv("CLIPPY_DEFAULT_LINTS"); override != "" {
+ return override
+ }
+ return strings.Join(defaultLints, " ")
+ })
+
+ // Rust lints that only applies to external code.
+ pctx.VariableFunc("ClippyVendorLints", func(ctx android.PackageVarContext) string {
+ if override := ctx.Config().Getenv("CLIPPY_VENDOR_LINTS"); override != "" {
+ return override
+ }
+ return strings.Join(defaultVendorLints, " ")
+ })
+}
+
+type PathBasedClippyConfig struct {
+ PathPrefix string
+ Enabled bool
+ ClippyConfig string
+}
+
+const clippyNone = ""
+const clippyDefault = "${config.ClippyDefaultLints}"
+const clippyVendor = "${config.ClippyVendorLints}"
+
+// This is a map of local path prefixes to a boolean indicating if the lint
+// rule should be generated and if so, the set of lints to use. The first entry
+// matching will be used. If no entry is matching, clippyDefault will be used.
+var DefaultLocalTidyChecks = []PathBasedClippyConfig{
+ {"external/", false, clippyNone},
+ {"hardware/", true, clippyVendor},
+ {"prebuilts/", false, clippyNone},
+ {"vendor/google", true, clippyDefault},
+ {"vendor/", true, clippyVendor},
+}
+
+// ClippyLintsForDir returns the Clippy lints to be used for a repository.
+func ClippyLintsForDir(dir string) (bool, string) {
+ for _, pathCheck := range DefaultLocalTidyChecks {
+ if strings.HasPrefix(dir, pathCheck.PathPrefix) {
+ return pathCheck.Enabled, pathCheck.ClippyConfig
+ }
+ }
+ return true, clippyDefault
+}