Skip to content

Commit 23138e5

Browse files
authored
Merge pull request #80837 from swiftlang/maxd/use-submodules
Add `--use-submodules` to `update_checkout` Not all repositories in `update-checkout-config.json` are tagged. For contributors that would like to achieve reproducible builds, it's useful to track exact state of checkouts with submodules. This also enables bisection scripts running across multiple repositories locally. New `--use-submodules` flag is added to `update-checkout`, which uses `git submodule add` instead of `git clone` when checking out new repositories. Contributors can then track changes to submodules in their own top-level repository if they wish to do so. The flag is optional and is not enabled by default.
2 parents 6cc65c5 + 32a7bd3 commit 23138e5

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def update_all_repositories(args, config, scheme_name, scheme_map, cross_repos_p
368368

369369
def obtain_additional_swift_sources(pool_args):
370370
(args, repo_name, repo_info, repo_branch, remote, with_ssh, scheme_name,
371-
skip_history, skip_tags, skip_repository_list) = pool_args
371+
skip_history, skip_tags, skip_repository_list, use_submodules) = pool_args
372372

373373
env = dict(os.environ)
374374
env.update({'GIT_TERMINAL_PROMPT': '0'})
@@ -383,6 +383,11 @@ def obtain_additional_swift_sources(pool_args):
383383
(['--no-tags'] if skip_tags else []),
384384
env=env,
385385
echo=True)
386+
elif use_submodules:
387+
shell.run(['git', 'submodule', 'add', remote, repo_name] +
388+
(['--no-tags'] if skip_tags else []),
389+
env=env,
390+
echo=True)
386391
else:
387392
shell.run(['git', 'clone', '--recursive', remote, repo_name] +
388393
(['--no-tags'] if skip_tags else []),
@@ -406,7 +411,7 @@ def obtain_additional_swift_sources(pool_args):
406411

407412
def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,
408413
skip_history, skip_tags,
409-
skip_repository_list):
414+
skip_repository_list, use_submodules):
410415

411416
pool_args = []
412417
with shell.pushd(args.source_root, dry_run=False, echo=False):
@@ -416,7 +421,20 @@ def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,
416421
"user")
417422
continue
418423

419-
if os.path.isdir(os.path.join(repo_name, ".git")):
424+
if use_submodules:
425+
repo_exists = False
426+
submodules_status = shell.capture(['git', 'submodule', 'status'],
427+
echo=False)
428+
if submodules_status:
429+
for line in submodules_status.splitlines():
430+
if line[0].endswith(repo_name):
431+
repo_exists = True
432+
break
433+
434+
else:
435+
repo_exists = os.path.isdir(os.path.join(repo_name, ".git"))
436+
437+
if repo_exists:
420438
print("Skipping clone of '" + repo_name + "', directory "
421439
"already exists")
422440
continue
@@ -450,16 +468,25 @@ def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,
450468
if repo_not_in_scheme:
451469
continue
452470

453-
pool_args.append([args, repo_name, repo_info, repo_branch, remote,
471+
472+
new_args = [args, repo_name, repo_info, repo_branch, remote,
454473
with_ssh, scheme_name, skip_history, skip_tags,
455-
skip_repository_list])
474+
skip_repository_list, use_submodules]
456475

457-
if not pool_args:
458-
print("Not cloning any repositories.")
459-
return
476+
if use_submodules:
477+
obtain_additional_swift_sources(new_args)
478+
else:
479+
pool_args.append(new_args)
460480

461-
return run_parallel(
462-
obtain_additional_swift_sources, pool_args, args.n_processes)
481+
# Only use `run_parallel` when submodules are not used, since `.git` dir
482+
# can't be accessed concurrently.
483+
if not use_submodules:
484+
if not pool_args:
485+
print("Not cloning any repositories.")
486+
return
487+
488+
return run_parallel(
489+
obtain_additional_swift_sources, pool_args, args.n_processes)
463490

464491

465492
def dump_repo_hashes(args, config, branch_scheme_name='repro'):
@@ -672,6 +699,10 @@ def main():
672699
help="The root directory to checkout repositories",
673700
default=SWIFT_SOURCE_ROOT,
674701
dest='source_root')
702+
parser.add_argument(
703+
"--use-submodules",
704+
help="Checkout repositories as git submodules.",
705+
action='store_true')
675706
args = parser.parse_args()
676707

677708
if not args.scheme:
@@ -693,6 +724,7 @@ def main():
693724
scheme_name = args.scheme
694725
github_comment = args.github_comment
695726
all_repos = args.all_repositories
727+
use_submodules = args.use_submodules
696728

697729
with open(args.config) as f:
698730
config = json.load(f)
@@ -726,7 +758,8 @@ def main():
726758
scheme_name,
727759
skip_history,
728760
skip_tags,
729-
skip_repo_list)
761+
skip_repo_list,
762+
use_submodules)
730763

731764
swift_repo_path = os.path.join(args.source_root, 'swift')
732765
if 'swift' not in skip_repo_list and os.path.exists(swift_repo_path):

0 commit comments

Comments
 (0)