From 8d3925b164822e2660d3b985402a5681432b0285 Mon Sep 17 00:00:00 2001 From: Joey Scarr Date: Sun, 15 Jul 2018 23:36:25 +0000 Subject: [PATCH] Add support to gclient for skipping CIPD deps. I want to use this in the Codesearch builder to replace the hack in crrev.com/c/1126693. Bug: 860397 Change-Id: I174a684cbff0f993b5c657bc2e32105cb49d253a Reviewed-on: https://chromium-review.googlesource.com/1132266 Commit-Queue: Joey Scarr Reviewed-by: Aaron Gable Reviewed-by: Edward Lesmes --- gclient.py | 6 ++++ tests/gclient_test.py | 84 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/gclient.py b/gclient.py index 2d3bdd1961..9e58342f74 100755 --- a/gclient.py +++ b/gclient.py @@ -604,6 +604,10 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): should_process = should_process and gclient_eval.EvaluateCondition( condition, self.get_vars()) + # The following option is only set by the 'revinfo' command. + if self._get_option('ignore_dep_type', None) == dep_type: + continue + if dep_type == 'cipd': cipd_root = self.GetCipdRoot() for package in dep_value.get('packages', []): @@ -2711,6 +2715,8 @@ def CMDrevinfo(parser, args): parser.add_option('--output-json', help='Output a json document to this path containing ' 'information about the revisions.') + parser.add_option('--ignore-dep-type', choices=['git', 'cipd'], + help='Specify to skip processing of a certain type of dep.') (options, args) = parser.parse_args(args) client = GClient.LoadCurrentConfig(options) if not client: diff --git a/tests/gclient_test.py b/tests/gclient_test.py index 3919e64910..47c41cfbd9 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -872,6 +872,48 @@ class GclientTest(trial_dir.TestCase): ], self._get_processed()) + def testIgnoresGitDependenciesWhenFlagIsSet(self): + """Verifies that git deps are ignored if --ignore-dep-type git is set.""" + write( + '.gclient', + 'solutions = [\n' + ' { "name": "foo", "url": "https://example.com/foo",\n' + ' "deps_file" : ".DEPS.git",\n' + ' },\n' + ']') + write( + os.path.join('foo', 'DEPS'), + 'vars = {\n' + ' "lemur_version": "version:1234",\n' + '}\n' + 'deps = {\n' + ' "bar": "/bar",\n' + ' "baz": {\n' + ' "packages": [{\n' + ' "package": "lemur",\n' + ' "version": Var("lemur_version"),\n' + ' }],\n' + ' "dep_type": "cipd",\n' + ' }\n' + '}') + options, _ = gclient.OptionParser().parse_args([]) + options.ignore_dep_type = 'git' + options.validate_syntax = True + obj = gclient.GClient.LoadCurrentConfig(options) + + self.assertEquals(1, len(obj.dependencies)) + sol = obj.dependencies[0] + sol._condition = 'some_condition' + + sol.ParseDepsFile() + self.assertEquals(1, len(sol.dependencies)) + dep = sol.dependencies[0] + + self.assertIsInstance(dep, gclient.CipdDependency) + self.assertEquals( + 'https://chrome-infra-packages.appspot.com/lemur@version:1234', + dep.url) + def testDepsFromNotAllowedHostsUnspecified(self): """Verifies gclient works fine with DEPS without allowed_hosts.""" write( @@ -991,7 +1033,7 @@ class GclientTest(trial_dir.TestCase): self._get_processed() def testCreatesCipdDependencies(self): - """Verifies something.""" + """Verifies that CIPD deps are created correctly.""" write( '.gclient', 'solutions = [\n' @@ -1030,6 +1072,46 @@ class GclientTest(trial_dir.TestCase): 'https://chrome-infra-packages.appspot.com/lemur@version:1234', dep.url) + def testIgnoresCipdDependenciesWhenFlagIsSet(self): + """Verifies that CIPD deps are ignored if --ignore-dep-type cipd is set.""" + write( + '.gclient', + 'solutions = [\n' + ' { "name": "foo", "url": "https://example.com/foo",\n' + ' "deps_file" : ".DEPS.git",\n' + ' },\n' + ']') + write( + os.path.join('foo', 'DEPS'), + 'vars = {\n' + ' "lemur_version": "version:1234",\n' + '}\n' + 'deps = {\n' + ' "bar": "/bar",\n' + ' "baz": {\n' + ' "packages": [{\n' + ' "package": "lemur",\n' + ' "version": Var("lemur_version"),\n' + ' }],\n' + ' "dep_type": "cipd",\n' + ' }\n' + '}') + options, _ = gclient.OptionParser().parse_args([]) + options.ignore_dep_type = 'cipd' + options.validate_syntax = True + obj = gclient.GClient.LoadCurrentConfig(options) + + self.assertEquals(1, len(obj.dependencies)) + sol = obj.dependencies[0] + sol._condition = 'some_condition' + + sol.ParseDepsFile() + self.assertEquals(1, len(sol.dependencies)) + dep = sol.dependencies[0] + + self.assertIsInstance(dep, gclient.GitDependency) + self.assertEquals('https://example.com/bar', dep.url) + def testSameDirAllowMultipleCipdDeps(self): """Verifies gclient allow multiple cipd deps under same directory.""" parser = gclient.OptionParser()