mirrored from https://chromium.googlesource.com/infra/luci/recipes-py
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlegacy_analyzers.py
158 lines (128 loc) · 4.88 KB
/
legacy_analyzers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Copyright 2020 The LUCI Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
"""Legacy analyzers which may be used by multiple projects."""
import attr
from attr.validators import instance_of
@attr.s(frozen=True)
class LegacyAnalyzer:
"""LegacyAnalyzer is a specification for legacy "simple" Tricium analyzer.
Legacy Tricium analyzers are executables packaged in CIPD packages.
These executables take the flags -input and -output, in addition to other
possible extra args:
* `-input` specifies the root of input to read, which includes the
tricium/data/ directory and any files to read.
* `-output` specifies the base directory for output, and results are written
to tricium/data/results.json relative to that directory.
"""
# Analyzer name, for UI purposes.
name = attr.ib(validator=instance_of(str))
# CIPD package path.
package = attr.ib(validator=instance_of(str))
# Executable binary file name.
executable = attr.ib(validator=instance_of(str))
# CIPD package version name, defaults to "live".
version = attr.ib(validator=instance_of(str), default='live')
# List of path glob patterns to match, e.g. ["*.c"].
#
# If this is non-empty, then at least one path must match at least
# one glob pattern for the analyzer to be run.
path_filters = attr.ib(validator=instance_of(list), default=[])
# List of extra arguments to add to the analyzer invocation.
extra_args = attr.ib(validator=instance_of(list), default=[])
class Analyzers:
"""Specifications of common legacy analyzers.
This is a namespace for common legacy analyzers that may be used across
multiple projects. The source code for each of these analyzers is in the
infra.git repo in go/src/infra/tricium/functions/; check there for
documentation and features.
"""
COMMITCHECK = LegacyAnalyzer(
name='Commitcheck',
package='infra/tricium/legacy_functions/commitcheck/linux-amd64',
version='latest',
executable='commitcheck')
COPYRIGHT = LegacyAnalyzer(
name='Copyright',
package='infra/tricium/legacy_functions/copyright/linux-amd64',
executable='copyright',
version='latest',
path_filters=[
'*.c',
'*.cc',
'*.cpp',
'*.go',
'*.h',
'*.java',
'*.js',
'*.py',
'*.sh',
])
CPPLINT = LegacyAnalyzer(
name='Cpplint',
package='infra/tricium/legacy_functions/cpplint/linux-amd64',
executable='cpplint',
version='latest',
path_filters=['*.cc', '*.cpp', '*.cu', '*.cuh', '*.h'],
extra_args=['-filter=-whitespace,-build/header_guard', '-verbose=4'])
ESLINT = LegacyAnalyzer(
name='Eslint',
package='infra/tricium/function/eslint',
executable='eslint_parser',
path_filters=['*.js'])
GOSEC = LegacyAnalyzer(
name='Gosec',
package='infra/tricium/function/gosec',
executable='gosec_wrapper',
path_filters=['*.go'])
HTTPS_CHECK = LegacyAnalyzer(
name='HttpsCheck',
package='infra/tricium/legacy_functions/https-check/linux-amd64',
version='latest',
executable='https-check')
INCLUSIVE_LANGUAGE_CHECK = LegacyAnalyzer(
name='InclusiveLanguageCheck',
package='infra/tricium/legacy_functions/inclusive/linux-amd64',
version='latest',
executable='inclusive')
MOJOM_COMMENTATOR = LegacyAnalyzer(
name='MojomCommentator',
package='infra/tricium/legacy_functions/mojom-commentator/linux-amd64',
version='latest',
executable='mojom-commentator',
path_filters=['*.mojom'])
OBJECTIVE_C_STYLE = LegacyAnalyzer(
name='ObjectiveCStyle',
package='infra/tricium/legacy_functions/objective-c-style/linux-amd64',
version='latest',
executable='objective-c-style',
path_filters=['*.m', '*.mm'])
PYLINT = LegacyAnalyzer(
name='Pylint',
package='infra/tricium/function/pylint',
executable='pylint_parser',
path_filters=['*.py'])
SPELLCHECKER = LegacyAnalyzer(
name='Spellchecker',
package='infra/tricium/legacy_functions/spellchecker/linux-amd64',
version='latest',
executable='spellchecker')
SPACEY = LegacyAnalyzer(
name='Spacey',
package='infra/tricium/legacy_functions/spacey/linux-amd64',
version='latest',
executable='spacey')
@classmethod
def by_name(cls):
"""Returns a dict mapping names to LegacyAnalyzers.
This mapping may be used to map names to analyzers, for example if a recipe
uses strings in an input proto message to specify analyzers.
"""
mapping = {}
for attr in cls.__dict__.values():
if isinstance(attr, LegacyAnalyzer):
assert attr.name not in mapping
mapping[attr.name] = attr
return mapping
# This will fail if duplicate names are registered.
Analyzers.by_name()