-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
78 lines (60 loc) · 2.01 KB
/
Copy pathbuild.py
File metadata and controls
78 lines (60 loc) · 2.01 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
import time
time0 = time.time()
import subprocess
import zipfile
from pathlib import Path
import argparse
import re
parser = argparse.ArgumentParser(description = '''
Build script for SortingVisualizer.
Output will be placed in SortingVisualizer.jar
SortingVisualizer itself supports the --help command too! Try it!
''')
parser.formatter_class = argparse.RawTextHelpFormatter
parser.add_argument('--test', action="store_true", help="Build tests")
result = parser.parse_args()
root = Path(".").absolute()
wrotePattern = re.compile("\[wrote\s+(.+?)\s*\]")
totalPattern = re.compile("\[total\s+(.+?)\s*\]")
temp = Path("temp")
def subpaths(p : Path):
for s in p.iterdir():
if s.is_dir():
yield from subpaths(s)
yield s
temp.mkdir(exist_ok=True)
Path("SortingVisualizer.jar").unlink(missing_ok=True)
args = ["javac","-d",temp.as_posix(),"-verbose"]
resources = [Path("net/balintgergely/sv/view/myIcon32.png").absolute()]
for k in subpaths(Path(".")):
a = k.as_posix()
if a.endswith(".java") and (result.test or not "test" in a):
args.append(a)
compiler = subprocess.Popen(args,stderr=subprocess.PIPE,text=True)
def classFiles():
for line in compiler.stderr:
if not totalPattern.search(line):
print(line,end="")
match = wrotePattern.search(line)
if match:
yield Path(match[1])
with zipfile.ZipFile("SortingVisualizer.jar","w") as zip:
with zip.open("META-INF/MANIFEST.MF","w") as manifest:
print("[packing META-INF/MANIFEST.MF]")
manifest.write(b"Manifest-Version: 1.0\n")
manifest.write(b"Class-Path: .\n")
manifest.write(b"Main-Class: net.balintgergely.sv.view.SortingVisualizer\n")
for s in resources:
if not s.is_dir():
a = s.as_posix()
b = s.relative_to(root).as_posix()
print(f"[packing {b}]")
zip.write(a,b)
for s in classFiles():
a = s.absolute().as_posix()
b = s.relative_to(temp).as_posix()
print(f"[packing {b}]")
zip.write(a,b)
time1 = time.time()
delta = time1 - time0
print(f"[total {delta:.3f}s]")