9
9
10
10
import zspdx .cmakefileapi
11
11
12
+
12
13
def parseReply (replyIndexPath ):
13
14
replyDir , _ = os .path .split (replyIndexPath )
14
15
15
16
# first we need to find the codemodel reply file
16
17
try :
17
- with open (replyIndexPath , 'r' ) as indexFile :
18
+ with open (replyIndexPath ) as indexFile :
18
19
js = json .load (indexFile )
19
20
20
21
# get reply object
21
22
reply_dict = js .get ("reply" , {})
22
23
if reply_dict == {}:
23
- log .err (f" no \ " reply\ " field found in index file" )
24
+ log .err (' no "reply" field found in index file' )
24
25
return None
25
26
# get codemodel object
26
27
cm_dict = reply_dict .get ("codemodel-v2" , {})
27
28
if cm_dict == {}:
28
- log .err (f" no \ " codemodel-v2\ " field found in \ " reply\ " object in index file" )
29
+ log .err (' no "codemodel-v2" field found in "reply" object in index file' )
29
30
return None
30
31
# and get codemodel filename
31
32
jsonFile = cm_dict .get ("jsonFile" , "" )
32
33
if jsonFile == "" :
33
- log .err (f" no \ " jsonFile\ " field found in \ " codemodel-v2\ " object in index file" )
34
+ log .err (' no "jsonFile" field found in "codemodel-v2" object in index file' )
34
35
return None
35
36
36
37
return parseCodemodel (replyDir , jsonFile )
@@ -46,23 +47,26 @@ def parseCodemodel(replyDir, codemodelFile):
46
47
codemodelPath = os .path .join (replyDir , codemodelFile )
47
48
48
49
try :
49
- with open (codemodelPath , 'r' ) as cmFile :
50
+ with open (codemodelPath ) as cmFile :
50
51
js = json .load (cmFile )
51
52
52
53
cm = zspdx .cmakefileapi .Codemodel ()
53
54
54
55
# for correctness, check kind and version
55
56
kind = js .get ("kind" , "" )
56
57
if kind != "codemodel" :
57
- log .err (f"Error loading CMake API reply: expected \" kind\" :\" codemodel\" in { codemodelPath } , got { kind } " )
58
+ log .err ('Error loading CMake API reply: expected "kind":"codemodel" '
59
+ f'in { codemodelPath } , got { kind } ' )
58
60
return None
59
61
version = js .get ("version" , {})
60
62
versionMajor = version .get ("major" , - 1 )
61
63
if versionMajor != 2 :
62
64
if versionMajor == - 1 :
63
- log .err (f"Error loading CMake API reply: expected major version 2 in { codemodelPath } , no version found" )
65
+ log .err ("Error loading CMake API reply: expected major version 2 "
66
+ f"in { codemodelPath } , no version found" )
64
67
return None
65
- log .err (f"Error loading CMake API reply: expected major version 2 in { codemodelPath } , got { versionMajor } " )
68
+ log .err ("Error loading CMake API reply: expected major version 2 "
69
+ f"in { codemodelPath } , got { versionMajor } " )
66
70
return None
67
71
68
72
# get paths
@@ -143,7 +147,7 @@ def parseConfig(cfg_dict, replyDir):
143
147
144
148
def parseTarget (targetPath ):
145
149
try :
146
- with open (targetPath , 'r' ) as targetFile :
150
+ with open (targetPath ) as targetFile :
147
151
js = json .load (targetFile )
148
152
149
153
target = zspdx .cmakefileapi .Target ()
@@ -191,20 +195,14 @@ def parseTarget(targetPath):
191
195
return None
192
196
193
197
def parseTargetType (targetType ):
194
- if targetType == "EXECUTABLE" :
195
- return zspdx .cmakefileapi .TargetType .EXECUTABLE
196
- elif targetType == "STATIC_LIBRARY" :
197
- return zspdx .cmakefileapi .TargetType .STATIC_LIBRARY
198
- elif targetType == "SHARED_LIBRARY" :
199
- return zspdx .cmakefileapi .TargetType .SHARED_LIBRARY
200
- elif targetType == "MODULE_LIBRARY" :
201
- return zspdx .cmakefileapi .TargetType .MODULE_LIBRARY
202
- elif targetType == "OBJECT_LIBRARY" :
203
- return zspdx .cmakefileapi .TargetType .OBJECT_LIBRARY
204
- elif targetType == "UTILITY" :
205
- return zspdx .cmakefileapi .TargetType .UTILITY
206
- else :
207
- return zspdx .cmakefileapi .TargetType .UNKNOWN
198
+ return {
199
+ "EXECUTABLE" : zspdx .cmakefileapi .TargetType .EXECUTABLE ,
200
+ "STATIC_LIBRARY" : zspdx .cmakefileapi .TargetType .STATIC_LIBRARY ,
201
+ "SHARED_LIBRARY" : zspdx .cmakefileapi .TargetType .SHARED_LIBRARY ,
202
+ "MODULE_LIBRARY" : zspdx .cmakefileapi .TargetType .MODULE_LIBRARY ,
203
+ "OBJECT_LIBRARY" : zspdx .cmakefileapi .TargetType .OBJECT_LIBRARY ,
204
+ "UTILITY" : zspdx .cmakefileapi .TargetType .UTILITY ,
205
+ }.get (targetType , zspdx .cmakefileapi .TargetType .UNKNOWN )
208
206
209
207
def parseTargetInstall (target , js ):
210
208
install_dict = js .get ("install" , {})
0 commit comments