1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
import logging
import os
import shlex
def install_bumper(ctx):
runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
srcdir = globals()["srcdir"]
# Add the directory with built Rust binaries to the path.
runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug"))
def git_init_and_commit_everything(ctx, dirname=None):
runcmd_run = globals()["runcmd_run"]
runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
runcmd_run(
ctx, ["git", "config", "--global", "user.email", "me@example.com", dirname]
)
runcmd_exit_code_is_zero(ctx)
runcmd_run(
ctx, ["git", "config", "--global", "user.name", "J. Random Hacker", dirname]
)
runcmd_exit_code_is_zero(ctx)
runcmd_run(ctx, ["git", "init", dirname])
runcmd_exit_code_is_zero(ctx)
runcmd_run(ctx, ["git", "add", "."], cwd=dirname)
runcmd_exit_code_is_zero(ctx)
runcmd_run(ctx, ["git", "commit", "-minitial"], cwd=dirname)
runcmd_exit_code_is_zero(ctx)
def remember_HEAD(ctx, dirname=None, varname=None):
runcmd_run = globals()["runcmd_run"]
runcmd_get_stdout = globals()["runcmd_get_stdout"]
runcmd_run(ctx, ["git", "rev-parse", "HEAD"], cwd=dirname)
runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
runcmd_exit_code_is_zero(ctx)
ctx[varname] = runcmd_get_stdout(ctx).strip()
def run_command_in_directory(ctx, dirname=None, argv0=None, args=None):
runcmd_run = globals()["runcmd_run"]
runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
argv = [shlex.quote(argv0)] + shlex.split(args)
runcmd_run(ctx, argv, cwd=dirname)
runcmd_exit_code_is_zero(ctx)
def try_to_run_command_in_directory(ctx, dirname=None, argv0=None, args=None):
runcmd_run = globals()["runcmd_run"]
argv = [shlex.quote(argv0)] + shlex.split(args)
runcmd_run(ctx, argv, cwd=dirname)
def only_these_files_exist_in(ctx, filenames=None, dirname=None):
assert_eq = globals()["assert_eq"]
expect = list(sorted(x for x in filenames.replace(",", "").split() if x != "and"))
actual = list(sorted(os.listdir(dirname)))
logging.debug(f"expect files; {expect}")
logging.debug(f"actual files; {actual}")
assert_eq(expect, actual)
def git_tag_points_at(ctx, dirname=None, tag=None, varname=None):
runcmd_run = globals()["runcmd_run"]
runcmd_get_stdout = globals()["runcmd_get_stdout"]
runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
runcmd_run(ctx, ["git", "show", "--raw", tag], cwd=dirname)
runcmd_exit_code_is_zero(ctx)
output = runcmd_get_stdout(ctx)
commit = ctx[varname]
logging.debug(f"expecting tag {tag} to point at {commit}")
logging.debug(f"tag: {output!r}")
assert output.startswith(f"tag {tag}\n")
assert f"\ncommit {commit}" in output
|