|
26 | 26 | ManifestProject, _manifest_content_at, ManifestImportFailed |
27 | 27 | from west.manifest import is_group as is_project_group |
28 | 28 | from west.manifest import MANIFEST_REV_BRANCH as MANIFEST_REV |
| 29 | +from west.manifest import Submodule |
29 | 30 | from west.manifest import QUAL_MANIFEST_REV_BRANCH as QUAL_MANIFEST_REV |
30 | 31 | from west.manifest import QUAL_REFS_WEST as QUAL_REFS |
31 | 32 |
|
@@ -1160,23 +1161,43 @@ def update_submodules(self, project): |
1160 | 1161 | for config_opt in self.args.submodule_init_config: |
1161 | 1162 | config_opts.extend(['-c', config_opt]) |
1162 | 1163 |
|
1163 | | - # For the list type, update given list of submodules. |
1164 | | - if isinstance(submodules, list): |
1165 | | - for submodule in submodules: |
| 1164 | + cache_dir = self.project_cache(project) |
| 1165 | + # For the boolean type, update all the submodules. |
| 1166 | + if isinstance(submodules, bool): |
| 1167 | + if cache_dir is None: |
1166 | 1168 | if self.sync_submodules: |
1167 | | - project.git(['submodule', 'sync', '--recursive', |
1168 | | - '--', submodule.path]) |
| 1169 | + project.git(['submodule', 'sync', '--recursive']) |
1169 | 1170 | project.git(config_opts + |
1170 | | - ['submodule', 'update', |
1171 | | - '--init', submodules_update_strategy, |
1172 | | - '--recursive', submodule.path]) |
1173 | | - # For the bool type, update all project submodules |
1174 | | - elif isinstance(submodules, bool): |
| 1171 | + ['submodule', 'update', '--init', |
| 1172 | + submodules_update_strategy, '--recursive']) |
| 1173 | + return |
| 1174 | + else: |
| 1175 | + # Cache used so convert to a list so that --reference can be used. |
| 1176 | + res = project.git(['submodule', 'status'], capture_stdout=True) |
| 1177 | + if not res.stdout or res.returncode: |
| 1178 | + self.die( |
| 1179 | + f"Submodule status failed for project: {project.name}.") |
| 1180 | + mod_list = [s.strip() for s in res.stdout.decode('utf-8').split('\n') if s] |
| 1181 | + submodules = [Submodule(line.split(' ')[1]) for line in mod_list] |
| 1182 | + |
| 1183 | + # For the list type, update given list of submodules. |
| 1184 | + for submodule in submodules: |
1175 | 1185 | if self.sync_submodules: |
1176 | | - project.git(['submodule', 'sync', '--recursive']) |
| 1186 | + project.git(['submodule', 'sync', '--recursive', |
| 1187 | + '--', submodule.path]) |
| 1188 | + ref = [] |
| 1189 | + if (cache_dir): |
| 1190 | + submodule_ref = Path(cache_dir, submodule.path) |
| 1191 | + if any(os.scandir(submodule_ref)): |
| 1192 | + ref = ['--reference', os.fspath(submodule_ref)] |
| 1193 | + self.small_banner(f'using reference from: {submodule_ref}') |
| 1194 | + self.dbg( |
| 1195 | + f'found {submodule.path} in --path-cache {submodule_ref}', |
| 1196 | + level=Verbosity.DBG_MORE) |
1177 | 1197 | project.git(config_opts + |
1178 | | - ['submodule', 'update', '--init', |
1179 | | - submodules_update_strategy, '--recursive']) |
| 1198 | + ['submodule', 'update', |
| 1199 | + '--init', submodules_update_strategy, |
| 1200 | + '--recursive'] + ref + [submodule.path]) |
1180 | 1201 |
|
1181 | 1202 | def update(self, project): |
1182 | 1203 | if self.args.stats: |
|
0 commit comments