@ -1717,171 +1717,128 @@ def CMDfetch(parser, args):
' --jobs= %d ' % options . jobs , ' --scm=git ' , ' git ' , ' fetch ' ] + args )
def CMDflatten ( parser , args ) :
""" Flattens the solutions into a single DEPS file. """
parser . add_option ( ' --output-deps ' , help = ' Path to the output DEPS file ' )
options , args = parser . parse_args ( args )
options . nohooks = True
client = GClient . LoadCurrentConfig ( options )
# Only print progress if we're writing to a file. Otherwise, progress updates
# could obscure intended output.
code = client . RunOnDeps ( ' flatten ' , args , progress = options . output_deps )
if code != 0 :
return code
allowed_hosts = set ( )
deps = { }
deps_os = { }
hooks = [ ]
hooks_os = { }
pre_deps_hooks = [ ]
for solution in client . dependencies :
_FlattenSolution (
solution , allowed_hosts , deps , deps_os , hooks , hooks_os , pre_deps_hooks )
flattened_deps = ' \n ' . join (
_GNSettingsToLines (
client . dependencies [ 0 ] . _gn_args_file ,
client . dependencies [ 0 ] . _gn_args ) +
_AllowedHostsToLines ( allowed_hosts ) +
_DepsToLines ( deps ) +
_DepsOsToLines ( deps_os ) +
_HooksToLines ( ' hooks ' , hooks ) +
_HooksToLines ( ' pre_deps_hooks ' , pre_deps_hooks ) +
_HooksOsToLines ( hooks_os ) +
[ ' ' ] # Ensure newline at end of file.
)
if options . output_deps :
with open ( options . output_deps , ' w ' ) as f :
f . write ( flattened_deps )
else :
print ( flattened_deps )
return 0
def _FlattenSolution (
solution , allowed_hosts , deps , deps_os , hooks , hooks_os , pre_deps_hooks ) :
""" Visits a solution in order to flatten it (see CMDflatten).
Arguments :
solution ( Dependency ) : one of top - level solutions in . gclient
Out - parameters :
allowed_hosts ( set of host names ) : host names from which
dependencies are allowed ( whitelist )
deps ( dict of name - > Dependency ) : will be filled with all Dependency
objects indexed by their name
deps_os ( dict of os name - > dep name - > Dependency ) : same as above ,
for OS - specific deps
hooks ( list of ( Dependency , hook ) ) : will be filled with flattened hooks
hooks_os ( dict of os name - > list of ( Dependency , hook ) ) : same as above ,
for OS - specific hooks
pre_deps_hooks ( list of ( Dependency , hook ) ) : will be filled with flattened
pre_deps_hooks
"""
logging . debug ( ' _FlattenSolution( %r ) ' , solution )
_FlattenDep ( solution , allowed_hosts , deps , deps_os , hooks , hooks_os ,
pre_deps_hooks )
_FlattenRecurse ( solution , allowed_hosts , deps , deps_os , hooks , hooks_os ,
pre_deps_hooks )
class Flattener ( object ) :
""" Flattens a gclient solution. """
def __init__ ( self , client ) :
""" Constructor.
def _FlattenDep ( dep , allowed_hosts , deps , deps_os , hooks , hooks_os ,
pre_deps_hooks ) :
""" Visits a dependency in order to flatten it (see CMDflatten).
Arguments :
client ( GClient ) : client to flatten
"""
self . _client = client
Arguments :
dep ( Dependency ) : dependency to process
self . _deps_string = None
Out - parameters :
allowed_hosts ( set ) : will be filled with flattened allowed_hosts
deps ( dict ) : will be filled with flattened deps
deps_os ( dict ) : will be filled with flattened deps_os
hooks ( list ) : will be filled with flattened hooks
hooks_os ( dict ) : will be filled with flattened hooks_os
pre_deps_hooks ( list ) : will be filled with flattened pre_deps_hooks
"""
logging . debug ( ' _FlattenDep( %r ) ' , dep )
self . _allowed_hosts = set ( )
self . _deps = { }
self . _deps_os = { }
self . _hooks = [ ]
self . _hooks_os = { }
self . _pre_deps_hooks = [ ]
_AddDep ( dep , allowed_hosts , deps )
self . _flatten ( )
_FlattenDepsOs ( dep , deps_os )
@property
def deps_string ( self ) :
assert self . _deps_string is not None
return self . _deps_string
def _flatten ( self ) :
""" Runs the flattener. Saves resulting DEPS string. """
for solution in self . _client . dependencies :
self . _flatten_solution ( solution )
self . _deps_string = ' \n ' . join (
_GNSettingsToLines (
self . _client . dependencies [ 0 ] . _gn_args_file ,
self . _client . dependencies [ 0 ] . _gn_args ) +
_AllowedHostsToLines ( self . _allowed_hosts ) +
_DepsToLines ( self . _deps ) +
_DepsOsToLines ( self . _deps_os ) +
_HooksToLines ( ' hooks ' , self . _hooks ) +
_HooksToLines ( ' pre_deps_hooks ' , self . _pre_deps_hooks ) +
_HooksOsToLines ( self . _hooks_os ) +
[ ' ' ] ) # Ensure newline at end of file.
def _flatten_solution ( self , solution ) :
""" Visits a solution in order to flatten it (see CMDflatten).
deps_by_name = dict ( ( d . name , d ) for d in dep . dependencies )
for recurse_dep_name in ( dep . recursedeps or [ ] ) :
_FlattenRecurse (
deps_by_name [ recurse_dep_name ] , allowed_hosts , deps , deps_os , hooks ,
hooks_os , pre_deps_hooks )
Arguments :
solution ( Dependency ) : one of top - level solutions in . gclient
"""
self . _flatten_dep ( solution )
self . _flatten_recurse ( solution )
hooks . extend ( [ ( dep , hook ) for hook in dep . orig_deps_hooks ] )
pre_deps_hooks . extend ( [ ( dep , hook ) for hook in dep . pre_deps_hooks ] )
def _flatten_dep ( self , dep ) :
""" Visits a dependency in order to flatten it (see CMDflatten).
for hook_os , os_hooks in dep . os_deps_hooks . iteritems ( ) :
hooks_os . setdefault ( hook_os , [ ] ) . extend ( [ ( dep , hook ) for hook in os_hooks ] )
Arguments :
dep ( Dependency ) : dependency to process
"""
self . _allowed_hosts . update ( dep . allowed_hosts )
assert dep . name not in self . _deps
self . _deps [ dep . name ] = dep
def _FlattenRecurse ( dep , allowed_hosts , deps , deps_os , hooks , hooks_os ,
pre_deps_hooks ) :
""" Helper for flatten that recurses into |dep| ' s dependencies.
self . _hooks . extend ( [ ( dep , hook ) for hook in dep . orig_deps_hooks ] )
self . _pre_deps_hooks . extend ( [ ( dep , hook ) for hook in dep . pre_deps_hooks ] )
Arguments :
dep ( Dependency ) : dependency to process
for hook_os , os_hooks in dep . os_deps_hooks . iteritems ( ) :
self . _hooks_os . setdefault ( hook_os , [ ] ) . extend (
[ ( dep , hook ) for hook in os_hooks ] )
Out - parameters :
allowed_hosts ( set ) : will be filled with flattened allowed_hosts
deps ( dict ) : will be filled with flattened deps
deps_os ( dict ) : will be filled with flattened deps_os
hooks ( list ) : will be filled with flattened hooks
hooks_os ( dict ) : will be filled with flattened hooks_os
pre_deps_hooks ( list ) : will be filled with flattened pre_deps_hooks
"""
logging . debug ( ' _FlattenRecurse( %r ) ' , dep )
self . _add_deps_os ( dep )
_FlattenDepsOs ( dep , deps_os )
deps_by_name = dict ( ( d . name , d ) for d in dep . dependencies )
for recurse_dep_name in ( dep . recursedeps or [ ] ) :
self . _flatten_recurse ( deps_by_name [ recurse_dep_name ] )
for sub_dep in dep . orig_dependencies :
_FlattenDep ( sub_dep , allowed_hosts , deps , deps_os , hooks , hooks_os ,
pre_deps_hooks )
def _flatten_recurse ( self , dep ) :
""" Helper for flatten that recurses into |dep| ' s dependencies.
Arguments :
dep ( Dependency ) : dependency to process
"""
self . _add_deps_os ( dep )
def _FlattenDepsOs ( dep , deps_os ) :
""" Helper to add a dependency to flattened lists.
for sub_dep in dep . orig_dependencies :
self . _flatten_dep ( sub_dep )
Arguments :
dep ( Dependency ) : dependency to process
def _add_deps_os ( self , dep ) :
""" Helper for flatten that collects deps_os from |dep|.
Out - parameters :
deps_os ( dict ) : will be filled with flattened deps_os
"""
logging . debug ( ' _FlattenDepsOs( %r ) ' , dep )
Arguments :
dep ( Dependency ) : dependency to process
"""
for dep_os , os_deps in dep . os_dependencies . iteritems ( ) :
for os_dep in os_deps :
self . _deps_os . setdefault ( dep_os , { } ) [ os_dep . name ] = os_dep
for dep_os , os_deps in dep . os_dependencies . iteritems ( ) :
for os_dep in os_deps :
deps_os . setdefault ( dep_os , { } ) [ os_dep . name ] = os_dep
def CMDflatten ( parser , args ) :
""" Flattens the solutions into a single DEPS file. """
parser . add_option ( ' --output-deps ' , help = ' Path to the output DEPS file ' )
options , args = parser . parse_args ( args )
def _AddDep ( dep , allowed_hosts , deps ) :
""" Helper to add a dependency to flattened lists.
options . nohooks = True
client = GClient . LoadCurrentConfig ( options )
Arguments :
dep ( Dependency ) : dependency to process
# Only print progress if we're writing to a file. Otherwise, progress updates
# could obscure intended output.
code = client . RunOnDeps ( ' flatten ' , args , progress = options . output_deps )
if code != 0 :
return code
Out - parameters :
allowed_hosts ( set ) : will be filled with flattened allowed_hosts
deps ( dict ) : will be filled with flattened deps
"""
logging . debug ( ' _AddDep( %r ) ' , dep )
flattener = Flattener ( client )
allowed_hosts . update ( dep . allowed_hosts )
if options . output_deps :
with open ( options . output_deps , ' w ' ) as f :
f . write ( flattener . deps_string )
else :
print ( flattener . deps_string )
assert dep . name not in deps
deps [ dep . name ] = dep
return 0
def _GNSettingsToLines ( gn_args_file , gn_args ) :