gclient: Fix getdep and setdep and add tests.

Bug: 843917, 839925
Change-Id: I84e52c95fc91d67375d4d954018f057561896914
Reviewed-on: https://chromium-review.googlesource.com/1064005
Reviewed-by: Aaron Gable <agable@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
changes/05/1064005/4
Edward Lemur 8 years ago committed by Commit Bot
parent 23a358764d
commit 4727c64750

@ -2727,9 +2727,8 @@ def CMDgetdep(parser, args):
'DEPS file %s does not exist.' % options.deps_file) 'DEPS file %s does not exist.' % options.deps_file)
with open(options.deps_file) as f: with open(options.deps_file) as f:
contents = f.read() contents = f.read()
local_scope = gclient_eval.Parse( local_scope = gclient_eval.Exec(
contents, expand_vars=True, validate_syntax=True, contents, expand_vars=True, filename=options.deps_file)
filename=options.deps_file)
for var in options.vars: for var in options.vars:
print(gclient_eval.GetVar(local_scope, var)) print(gclient_eval.GetVar(local_scope, var))
@ -2778,9 +2777,8 @@ def CMDsetdep(parser, args):
'DEPS file %s does not exist.' % options.deps_file) 'DEPS file %s does not exist.' % options.deps_file)
with open(options.deps_file) as f: with open(options.deps_file) as f:
contents = f.read() contents = f.read()
local_scope = gclient_eval.Parse( local_scope = gclient_eval.Exec(
contents, expand_vars=True, validate_syntax=True, contents, expand_vars=True, filename=options.deps_file)
filename=options.deps_file)
for var in options.vars: for var in options.vars:
name, _, value = var.partition('=') name, _, value = var.partition('=')

@ -1,4 +1,4 @@
No-op file. Edit this to kick recipes. (Did they do something wrong?) No-op file. Edit this to kick recipes.
This is a beginning of a story in this silly file. This is a beginning of a story in this silly file.
Once upon a time, a budding web browser dev team needed a CI system. Once upon a time, a budding web browser dev team needed a CI system.

@ -823,6 +823,68 @@ class GClientSmokeGIT(GClientSmokeBase):
}] }]
self.assertEqual(out, output_json) self.assertEqual(out, output_json)
def testSetDep(self):
fake_deps = os.path.join(self.root_dir, 'DEPS.fake')
with open(fake_deps, 'w') as f:
f.write('\n'.join([
'vars = { ',
' "foo_var": "foo_val",',
' "foo_rev": "foo_rev",',
'}',
'deps = {',
' "foo": {',
' "url": "url@{foo_rev}",',
' },',
' "bar": "url@bar_rev",',
'}',
]))
self.gclient([
'setdep', '-r', 'foo@new_foo', '-r', 'bar@new_bar',
'--var', 'foo_var=new_val', '--deps-file', fake_deps])
with open(fake_deps) as f:
contents = f.read().splitlines()
self.assertEqual([
'vars = { ',
' "foo_var": "new_val",',
' "foo_rev": "new_foo",',
'}',
'deps = {',
' "foo": {',
' "url": "url@{foo_rev}",',
' },',
' "bar": "url@new_bar",',
'}',
], contents)
def testGetDep(self):
fake_deps = os.path.join(self.root_dir, 'DEPS.fake')
with open(fake_deps, 'w') as f:
f.write('\n'.join([
'vars = { ',
' "foo_var": "foo_val",',
' "foo_rev": "foo_rev",',
'}',
'deps = {',
' "foo": {',
' "url": "url@{foo_rev}",',
' },',
' "bar": "url@bar_rev",',
'}',
]))
results = self.gclient([
'getdep', '-r', 'foo', '-r', 'bar','--var', 'foo_var',
'--deps-file', fake_deps])
self.assertEqual([
'foo_val',
'foo_rev',
'bar_rev',
], results[0].splitlines())
def testFlatten(self): def testFlatten(self):
if not self.enabled: if not self.enabled:
return return

Loading…
Cancel
Save