Commit 3ba2a7cf authored by Paweł Hajdan, Jr's avatar Paweł Hajdan, Jr Committed by Commit Bot

gclient config: add support for custom vars

Bug: 570091
Change-Id: I44da3366fe4aa91240f4b3076f53e27aa4a81806
Reviewed-on: https://chromium-review.googlesource.com/700498Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Paweł Hajdan Jr. <phajdan.jr@chromium.org>
parent d325eb34
...@@ -1214,6 +1214,7 @@ solutions = [ ...@@ -1214,6 +1214,7 @@ solutions = [
"managed" : %(managed)s, "managed" : %(managed)s,
"custom_deps" : { "custom_deps" : {
}, },
"custom_vars": %(custom_vars)r,
}, },
] ]
cache_dir = %(cache_dir)r cache_dir = %(cache_dir)r
...@@ -1375,13 +1376,14 @@ it or fix the checkout. ...@@ -1375,13 +1376,14 @@ it or fix the checkout.
return client return client
def SetDefaultConfig(self, solution_name, deps_file, solution_url, def SetDefaultConfig(self, solution_name, deps_file, solution_url,
managed=True, cache_dir=None): managed=True, cache_dir=None, custom_vars=None):
self.SetConfig(self.DEFAULT_CLIENT_FILE_TEXT % { self.SetConfig(self.DEFAULT_CLIENT_FILE_TEXT % {
'solution_name': solution_name, 'solution_name': solution_name,
'solution_url': solution_url, 'solution_url': solution_url,
'deps_file': deps_file, 'deps_file': deps_file,
'managed': managed, 'managed': managed,
'cache_dir': cache_dir, 'cache_dir': cache_dir,
'custom_vars': custom_vars or {},
}) })
def _SaveEntries(self): def _SaveEntries(self):
...@@ -2174,6 +2176,9 @@ def CMDconfig(parser, args): ...@@ -2174,6 +2176,9 @@ def CMDconfig(parser, args):
'to have the main solution untouched by gclient ' 'to have the main solution untouched by gclient '
'(gclient will check out unmanaged dependencies but ' '(gclient will check out unmanaged dependencies but '
'will never sync them)') 'will never sync them)')
parser.add_option('--custom-var', action='append', dest='custom_vars',
default=[],
help='overrides variables; key=value syntax')
parser.set_defaults(config_filename=None) parser.set_defaults(config_filename=None)
(options, args) = parser.parse_args(args) (options, args) = parser.parse_args(args)
if options.output_config_file: if options.output_config_file:
...@@ -2182,6 +2187,13 @@ def CMDconfig(parser, args): ...@@ -2182,6 +2187,13 @@ def CMDconfig(parser, args):
(not options.spec and not args)): (not options.spec and not args)):
parser.error('Inconsistent arguments. Use either --spec or one or 2 args') parser.error('Inconsistent arguments. Use either --spec or one or 2 args')
custom_vars = {}
for arg in options.custom_vars:
kv = arg.split('=', 1)
if len(kv) != 2:
parser.error('Invalid --custom-var argument: %r' % arg)
custom_vars[kv[0]] = gclient_eval.EvaluateCondition(kv[1], {})
client = GClient('.', options) client = GClient('.', options)
if options.spec: if options.spec:
client.SetConfig(options.spec) client.SetConfig(options.spec)
...@@ -2203,7 +2215,8 @@ def CMDconfig(parser, args): ...@@ -2203,7 +2215,8 @@ def CMDconfig(parser, args):
deps_file = options.deps_file deps_file = options.deps_file
client.SetDefaultConfig(name, deps_file, base_url, client.SetDefaultConfig(name, deps_file, base_url,
managed=not options.unmanaged, managed=not options.unmanaged,
cache_dir=options.cache_dir) cache_dir=options.cache_dir,
custom_vars=custom_vars)
client.SaveConfig() client.SaveConfig()
return 0 return 0
......
...@@ -200,6 +200,7 @@ class GClientSmoke(GClientSmokeBase): ...@@ -200,6 +200,7 @@ class GClientSmoke(GClientSmokeBase):
' "managed" : True,\n' ' "managed" : True,\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
' },\n' ' },\n'
' "custom_vars": {},\n'
' },\n' ' },\n'
']\n' ']\n'
'cache_dir = None\n') % self.git_base) 'cache_dir = None\n') % self.git_base)
...@@ -212,6 +213,7 @@ class GClientSmoke(GClientSmokeBase): ...@@ -212,6 +213,7 @@ class GClientSmoke(GClientSmokeBase):
' "managed" : True,\n' ' "managed" : True,\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
' },\n' ' },\n'
' "custom_vars": {},\n'
' },\n' ' },\n'
']\n' ']\n'
'cache_dir = None\n') % self.git_base) 'cache_dir = None\n') % self.git_base)
...@@ -224,6 +226,7 @@ class GClientSmoke(GClientSmokeBase): ...@@ -224,6 +226,7 @@ class GClientSmoke(GClientSmokeBase):
' "managed" : True,\n' ' "managed" : True,\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
' },\n' ' },\n'
' "custom_vars": {},\n'
' },\n' ' },\n'
']\n' ']\n'
'cache_dir = None\n') 'cache_dir = None\n')
...@@ -236,10 +239,26 @@ class GClientSmoke(GClientSmokeBase): ...@@ -236,10 +239,26 @@ class GClientSmoke(GClientSmokeBase):
' "managed" : True,\n' ' "managed" : True,\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
' },\n' ' },\n'
' "custom_vars": {},\n'
' },\n' ' },\n'
']\n' ']\n'
'cache_dir = None\n') 'cache_dir = None\n')
test(['config', self.git_base + 'src/',
'--custom-var', 'bool_var=True',
'--custom-var', 'str_var="abc"'],
('solutions = [\n'
' { "name" : "src",\n'
' "url" : "%ssrc",\n'
' "deps_file" : "DEPS",\n'
' "managed" : True,\n'
' "custom_deps" : {\n'
' },\n'
' "custom_vars": {\'bool_var\': True, \'str_var\': \'abc\'},\n'
' },\n'
']\n'
'cache_dir = None\n') % self.git_base)
test(['config', '--spec', '["blah blah"]'], '["blah blah"]') test(['config', '--spec', '["blah blah"]'], '["blah blah"]')
os.remove(p) os.remove(p)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment