From 375aa58877e88f94d45b1af03381680b834122e8 Mon Sep 17 00:00:00 2001 From: "martiniss@chromium.org" Date: Fri, 18 Mar 2016 23:19:30 +0000 Subject: [PATCH] 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 --- recipe_modules/bot_update/api.py | 34 +------------------------------- recipe_modules/gclient/api.py | 14 ++++++++++--- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/recipe_modules/bot_update/api.py b/recipe_modules/bot_update/api.py index 26367bb85..2b64807e5 100644 --- a/recipe_modules/bot_update/api.py +++ b/recipe_modules/bot_update/api.py @@ -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], diff --git a/recipe_modules/gclient/api.py b/recipe_modules/gclient/api.py index 558e9d9c5..2d9ed949f 100644 --- a/recipe_modules/gclient/api.py +++ b/recipe_modules/gclient/api.py @@ -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: