-
Notifications
You must be signed in to change notification settings - Fork 0
/
umake.py
183 lines (165 loc) · 6.95 KB
/
umake.py
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
"""
A minimal build tool for c++ under MIT license.
Written by TheVeryDarkness, [email protected] on Github.
"""
import os.path as path
from cmake import write_cmake
from config import *
from sys import stderr, stdout
from scan import *
def escapeSource(relSrcToRoot: str):
return relSrcToRoot.replace("/", "__").replace("\\", "__")
def main():
modulesToBePreCompiledBySources: dict[str, modulesDependency] = dict()
# relSrcToRoot <--> relExtraSrcToRoot
extraSourcesBySources: dict[str, sourcesDependency] = dict()
extraSourcesToRoot: sourcesDependency = sourcesDependency(set())
# relSrcToRoot <--> targetName
objectsDict: bidict[str, str] = bidict()
if not cacheDisabled:
loadCache(relRoot)
try:
ext: extensionMapper = extensionMapper(
extHeaders, extSources, extHeaderSourcePairs
)
for relFolderToCur in relFoldersToCur:
scanAllFiles(
relFolderToCur,
relRoot,
excludeFiles,
excludeDirs,
encoding,
ext,
moduleExtension,
verbosity,
logUpdate,
)
cleanCache()
for source in sources:
relSource = path.relpath(source, relRoot)
(
modulesToBePreCompiledBySources[relSource],
extraSourcesBySources[relSource],
) = recursiveCollectDependencies(
source, relRoot, verbosity, encoding, ext, logUpdate, set()
)
for relModuleToRoot in modulesBiDict.values():
relModuleToCur = path.relpath(path.join(relRoot, relModuleToRoot))
(
modulesToBePreCompiledBySources[relModuleToRoot],
extraSourcesBySources[relModuleToRoot],
) = recursiveCollectDependencies(
relModuleToCur, relRoot, verbosity, encoding, ext, logUpdate, set()
)
for relModuleToRoot in implDict.values():
relModuleToCur = path.relpath(path.join(relRoot, relModuleToRoot))
(
modulesToBePreCompiledBySources[relModuleToRoot],
extraSourcesBySources[relModuleToRoot],
) = recursiveCollectDependencies(
relModuleToCur, relRoot, verbosity, encoding, ext, logUpdate, set()
)
if autoObj:
for extraSourcesBySource in extraSourcesBySources.values():
extraSourcesToRoot.unionWith(extraSourcesBySource)
for extraSrcToRoot in extraSourcesToRoot.sources:
extraSrcToCur = path.relpath(path.join(relRoot, extraSrcToRoot))
(
modulesToBePreCompiledBySources[extraSrcToRoot],
extraSourcesBySources[extraSrcToRoot],
) = recursiveCollectDependencies(
extraSrcToCur, relRoot, verbosity, encoding, ext, logUpdate, set()
)
objectsDict[extraSrcToRoot] = escapeSource(extraSrcToRoot)
updated_one_source = True
while updated_one_source:
updated_one_source = False
for source, extraSourcesToRoot in extraSourcesBySources.copy().items():
for extraSrcToRoot in extraSourcesToRoot.sources:
extraSrcToCur = path.relpath(path.join(relRoot, extraSrcToRoot))
if extraSrcToRoot not in extraSourcesBySources.keys():
(
modulesToBePreCompiledBySources[extraSrcToRoot],
extraSourcesBySources[extraSrcToRoot],
) = recursiveCollectDependencies(
extraSrcToCur,
relRoot,
verbosity,
encoding,
ext,
logUpdate,
set(),
)
objectsDict[extraSrcToRoot] = escapeSource(extraSrcToRoot)
updated_one_source = True
modules_not_found: list[str] = []
for _source, modulesToBePreCompiled in modulesToBePreCompiledBySources.items():
for moduleToBePreCompiled in modulesToBePreCompiled.module:
if moduleToBePreCompiled not in modulesBiDict:
print(
YELLOW
+ 'Imported module "{}" from dependencies of {} is not found'.format(
moduleToBePreCompiled, _source
)
+ RESET
)
modules_not_found.append(modulesToBePreCompiled)
if len(modules_not_found) != 0:
for _source, _deps in depsDict.items():
for imported in _deps.modules.module:
if imported not in modulesBiDict:
print(
YELLOW
+ 'Module "{}" imported from "{}" is not found.'.format(
imported, _source
)
+ RESET
)
if target == "info-only":
print(GREEN + str(modulesToBePreCompiledBySources) + RESET)
print(BLUE + str(modulesBiDict) + RESET)
if verbosity >= 2:
print(str(depsDict))
elif target == "cmake":
write_cmake(
out=stdout,
modulesToBePreCompiledBySources=modulesToBePreCompiledBySources,
objectsDict=objectsDict,
extraSourcesBySources=extraSourcesBySources,
)
elif target == "cmake-store":
with open(relOutToCur, "w", encoding="utf-8") as out:
write_cmake(
out=out,
modulesToBePreCompiledBySources=modulesToBePreCompiledBySources,
objectsDict=objectsDict,
extraSourcesBySources=extraSourcesBySources,
)
else:
print(depsDict)
if not cacheDisabled:
saveCache(relRoot)
except Exception as e:
print("\t", RED + str(e) + RESET, sep="", file=stderr)
print(
RED + "Failed for parsed arguments: {}.".format(args) + RESET, file=stderr
)
if not cacheDisabled:
deleteCache(relRoot)
if verbosity >= VERBOSITY_SHOW_STACKTRACE:
print(YELLOW + "Re-raise for stack trace." + RESET)
raise
if __name__ == "__main__":
# import profile
# profile.run("main()")
# import cProfile
# cProfile.run("main()")
main()
# import tracemalloc
# tracemalloc.start()
# main()
# snapshot = tracemalloc.take_snapshot()
# top_stats = snapshot.statistics('lineno')
# print("[ Top 10 ]")
# for stat in top_stats[:10]:
# print(stat)