Repository navigation
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·90 lines (74 loc) · 1.9 KB
/
Copy pathbuild.py
File metadata and controls
executable file
·90 lines (74 loc) · 1.9 KB
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
88
89
90
#!/usr/bin/env python3
import argparse
import json
import os
import shutil
import stat
import subprocess
exe_path = ".build/debug/audioctl"
def get_tarname():
out = subprocess.run(
["swift", "package", "dump-package"], capture_output=True, text=True
)
data = json.loads(out.stdout)
name = data["name"]
return name + ".tar.gz"
def swift_build() -> None:
res = subprocess.run(["swift", "build"])
exit(res.returncode)
def install(prefix: str) -> None:
bindir = os.path.join(prefix, "bin")
if not os.path.exists(bindir):
os.makedirs(bindir)
dest_path = os.path.join(bindir, os.path.basename(exe_path))
shutil.copyfile(exe_path, dest_path)
mode: int = (
stat.S_IRUSR
| stat.S_IWUSR
| stat.S_IXUSR
| stat.S_IRGRP
| stat.S_IXGRP
| stat.S_IROTH
| stat.S_IXOTH
)
os.chmod(dest_path, mode)
print(f"Installed to {dest_path}")
exit(0)
def distribute() -> None:
cwd = os.getcwd()
tarname = get_tarname()
subprocess.run(
[
"tar",
"-czvf",
f"{cwd}/{tarname}",
"Sources/",
"build.py",
"Package.swift",
"README.md",
],
cwd=cwd,
)
print(f"Created distribution: {tarname}")
def main():
parser = argparse.ArgumentParser(description="Build helper for audioctl")
parser.add_argument(
"action",
choices=["install", "build", "dist"],
help="Action to perform (install|build|dist)",
)
parser.add_argument(
"-p",
"--prefix",
help="Prefix for installation",
default="/usr/local",
)
args = parser.parse_args()
if args.action == "build":
swift_build()
elif args.action == "install":
install(args.prefix)
elif args.action == "dist":
distribute()
if __name__ == "__main__":
main()