summaryrefslogtreecommitdiffstats
path: root/components/tools/metrics/browser_components_metrics.py
blob: c1f5b4b05d0f3bce2b260d772148fdbb25cb5805 (plain)
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
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Generates the metrics collected weekly for the Browser Components project.

See
http://www.chromium.org/developers/design-documents/browser-components
for details.
"""

import os
import sys


# This is done so that we can import checkdeps.  If not invoked as
# main, our user must ensure it is in PYTHONPATH.
if __name__ == '__main__':
  sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..',
                               'buildtools', 'checkdeps'))


import count_ifdefs
import checkdeps
import results


# Preprocessor pattern to find OS_XYZ defines.
PREPROCESSOR_PATTERN = 'OS_[A-Z]+'


class BrowserComponentsMetricsGenerator(object):
  def __init__(self, checkout_root):
    self.checkout_root = checkout_root
    self.chrome_browser = os.path.join(checkout_root, 'chrome', 'browser')

  def CountIfdefs(self, skip_tests):
    return count_ifdefs.CountIfdefs(
        PREPROCESSOR_PATTERN, self.chrome_browser, skip_tests)

  def CountViolations(self, skip_tests):
    deps_checker = checkdeps.DepsChecker(self.checkout_root,
                                         ignore_temp_rules=True,
                                         skip_tests=skip_tests)
    deps_checker.results_formatter = results.CountViolationsFormatter()
    deps_checker.CheckDirectory(os.path.join('chrome', 'browser'))
    return int(deps_checker.results_formatter.GetResults())


def main():
  generator = BrowserComponentsMetricsGenerator(
      os.path.join(os.path.dirname(__file__), '..', '..', '..'))

  print "All metrics are for chrome/browser.\n"
  print "OS ifdefs, all:                   %d" % generator.CountIfdefs(False)
  print "OS ifdefs, -tests:                %d" % generator.CountIfdefs(True)
  print ("Intended DEPS violations, all:    %d" %
         generator.CountViolations(False))
  print "Intended DEPS violations, -tests: %d" % generator.CountViolations(True)
  return 0


if __name__ == '__main__':
  sys.exit(main())