Skip to content

Commit 9ceca8d

Browse files
committed
[cmake_frontend.py] remove Codemodel class and relevant changes
1 parent 0cda4a1 commit 9ceca8d

1 file changed

Lines changed: 21 additions & 74 deletions

File tree

clang_bind/cmake_frontend.py

Lines changed: 21 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -35,79 +35,11 @@ def get_compilation_arguments(self, filename=None):
3535
}
3636

3737

38-
class Codemodel:
39-
"""Class to get information about the Codemodel generated by the CMake file API."""
40-
41-
def __init__(self, reply_dir):
42-
self.reply_dir = reply_dir
43-
self.codemodel = {}
44-
self.codemodel_targets = {}
45-
46-
def set_codemodel(self, codemodel_file=None):
47-
"""Set the codemodel variable.
48-
49-
:param codemodel_file: codemodel file to read from, defaults to None
50-
:type codemodel_file: str, optional
51-
"""
52-
if not codemodel_file:
53-
for file in Path(self.reply_dir).iterdir():
54-
if file.name.startswith("codemodel"):
55-
codemodel_file = Path(self.reply_dir, file)
56-
with open(codemodel_file) as f:
57-
self.codemodel = json.load(f)
58-
59-
def get_codemodel(self):
60-
"""Get the codemodel.
61-
62-
:return: JSON codemodel object.
63-
:rtype: dict
64-
"""
65-
if not self.codemodel:
66-
self.set_codemodel()
67-
return self.codemodel
68-
69-
def set_codemodel_targets(self, codemodel=None):
70-
"""Set targets variable.
71-
72-
:param codemodel: Codemodel dict object, defaults to None
73-
:type codemodel: dict, optional
74-
"""
75-
if not codemodel:
76-
codemodel = self.get_codemodel()
77-
configurations = codemodel.get("configurations", [])
78-
for configuration in configurations:
79-
targets = configuration.get("targets", [])
80-
for target in targets:
81-
self.codemodel_targets.update({target["name"]: target["jsonFile"]})
82-
83-
def get_codemodel_targets(self):
84-
"""Get codemodel targets.
85-
86-
:return: dict of targets and the corresponding file
87-
:rtype: dict
88-
"""
89-
if not self.codemodel_targets:
90-
self.set_codemodel_targets()
91-
return self.codemodel_targets
92-
93-
9438
class Target:
9539
"""Class to get information about targets found from the CMake file API."""
9640

97-
def __init__(self, reply_dir, target_name):
98-
self.reply_dir = reply_dir
99-
self.target_file = Codemodel(reply_dir).get_codemodel_targets().get(target_name)
100-
self.target = {}
101-
102-
def set_target(self, target_file=None):
103-
"""Set target variable.
104-
105-
:param target_file: File to get target from, defaults to None
106-
:type target_file: str, optional
107-
"""
108-
if not target_file:
109-
target_file = self.target_file
110-
with open(Path(self.reply_dir, target_file)) as f:
41+
def __init__(self, target_file):
42+
with open(target_file) as f:
11143
self.target = json.load(f)
11244

11345
def get_target(self):
@@ -280,11 +212,26 @@ class CMakeFileAPI:
280212
"""CMake File API front end."""
281213

282214
def __init__(self, build_dir):
283-
reply_dir = Path(build_dir, ".cmake", "api", "v1", "reply")
215+
self.reply_dir = Path(build_dir, ".cmake", "api", "v1", "reply")
284216
self.targets = {}
285-
for codemodel_target in Codemodel(reply_dir).get_codemodel_targets():
286-
target = Target(reply_dir, codemodel_target)
287-
self.targets[target.get_name()] = target
217+
self._set_targets_from_codemodel()
218+
219+
def _set_targets_from_codemodel(self):
220+
"""Populate targets dict by accessing values in the codemodel file."""
221+
222+
for file in Path(self.reply_dir).iterdir(): # iterate for all files
223+
if file.name.startswith("codemodel"): # find the codemodel file
224+
codemodel_file = Path(self.reply_dir, file)
225+
with open(codemodel_file) as f:
226+
codemodel = json.load(f) # load the JSON codemodel
227+
228+
for configuration in codemodel.get(
229+
"configurations", []
230+
): # for each configuration
231+
for target in configuration.get("targets", []): # for each targets
232+
target_file = target["jsonFile"] # get the target file
233+
target_obj = Target(Path(self.reply_dir, target_file))
234+
self.targets[target_obj.get_name()] = target_obj
288235

289236
def get_dependencies(self, target=None):
290237
"""Get dependencies of the target(s).

0 commit comments

Comments
 (0)