Skip to content

Commit

Permalink
[update-checkout] Change dump-hashes to dump a update-checkout config…
Browse files Browse the repository at this point in the history
… file rather than a textual dump format.

Previously -dump-hashes dumped the current state of the hashes in a format like
the following:

$REPO_NAME $HASH $SUBJECT

While this dumps the relevant information, it is not machine parseable. Instead
in this commit, we dump out the hashes into a update-checkout config json file
with a scheme name of repro. Thus to reproduce the current repository state on
someone else's machine, you don't need to type in the exact hashes. Instead, one
can just do:

```
$ ./swift/utils/update-checkout -dump-hashes > repro.json
```

and then give the repro.json file to another swift developer. They then can run:

```
$ ./swift/utils/update-checkout -config=repro.json -scheme=repro
```

which will checkout all of the appropriate hashes for each repository to
reproduce the build on the other user's machine.
  • Loading branch information
gottesmm committed Jul 22, 2018
1 parent 67c277d commit aa4bd9c
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions utils/update_checkout.py
Expand Up @@ -297,19 +297,28 @@ def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,


def dump_repo_hashes(config):
max_len = reduce(lambda acc, x: max(acc, len(x)),
config['repos'].keys(), 0)
fmt = "{:<%r}{}" % (max_len + 5)
"""
Dumps the current state of the repo into a new config file that contains a
master branch scheme with the relevant branches set to the appropriate
hashes.
"""
branch_scheme_name = 'repro'
new_config = {}
config_copy_keys = ['ssh-clone-pattern', 'https-clone-pattern', 'repos']
for config_copy_key in config_copy_keys:
new_config[config_copy_key] = config[config_copy_key]
repos = {}
branch_scheme = {'aliases': [branch_scheme_name], 'repos': repos}
new_config['branch-schemes'] = {branch_scheme_name: branch_scheme}
for repo_name, repo_info in sorted(config['repos'].items(),
key=lambda x: x[0]):
repo_path = os.path.join(SWIFT_SOURCE_ROOT, repo_name)
if os.path.isdir(repo_path):
with shell.pushd(repo_path, dry_run=False, echo=False):
h = shell.capture(["git", "log", "--oneline", "-n", "1"],
echo=False).strip()
print(fmt.format(repo_name, h))
else:
print(fmt.format(repo_name, "(not checked out)"))
with shell.pushd(os.path.join(SWIFT_SOURCE_ROOT, repo_name),
dry_run=False,
echo=False):
h = shell.capture(["git", "rev-parse", "HEAD"],
echo=False).strip()
repos[repo_name] = str(h)
json.dump(new_config, sys.stdout, indent=4)


def dump_hashes_config(args, config):
Expand Down

0 comments on commit aa4bd9c

Please sign in to comment.