Skip to content

Commit b522e99

Browse files
committed
get ready to add the "split" tool
1 parent d116782 commit b522e99

File tree

4 files changed

+55
-26
lines changed

4 files changed

+55
-26
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/win32json
2-
/out-*
2+
/out_*
33
.mypy_cache/
44
__pycache__/

apiload.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
import sys
3+
4+
BRANCH = "10.0.19041.202-preview"
5+
SHA = "7164f4ce9fe17b7c5da3473eed26886753ce1173"
6+
7+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
8+
WIN32JSON_REPO = os.path.join(SCRIPT_DIR, "win32json")
9+
WIN32JSON_API_DIR = os.path.join(WIN32JSON_REPO, "api")
10+
11+
def loadSortedList():
12+
if not os.path.exists(WIN32JSON_REPO):
13+
print("Error: missing '{}'".format(WIN32JSON_REPO))
14+
print("Clone it with:")
15+
print(" git clone https://github.com/marlersoft/win32json {} -b {} && git -C {} checkout {} -b for_win32_transform".format(WIN32JSON_REPO, win32json_branch, win32json, win32json_sha))
16+
sys.exit(1)
17+
18+
def getApiName(basename: str) -> str:
19+
if not basename.endswith(".json"):
20+
sys.exit("found a non-json file '{}' in directory '{}'".format(basename, WIN32JSON_API_DIR))
21+
return basename[:-5]
22+
apis = [getApiName(basename) for basename in os.listdir(WIN32JSON_API_DIR)]
23+
24+
# just always sort to aid in predictable output
25+
apis.sort()
26+
27+
return apis

find-cycles

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ from typing import List, Set, Dict, Optional
1616
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
1717

1818
from apiref import ApiRef
19+
import apiload
1920

2021
def getApiRefTopLevelType(type_obj):
2122
parents = type_obj["Parents"]
@@ -56,29 +57,13 @@ def isAnonType(type_name):
5657
return type_name.endswith("_e__Struct") or type_name.endswith("_e__Union")
5758

5859
def main():
59-
win32json_branch = "10.0.19041.202-preview"
60-
win32json_sha = "7164f4ce9fe17b7c5da3473eed26886753ce1173"
61-
62-
win32json = os.path.join(SCRIPT_DIR, "win32json")
63-
if not os.path.exists(win32json):
64-
print("Error: missing '{}'".format(win32json))
65-
print("Clone it with:")
66-
print(" git clone https://github.com/marlersoft/win32json {} -b {} && git -C {} checkout {} -b for_win32_transform".format(win32json, win32json_branch, win32json, win32json_sha))
67-
68-
api_dir = os.path.join(win32json, "api")
69-
70-
def getApiName(basename: str) -> str:
71-
if not basename.endswith(".json"):
72-
sys.exit("found a non-json file '{}' in directory '{}'".format(basename, api_dir))
73-
return basename[:-5]
74-
apis = [getApiName(basename) for basename in os.listdir(api_dir)]
75-
apis.sort()
60+
apis = apiload.loadSortedList()
7661

7762
api_direct_type_refs_table: Dict[str,ApiTypeNameToApiRefMap] = {}
7863
print("loading types...")
7964
for api_name in apis:
8065
#print(api_name)
81-
filename = os.path.join(api_dir, api_name + ".json")
66+
filename = os.path.join(apiload.WIN32JSON_API_DIR, api_name + ".json")
8267
with open(filename, "r", encoding='utf-8-sig') as file:
8368
api = json.load(file)
8469
constants = api["Constants"]
@@ -165,7 +150,7 @@ def main():
165150

166151
print("types verified")
167152

168-
out_direct_deps_filename = "out-direct-deps.txt"
153+
out_direct_deps_filename = "out_direct_deps.txt"
169154
print("generating {}...".format(out_direct_deps_filename))
170155
with open(os.path.join(SCRIPT_DIR, out_direct_deps_filename), "w") as file:
171156
for api in apis:
@@ -176,7 +161,7 @@ def main():
176161
file.write(" {}\n".format(ref))
177162

178163

179-
out_recursive_deps_filename = "out-recursive-deps.txt"
164+
out_recursive_deps_filename = "out_recursive_deps.txt"
180165
print("calculating recursive type references (will store in {})...".format(out_recursive_deps_filename))
181166
api_recursive_type_refs_table: Dict[str,dict[str,Set[ApiRef]]] = {}
182167
with open(os.path.join(SCRIPT_DIR, out_recursive_deps_filename), "w") as file:
@@ -207,7 +192,7 @@ def main():
207192
else:
208193
type_set[t] = cycle
209194

210-
with open(os.path.join(SCRIPT_DIR, "out-cycles.txt"), "w") as file:
195+
with open(os.path.join(SCRIPT_DIR, "out_cycles.txt"), "w") as file:
211196
for api in apis:
212197
#print("API: {}".format(api))
213198
table = api_recursive_type_refs_table[api]
@@ -247,20 +232,20 @@ def main():
247232

248233
api_types_list = list(api_cycle_type_set)
249234
api_types_list.sort()
250-
with open(os.path.join(SCRIPT_DIR, "out-cycle-types.txt"), "w") as file:
235+
with open(os.path.join(SCRIPT_DIR, "out_cycle_types.txt"), "w") as file:
251236
for cycle_type in api_types_list:
252237
file.write("{}\n".format(cycle_type))
253238
for t in api_cycle_type_set[cycle_type]:
254239
file.write(" {}\n".format(t))
255-
with open(os.path.join(SCRIPT_DIR, "out-cycle-types.py"), "w") as file:
240+
with open(os.path.join(SCRIPT_DIR, "out_cycle_types.py"), "w") as file:
256241
file.write("from apiref import ApiRef\n")
257242
file.write("CYCLE_TYPES = {\n")
258243
for cycle_type in api_types_list:
259244
file.write(" ApiRef(\"{}\", \"{}\"),\n".format(cycle_type.api, cycle_type.name))
260245
file.write("}\n")
261246

262247
# NOTE: this is not all the cycles, just some of the for now
263-
with open(os.path.join(SCRIPT_DIR, "out-cycle-types.dot"), "w") as file:
248+
with open(os.path.join(SCRIPT_DIR, "out_cycle_types.dot"), "w") as file:
264249
file.write("digraph type_cycles {\n")
265250
links = collections.defaultdict(set)
266251
def addLink(links, a, b):
@@ -274,7 +259,7 @@ def main():
274259
for i in range(1, len(cycle)):
275260
addLink(links, cycle[i-1], cycle[i])
276261
file.write("}\n")
277-
#with open(os.path.join(SCRIPT_DIR, "out-self-cycle-types.txt"), "w") as file:
262+
#with open(os.path.join(SCRIPT_DIR, "out_self_cycle_types.txt"), "w") as file:
278263
# types_list = list(self_cycle_type_set)
279264
# types_list.sort()
280265
# for cycle_type in types_list:

split

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import sys
4+
import json
5+
from typing import List, Set, Dict, Optional
6+
7+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
8+
9+
import apiload
10+
from out_cycle_types import CYCLE_TYPES
11+
12+
def main():
13+
apis = apiload.loadSortedList()
14+
for api in apis:
15+
print(api)
16+
17+
main()

0 commit comments

Comments
 (0)