-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
82 lines (63 loc) · 2.26 KB
/
Copy pathbuild.py
File metadata and controls
82 lines (63 loc) · 2.26 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
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
"""Package ParaLOD into release zip archives.
Runs `dotnet build -c Release` and packages ParaLOD.dll, README.md, and LICENSE
into dist/ParaLOD-v<version>.zip and dist/ParaLOD.zip.
"""
import argparse
import os
import re
import shutil
import subprocess
import sys
import zipfile
ROOT = os.path.dirname(os.path.abspath(__file__))
CSPROJ = os.path.join(ROOT, "ParaLOD.csproj")
BIN_RELEASE = os.path.join(ROOT, "bin", "Release")
DLL_PATH = os.path.join(BIN_RELEASE, "ParaLOD.dll")
DIST = os.path.join(ROOT, "dist")
def read_version():
with open(CSPROJ, "r", encoding="utf-8") as handle:
text = handle.read()
match = re.search(r"<Version>([^<]+)</Version>", text)
if not match:
return "1.0.1"
return match.group(1)
def build_dotnet():
print("Building ParaLOD (Release)...")
res = subprocess.run(["dotnet", "build", CSPROJ, "-c", "Release"], cwd=ROOT)
if res.returncode != 0:
raise RuntimeError("dotnet build failed")
def build_zip():
version = read_version()
if not os.path.exists(DLL_PATH):
build_dotnet()
os.makedirs(DIST, exist_ok=True)
versioned_zip = os.path.join(DIST, f"ParaLOD-v{version}.zip")
generic_zip = os.path.join(DIST, "ParaLOD.zip")
files_to_pack = [
(DLL_PATH, "ParaLOD.dll"),
(os.path.join(ROOT, "README.md"), "README.md"),
(os.path.join(ROOT, "LICENSE"), "LICENSE"),
]
for zip_path in [versioned_zip, generic_zip]:
if os.path.exists(zip_path):
os.remove(zip_path)
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as archive:
for src, arcname in files_to_pack:
if os.path.exists(src):
archive.write(src, arcname)
print(f"Created: {zip_path}")
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--clean", action="store_true", help="Remove dist first")
parser.add_argument("--no-build", action="store_true", help="Skip dotnet build")
args = parser.parse_args(argv)
if args.clean and os.path.isdir(DIST):
shutil.rmtree(DIST)
if not args.no_build:
build_dotnet()
build_zip()
return 0
if __name__ == "__main__":
sys.exit(main())