Skip to content

Commit 19026ba

Browse files
committed
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 be able to track exact state of checkouts with submodules. New `--use-submodules` flag is added to `update-checkout`, which uses `git submodule add` instead of `git clone` when checking out new repositories.
1 parent 8eb43af commit 19026ba

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 42 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,23 @@ 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+
if not use_submodules:
482+
if not pool_args:
483+
print("Not cloning any repositories.")
484+
return
485+
486+
return run_parallel(
487+
obtain_additional_swift_sources, pool_args, args.n_processes)
463488

464489

465490
def dump_repo_hashes(args, config, branch_scheme_name='repro'):
@@ -672,6 +697,10 @@ def main():
672697
help="The root directory to checkout repositories",
673698
default=SWIFT_SOURCE_ROOT,
674699
dest='source_root')
700+
parser.add_argument(
701+
"--use-submodules",
702+
help="Checkout repositories as git submodules.",
703+
action='store_true')
675704
args = parser.parse_args()
676705

677706
if not args.scheme:
@@ -693,6 +722,7 @@ def main():
693722
scheme_name = args.scheme
694723
github_comment = args.github_comment
695724
all_repos = args.all_repositories
725+
use_submodules = args.use_submodules
696726

697727
with open(args.config) as f:
698728
config = json.load(f)
@@ -726,7 +756,8 @@ def main():
726756
scheme_name,
727757
skip_history,
728758
skip_tags,
729-
skip_repo_list)
759+
skip_repo_list,
760+
use_submodules)
730761

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

0 commit comments

Comments
 (0)