From 76ce73c726a47dcac33bcfe596b7d1c3cdf09236 Mon Sep 17 00:00:00 2001 From: "cmp@chromium.org" Date: Wed, 2 Jul 2014 00:13:18 +0000 Subject: [PATCH] Add fallback to DEPS from a missing deps file. It's possible to tell gclient to use a different "deps" file from the default DEPS through the "deps_file" variable in the .gclient file. If this file is missing, fallback to DEPS (the default). BUG=390700 Review URL: https://codereview.chromium.org/368713002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@280921 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 24 +++++++++++---- tests/gclient_smoketest.py | 2 ++ tests/gclient_test.py | 60 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/gclient.py b/gclient.py index 8d67b5a9e..50ebf9f3e 100755 --- a/gclient.py +++ b/gclient.py @@ -535,14 +535,26 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): deps_content = None use_strict = False - filepath = os.path.join(self.root.root_dir, self.name, self.deps_file) - if not os.path.isfile(filepath): + + # First try to locate the configured deps file. If it's missing, fallback + # to DEPS. + deps_files = [self.deps_file] + if 'DEPS' not in deps_files: + deps_files.append('DEPS') + for deps_file in deps_files: + filepath = os.path.join(self.root.root_dir, self.name, deps_file) + if os.path.isfile(filepath): + logging.info( + 'ParseDepsFile(%s): %s file found at %s', self.name, deps_file, + filepath) + break logging.info( - 'ParseDepsFile(%s): No %s file found at %s' % ( - self.name, self.deps_file, filepath)) - else: + 'ParseDepsFile(%s): No %s file found at %s', self.name, deps_file, + filepath) + + if os.path.isfile(filepath): deps_content = gclient_utils.FileRead(filepath) - logging.debug('ParseDepsFile(%s) read:\n%s' % (self.name, deps_content)) + logging.debug('ParseDepsFile(%s) read:\n%s', self.name, deps_content) use_strict = 'use strict' in deps_content.splitlines()[0] local_scope = {} diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index 046e2fe10..3c56da8f5 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -705,6 +705,8 @@ class GClientSmokeSVN(GClientSmokeBase): ' "deps_file" : "DEPS.alt",\n' ' "managed" : True,\n' ' "custom_deps" : {\n' + ' "foo/bar": None,\n' + ' "invalid": None,\n' ' "src/other2": \'%(base)s/other@2\',\n' ' },\n' ' "safesync_url": "",\n' diff --git a/tests/gclient_test.py b/tests/gclient_test.py index fb6577913..0d5b235a7 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -809,6 +809,66 @@ class GclientTest(trial_dir.TestCase): ], self._get_processed()) + def testGitDeps(self): + """Verifies gclient respects a .DEPS.git deps file. + + Along the way, we also test that if both DEPS and .DEPS.git are present, + that gclient does not read the DEPS file. This will reliably catch bugs + where gclient is always hitting the wrong file (DEPS). + """ + write( + '.gclient', + 'solutions = [\n' + ' { "name": "foo", "url": "svn://example.com/foo",\n' + ' "deps_file" : ".DEPS.git",\n' + ' },\n' + ']') + write( + os.path.join('foo', '.DEPS.git'), + 'deps = {\n' + ' "bar": "/bar",\n' + '}') + write( + os.path.join('foo', 'DEPS'), + 'deps = {\n' + ' "baz": "/baz",\n' + '}') + + options, _ = gclient.OptionParser().parse_args([]) + obj = gclient.GClient.LoadCurrentConfig(options) + obj.RunOnDeps('None', []) + self.assertEquals( + [ + 'svn://example.com/foo', + 'svn://example.com/foo/bar', + ], + self._get_processed()) + + def testGitDepsFallback(self): + """Verifies gclient respects fallback to DEPS upon missing deps file.""" + write( + '.gclient', + 'solutions = [\n' + ' { "name": "foo", "url": "svn://example.com/foo",\n' + ' "deps_file" : ".DEPS.git",\n' + ' },\n' + ']') + write( + os.path.join('foo', 'DEPS'), + 'deps = {\n' + ' "bar": "/bar",\n' + '}') + + options, _ = gclient.OptionParser().parse_args([]) + obj = gclient.GClient.LoadCurrentConfig(options) + obj.RunOnDeps('None', []) + self.assertEquals( + [ + 'svn://example.com/foo', + 'svn://example.com/foo/bar', + ], + self._get_processed()) + if __name__ == '__main__': sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)