52
52
'silabs_docker' ,
53
53
])
54
54
55
- Module = namedtuple ('Module' , 'name path platforms' )
55
+ Module = namedtuple ('Module' , 'name path platforms recursive ' )
56
56
57
57
58
58
def load_module_info () -> None :
@@ -63,9 +63,11 @@ def load_module_info() -> None:
63
63
if name != 'DEFAULT' :
64
64
platforms = module .get ('platforms' , '' ).split (',' )
65
65
platforms = set (filter (None , platforms ))
66
- assert not (platforms - ALL_PLATFORMS ), "Submodule's platform not contained in ALL_PLATFORMS"
66
+ assert not (
67
+ platforms - ALL_PLATFORMS ), "Submodule's platform not contained in ALL_PLATFORMS"
68
+ recursive = module .getboolean ('recursive' , False )
67
69
name = name .replace ('submodule "' , '' ).replace ('"' , '' )
68
- yield Module (name = name , path = module ['path' ], platforms = platforms )
70
+ yield Module (name = name , path = module ['path' ], platforms = platforms , recursive = recursive )
69
71
70
72
71
73
def module_matches_platforms (module : Module , platforms : set ) -> bool :
@@ -88,8 +90,10 @@ def make_chip_root_safe_directory() -> None:
88
90
config .check_returncode ()
89
91
existing = config .stdout .split ('\0 ' )
90
92
if CHIP_ROOT not in existing :
91
- logging .info ("Adding CHIP_ROOT to global git safe.directory configuration" )
92
- subprocess .check_call (['git' , 'config' , '--global' , '--add' , 'safe.directory' , CHIP_ROOT ])
93
+ logging .info (
94
+ "Adding CHIP_ROOT to global git safe.directory configuration" )
95
+ subprocess .check_call (
96
+ ['git' , 'config' , '--global' , '--add' , 'safe.directory' , CHIP_ROOT ])
93
97
94
98
95
99
def checkout_modules (modules : list , shallow : bool , force : bool , recursive : bool , jobs : int ) -> None :
@@ -101,9 +105,21 @@ def checkout_modules(modules: list, shallow: bool, force: bool, recursive: bool,
101
105
cmd += ['--force' ] if force else []
102
106
cmd += ['--recursive' ] if recursive else []
103
107
cmd += ['--jobs' , f'{ jobs } ' ] if jobs else []
104
- cmd + = [module .path for module in modules ]
108
+ module_paths = [module .path for module in modules ]
105
109
106
- subprocess .check_call (cmd )
110
+ subprocess .check_call (cmd + module_paths )
111
+
112
+ if recursive :
113
+ # We've recursively checkouted all submodules.
114
+ pass
115
+ else :
116
+ # We've checkouted all top-level submodules.
117
+ # We're going to recursively checkout submodules whose recursive configuration is true.
118
+ cmd += ['--recursive' ]
119
+ module_paths = [module .path for module in modules if module .recursive ]
120
+
121
+ if module_paths :
122
+ subprocess .check_call (cmd + module_paths )
107
123
108
124
109
125
def deinit_modules (modules : list , force : bool ) -> None :
@@ -120,28 +136,35 @@ def deinit_modules(modules: list, force: bool) -> None:
120
136
def main ():
121
137
logging .basicConfig (format = '%(message)s' , level = logging .INFO )
122
138
123
- parser = argparse .ArgumentParser (description = 'Checkout or update relevant git submodules' )
139
+ parser = argparse .ArgumentParser (
140
+ description = 'Checkout or update relevant git submodules' )
124
141
parser .add_argument ('--allow-changing-global-git-config' , action = 'store_true' ,
125
142
help = 'Allow global git options to be modified if necessary, e.g. safe.directory' )
126
- parser .add_argument ('--shallow' , action = 'store_true' , help = 'Fetch submodules without history' )
143
+ parser .add_argument ('--shallow' , action = 'store_true' ,
144
+ help = 'Fetch submodules without history' )
127
145
parser .add_argument ('--platform' , nargs = '+' , choices = ALL_PLATFORMS , default = [],
128
146
help = 'Process submodules for specific platforms only' )
129
- parser .add_argument ('--force' , action = 'store_true' , help = 'Perform action despite of warnings' )
147
+ parser .add_argument ('--force' , action = 'store_true' ,
148
+ help = 'Perform action despite of warnings' )
130
149
parser .add_argument ('--deinit-unmatched' , action = 'store_true' ,
131
150
help = 'Deinitialize submodules for non-matching platforms' )
132
- parser .add_argument ('--recursive' , action = 'store_true' , help = 'Recursive init of the listed submodules' )
133
- parser .add_argument ('--jobs' , type = int , metavar = 'N' , help = 'Clone new submodules in parallel with N jobs' )
151
+ parser .add_argument ('--recursive' , action = 'store_true' ,
152
+ help = 'Recursive init of the listed submodules' )
153
+ parser .add_argument ('--jobs' , type = int , metavar = 'N' ,
154
+ help = 'Clone new submodules in parallel with N jobs' )
134
155
args = parser .parse_args ()
135
156
136
157
modules = list (load_module_info ())
137
158
selected_platforms = set (args .platform )
138
- selected_modules = [m for m in modules if module_matches_platforms (m , selected_platforms )]
159
+ selected_modules = [
160
+ m for m in modules if module_matches_platforms (m , selected_platforms )]
139
161
unmatched_modules = [m for m in modules if not module_matches_platforms (
140
162
m , selected_platforms ) and module_initialized (m )]
141
163
142
164
if args .allow_changing_global_git_config :
143
165
make_chip_root_safe_directory () # ignore directory ownership issues for sub-modules
144
- checkout_modules (selected_modules , args .shallow , args .force , args .recursive , args .jobs )
166
+ checkout_modules (selected_modules , args .shallow ,
167
+ args .force , args .recursive , args .jobs )
145
168
146
169
if args .deinit_unmatched and unmatched_modules :
147
170
deinit_modules (unmatched_modules , args .force )
0 commit comments