-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAAS.py
More file actions
105 lines (94 loc) · 3.15 KB
/
AAS.py
File metadata and controls
105 lines (94 loc) · 3.15 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import shutil
def MakeDirIfNeeded(dir):
if not os.path.exists(dir):
os.makedirs(dir)
def Clean():
if os.path.exists("./Output"):
shutil.rmtree("./Output");
def CopyDirStructure(src, dst):
for x in os.listdir(src):
px = os.path.join(src, x)
if not os.path.isdir(px):
continue
dstpx = os.path.join(dst, x)
MakeDirIfNeeded(dstpx)
CopyDirStructure(px, dstpx)
def MakeDirs(conf, arch):
MakeDirIfNeeded("./Output")
MakeDirIfNeeded(f"./Output/{conf}_{arch}")
MakeDirIfNeeded(f"./Output/{conf}_{arch}/Objects")
MakeDirIfNeeded(f"./Output/{conf}_{arch}/Objects/Sources")
MakeDirIfNeeded(f"./Output/{conf}_{arch}/Objects/SDK")
MakeDirIfNeeded(f"./Output/{conf}_{arch}/AAS")
MakeDirIfNeeded(f"./Output/Deploy")
CopyDirStructure("./Sources", f"./Output/{conf}_{arch}/Objects/Sources")
CopyDirStructure("./SDK", f"./Output/{conf}_{arch}/Objects/SDK")
def Copy(src, dst):
if os.path.exists(dst):
os.remove(dst)
shutil.copy(src, dst)
def MakeCompileCommands(file, args):
outf = open(file, 'w')
outf.write("[\n")
for fname in args:
inf = open(fname, 'r')
content = inf.read()
# if last element removes ",\n"
if fname == args[-1]:
outf.write(content[0:-2])
else:
outf.write(content)
outf.write("\n]")
outf.close()
def EmbedAndDeleteManifest(exePath):
if not os.path.exists(f"{exePath}.manifest"):
return
os.system(f"mt.exe -manifest \"{exePath}.manifest\" -outputresource:\"{exePath}\"")
os.remove(f"{exePath}.manifest")
def MakeArchive(srcDir):
arch = ''
if 'aarch64' in srcDir:
arch = 'aarch64'
elif 'x86_64' in srcDir:
arch = 'x86_64'
else:
raise Exception("Can't resolve arch")
versionStr = ''
with open('Sources/Utils/Version.h', 'r') as f:
versionStr = f.read()
tokens = versionStr.split()
versionStr = 'v{}_{}'.format(tokens[2], tokens[5])
dstZip = f'Output/Deploy/AltAppSwitcher_{versionStr}_{arch}.zip'
tempDir = f"{dstZip}".replace(".zip", "")
if os.path.exists(tempDir):
shutil.rmtree(tempDir)
shutil.copytree(srcDir, tempDir)
for x in os.listdir(tempDir):
if x.endswith(".exe"):
EmbedAndDeleteManifest(os.path.join(tempDir, x))
print(shutil.get_archive_formats())
shutil.make_archive(tempDir, "zip", tempDir)
shutil.rmtree(tempDir)
def Format():
for path, subdirs, files in os.walk("./Sources"):
for name in files:
if name.endswith(".c") or name.endswith(".h"):
os.system(f"clang-format.exe { path }/{ name } -i")
print(f"clang-format.exe { path }/{ name } -i")
import sys
if __name__ == "__main__":
args = sys.argv[1:]
fn = args[0]
if fn == "Copy":
Copy(args[1], args[2])
elif fn == "MakeDirs":
MakeDirs(args[1], args[2])
elif fn == "Clean":
Clean()
elif fn == "MakeCompileCommands":
MakeCompileCommands(args[1], args[2:])
elif fn == "MakeArchive":
MakeArchive(args[1])
elif fn == "Format":
Format()