From ad30de63893abcb18f4cc1d031dcc5096723fedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Hajdan=2C=20Jr?= Date: Mon, 26 Jun 2017 18:51:58 +0200 Subject: [PATCH] gclient flatten: syntax and schema fixes from actual testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: 570091 Change-Id: Iae9dad68a75d751ceac6379baac588f32c59aa06 Reviewed-on: https://chromium-review.googlesource.com/548935 Reviewed-by: Michael Moss Commit-Queue: Paweł Hajdan Jr. --- gclient.py | 14 +++++++++++-- gclient_eval.py | 35 ++++++++++++++++--------------- tests/gclient_smoketest.py | 43 +++++++++++++++----------------------- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/gclient.py b/gclient.py index 72c1e0484a..380a2e7a84 100755 --- a/gclient.py +++ b/gclient.py @@ -1864,7 +1864,17 @@ def _DepsOsToLines(deps_os): s = ['deps_os = {'] for dep_os, os_deps in sorted(deps_os.iteritems()): s.append(' "%s": {' % dep_os) - s.extend([' %s' % l for l in _DepsToLines(os_deps)]) + for name, dep in sorted(os_deps.iteritems()): + condition_part = ([' "condition": "%s",' % dep.condition] + if dep.condition else []) + s.extend([ + ' # %s' % dep.hierarchy(include_url=False), + ' "%s": {' % (name,), + ' "url": "%s",' % (dep.url,), + ] + condition_part + [ + ' },', + '', + ]) s.extend([' },', '']) s.extend(['}', '']) return s @@ -1884,7 +1894,7 @@ def _HooksToLines(name, hooks): s.append(' "pattern": "%s",' % hook.pattern) s.extend( # Hooks run in the parent directory of their dep. - [' "cwd": "%s"' % os.path.normpath(os.path.dirname(dep.name))] + + [' "cwd": "%s",' % os.path.normpath(os.path.dirname(dep.name))] + [' "action": ['] + [' "%s",' % arg for arg in hook.action] + [' ]', ' },', ''] diff --git a/gclient_eval.py b/gclient_eval.py index 2ce4f9cb22..c1dee2aeed 100644 --- a/gclient_eval.py +++ b/gclient_eval.py @@ -9,6 +9,22 @@ from third_party import schema # See https://github.com/keleshev/schema for docs how to configure schema. +_GCLIENT_DEPS_SCHEMA = { + schema.Optional(basestring): schema.Or( + None, + basestring, + { + # Repo and revision to check out under the path + # (same as if no dict was used). + 'url': basestring, + + # Optional condition string. The dep will only be processed + # if the condition evaluates to True. + schema.Optional('condition'): basestring, + }, + ), +} + _GCLIENT_HOOKS_SCHEMA = [{ # Hook action: list of command-line arguments to invoke. 'action': [basestring], @@ -43,27 +59,12 @@ _GCLIENT_SCHEMA = schema.Schema({ # # Var(): allows variable substitution (either from 'vars' dict below, # or command-line override) - schema.Optional('deps'): { - schema.Optional(basestring): schema.Or( - basestring, - { - # Repo and revision to check out under the path - # (same as if no dict was used). - 'url': basestring, - - # Optional condition string. The dep will only be processed - # if the condition evaluates to True. - schema.Optional('condition'): basestring, - }, - ), - }, + schema.Optional('deps'): _GCLIENT_DEPS_SCHEMA, # Similar to 'deps' (see above) - also keyed by OS (e.g. 'linux'). # Also see 'target_os'. schema.Optional('deps_os'): { - schema.Optional(basestring): { - schema.Optional(basestring): schema.Or(basestring, None) - } + schema.Optional(basestring): _GCLIENT_DEPS_SCHEMA, }, # Path to GN args file to write selected variables. diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index bf59678af8..8fefd4c41f 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -609,36 +609,27 @@ class GClientSmokeGIT(GClientSmokeBase): '', 'deps_os = {', ' "mac": {', - ' deps = {', - ' # src -> src/mac_repo', - ' "src/mac_repo": {', - ' "url": "/repo_5",', - ' },', - ' ', - ' }', - ' ', + ' # src -> src/mac_repo', + ' "src/mac_repo": {', + ' "url": "/repo_5",', + ' },', + '', ' },', '', ' "unix": {', - ' deps = {', - ' # src -> src/unix_repo', - ' "src/unix_repo": {', - ' "url": "/repo_5",', - ' },', - ' ', - ' }', - ' ', + ' # src -> src/unix_repo', + ' "src/unix_repo": {', + ' "url": "/repo_5",', + ' },', + '', ' },', '', ' "win": {', - ' deps = {', - ' # src -> src/win_repo', - ' "src/win_repo": {', - ' "url": "/repo_5",', - ' },', - ' ', - ' }', - ' ', + ' # src -> src/win_repo', + ' "src/win_repo": {', + ' "url": "/repo_5",', + ' },', + '', ' },', '', '}', @@ -647,7 +638,7 @@ class GClientSmokeGIT(GClientSmokeBase): ' # src', ' {', ' "pattern": ".",', - ' "cwd": "."', + ' "cwd": ".",', ' "action": [', ' "python",', ' "-c",', @@ -658,7 +649,7 @@ class GClientSmokeGIT(GClientSmokeBase): ' # src', ' {', ' "pattern": "nonexistent",', - ' "cwd": "."', + ' "cwd": ".",', ' "action": [', ' "python",', ' "-c",',