diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-06 17:26:36 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-06 17:26:36 +0000 |
commit | 7c7503390271018572571ca67acc0fb6ab417d62 (patch) | |
tree | ed4b5114be40c96769f2221be9c90faf6f3965e0 /tools | |
parent | 4c032ee0623ddd773d97ee99d907670b374fcca8 (diff) | |
download | chromium_src-7c7503390271018572571ca67acc0fb6ab417d62.zip chromium_src-7c7503390271018572571ca67acc0fb6ab417d62.tar.gz chromium_src-7c7503390271018572571ca67acc0fb6ab417d62.tar.bz2 |
Fix a bug in checkdeps due to a shallow copy.
Add regression test that now passes and would have caught the bug.
Kudos to jam@ for spotting the symptoms of the bug, which primarily
would manifest when specific_include_rules are being used, and only (I
think) when running presubmit or doing checkdeps for a specific
directory since in that case rules get built up in child->parent order
rather than the parent->child order that the normal checkdeps run
would use.
BUG=None
Review URL: https://chromiumcodereview.appspot.com/11440013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171516 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/checkdeps/checkdeps.py | 2 | ||||
-rwxr-xr-x | tools/checkdeps/checkdeps_test.py | 23 | ||||
-rw-r--r-- | tools/checkdeps/testdata/allowed/DEPS | 1 | ||||
-rw-r--r-- | tools/checkdeps/testdata/disallowed/foo_unittest.cc | 10 |
4 files changed, 35 insertions, 1 deletions
diff --git a/tools/checkdeps/checkdeps.py b/tools/checkdeps/checkdeps.py index b7b109a..8333ef6 100755 --- a/tools/checkdeps/checkdeps.py +++ b/tools/checkdeps/checkdeps.py @@ -178,7 +178,7 @@ class DepsChecker(object): Returns: A new set of rules combining the existing_rules with the other arguments. """ - rules = copy.copy(existing_rules) + rules = copy.deepcopy(existing_rules) # First apply the implicit "allow" rule for the current directory. if cur_dir.startswith( diff --git a/tools/checkdeps/checkdeps_test.py b/tools/checkdeps/checkdeps_test.py index 2ce80fa..e8835a5 100755 --- a/tools/checkdeps/checkdeps_test.py +++ b/tools/checkdeps/checkdeps_test.py @@ -149,6 +149,29 @@ class CheckDepsTest(unittest.TestCase): ]]) self.failUnless(problems) + def testCopyIsDeep(self): + # Regression test for a bug where we were making shallow copies of + # Rules objects and therefore all Rules objects shared the same + # dictionary for specific rules. + # + # The first pair should bring in a rule from testdata/allowed/DEPS + # into that global dictionary that allows the + # temp_allowed_for_tests.h file to be included in files ending + # with _unittest.cc, and the second pair should completely fail + # once the bug is fixed, but succeed (with a temporary allowance) + # if the bug is in place. + problems = self.deps_checker.CheckAddedCppIncludes( + [['tools/checkdeps/testdata/allowed/test.cc', + ['#include "tools/checkdeps/testdata/disallowed/temporarily_allowed.h"'] + ], + ['tools/checkdeps/testdata/disallowed/foo_unittest.cc', + ['#include "tools/checkdeps/testdata/bongo/temp_allowed_for_tests.h"'] + ]]) + # With the bug in place, there would be two problems reported, and + # the second would be for foo_unittest.cc. + self.failUnless(len(problems) == 1) + self.failUnless(problems[0][0].endswith('/test.cc')) + if __name__ == '__main__': unittest.main() diff --git a/tools/checkdeps/testdata/allowed/DEPS b/tools/checkdeps/testdata/allowed/DEPS index 362623c..8fb0905 100644 --- a/tools/checkdeps/testdata/allowed/DEPS +++ b/tools/checkdeps/testdata/allowed/DEPS @@ -7,5 +7,6 @@ include_rules = [ specific_include_rules = { ".*_unittest\.cc": [ "+tools/checkdeps/testdata/disallowed/teststuff", + "!tools/checkdeps/testdata/bongo/temp_allowed_for_tests.h", ] } diff --git a/tools/checkdeps/testdata/disallowed/foo_unittest.cc b/tools/checkdeps/testdata/disallowed/foo_unittest.cc new file mode 100644 index 0000000..144c05e --- /dev/null +++ b/tools/checkdeps/testdata/disallowed/foo_unittest.cc @@ -0,0 +1,10 @@ +// 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. + +// Not allowed for code under disallowed/ but temporarily allowed +// specifically for test code under allowed/. This regression tests a +// bug where we were taking shallow copies of rules when generating +// rules for subdirectories, so all rule objects were getting the same +// dictionary for specific rules. +#include "tools/checkdeps/testdata/disallowed/temp_allowed_for_tests.h" |