Skip to content

Commit e8ad320

Browse files
committed
[update-checkout] Allow the source root to be passed in instead of hard coding to SWIFT_SOURCE_ROOT.
This enables mocking testing to work (otherwise we would create repos in SWIFT_SOURCE_ROOT). SWIFT_SOURCE_ROOT is the default value so nothing changes unless one specifies the argument explicitly.
1 parent 15bcd23 commit e8ad320

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def get_branch_for_repo(config, repo_name, scheme_name, scheme_map,
8181
return repo_branch, cross_repo
8282

8383

84-
def update_single_repository(args):
85-
config, repo_name, scheme_name, scheme_map, tag, timestamp, \
86-
reset_to_remote, should_clean, cross_repos_pr = args
87-
repo_path = os.path.join(SWIFT_SOURCE_ROOT, repo_name)
84+
def update_single_repository(pool_args):
85+
source_root, config, repo_name, scheme_name, scheme_map, tag, timestamp, \
86+
reset_to_remote, should_clean, cross_repos_pr = pool_args
87+
repo_path = os.path.join(source_root, repo_name)
8888
if not os.path.isdir(repo_path):
8989
return
9090

@@ -175,7 +175,7 @@ def update_single_repository(args):
175175
def get_timestamp_to_match(args):
176176
if not args.match_timestamp:
177177
return None
178-
with shell.pushd(os.path.join(SWIFT_SOURCE_ROOT, "swift"),
178+
with shell.pushd(os.path.join(args.source_root, "swift"),
179179
dry_run=False, echo=False):
180180
return shell.capture(["git", "log", "-1", "--format=%cI"],
181181
echo=False).strip()
@@ -198,7 +198,7 @@ def update_all_repositories(args, config, scheme_name, cross_repos_pr):
198198
if repo_name in args.skip_repository_list:
199199
print("Skipping update of '" + repo_name + "', requested by user")
200200
continue
201-
my_args = [config,
201+
my_args = [args.source_root, config,
202202
repo_name,
203203
scheme_name,
204204
scheme_map,
@@ -220,7 +220,7 @@ def obtain_additional_swift_sources(pool_args):
220220
env = dict(os.environ)
221221
env.update({'GIT_TERMINAL_PROMPT': 0})
222222

223-
with shell.pushd(SWIFT_SOURCE_ROOT, dry_run=False, echo=False):
223+
with shell.pushd(args.source_root, dry_run=False, echo=False):
224224

225225
print("Cloning '" + repo_name + "'")
226226

@@ -236,14 +236,14 @@ def obtain_additional_swift_sources(pool_args):
236236
env=env,
237237
echo=True)
238238
if scheme_name:
239-
src_path = os.path.join(SWIFT_SOURCE_ROOT, repo_name, ".git")
239+
src_path = os.path.join(args.source_root, repo_name, ".git")
240240
shell.run(['git', '--git-dir',
241241
src_path, '--work-tree',
242-
os.path.join(SWIFT_SOURCE_ROOT, repo_name),
242+
os.path.join(args.source_root, repo_name),
243243
'checkout', repo_branch],
244244
env=env,
245245
echo=False)
246-
with shell.pushd(os.path.join(SWIFT_SOURCE_ROOT, repo_name),
246+
with shell.pushd(os.path.join(args.source_root, repo_name),
247247
dry_run=False, echo=False):
248248
shell.run(["git", "submodule",
249249
"update", "--recursive"],
@@ -255,7 +255,7 @@ def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,
255255
skip_history, skip_repository_list):
256256

257257
pool_args = []
258-
with shell.pushd(SWIFT_SOURCE_ROOT, dry_run=False, echo=False):
258+
with shell.pushd(args.source_root, dry_run=False, echo=False):
259259
for repo_name, repo_info in config['repos'].items():
260260
if repo_name in skip_repository_list:
261261
print("Skipping clone of '" + repo_name + "', requested by "
@@ -308,7 +308,7 @@ def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,
308308
args.n_processes)
309309

310310

311-
def dump_repo_hashes(config, branch_scheme_name='repro'):
311+
def dump_repo_hashes(args, config, branch_scheme_name='repro'):
312312
"""
313313
Dumps the current state of the repo into a new config file that contains a
314314
master branch scheme with the relevant branches set to the appropriate
@@ -319,17 +319,17 @@ def dump_repo_hashes(config, branch_scheme_name='repro'):
319319
for config_copy_key in config_copy_keys:
320320
new_config[config_copy_key] = config[config_copy_key]
321321
repos = {}
322-
repos = repo_hashes(config)
322+
repos = repo_hashes(args, config)
323323
branch_scheme = {'aliases': [branch_scheme_name], 'repos': repos}
324324
new_config['branch-schemes'] = {branch_scheme_name: branch_scheme}
325325
json.dump(new_config, sys.stdout, indent=4)
326326

327327

328-
def repo_hashes(config):
328+
def repo_hashes(args, config):
329329
repos = {}
330330
for repo_name, repo_info in sorted(config['repos'].items(),
331331
key=lambda x: x[0]):
332-
repo_path = os.path.join(SWIFT_SOURCE_ROOT, repo_name)
332+
repo_path = os.path.join(args.source_root, repo_name)
333333
if os.path.exists(repo_path):
334334
with shell.pushd(repo_path, dry_run=False, echo=False):
335335
h = shell.capture(["git", "rev-parse", "HEAD"],
@@ -340,8 +340,8 @@ def repo_hashes(config):
340340
return repos
341341

342342

343-
def print_repo_hashes(config):
344-
repos = repo_hashes(config)
343+
def print_repo_hashes(args, config):
344+
repos = repo_hashes(args, config)
345345
for repo_name, repo_hash in sorted(repos.items(),
346346
key=lambda x: x[0]):
347347
print("{:<35}: {:<35}".format(repo_name, repo_hash))
@@ -484,6 +484,11 @@ def main():
484484
help="Number of threads to run at once",
485485
default=0,
486486
dest="n_processes")
487+
parser.add_argument(
488+
"--source-root",
489+
help="The root directory to checkout repositories",
490+
default=SWIFT_SOURCE_ROOT,
491+
dest='source_root')
487492
args = parser.parse_args()
488493

489494
if not args.scheme:
@@ -513,7 +518,7 @@ def main():
513518
return (None, None)
514519

515520
if args.dump_hashes_config:
516-
dump_repo_hashes(config, args.dump_hashes_config)
521+
dump_repo_hashes(args, config, args.dump_hashes_config)
517522
return (None, None)
518523

519524
cross_repos_pr = {}
@@ -540,7 +545,7 @@ def main():
540545
skip_repo_list)
541546

542547
# Quick check whether somebody is calling update in an empty directory
543-
directory_contents = os.listdir(SWIFT_SOURCE_ROOT)
548+
directory_contents = os.listdir(args.source_root)
544549
if not ('cmark' in directory_contents or
545550
'llvm' in directory_contents or
546551
'clang' in directory_contents):
@@ -556,5 +561,5 @@ def main():
556561
print("update-checkout failed, fix errors and try again")
557562
else:
558563
print("update-checkout succeeded")
559-
print_repo_hashes(config)
564+
print_repo_hashes(args, config)
560565
sys.exit(fail_count)

0 commit comments

Comments
 (0)