forked from mciantyre/teensy4-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish-pacs.py
executable file
·66 lines (57 loc) · 1.88 KB
/
publish-pacs.py
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
#!/usr/bin/env python3
"""Script to automate the publication of PAC subcrates to crates.io
"""
import argparse
import pathlib
import subprocess
import sys
def build_cargo_publish(dry_run, allow_dirty):
def _call(crate_path):
cmd = [
"cargo",
"publish",
"--manifest-path", pathlib.Path(crate_path) / "Cargo.toml",
"--target", "thumbv7em-none-eabihf"
]
if dry_run:
cmd.append("--dry-run")
if allow_dirty:
cmd.append("--allow-dirty")
try:
subprocess.run(cmd, check=True, capture_output=True)
dry_run_notice = "(dry run)" if dry_run else ""
print(f"Crate '{crate_path}' published OK {dry_run_notice}")
except subprocess.CalledProcessError as e:
if b"crate version" in e.stderr and b"is already uploaded" in e.stderr:
print(f"publish-pacs: skipping crate '{crate_path}', since the version already exists in crates.io")
else:
print(e)
raise
return _call
parser = argparse.ArgumentParser(description="Automate the publishing of crates from this repo")
parser.add_argument(
"--only-pac-subcrates",
help="Only publish all of the PAC subcrates",
action="store_true",
)
parser.add_argument(
"--dry-run",
help="Perform all checks without uploading",
action="store_true",
)
parser.add_argument(
"--allow-dirty",
help="Allow dirty working directories to be packaged",
action="store_true"
)
args = parser.parse_args()
cargo_publish = build_cargo_publish(args.dry_run, args.allow_dirty)
# PAC subcrates
PAC_PATH = pathlib.Path("imxrt1062-pac")
subcrates = [
imxrt1062_dir
for imxrt1062_dir in PAC_PATH.iterdir()
if "imxrt1062-" in str(imxrt1062_dir.name) and imxrt1062_dir.is_dir()
]
for subcrate in subcrates:
cargo_publish(subcrate)