• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Generates the metrics collected weekly for the Browser Components project.
7
8See
9http://www.chromium.org/developers/design-documents/browser-components
10for details.
11"""
12
13import os
14import sys
15
16
17# This is done so that we can import checkdeps.  If not invoked as
18# main, our user must ensure it is in PYTHONPATH.
19if __name__ == '__main__':
20  sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..',
21                               'tools', 'checkdeps'))
22
23
24import count_ifdefs
25import checkdeps
26import results
27
28
29# Preprocessor pattern to find OS_XYZ defines.
30PREPROCESSOR_PATTERN = 'OS_[A-Z]+'
31
32
33class BrowserComponentsMetricsGenerator(object):
34  def __init__(self, checkout_root):
35    self.checkout_root = checkout_root
36    self.chrome_browser = os.path.join(checkout_root, 'chrome', 'browser')
37
38  def CountIfdefs(self, skip_tests):
39    return count_ifdefs.CountIfdefs(
40        PREPROCESSOR_PATTERN, self.chrome_browser, skip_tests)
41
42  def CountViolations(self, skip_tests):
43    deps_checker = checkdeps.DepsChecker(self.checkout_root,
44                                         ignore_temp_rules=True,
45                                         skip_tests=skip_tests)
46    deps_checker.results_formatter = results.CountViolationsFormatter()
47    deps_checker.CheckDirectory(os.path.join('chrome', 'browser'))
48    return int(deps_checker.results_formatter.GetResults())
49
50
51def main():
52  generator = BrowserComponentsMetricsGenerator(
53      os.path.join(os.path.dirname(__file__), '..', '..', '..'))
54
55  print "All metrics are for chrome/browser.\n"
56  print "OS ifdefs, all:                   %d" % generator.CountIfdefs(False)
57  print "OS ifdefs, -tests:                %d" % generator.CountIfdefs(True)
58  print ("Intended DEPS violations, all:    %d" %
59         generator.CountViolations(False))
60  print "Intended DEPS violations, -tests: %d" % generator.CountViolations(True)
61  return 0
62
63
64if __name__ == '__main__':
65  sys.exit(main())
66