This repository was archived by the owner on Mar 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
152 lines (112 loc) · 5.83 KB
/
build.py
File metadata and controls
152 lines (112 loc) · 5.83 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from json import JSONDecoder
import sys
import os
import shutil
#import subprocess
if len(sys.argv) >= (1) + 1:
if os.path.isfile(sys.argv[1]):
with open(sys.argv[1], "r") as f:
dec = JSONDecoder()
info = dec.decode(f.read())
compiler_info = info["compiler"]
compiler_command = compiler_info["command"]
compiler_options = compiler_info["options"]
compiler_include_pathes = compiler_info["include-pathes"]
linker_info = info["linker"]
linker_command = linker_info["command"]
linker_options = linker_info["options"]
linker_libs_pathes = linker_info["libraries-pathes"]
linker_static_libs_pathes = linker_info["static-libraries-files-pathes"]
linker_libraries = linker_info["libraries"]
output_file_path = linker_info["output-file-path"]
general_info = info["general"]
general_tempfolder = general_info["temporary-folder"]
copy_files = general_info["copy-files"]
copy_folders = general_info["copy-folders"]
copy_dest_folder = general_info["copy-destination-folder"]
project_info = info["project"]
project_files = project_info["files"]
if os.path.isdir(general_tempfolder):
print(f"Building general error: temporary folder \"{general_tempfolder}\" already exist any may be contains neccessary user files. Please change temporary folder or manually delete exist.")
exit(1)
compiler_cmd = f"{compiler_command} {compiler_options} "
for inclfold in compiler_include_pathes:
if os.path.isdir(inclfold):
compiler_cmd += f" -I\"{inclfold}\""
else:
print(f"Warning: includes folder \"{inclfold}\" doesn't exist, adding to list skipped.")
linker_cmd = f"{linker_command} {linker_options}"
for libfold in linker_libs_pathes:
if os.path.isdir(libfold):
linker_cmd += f" -L\"{libfold}\""
else:
print(f"Warning: libraries folder \"{libfold}\" doesn't exist, adding to list skipped.")
linker_cmd_statlibfiles = ""
for statlibfile in linker_static_libs_pathes:
if os.path.isfile(statlibfile):
linker_cmd_statlibfiles += f" \"{statlibfile}\""
else:
print(f"Warning: specified static library \"{statlibfile}\" doesn't exist, adding to list skipped. This may be cause linking errors in your project.")
linker_cmd_libsopts = ""
for libopt in linker_libraries:
linker_cmd_libsopts += f" -l{libopt}"
# store only verifed source files.
build_files = []
for fl in project_files:
if os.path.isfile(fl):
build_files.append(fl)
else:
print(f"Warning: specified file to build \"{fl}\" doesn't exist. This may be cause error on linking project.")
# create temp folder.
os.mkdir(general_tempfolder)
print("Created temporary folder.")
# build files and correct linker cmd line options.
linker_cmd_objfiles = ""
for fl in build_files:
print(f"Compiling file \"{fl}\"...")
outfile = os.path.join(general_tempfolder, os.path.basename(fl) + ".o")
result = os.system(compiler_cmd + f" \"{fl}\" -o \"{outfile}\"")
if result != 0 or not os.path.isfile(outfile):
print(f"Error compiling \"{fl}\" file. Building halted.")
print("Removed temporary folder.")
shutil.rmtree(general_tempfolder)
exit(1)
linker_cmd_objfiles += f" \"{outfile}\""
build_folder = os.path.dirname(output_file_path)
if not os.path.isdir(build_folder):
os.makedirs(build_folder)
print("Created tree of build folder.")
print(f"Linking \"{output_file_path}\"...")
linker_cmd = f"{linker_cmd} {linker_cmd_objfiles} {linker_cmd_statlibfiles} {linker_cmd_libsopts} -o {output_file_path}"
#print(linker_cmd)
os.system(linker_cmd)
print("Removed temporary folder.")
shutil.rmtree(general_tempfolder)
for fl in copy_files:
if os.path.isfile(fl):
shutil.copy(fl, os.path.join(build_folder, os.path.basename(fl)))
print(f"Copied file \"{fl}\" to build folder \"{build_folder}\".")
else:
print(f"Warning: specified file to copy \"{fl}\" doesn't exist, coping skipped.")
for fold in copy_folders:
if os.path.isdir(fold):
shutil.copytree(fold, os.path.join(build_folder, fold))
print(f"Copied folder \"{fold}\" to build folder \"{build_folder}\".")
else:
print(f"Warning: specified folder to copy \"{fl}\" doesn't exist, coping skipped.")
exit(0)
print("Running output executable...")
#os.system(f"\"{output_file_path}\"")
#print(output_file_path)
currdir = os.getcwd()
os.chdir(build_folder)
#os.system(os.path.basename(output_file_path))
os.startfile(os.path.basename(output_file_path))
os.chdir(currdir)
#subprocess.Popen([os.path.realpath(output_file_path)], cwd=build_folder)
print("Done.")
else:
print("Specified build info file doesn't exist.")
else:
print("Usage: ")
print(f" {sys.argv[0]} <build info .json file path>")