Repository navigation
Expand file tree
/
Copy pathgen.py
More file actions
63 lines (48 loc) · 1.35 KB
/
Copy pathgen.py
File metadata and controls
63 lines (48 loc) · 1.35 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
#! /usr/bin/env python3
import os
from typing import Any, Callable
def px(msg: str, ec: int = 0):
print(msg)
exit(ec)
def smother(fn: Callable, *args: Any) -> Any:
try:
return fn(*args)
except Exception:
pass
with open("version.txt", "rt") as v:
VERSION = v.read().strip()
APPNAME = "reqproc"
MAKE = "makefile"
OUTFOLDER = "build"
WINARCH = ["amd64", "arm64"]
LINARCH = ["386", *WINARCH]
TARGETS = {
"wasip1": ["wasm"],
"darwin": ["arm64"],
"windows": WINARCH,
"linux": LINARCH,
"freebsd": LINARCH,
"netbsd": LINARCH,
"openbsd": LINARCH,
}
def create_commands(targets: dict[str, list[str]]) -> list[str]:
BPATH = f"{OUTFOLDER}/{APPNAME}"
return [
"\n".join(
[
f"\tGOOS={tos} GOARCH={tarch} go build -o {BPATH} .\n"
+ f"\tzip -r {BPATH}-{tos}_{tarch}-{VERSION}.zip {BPATH}\n"
+ f"\trm -rf {BPATH}"
for tarch in tarches
]
)
for tos, tarches in targets.items()
]
def generate_targets(targets: dict[str, list[str]]) -> str:
return (
"main: clean\n"
+ "\n".join(create_commands(targets))
+ f"\n\nclean:\n\trm -rf {OUTFOLDER}\n\tmkdir {OUTFOLDER}"
)
with open(MAKE, "wt" if os.path.exists(MAKE) else "xt") as f:
f.write(generate_targets(TARGETS))