From b6eaed26fce285228743f626ccd8de1b5a26a6dd Mon Sep 17 00:00:00 2001 From: Aravind Vasudevan Date: Thu, 6 Jul 2023 20:50:42 +0000 Subject: [PATCH] Add git_dependencies flag to DEPS This change adds `git_dependencies` flag to the DEPS. This will be used to track the submodule migration state. Design Doc: go/depot-tools-on-submodules Change-Id: I547ad8ebbce2535960d4b6e00c0b14c00118f544 Bug: 1429149 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4591777 Reviewed-by: Josip Sokcevic Commit-Queue: Aravind Vasudevan --- gclient.py | 66 ++++++++++++++++++++++++++++++----------------- gclient_eval.py | 68 +++++++++++++++++++++++++++++++------------------ 2 files changed, 86 insertions(+), 48 deletions(-) diff --git a/gclient.py b/gclient.py index 60346178f2..5e326dfc49 100755 --- a/gclient.py +++ b/gclient.py @@ -401,9 +401,21 @@ class DependencySettings(object): class Dependency(gclient_utils.WorkItem, DependencySettings): """Object that represents a dependency checkout.""" - def __init__(self, parent, name, url, managed, custom_deps, - custom_vars, custom_hooks, deps_file, should_process, - should_recurse, relative, condition, protocol='https', + def __init__(self, + parent, + name, + url, + managed, + custom_deps, + custom_vars, + custom_hooks, + deps_file, + should_process, + should_recurse, + relative, + condition, + protocol='https', + git_dependencies_state=gclient_eval.DEPS, print_outbuf=False): gclient_utils.WorkItem.__init__(self, name) DependencySettings.__init__( @@ -479,6 +491,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): self.print_outbuf = print_outbuf self.protocol = protocol + self.git_dependencies_state = git_dependencies_state if not self.name and self.parent: raise gclient_utils.Error('Dependency without name') @@ -747,7 +760,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): should_recurse=name in self.recursedeps, relative=use_relative_paths, condition=condition, - protocol=self.protocol)) + protocol=self.protocol, + git_dependencies_state=self.git_dependencies_state)) # TODO(crbug.com/1341285): Understand why we need this and remove # it if we don't. @@ -790,6 +804,9 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): except SyntaxError as e: gclient_utils.SyntaxErrorToError(filepath, e) + if 'git_dependencies' in local_scope: + self.git_dependencies_state = local_scope['git_dependencies'] + if 'allowed_hosts' in local_scope: try: self._allowed_hosts = frozenset(local_scope.get('allowed_hosts')) @@ -1615,24 +1632,26 @@ it or fix the checkout. deps_to_add = [] for s in config_dict.get('solutions', []): try: - deps_to_add.append(GitDependency( - parent=self, - name=s['name'], - # Update URL with scheme in protocol_override - url=GitDependency.updateProtocol( - s['url'], s.get('protocol_override', None)), - managed=s.get('managed', True), - custom_deps=s.get('custom_deps', {}), - custom_vars=s.get('custom_vars', {}), - custom_hooks=s.get('custom_hooks', []), - deps_file=s.get('deps_file', 'DEPS'), - should_process=True, - should_recurse=True, - relative=None, - condition=None, - print_outbuf=True, - # Pass protocol_override down the tree for child deps to use. - protocol=s.get('protocol_override', None))) + deps_to_add.append( + GitDependency( + parent=self, + name=s['name'], + # Update URL with scheme in protocol_override + url=GitDependency.updateProtocol( + s['url'], s.get('protocol_override', None)), + managed=s.get('managed', True), + custom_deps=s.get('custom_deps', {}), + custom_vars=s.get('custom_vars', {}), + custom_hooks=s.get('custom_hooks', []), + deps_file=s.get('deps_file', 'DEPS'), + should_process=True, + should_recurse=True, + relative=None, + condition=None, + print_outbuf=True, + # Pass protocol_override down the tree for child deps to use. + protocol=s.get('protocol_override', None), + git_dependencies_state=self.git_dependencies_state)) except KeyError: raise gclient_utils.Error('Invalid .gclient file. Solution is ' 'incomplete: %s' % s) @@ -1966,7 +1985,8 @@ it or fix the checkout. should_recurse=False, relative=None, condition=None, - protocol=self.protocol)) + protocol=self.protocol, + git_dependencies_state=self.git_dependencies_state)) if modified_files and self._options.delete_unversioned_trees: print('\nWARNING: \'%s\' is no longer part of this client.\n' 'Despite running \'gclient sync -D\' no action was taken ' diff --git a/gclient_eval.py b/gclient_eval.py index 5571946c47..ac4f49bbb5 100644 --- a/gclient_eval.py +++ b/gclient_eval.py @@ -24,6 +24,13 @@ else: basestring = str +# git_dependencies migration states. Used within the DEPS file to indicate +# the current migration state. +DEPS = 'DEPS' +SYNC = 'SYNC' +SUBMODULES = 'SUBMODULES' + + class ConstantString(object): def __init__(self, value): self.value = value @@ -156,6 +163,11 @@ _GCLIENT_HOOKS_SCHEMA = [ _GCLIENT_SCHEMA = schema.Schema( _NodeDictSchema({ + # Current state of the git submodule migration. + # git_dependencies = [DEPS (default) | SUBMODULES | SYNC] + schema.Optional('git_dependencies'): + schema.Or(DEPS, SYNC, SUBMODULES), + # List of host names from which dependencies are allowed (allowlist). # NOTE: when not present, all hosts are allowed. # NOTE: scoped to current DEPS file, not recursive. @@ -169,21 +181,25 @@ _GCLIENT_SCHEMA = schema.Schema( # # Var(): allows variable substitution (either from 'vars' dict below, # or command-line override) - schema.Optional('deps'): _GCLIENT_DEPS_SCHEMA, + 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'): _NodeDictSchema({ + schema.Optional('deps_os'): + _NodeDictSchema({ schema.Optional(basestring): _GCLIENT_DEPS_SCHEMA, }), # Dependency to get gclient_gn_args* settings from. This allows these # values to be set in a recursedeps file, rather than requiring that # they exist in the top-level solution. - schema.Optional('gclient_gn_args_from'): basestring, + schema.Optional('gclient_gn_args_from'): + basestring, # Path to GN args file to write selected variables. - schema.Optional('gclient_gn_args_file'): basestring, + schema.Optional('gclient_gn_args_file'): + basestring, # Subset of variables to write to the GN args file (see above). schema.Optional('gclient_gn_args'): [schema.Optional(basestring)], @@ -191,12 +207,12 @@ _GCLIENT_SCHEMA = schema.Schema( # Hooks executed after gclient sync (unless suppressed), or explicitly # on gclient hooks. See _GCLIENT_HOOKS_SCHEMA for details. # Also see 'pre_deps_hooks'. - schema.Optional('hooks'): _GCLIENT_HOOKS_SCHEMA, + schema.Optional('hooks'): + _GCLIENT_HOOKS_SCHEMA, # Similar to 'hooks', also keyed by OS. - schema.Optional('hooks_os'): _NodeDictSchema({ - schema.Optional(basestring): _GCLIENT_HOOKS_SCHEMA - }), + schema.Optional('hooks_os'): + _NodeDictSchema({schema.Optional(basestring): _GCLIENT_HOOKS_SCHEMA}), # Rules which #includes are allowed in the directory. # Also see 'skip_child_includes' and 'specific_include_rules'. @@ -208,21 +224,22 @@ _GCLIENT_SCHEMA = schema.Schema( # will not inherit rules from //base/DEPS and //base/allocator/DEPS, # forcing each //base/allocator/partition_allocator/{foo,bar,...} to # declare all its dependencies. - schema.Optional('noparent'): bool, + schema.Optional('noparent'): + bool, # Hooks executed before processing DEPS. See 'hooks' for more details. - schema.Optional('pre_deps_hooks'): _GCLIENT_HOOKS_SCHEMA, + schema.Optional('pre_deps_hooks'): + _GCLIENT_HOOKS_SCHEMA, # Recursion limit for nested DEPS. - schema.Optional('recursion'): int, + schema.Optional('recursion'): + int, # Allowlists deps for which recursion should be enabled. schema.Optional('recursedeps'): [ - schema.Optional(schema.Or( - basestring, - (basestring, basestring), - [basestring, basestring] - )), + schema.Optional( + schema.Or(basestring, (basestring, basestring), + [basestring, basestring])), ], # Blocklists directories for checking 'include_rules'. @@ -230,9 +247,8 @@ _GCLIENT_SCHEMA = schema.Schema( # Mapping from paths to include rules specific for that path. # See 'include_rules' for more details. - schema.Optional('specific_include_rules'): _NodeDictSchema({ - schema.Optional(basestring): [basestring] - }), + schema.Optional('specific_include_rules'): + _NodeDictSchema({schema.Optional(basestring): [basestring]}), # List of additional OS names to consider when selecting dependencies # from deps_os. @@ -241,17 +257,19 @@ _GCLIENT_SCHEMA = schema.Schema( # For recursed-upon sub-dependencies, check out their own dependencies # relative to the parent's path, rather than relative to the .gclient # file. - schema.Optional('use_relative_paths'): bool, + schema.Optional('use_relative_paths'): + bool, # For recursed-upon sub-dependencies, run their hooks relative to the # parent's path instead of relative to the .gclient file. - schema.Optional('use_relative_hooks'): bool, + schema.Optional('use_relative_hooks'): + bool, # Variables that can be referenced using Var() - see 'deps'. - schema.Optional('vars'): _NodeDictSchema({ - schema.Optional(basestring): schema.Or(ConstantString, - basestring, - bool), + schema.Optional('vars'): + _NodeDictSchema({ + schema.Optional(basestring): + schema.Or(ConstantString, basestring, bool), }), }))