blob: dd394216712a20810906f7badd9b9aacd5f741ac [file] [log] [blame]
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package config
16
17import (
18 "strings"
19)
20
21func init() {
22 // Most Android source files are not clang-tidy clean yet.
23 // Global tidy checks include only google*, performance*,
24 // and misc-macro-parentheses, but not google-readability*
25 // or google-runtime-references.
26 pctx.StaticVariable("TidyDefaultGlobalChecks", strings.Join([]string{
27 "-*",
28 "google*",
29 "misc-macro-parentheses",
30 "performance*",
31 "-google-readability*",
32 "-google-runtime-references",
33 }, ","))
34
35 // There are too many clang-tidy warnings in external and vendor projects.
36 // Enable only some google checks for these projects.
37 pctx.StaticVariable("TidyExternalVendorChecks", strings.Join([]string{
38 "-*",
39 "google*",
40 "-google-build-using-namespace",
41 "-google-default-arguments",
42 "-google-explicit-constructor",
43 "-google-readability*",
44 "-google-runtime-int",
45 "-google-runtime-references",
46 }, ","))
47
48 // Give warnings to header files only in selected directories.
49 // Do not give warnings to external or vendor header files, which contain too
50 // many warnings.
51 pctx.StaticVariable("TidyDefaultHeaderDirs", strings.Join([]string{
52 "art/",
53 "bionic/",
54 "bootable/",
55 "build/",
56 "cts/",
57 "dalvik/",
58 "developers/",
59 "development/",
60 "frameworks/",
61 "libcore/",
62 "libnativehelper/",
63 "system/",
64 }, "|"))
65}
66
67type PathBasedTidyCheck struct {
68 PathPrefix string
69 Checks string
70}
71
72const tidyDefault = "${config.TidyDefaultGlobalChecks}"
73const tidyExternalVendor = "${config.TidyExternalVendorChecks}"
74
75// This is a map of local path prefixes to the set of default clang-tidy checks
76// to be used.
77// The last matched local_path_prefix should be the most specific to be used.
78var DefaultLocalTidyChecks = []PathBasedTidyCheck{
79 {"external/", tidyExternalVendor},
80 {"external/google", tidyDefault},
81 {"external/webrtc", tidyDefault},
82 {"frameworks/compile/mclinker/", tidyExternalVendor},
83 {"hardware/qcom", tidyExternalVendor},
84 {"vendor/", tidyExternalVendor},
85 {"vendor/google", tidyDefault},
86 {"vendor/google_devices", tidyExternalVendor},
87}
88
89var reversedDefaultLocalTidyChecks = reverseTidyChecks(DefaultLocalTidyChecks)
90
91func reverseTidyChecks(in []PathBasedTidyCheck) []PathBasedTidyCheck {
92 ret := make([]PathBasedTidyCheck, len(in))
93 for i, check := range in {
94 ret[len(in)-i-1] = check
95 }
96 return ret
97}
98
99func TidyChecksForDir(dir string) string {
100 for _, pathCheck := range reversedDefaultLocalTidyChecks {
101 if strings.HasPrefix(dir, pathCheck.PathPrefix) {
102 return pathCheck.Checks
103 }
104 }
105 return tidyDefault
106}