From 27ca3a99b45d25b7af50a728dab63fa8303f0f74 Mon Sep 17 00:00:00 2001 From: "ilevy@chromium.org" Date: Wed, 17 Oct 2012 18:11:02 +0000 Subject: [PATCH] Add recursion=n syntax to DEPS files. This will let DEPS files specify a higher local bound for recursion. Note there is an edge case where a dependency can be initially pulled in with a lower recursion level and then gets ignored subsequently when a lower level DEPS overrides it's inclusion level and then includes the same dependency. I do not solve this case, as I am intending to use this syntax for top level deps files. BUG=155780 Review URL: https://chromiumcodereview.appspot.com/11146032 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@162464 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 10 +++++++++ tests/gclient_test.py | 52 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/gclient.py b/gclient.py index 9065952bd..ab52cc8ee 100644 --- a/gclient.py +++ b/gclient.py @@ -168,6 +168,10 @@ class DependencySettings(GClientKeywords): # recursion limit and controls gclient's behavior so it does not misbehave. self._managed = managed self._should_process = should_process + # This is a mutable value that overrides the normal recursion limit for this + # dependency. It is read from the actual DEPS file so cannot be set on + # class instantiation. + self.recursion_override = None # These are only set in .gclient and not in DEPS files. self._custom_vars = custom_vars or {} @@ -231,6 +235,8 @@ class DependencySettings(GClientKeywords): @property def recursion_limit(self): """Returns > 0 if this dependency is not too recursed to be processed.""" + if self.recursion_override is not None: + return self.recursion_override return max(self.parent.recursion_limit - 1, 0) def get_custom_deps(self, name, url): @@ -445,6 +451,10 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): except SyntaxError, e: gclient_utils.SyntaxErrorToError(filepath, e) deps = local_scope.get('deps', {}) + if 'recursion' in local_scope: + self.recursion_override = local_scope.get('recursion') + logging.warning( + 'Setting %s recursion to %d.', self.name, self.recursion_limit) # load os specific dependencies if defined. these dependencies may # override or extend the values defined by the 'deps' member. if 'deps_os' in local_scope: diff --git a/tests/gclient_test.py b/tests/gclient_test.py index 235ca54f5..801f784f1 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -306,7 +306,57 @@ class GclientTest(trial_dir.TestCase): obj = gclient.GClient.LoadCurrentConfig(options) self.assertEqual(['baz', 'unix'], sorted(obj.enforced_os)) - + + def testRecursionOverride(self): + """Verifies gclient respects the recursion var syntax. + + We check several things here: + - recursion = 3 sets recursion on the foo dep to exactly 3 + (we pull /fizz, but not /fuzz) + - pulling foo/bar at recursion level 1 (in .gclient) is overriden by + a later pull of foo/bar at recursion level 2 (in the dep tree) + """ + write( + '.gclient', + 'solutions = [\n' + ' { "name": "foo", "url": "svn://example.com/foo" },\n' + ' { "name": "foo/bar", "url": "svn://example.com/bar" },\n' + ']') + write( + os.path.join('foo', 'DEPS'), + 'deps = {\n' + ' "bar": "/bar",\n' + '}\n' + 'recursion = 3') + write( + os.path.join('bar', 'DEPS'), + 'deps = {\n' + ' "baz": "/baz",\n' + '}') + write( + os.path.join('baz', 'DEPS'), + 'deps = {\n' + ' "fizz": "/fizz",\n' + '}') + write( + os.path.join('fizz', 'DEPS'), + 'deps = {\n' + ' "fuzz": "/fuzz",\n' + '}') + + options, _ = gclient.Parser().parse_args([]) + obj = gclient.GClient.LoadCurrentConfig(options) + obj.RunOnDeps('None', []) + self.assertEquals( + [ + 'svn://example.com/foo', + 'svn://example.com/bar', + 'svn://example.com/foo/bar', + 'svn://example.com/foo/bar/baz', + 'svn://example.com/foo/bar/baz/fizz', + ], + self._get_processed()) + if __name__ == '__main__': sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)