Index: tools/checkdeps/builddeps.py |
diff --git a/tools/checkdeps/builddeps.py b/tools/checkdeps/builddeps.py |
index 01e107b0b80a9708fcdd472336e790fc1565a149..63f62d36a775e157c57b9251422b70a10ff79a6c 100755 |
--- a/tools/checkdeps/builddeps.py |
+++ b/tools/checkdeps/builddeps.py |
@@ -75,9 +75,9 @@ backslashes. All directories should be relative to the source root and use |
only lowercase. |
""" |
+import copy |
import os |
import subprocess |
-import copy |
from rules import Rule, Rules |
@@ -116,8 +116,8 @@ class DepsBuilder(object): |
Args: |
base_directory: OS-compatible path to root of checkout, e.g. C:\chr\src. |
- verbose: Set to true for debug output. |
- being_tested: Set to true to ignore the DEPS file at tools/checkdeps/DEPS. |
+ verbose: Set to True for debug output. |
+ being_tested: Set to True to ignore the DEPS file at tools/checkdeps/DEPS. |
ignore_temp_rules: Ignore rules that start with Rule.TEMP_ALLOW ("!"). |
""" |
base_directory = (base_directory or |
@@ -153,20 +153,19 @@ class DepsBuilder(object): |
rules = copy.deepcopy(existing_rules) |
# First apply the implicit "allow" rule for the current directory. |
- if cur_dir.startswith( |
- NormalizePath(os.path.normpath(self.base_directory))): |
- relative_dir = cur_dir[len(self.base_directory) + 1:] |
- |
- source = relative_dir |
- if len(source) == 0: |
- source = 'top level' # Make the help string a little more meaningful. |
- rules.AddRule('+' + relative_dir, |
- relative_dir, |
- 'Default rule for ' + source) |
- else: |
- raise Exception('Internal error: base directory is not at the beginning' + |
- ' for\n %s and base dir\n %s' % |
- (cur_dir, self.base_directory)) |
+ norm_base_dir = NormalizePath(os.path.normpath(self.base_directory)) |
+ if not cur_dir.startswith(norm_base_dir): |
+ raise Exception( |
+ 'Internal error: base directory is not at the beginning for\n' |
+ ' %s and base dir\n' |
+ ' %s' % (cur_dir, norm_base_dir)) |
+ relative_dir = os.path.relpath(cur_dir, norm_base_dir) |
+ |
+ # Make the help string a little more meaningful. |
+ source = relative_dir or 'top level' |
+ rules.AddRule('+' + relative_dir, |
+ relative_dir, |
+ 'Default rule for ' + source) |
def ApplyOneRule(rule_str, cur_dir, dependee_regexp=None): |
"""Deduces a sensible description for the rule being added, and |
@@ -181,14 +180,14 @@ class DepsBuilder(object): |
rule_block_name = 'include_rules' |
if dependee_regexp: |
rule_block_name = 'specific_include_rules' |
- if not relative_dir: |
- rule_description = 'the top level %s' % rule_block_name |
- else: |
+ if relative_dir: |
rule_description = relative_dir + "'s %s" % rule_block_name |
+ else: |
+ rule_description = 'the top level %s' % rule_block_name |
rules.AddRule(rule_str, relative_dir, rule_description, dependee_regexp) |
# Apply the additional explicit rules. |
- for (_, rule_str) in enumerate(includes): |
+ for rule_str in includes: |
ApplyOneRule(rule_str, cur_dir) |
# Finally, apply the specific rules. |
@@ -222,17 +221,17 @@ class DepsBuilder(object): |
# Check for a .svn directory in this directory or check this directory is |
# contained in git source direcotries. This will tell us if it's a source |
# directory and should be checked. |
- if not (os.path.exists(os.path.join(dir_name, ".svn")) or |
+ if not (os.path.exists(os.path.join(dir_name, '.svn')) or |
(norm_dir_name in self.git_source_directories)): |
- return (None, []) |
+ return None, [] |
# Check the DEPS file in this directory. |
if self.verbose: |
print 'Applying rules from', dir_name |
- def FromImpl(_unused, _unused2): |
+ def FromImpl(*_): |
pass # NOP function so "From" doesn't fail. |
- def FileImpl(_unused): |
+ def FileImpl(_): |
pass # NOP function so "File" doesn't fail. |
class _VarImpl: |
@@ -241,16 +240,17 @@ class DepsBuilder(object): |
def Lookup(self, var_name): |
"""Implements the Var syntax.""" |
- if var_name in self._local_scope.get('vars', {}): |
+ try: |
return self._local_scope['vars'][var_name] |
- raise Exception('Var is not defined: %s' % var_name) |
+ except KeyError: |
+ raise Exception('Var is not defined: %s' % var_name) |
local_scope = {} |
global_scope = { |
- 'File': FileImpl, |
- 'From': FromImpl, |
- 'Var': _VarImpl(local_scope).Lookup, |
- } |
+ 'File': FileImpl, |
+ 'From': FromImpl, |
+ 'Var': _VarImpl(local_scope).Lookup, |
+ } |
deps_file = os.path.join(dir_name, 'DEPS') |
# The second conditional here is to disregard the |
@@ -262,7 +262,7 @@ class DepsBuilder(object): |
# directory to trigger those intended violations and see that they |
# are handled correctly. |
if os.path.isfile(deps_file) and ( |
- not self._under_test or not os.path.split(dir_name)[1] == 'checkdeps'): |
+ not self._under_test or not os.path.basename(dir_name) == 'checkdeps'): |
execfile(deps_file, global_scope, local_scope) |
elif self.verbose: |
print ' No deps file found in', dir_name |
@@ -310,7 +310,7 @@ class DepsBuilder(object): |
parent_dir = os.path.dirname(dir_path) |
parent_rules = None |
- if not norm_dir_path in self.directory_rules: |
+ if norm_dir_path not in self.directory_rules: |
parent_rules = self.GetDirectoryRules(parent_dir) |
# We need to check for an entry for our dir_path again, in case we |
@@ -318,13 +318,13 @@ class DepsBuilder(object): |
# subdirectory to be skipped; in this case, the invocation to |
# GetDirectoryRules(parent_dir) has already filled in an entry for |
# A/B/C. |
- if not norm_dir_path in self.directory_rules: |
- if not parent_rules: |
+ if norm_dir_path not in self.directory_rules: |
+ if parent_rules: |
+ self._ApplyDirectoryRulesAndSkipSubdirs(parent_rules, dir_path) |
+ else: |
# If the parent directory should be skipped, then the current |
# directory should also be skipped. |
self.directory_rules[norm_dir_path] = None |
- else: |
- self._ApplyDirectoryRulesAndSkipSubdirs(parent_rules, dir_path) |
return self.directory_rules[norm_dir_path] |
def _AddGitSourceDirectories(self): |