Bug 1402302 - sync checkers for static-analysis with the mozreview bot. r=sylvestre
☠☠ backed out by 810eae249662 ☠ ☠
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Fri, 29 Sep 2017 23:48:19 +0300
changeset 434592 048af66f77118db46c2fa03d0e3ede5cb731e48f
parent 434591 3b5b98033433fcba6a8d2a31dd4331bd01dff4e5
child 434593 cecd6d07c8bf48c982f000142693a73685efcf36
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssylvestre
bugs1402302
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1402302 - sync checkers for static-analysis with the mozreview bot. r=sylvestre MozReview-Commit-ID: I5rn4DEXGOK
python/mozbuild/mozbuild/mach_commands.py
tools/clang-tidy/config.yaml
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -2191,42 +2191,45 @@ class StaticAnalysis(MachCommandBase):
     @CommandArgument('source', nargs='*', default=['.*'],
                      help='Source files to be analyzed (regex on path). '
                           'Can be omitted, in which case the entire code base '
                           'is analyzed.  The source argument is ignored if '
                           'there is anything fed through stdin, in which case '
                           'the analysis is only performed on the files changed '
                           'in the patch streamed through stdin.  This is called '
                           'the diff mode.')
-    @CommandArgument('--checks', '-c', default='-*,mozilla-*', metavar='checks',
+    @CommandArgument('--checks', '-c', default='-*', metavar='checks',
         help='Static analysis checks to enable.  By default, this enables only '
              'custom Mozilla checks, but can be any clang-tidy checks syntax.')
     @CommandArgument('--jobs', '-j', default='0', metavar='jobs', type=int,
         help='Number of concurrent jobs to run. Default is the number of CPUs.')
     @CommandArgument('--strip', '-p', default='1', metavar='NUM',
                      help='Strip NUM leading components from file names in diff mode.')
     @CommandArgument('--fix', '-f', default=False, action='store_true',
                      help='Try to autofix errors detected by clang-tidy checkers.')
     def check(self, source=None, jobs=2, strip=1, verbose=False,
-              checks='-*,mozilla-*', fix=False):
+              checks='-*', fix=False):
         self._set_log_level(verbose)
         rc = self._build_compile_db(verbose=verbose)
         if rc != 0:
             return rc
 
         rc = self._build_export(jobs=jobs, verbose=verbose)
         if rc != 0:
             return rc
 
         rc = self._get_clang_tidy(verbose=verbose)
         if rc != 0:
             return rc
 
         python = self.virtualenv_manager.python_path
 
+        if checks == '-*':
+            checks = self._get_checks()
+
         common_args = ['-clang-tidy-binary', self._clang_tidy_path,
                        '-checks=%s' % checks,
                        '-extra-arg=-DMOZ_CLANG_PLUGIN']
         if fix:
             common_args.append('-fix')
 
         self.log_manager.register_structured_logger(logging.getLogger('mozbuild'))
 
@@ -2291,16 +2294,31 @@ class StaticAnalysis(MachCommandBase):
     def print_checks(self, verbose=False):
         self._set_log_level(verbose)
         rc = self._get_clang_tidy(verbose=verbose)
         if rc != 0:
             return rc
         args = [self._clang_tidy_path, '-list-checks', '-checks=-*,mozilla-*']
         return self._run_command_in_objdir(args=args, pass_thru=True)
 
+    def _get_checks(self):
+        checks = '-*'
+        import yaml
+        with open(mozpath.join(self.topsrcdir, "tools", "clang-tidy", "config.yaml")) as f:
+            try:
+                config = yaml.load(f)
+                for item in config['clang_checkers']:
+                    if item['publish']:
+                        checks += ',' + item['name']
+            except Exception:
+                print('Looks like config.yaml is not valid, so we are unable to '
+                      'determine default checkers, using \'-checks=-*,mozilla-*\'')
+                checks += ',mozilla-*'
+        return checks
+
     def _get_config_environment(self):
         ran_configure = False
         config = None
         builder = Build(self._mach_context)
 
         try:
             config = self.config_environment
         except Exception:
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/config.yaml
@@ -0,0 +1,56 @@
+target: obj-x86_64-pc-linux-gnu
+# It is used by 'mach static-analysis' and 'mozreview static-analysis bot'
+# in order to have consistency across the used checkers.
+# All the clang checks used by the static-analysis tools.
+clang_checkers:
+ - name: -*
+   publish: no
+ - name: clang-analyzer-deadcode.DeadStores
+   publish: yes
+ - name: clang-analyzer-security.*
+   publish: no
+ - name: misc-assert-side-effect
+   publish: yes
+ - name: misc-suspicious-missing-comma
+   publish: yes
+ - name: misc-suspicious-semicolon
+   publish: yes
+ - name: modernize-loop-convert
+   publish: yes
+ - name: modernize-raw-string-literal
+   publish: yes
+ - name: modernize-redundant-void-arg
+   publish: no
+ - name: modernize-shrink-to-fit
+   publish: yes
+ - name: modernize-use-equals-default
+   publish: yes
+ - name: modernize-use-equals-delete
+   publish: yes
+ - name: modernize-use-nullptr
+   publish: yes
+ - name: modernize-use-override
+   publish: yes
+ - name: mozilla-*
+   publish: yes
+ - name: performance-*
+   publish: yes
+ - name: readability-container-size-empty
+   publish: yes
+ - name: readability-else-after-return
+   publish: yes
+ - name: readability-misleading-indentation
+   publish: yes
+ - name: readability-redundant-control-flow
+   publish: yes
+ - name: readability-redundant-smartptr-get
+   publish: no
+ - name: readability-uniqueptr-delete-release
+   publish: yes
+ - name: modernize-use-auto # (controversial, see bug 1371052)
+   publish: no
+ - name: modernize-use-bool-literals # (too noisy because of `while (0)` in many macros)
+   publish: no
+
+# Third party files from mozilla-central
+third_party: tools/rewriting/ThirdPartyPaths.txt
\ No newline at end of file