Make the config -> pythonish conversion a gclient module function.

Also makes bot_update use this.

This allows for clank to manually set the gclient config.

BUG=590788

Review URL: https://codereview.chromium.org/1815863002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299398 0039d316-1c4b-4281-b951-d872f2087c98
parent 5b48e48c
......@@ -15,37 +15,6 @@ SVN_MASTERS = (
)
def jsonish_to_python(spec, is_top=False):
"""Turn a json spec into a python parsable object.
This exists because Gclient specs, while resembling json, is actually
ingested using a python "eval()". Therefore a bit of plumming is required
to turn our newly constructed Gclient spec into a gclient-readable spec.
"""
ret = ''
if is_top: # We're the 'top' level, so treat this dict as a suite.
ret = '\n'.join(
'%s = %s' % (k, jsonish_to_python(spec[k])) for k in sorted(spec)
)
else:
if isinstance(spec, dict):
ret += '{'
ret += ', '.join(
"%s: %s" % (repr(str(k)), jsonish_to_python(spec[k]))
for k in sorted(spec)
)
ret += '}'
elif isinstance(spec, list):
ret += '['
ret += ', '.join(jsonish_to_python(x) for x in spec)
ret += ']'
elif isinstance(spec, basestring):
ret = repr(str(spec))
else:
ret = repr(spec)
return ret
class BotUpdateApi(recipe_api.RecipeApi):
def __init__(self, mastername, buildername, slavename, issue, patchset,
......@@ -107,7 +76,6 @@ class BotUpdateApi(recipe_api.RecipeApi):
# We can re-use the gclient spec from the gclient module, since all the
# data bot_update needs is already configured into the gclient spec.
cfg = gclient_config or self.m.gclient.c
spec_string = jsonish_to_python(cfg.as_jsonish(), True)
# Used by bot_update to determine if we want to run or not.
master = self._mastername
......@@ -169,7 +137,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
['--slave', slave],
# 2. What do we want to check out (spec/root/rev/rev_map).
['--spec', spec_string],
['--spec', self.m.gclient.config_to_pythonish(cfg)],
['--root', root],
['--revision_mapping_file', self.m.json.input(rev_map)],
['--git-cache-dir', cfg.cache_dir],
......
......@@ -50,6 +50,12 @@ class ProjectRevisionResolver(RevisionResolver):
def jsonish_to_python(spec, is_top=False):
"""Turn a json spec into a python parsable object.
This exists because Gclient specs, while resembling json, is actually
ingested using a python "eval()". Therefore a bit of plumming is required
to turn our newly constructed Gclient spec into a gclient-readable spec.
"""
ret = ''
if is_top: # We're the 'top' level, so treat this dict as a suite.
ret = '\n'.join(
......@@ -131,6 +137,10 @@ class GclientApi(recipe_api.RecipeApi):
'CACHE_DIR': self.m.path['git_cache'],
}
@staticmethod
def config_to_pythonish(cfg):
return jsonish_to_python(cfg.as_jsonish(), True)
def resolve_revision(self, revision):
if hasattr(revision, 'resolve'):
return revision.resolve(self.m.properties)
......@@ -241,9 +251,7 @@ class GclientApi(recipe_api.RecipeApi):
if inject_parent_got_revision:
self.inject_parent_got_revision(cfg, override=True)
spec_string = jsonish_to_python(cfg.as_jsonish(), True)
self('setup', ['config', '--spec', spec_string], **kwargs)
self('setup', ['config', '--spec', self.config_to_pythonish(cfg)], **kwargs)
sync_step = None
try:
......
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