codemodel-v2-check.py 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. from check_index import *
  2. import json
  3. import sys
  4. import os
  5. def read_codemodel_json_data(filename):
  6. abs_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "codemodel-v2-data", filename)
  7. with open(abs_filename, "r") as f:
  8. return json.load(f)
  9. def check_objects(o, g):
  10. assert is_list(o)
  11. assert len(o) == 1
  12. major = 2
  13. minor = 10
  14. check_index_object(o[0], "codemodel", major, minor, check_object_codemodel(g, major, minor))
  15. def check_backtrace(t, b, backtrace):
  16. btg = t["backtraceGraph"]
  17. for expected in backtrace:
  18. assert is_int(b)
  19. node = btg["nodes"][b]
  20. expected_keys = ["file"]
  21. assert matches(btg["files"][node["file"]], expected["file"])
  22. if expected["line"] is not None:
  23. expected_keys.append("line")
  24. assert is_int(node["line"], expected["line"]), repr(node["line"]) + " != " + repr(expected["line"])
  25. if expected["command"] is not None:
  26. expected_keys.append("command")
  27. assert is_int(node["command"])
  28. assert is_string(btg["commands"][node["command"]], expected["command"])
  29. if expected["hasParent"]:
  30. expected_keys.append("parent")
  31. assert is_int(node["parent"])
  32. b = node["parent"]
  33. else:
  34. b = None
  35. assert sorted(node.keys()) == sorted(expected_keys)
  36. assert b is None
  37. def check_backtraces(t, actual, expected):
  38. assert is_list(actual)
  39. assert is_list(expected)
  40. assert len(actual) == len(expected)
  41. i = 0
  42. while i < len(actual):
  43. check_backtrace(t, actual[i], expected[i])
  44. i += 1
  45. def check_directory(c, major, minor):
  46. def _check(actual, expected):
  47. assert is_dict(actual)
  48. expected_keys = ["build", "jsonFile", "source", "projectIndex"]
  49. assert matches(actual["build"], expected["build"])
  50. assert is_int(actual["projectIndex"])
  51. assert is_string(c["projects"][actual["projectIndex"]]["name"], expected["projectName"])
  52. if expected["parentSource"] is not None:
  53. expected_keys.append("parentIndex")
  54. assert is_int(actual["parentIndex"])
  55. assert matches(c["directories"][actual["parentIndex"]]["source"], expected["parentSource"])
  56. if expected["childSources"] is not None:
  57. expected_keys.append("childIndexes")
  58. check_list_match(lambda a, e: matches(c["directories"][a]["source"], e),
  59. actual["childIndexes"], expected["childSources"],
  60. missing_exception=lambda e: "Child source: %s" % e,
  61. extra_exception=lambda a: "Child source: %s" % a["source"])
  62. if expected["targetIds"] is not None:
  63. expected_keys.append("targetIndexes")
  64. check_list_match(lambda a, e: matches(c["targets"][a]["id"], e),
  65. actual["targetIndexes"], expected["targetIds"],
  66. missing_exception=lambda e: "Target ID: %s" % e,
  67. extra_exception=lambda a: "Target ID: %s" % c["targets"][a]["id"])
  68. if expected["abstractTargetIds"] is not None:
  69. expected_keys.append("abstractTargetIndexes")
  70. check_list_match(lambda a, e: matches(c["abstractTargets"][a]["id"], e),
  71. actual["abstractTargetIndexes"], expected["abstractTargetIds"],
  72. missing_exception=lambda e: "Abstract target ID: %s" % e,
  73. extra_exception=lambda a: "Abstract target ID: %s" % c["abstractTargets"][a]["id"])
  74. if expected["minimumCMakeVersion"] is not None:
  75. expected_keys.append("minimumCMakeVersion")
  76. assert is_dict(actual["minimumCMakeVersion"])
  77. assert sorted(actual["minimumCMakeVersion"].keys()) == ["string"]
  78. assert is_string(actual["minimumCMakeVersion"]["string"], expected["minimumCMakeVersion"])
  79. if expected["hasInstallRule"] is not None:
  80. expected_keys.append("hasInstallRule")
  81. assert is_bool(actual["hasInstallRule"], expected["hasInstallRule"])
  82. assert sorted(actual.keys()) == sorted(expected_keys)
  83. assert is_string(actual["jsonFile"])
  84. filepath = os.path.join(reply_dir, actual["jsonFile"])
  85. maximum_filename_length = 140
  86. assert len(actual["jsonFile"]) <= maximum_filename_length
  87. with open(filepath) as f:
  88. d = json.load(f)
  89. assert is_dict(d)
  90. assert sorted(d.keys()) == ["backtraceGraph", "codemodelVersion", "installers", "paths"]
  91. # We get the values for major and minor directly rather than from the "expected" data.
  92. # This avoids having to update every data file any time the major or minor version changes.
  93. assert is_int(d["codemodelVersion"]["major"], major)
  94. assert is_int(d["codemodelVersion"]["minor"], minor)
  95. assert is_string(d["paths"]["source"], actual["source"])
  96. assert is_string(d["paths"]["build"], actual["build"])
  97. check_backtrace_graph(d["backtraceGraph"])
  98. assert is_list(d["installers"])
  99. assert len(d["installers"]) == len(expected["installers"])
  100. for a, e in zip(d["installers"], expected["installers"]):
  101. assert is_dict(a)
  102. expected_keys = ["component", "type"]
  103. assert is_string(a["component"], e["component"])
  104. assert is_string(a["type"], e["type"])
  105. if e["destination"] is not None:
  106. expected_keys.append("destination")
  107. assert is_string(a["destination"], e["destination"])
  108. if e["paths"] is not None:
  109. expected_keys.append("paths")
  110. assert is_list(a["paths"])
  111. assert len(a["paths"]) == len(e["paths"])
  112. for ap, ep in zip(a["paths"], e["paths"]):
  113. if is_string(ep):
  114. assert matches(ap, ep)
  115. else:
  116. assert is_dict(ap)
  117. assert sorted(ap.keys()) == ["from", "to"]
  118. assert matches(ap["from"], ep["from"])
  119. assert matches(ap["to"], ep["to"])
  120. if e["isExcludeFromAll"] is not None:
  121. expected_keys.append("isExcludeFromAll")
  122. assert is_bool(a["isExcludeFromAll"], e["isExcludeFromAll"])
  123. if e["isForAllComponents"] is not None:
  124. expected_keys.append("isForAllComponents")
  125. assert is_bool(a["isForAllComponents"], e["isForAllComponents"])
  126. if e["isOptional"] is not None:
  127. expected_keys.append("isOptional")
  128. assert is_bool(a["isOptional"], e["isOptional"])
  129. if e["targetId"] is not None:
  130. expected_keys.append("targetId")
  131. assert matches(a["targetId"], e["targetId"])
  132. if e["targetIndex"] is not None:
  133. expected_keys.append("targetIndex")
  134. assert is_int(a["targetIndex"])
  135. assert c["targets"][a["targetIndex"]]["name"] == e["targetIndex"]
  136. if e["targetIsImportLibrary"] is not None:
  137. expected_keys.append("targetIsImportLibrary")
  138. assert is_bool(a["targetIsImportLibrary"], e["targetIsImportLibrary"])
  139. if e["targetInstallNamelink"] is not None:
  140. expected_keys.append("targetInstallNamelink")
  141. assert is_string(a["targetInstallNamelink"], e["targetInstallNamelink"])
  142. if e["exportName"] is not None:
  143. expected_keys.append("exportName")
  144. assert is_string(a["exportName"], e["exportName"])
  145. if e["exportTargets"] is not None:
  146. expected_keys.append("exportTargets")
  147. assert is_list(a["exportTargets"])
  148. assert len(a["exportTargets"]) == len(e["exportTargets"])
  149. for at, et in zip(a["exportTargets"], e["exportTargets"]):
  150. assert is_dict(at)
  151. assert sorted(at.keys()) == ["id", "index"]
  152. assert matches(at["id"], et["id"])
  153. assert is_int(at["index"])
  154. assert c["targets"][at["index"]]["name"] == et["index"]
  155. if e["scriptFile"] is not None:
  156. expected_keys.append("scriptFile")
  157. assert is_string(a["scriptFile"], e["scriptFile"])
  158. if e.get("runtimeDependencySetName", None) is not None:
  159. expected_keys.append("runtimeDependencySetName")
  160. assert is_string(a["runtimeDependencySetName"], e["runtimeDependencySetName"])
  161. if e.get("runtimeDependencySetType", None) is not None:
  162. expected_keys.append("runtimeDependencySetType")
  163. assert is_string(a["runtimeDependencySetType"], e["runtimeDependencySetType"])
  164. if e.get("fileSetName", None) is not None:
  165. expected_keys.append("fileSetName")
  166. assert is_string(a["fileSetName"], e["fileSetName"])
  167. if e.get("fileSetType", None) is not None:
  168. expected_keys.append("fileSetType")
  169. assert is_string(a["fileSetType"], e["fileSetType"])
  170. if e.get("fileSetDirectories", None) is not None:
  171. expected_keys.append("fileSetDirectories")
  172. assert is_list(a["fileSetDirectories"])
  173. assert len(a["fileSetDirectories"]) == len(e["fileSetDirectories"])
  174. for ad, ed in zip(a["fileSetDirectories"], e["fileSetDirectories"]):
  175. assert matches(ad, ed)
  176. if e.get("fileSetTarget", None) is not None:
  177. expected_keys.append("fileSetTarget")
  178. et = e["fileSetTarget"]
  179. at = a["fileSetTarget"]
  180. assert is_dict(at)
  181. assert sorted(at.keys()) == ["id", "index"]
  182. assert matches(at["id"], et["id"])
  183. assert is_int(at["index"])
  184. assert c["targets"][at["index"]]["name"] == et["index"]
  185. if e.get("cxxModuleBmiTarget", None) is not None:
  186. expected_keys.append("cxxModuleBmiTarget")
  187. et = e["cxxModuleBmiTarget"]
  188. at = a["cxxModuleBmiTarget"]
  189. assert is_dict(at)
  190. assert sorted(at.keys()) == ["id", "index"]
  191. assert matches(at["id"], et["id"])
  192. assert is_int(at["index"])
  193. assert c["targets"][at["index"]]["name"] == et["index"]
  194. if e["backtrace"] is not None:
  195. expected_keys.append("backtrace")
  196. check_backtrace(d, a["backtrace"], e["backtrace"])
  197. assert sorted(a.keys()) == sorted(expected_keys)
  198. return _check
  199. def check_backtrace_graph(btg):
  200. assert is_dict(btg)
  201. assert sorted(btg.keys()) == ["commands", "files", "nodes"]
  202. assert is_list(btg["commands"])
  203. for c in btg["commands"]:
  204. assert is_string(c)
  205. for f in btg["files"]:
  206. assert is_string(f)
  207. for n in btg["nodes"]:
  208. expected_keys = ["file"]
  209. assert is_dict(n)
  210. assert is_int(n["file"])
  211. assert 0 <= n["file"] < len(btg["files"])
  212. if "line" in n:
  213. expected_keys.append("line")
  214. assert is_int(n["line"])
  215. if "command" in n:
  216. expected_keys.append("command")
  217. assert is_int(n["command"])
  218. assert 0 <= n["command"] < len(btg["commands"])
  219. if "parent" in n:
  220. expected_keys.append("parent")
  221. assert is_int(n["parent"])
  222. assert 0 <= n["parent"] < len(btg["nodes"])
  223. assert sorted(n.keys()) == sorted(expected_keys)
  224. def check_target(c, major, minor):
  225. def _check(actual, expected):
  226. assert is_dict(actual)
  227. assert sorted(actual.keys()) == ["directoryIndex", "id", "jsonFile", "name", "projectIndex"]
  228. assert is_int(actual["directoryIndex"])
  229. assert matches(c["directories"][actual["directoryIndex"]]["source"], expected["directorySource"])
  230. assert is_string(actual["name"], expected["name"])
  231. assert is_string(actual["jsonFile"])
  232. assert is_int(actual["projectIndex"])
  233. assert is_string(c["projects"][actual["projectIndex"]]["name"], expected["projectName"])
  234. filepath = os.path.join(reply_dir, actual["jsonFile"])
  235. with open(filepath) as f:
  236. obj = json.load(f)
  237. expected_keys = ["codemodelVersion", "name", "id", "type", "backtraceGraph", "paths", "sources"]
  238. assert is_dict(obj)
  239. assert is_string(obj["name"], expected["name"])
  240. assert matches(obj["id"], expected["id"])
  241. assert is_string(obj["type"], expected["type"])
  242. check_backtrace_graph(obj["backtraceGraph"])
  243. if expected["imported"] is not None:
  244. expected_keys.append("imported")
  245. assert is_bool(obj["imported"], expected["imported"])
  246. if expected["local"] is not None:
  247. expected_keys.append("local")
  248. assert is_bool(obj["local"], expected["local"])
  249. if expected["abstract"] is not None:
  250. expected_keys.append("abstract")
  251. assert is_bool(obj["abstract"], expected["abstract"])
  252. if expected["symbolic"] is not None:
  253. expected_keys.append("symbolic")
  254. assert is_bool(obj["symbolic"], expected["symbolic"])
  255. if expected["interfaceSources"] is not None:
  256. expected_keys.append("interfaceSources")
  257. assert is_list(obj["interfaceSources"])
  258. assert len(obj["interfaceSources"]) == len(expected["interfaceSources"])
  259. assert is_dict(obj["paths"])
  260. assert sorted(obj["paths"].keys()) == ["build", "source"]
  261. assert matches(obj["paths"]["build"], expected["build"])
  262. assert matches(obj["paths"]["source"], expected["source"])
  263. # We get the values for major and minor directly rather than from the "expected" data.
  264. # This avoids having to update every data file any time the major or minor version changes.
  265. assert is_dict(obj["codemodelVersion"])
  266. assert sorted(obj["codemodelVersion"].keys()) == ["major", "minor"]
  267. assert is_int(obj["codemodelVersion"]["major"], major)
  268. assert is_int(obj["codemodelVersion"]["minor"], minor)
  269. def check_file_set(actual, expected):
  270. assert is_dict(actual)
  271. expected_keys = ["name", "type", "visibility", "baseDirectories"]
  272. assert is_string(actual["name"], expected["name"])
  273. assert is_string(actual["type"], expected["type"])
  274. assert is_string(actual["visibility"], expected["visibility"])
  275. check_list_match(lambda a, e: matches(a, e), actual["baseDirectories"],
  276. expected["baseDirectories"],
  277. check_exception=lambda a, e: "File set base directory (check): %s" % a,
  278. missing_exception=lambda e: "File set base directory (missing): %s" % e,
  279. extra_exception=lambda a: "File set base directory (extra): %s" % a)
  280. assert sorted(actual.keys()) == sorted(expected_keys)
  281. def check_source(actual, expected):
  282. assert is_dict(actual)
  283. expected_keys = ["path"]
  284. if expected["fileSetName"] is not None:
  285. expected_keys.append("fileSetIndex")
  286. assert is_string(obj["fileSets"][actual["fileSetIndex"]]["name"], expected["fileSetName"])
  287. if expected["compileGroupLanguage"] is not None:
  288. expected_keys.append("compileGroupIndex")
  289. assert is_string(obj["compileGroups"][actual["compileGroupIndex"]]["language"], expected["compileGroupLanguage"])
  290. if expected["sourceGroupName"] is not None:
  291. expected_keys.append("sourceGroupIndex")
  292. assert is_string(obj["sourceGroups"][actual["sourceGroupIndex"]]["name"], expected["sourceGroupName"])
  293. if expected["isGenerated"] is not None:
  294. expected_keys.append("isGenerated")
  295. assert is_bool(actual["isGenerated"], expected["isGenerated"])
  296. if expected["backtrace"] is not None:
  297. expected_keys.append("backtrace")
  298. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  299. assert sorted(actual.keys()) == sorted(expected_keys)
  300. if expected["fileSets"] is not None:
  301. expected_keys.append("fileSets")
  302. check_list_match(lambda a, e: matches(a["name"], e["name"]), obj["fileSets"],
  303. expected["fileSets"], check=check_file_set,
  304. check_exception=lambda a, e: "File set: %s" % a["name"],
  305. missing_exception=lambda e: "File set: %s" % e["name"],
  306. extra_exception=lambda a: "File set: %s" % a["name"])
  307. check_list_match(lambda a, e: matches(a["path"], e["path"]), obj["sources"],
  308. expected["sources"], check=check_source,
  309. check_exception=lambda a, e: "Source file: %s" % a["path"],
  310. missing_exception=lambda e: "Source file: %s" % e["path"],
  311. extra_exception=lambda a: "Source file: %s" % a["path"])
  312. if expected["backtrace"] is not None:
  313. expected_keys.append("backtrace")
  314. check_backtrace(obj, obj["backtrace"], expected["backtrace"])
  315. if expected["folder"] is not None:
  316. expected_keys.append("folder")
  317. assert is_dict(obj["folder"])
  318. assert sorted(obj["folder"].keys()) == ["name"]
  319. assert is_string(obj["folder"]["name"], expected["folder"])
  320. if expected["nameOnDisk"] is not None:
  321. expected_keys.append("nameOnDisk")
  322. assert matches(obj["nameOnDisk"], expected["nameOnDisk"])
  323. if expected["artifacts"] is not None:
  324. expected_keys.append("artifacts")
  325. def check_artifact(actual, expected):
  326. assert is_dict(actual)
  327. assert sorted(actual.keys()) == ["path"]
  328. check_list_match(lambda a, e: matches(a["path"], e["path"]),
  329. obj["artifacts"], expected["artifacts"],
  330. check=check_artifact,
  331. check_exception=lambda a, e: "Artifact: %s" % a["path"],
  332. missing_exception=lambda e: "Artifact: %s" % e["path"],
  333. extra_exception=lambda a: "Artifact: %s" % a["path"])
  334. if expected["isGeneratorProvided"] is not None:
  335. expected_keys.append("isGeneratorProvided")
  336. assert is_bool(obj["isGeneratorProvided"], expected["isGeneratorProvided"])
  337. if expected["install"] is not None:
  338. expected_keys.append("install")
  339. assert is_dict(obj["install"])
  340. assert sorted(obj["install"].keys()) == ["destinations", "prefix"]
  341. assert is_dict(obj["install"]["prefix"])
  342. assert sorted(obj["install"]["prefix"].keys()) == ["path"]
  343. assert matches(obj["install"]["prefix"]["path"], expected["install"]["prefix"])
  344. def check_install_destination(actual, expected):
  345. assert is_dict(actual)
  346. expected_keys = ["path"]
  347. if expected["backtrace"] is not None:
  348. expected_keys.append("backtrace")
  349. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  350. assert sorted(actual.keys()) == sorted(expected_keys)
  351. check_list_match(lambda a, e: matches(a["path"], e["path"]),
  352. obj["install"]["destinations"], expected["install"]["destinations"],
  353. check=check_install_destination,
  354. check_exception=lambda a, e: "Install path: %s" % a["path"],
  355. missing_exception=lambda e: "Install path: %s" % e["path"],
  356. extra_exception=lambda a: "Install path: %s" % a["path"])
  357. if "launchers" in expected:
  358. if expected["launchers"] is not None:
  359. expected_keys.append("launchers")
  360. def check_launcher(actual, expected):
  361. assert is_dict(actual)
  362. launcher_keys = ["command", "type"]
  363. if "arguments" in expected:
  364. launcher_keys.append("arguments")
  365. assert sorted(actual.keys()) == sorted(launcher_keys)
  366. assert matches(actual["command"], expected["command"])
  367. assert matches(actual["type"], expected["type"])
  368. if "arguments" in expected:
  369. if expected["arguments"] is not None:
  370. check_list_match(lambda a, e: matches(a, e),
  371. actual["arguments"], expected["arguments"],
  372. missing_exception=lambda e: "argument: %s" % e,
  373. extra_exception=lambda a: "argument: %s" % actual["arguments"])
  374. check_list_match(lambda a, e: matches(a["type"], e["type"]),
  375. obj["launchers"], expected["launchers"],
  376. check=check_launcher,
  377. check_exception=lambda a, e: "launchers: %s" % a,
  378. missing_exception=lambda e: "launchers: %s" % e,
  379. extra_exception=lambda a: "launchers: %s" % a)
  380. if "debugger" in expected:
  381. if expected["debugger"] is not None:
  382. expected_keys.append("debugger")
  383. assert is_dict(obj["debugger"])
  384. debugger_keys = ["workingDirectory"]
  385. assert sorted(obj["debugger"].keys()) == sorted(debugger_keys)
  386. assert matches(obj["debugger"]["workingDirectory"], expected["debugger"]["workingDirectory"])
  387. if expected["link"] is not None:
  388. expected_keys.append("link")
  389. assert is_dict(obj["link"])
  390. link_keys = ["language"]
  391. assert is_string(obj["link"]["language"], expected["link"]["language"])
  392. if "commandFragments" in obj["link"]:
  393. link_keys.append("commandFragments")
  394. assert is_list(obj["link"]["commandFragments"])
  395. for f in obj["link"]["commandFragments"]:
  396. assert is_dict(f)
  397. assert sorted(f.keys()) == ["fragment", "role"] or sorted(f.keys()) == ["backtrace", "fragment", "role"]
  398. assert is_string(f["fragment"])
  399. assert is_string(f["role"])
  400. assert f["role"] in ("flags", "libraries", "libraryPath", "frameworkPath")
  401. if expected["link"]["commandFragments"] is not None:
  402. def check_link_command_fragments(actual, expected):
  403. assert is_dict(actual)
  404. expected_keys = ["fragment", "role"]
  405. if expected["backtrace"] is not None:
  406. expected_keys.append("backtrace")
  407. assert matches(actual["fragment"], expected["fragment"])
  408. assert actual["role"] == expected["role"]
  409. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  410. assert sorted(actual.keys()) == sorted(expected_keys)
  411. check_list_match(lambda a, e: matches(a["fragment"], e["fragment"]),
  412. obj["link"]["commandFragments"], expected["link"]["commandFragments"],
  413. check=check_link_command_fragments,
  414. check_exception=lambda a, e: "Link fragment: %s" % a["fragment"],
  415. missing_exception=lambda e: "Link fragment: %s" % e["fragment"],
  416. extra_exception=lambda a: "Link fragment: %s" % a["fragment"],
  417. allow_extra=True)
  418. if expected["link"]["lto"] is not None:
  419. link_keys.append("lto")
  420. assert is_bool(obj["link"]["lto"], expected["link"]["lto"])
  421. # FIXME: Properly test sysroot
  422. if "sysroot" in obj["link"]:
  423. link_keys.append("sysroot")
  424. assert is_string(obj["link"]["sysroot"])
  425. assert sorted(obj["link"].keys()) == sorted(link_keys)
  426. if expected["archive"] is not None:
  427. expected_keys.append("archive")
  428. assert is_dict(obj["archive"])
  429. archive_keys = []
  430. # FIXME: Properly test commandFragments
  431. if "commandFragments" in obj["archive"]:
  432. archive_keys.append("commandFragments")
  433. assert is_list(obj["archive"]["commandFragments"])
  434. for f in obj["archive"]["commandFragments"]:
  435. assert is_dict(f)
  436. assert sorted(f.keys()) == ["fragment", "role"]
  437. assert is_string(f["fragment"])
  438. assert is_string(f["role"])
  439. assert f["role"] in ("flags")
  440. if expected["archive"]["lto"] is not None:
  441. archive_keys.append("lto")
  442. assert is_bool(obj["archive"]["lto"], expected["archive"]["lto"])
  443. assert sorted(obj["archive"].keys()) == sorted(archive_keys)
  444. if expected["dependencies"] is not None:
  445. expected_keys.append("dependencies")
  446. def check_dependency(actual, expected):
  447. assert is_dict(actual)
  448. expected_keys = ["id"]
  449. if expected["backtrace"] is not None:
  450. expected_keys.append("backtrace")
  451. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  452. assert sorted(actual.keys()) == sorted(expected_keys)
  453. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  454. obj["dependencies"], expected["dependencies"],
  455. check=check_dependency,
  456. check_exception=lambda a, e: "Dependency ID: %s" % a["id"],
  457. missing_exception=lambda e: "Dependency ID: %s" % e["id"],
  458. extra_exception=lambda a: "Dependency ID: %s" % a["id"])
  459. def is_same_link_library(actual, expected):
  460. if "id" in actual:
  461. return expected["id"] is not None and matches(actual["id"], expected["id"])
  462. if "fragment" in actual:
  463. return expected["fragment"] is not None and is_string(actual["fragment"], expected["fragment"])
  464. assert False # actual must have one of id or fragment
  465. if expected["linkLibraries"] is not None:
  466. expected_keys.append("linkLibraries")
  467. def check_link_library(actual, expected):
  468. assert is_dict(actual)
  469. expected_keys = []
  470. # We always require exactly one of id or fragment
  471. if expected["id"] is not None:
  472. expected_keys.append("id")
  473. assert matches(actual["id"], expected["id"])
  474. assert "fragment" not in actual
  475. else:
  476. expected_keys.append("fragment")
  477. assert is_string(actual["fragment"], expected["fragment"])
  478. assert "id" not in actual
  479. if expected["backtrace"] is not None:
  480. expected_keys.append("backtrace")
  481. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  482. if expected["fromDependency"] is not None:
  483. expected_keys.append("fromDependency")
  484. assert is_dict(actual["fromDependency"])
  485. assert matches(actual["fromDependency"]["id"], expected["fromDependency"])
  486. assert sorted(actual["fromDependency"].keys()) == ["id"]
  487. assert sorted(actual.keys()) == sorted(expected_keys)
  488. check_list_match(is_same_link_library,
  489. obj["linkLibraries"], expected["linkLibraries"],
  490. check=check_link_library,
  491. check_exception=lambda a, e: "Mismatched link library: %s" % (a["id"] if "id" in a else a["fragment"]),
  492. missing_exception=lambda e: "Missing link library: %s" % (e["id"] if e["id"] is not None else e["fragment"]),
  493. extra_exception=lambda a: "Extra link library: %s" % (a["id"] if "id" in a else a["fragment"]))
  494. if expected["interfaceLinkLibraries"] is not None:
  495. expected_keys.append("interfaceLinkLibraries")
  496. def check_interface_link_library(actual, expected):
  497. assert is_dict(actual)
  498. expected_keys = []
  499. # We always require exactly one of id or fragment
  500. if expected["id"] is not None:
  501. expected_keys.append("id")
  502. assert matches(actual["id"], expected["id"])
  503. assert "fragment" not in actual
  504. else:
  505. expected_keys.append("fragment")
  506. assert is_string(actual["fragment"], expected["fragment"])
  507. assert "id" not in actual
  508. if expected["backtrace"] is not None:
  509. expected_keys.append("backtrace")
  510. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  511. assert sorted(actual.keys()) == sorted(expected_keys)
  512. check_list_match(is_same_link_library,
  513. obj["interfaceLinkLibraries"], expected["interfaceLinkLibraries"],
  514. check=check_interface_link_library,
  515. check_exception=lambda a, e: "Mismatched interface link library: %s" % (a["id"] if "id" in a else a["fragment"]),
  516. missing_exception=lambda e: "Missing interface link library: %s" % (e["id"] if e["id"] is not None else e["fragment"]),
  517. extra_exception=lambda a: "Extra interface link library: %s" % (a["id"] if "id" in a else a["fragment"]))
  518. if expected["compileDependencies"] is not None:
  519. expected_keys.append("compileDependencies")
  520. def check_usage_dependency(actual, expected):
  521. assert is_dict(actual)
  522. assert matches(actual["id"], expected["id"])
  523. expected_keys = ["id"]
  524. if expected["backtrace"] is not None:
  525. expected_keys.append("backtrace")
  526. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  527. if expected["fromDependency"] is not None:
  528. expected_keys.append("fromDependency")
  529. assert is_dict(actual["fromDependency"])
  530. assert matches(actual["fromDependency"]["id"], expected["fromDependency"])
  531. assert sorted(actual["fromDependency"].keys()) == ["id"]
  532. assert sorted(actual.keys()) == sorted(expected_keys)
  533. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  534. obj["compileDependencies"], expected["compileDependencies"],
  535. check=check_usage_dependency,
  536. check_exception=lambda a, e: "Mismatched compile dependency: %s" % a["id"],
  537. missing_exception=lambda e: "Missing compile dependency: %s" % e["id"],
  538. extra_exception=lambda a: "Extra compile dependency: %s" % a["id"])
  539. def check_only_target_dependency(actual, expected):
  540. assert is_dict(actual)
  541. assert matches(actual["id"], expected["id"])
  542. expected_keys = ["id"]
  543. if expected["backtrace"] is not None:
  544. expected_keys.append("backtrace")
  545. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  546. assert sorted(actual.keys()) == sorted(expected_keys)
  547. if expected["interfaceCompileDependencies"] is not None:
  548. expected_keys.append("interfaceCompileDependencies")
  549. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  550. obj["interfaceCompileDependencies"], expected["interfaceCompileDependencies"],
  551. check=check_only_target_dependency,
  552. check_exception=lambda a, e: "Mismatched interface compile dependency: %s" % a["id"],
  553. missing_exception=lambda e: "Missing interface compile dependency: %s" % e["id"],
  554. extra_exception=lambda a: "Extra interface compile dependency: %s" % a["id"])
  555. if expected["objectDependencies"] is not None:
  556. expected_keys.append("objectDependencies")
  557. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  558. obj["objectDependencies"], expected["objectDependencies"],
  559. check=check_only_target_dependency,
  560. check_exception=lambda a, e: "Mismatched object dependency: %s" % a["id"],
  561. missing_exception=lambda e: "Missing object dependency: %s" % e["id"],
  562. extra_exception=lambda a: "Extra object dependency: %s" % a["id"])
  563. if expected["orderDependencies"] is not None:
  564. expected_keys.append("orderDependencies")
  565. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  566. obj["orderDependencies"], expected["orderDependencies"],
  567. check=check_only_target_dependency,
  568. check_exception=lambda a, e: "Mismatched order dependency: %s" % a["id"],
  569. missing_exception=lambda e: "Missing order dependency: %s" % e["id"],
  570. extra_exception=lambda a: "Extra order dependency: %s" % a["id"])
  571. if expected["sourceGroups"] is not None:
  572. expected_keys.append("sourceGroups")
  573. def check_source_group(actual, expected):
  574. assert is_dict(actual)
  575. expected_group_keys = ["name", "sourceIndexes"]
  576. if expected["interfaceSourcePaths"] is not None:
  577. expected_group_keys.append("interfaceSourceIndexes")
  578. check_list_match(lambda a, e: matches(obj["interfaceSources"][a]["path"], e),
  579. actual["interfaceSourceIndexes"], expected["interfaceSourcePaths"],
  580. missing_exception=lambda e: "Interface source path: %s" % e,
  581. extra_exception=lambda a: "Interface source path: %s" % obj["interfaceSources"][a]["path"])
  582. assert sorted(actual.keys()) == sorted(expected_group_keys)
  583. check_list_match(lambda a, e: matches(obj["sources"][a]["path"], e),
  584. actual["sourceIndexes"], expected["sourcePaths"],
  585. missing_exception=lambda e: "Source path: %s" % e,
  586. extra_exception=lambda a: "Source path: %s" % obj["sources"][a]["path"])
  587. check_list_match(lambda a, e: is_string(a["name"], e["name"]),
  588. obj["sourceGroups"], expected["sourceGroups"],
  589. check=check_source_group,
  590. check_exception=lambda a, e: "Source group: %s" % a["name"],
  591. missing_exception=lambda e: "Source group: %s" % e["name"],
  592. extra_exception=lambda a: "Source group: %s" % a["name"])
  593. if expected["compileGroups"] is not None:
  594. expected_keys.append("compileGroups")
  595. def check_compile_group(actual, expected):
  596. assert is_dict(actual)
  597. expected_keys = ["sourceIndexes", "language"]
  598. check_list_match(lambda a, e: matches(obj["sources"][a]["path"], e),
  599. actual["sourceIndexes"], expected["sourcePaths"],
  600. missing_exception=lambda e: "Source path: %s" % e,
  601. extra_exception=lambda a: "Source path: %s" % obj["sources"][a]["path"])
  602. if "compileCommandFragments" in actual:
  603. expected_keys.append("compileCommandFragments")
  604. assert is_list(actual["compileCommandFragments"])
  605. for f in actual["compileCommandFragments"]:
  606. assert is_dict(f)
  607. assert is_string(f["fragment"])
  608. if expected["compileCommandFragments"] is not None:
  609. def check_compile_command_fragments(actual, expected):
  610. assert is_dict(actual)
  611. expected_keys = ["fragment"]
  612. if expected["backtrace"] is not None:
  613. expected_keys.append("backtrace")
  614. assert actual["fragment"] == expected["fragment"]
  615. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  616. assert sorted(actual.keys()) == sorted(expected_keys)
  617. check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]),
  618. actual["compileCommandFragments"], expected["compileCommandFragments"],
  619. check=check_compile_command_fragments,
  620. check_exception=lambda a, e: "Compile fragment: %s" % a["fragment"],
  621. missing_exception=lambda e: "Compile fragment: %s" % e["fragment"],
  622. extra_exception=lambda a: "Compile fragment: %s" % a["fragment"],
  623. allow_extra=True)
  624. if expected["includes"] is not None:
  625. expected_keys.append("includes")
  626. def check_include(actual, expected):
  627. assert is_dict(actual)
  628. expected_keys = ["path"]
  629. if expected["isSystem"] is not None:
  630. expected_keys.append("isSystem")
  631. assert is_bool(actual["isSystem"], expected["isSystem"])
  632. if expected["backtrace"] is not None:
  633. expected_keys.append("backtrace")
  634. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  635. assert sorted(actual.keys()) == sorted(expected_keys)
  636. check_list_match(lambda a, e: matches(a["path"], e["path"]),
  637. actual["includes"], expected["includes"],
  638. check=check_include,
  639. check_exception=lambda a, e: "Include path: %s" % a["path"],
  640. missing_exception=lambda e: "Include path: %s" % e["path"],
  641. extra_exception=lambda a: "Include path: %s" % a["path"])
  642. if expected["frameworks"] is not None:
  643. expected_keys.append("frameworks")
  644. def check_include(actual, expected):
  645. assert is_dict(actual)
  646. expected_keys = ["path"]
  647. if expected["isSystem"] is not None:
  648. expected_keys.append("isSystem")
  649. assert is_bool(actual["isSystem"], expected["isSystem"])
  650. if expected["backtrace"] is not None:
  651. expected_keys.append("backtrace")
  652. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  653. assert sorted(actual.keys()) == sorted(expected_keys)
  654. check_list_match(lambda a, e: matches(a["path"], e["path"]),
  655. actual["frameworks"], expected["frameworks"],
  656. check=check_include,
  657. check_exception=lambda a, e: "Framework path: %s" % a["path"],
  658. missing_exception=lambda e: "Framework path: %s" % e["path"],
  659. extra_exception=lambda a: "Framework path: %s" % a["path"])
  660. if "precompileHeaders" in expected:
  661. expected_keys.append("precompileHeaders")
  662. def check_precompile_header(actual, expected):
  663. assert is_dict(actual)
  664. expected_keys = ["backtrace", "header"]
  665. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  666. assert sorted(actual.keys()) == sorted(expected_keys)
  667. check_list_match(lambda a, e: matches(a["header"], e["header"]),
  668. actual["precompileHeaders"], expected["precompileHeaders"],
  669. check=check_precompile_header,
  670. check_exception=lambda a, e: "Precompile header: %s" % a["header"],
  671. missing_exception=lambda e: "Precompile header: %s" % e["header"],
  672. extra_exception=lambda a: "Precompile header: %s" % a["header"])
  673. if "languageStandard" in expected:
  674. expected_keys.append("languageStandard")
  675. def check_language_standard(actual, expected):
  676. assert is_dict(actual)
  677. expected_keys = ["backtraces", "standard"]
  678. assert actual["standard"] == expected["standard"]
  679. check_backtraces(obj, actual["backtraces"], expected["backtraces"])
  680. assert sorted(actual.keys()) == sorted(expected_keys)
  681. check_language_standard(actual["languageStandard"], expected["languageStandard"])
  682. if expected["defines"] is not None:
  683. expected_keys.append("defines")
  684. def check_define(actual, expected):
  685. assert is_dict(actual)
  686. expected_keys = ["define"]
  687. if expected["backtrace"] is not None:
  688. expected_keys.append("backtrace")
  689. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  690. assert sorted(actual.keys()) == sorted(expected_keys)
  691. check_list_match(lambda a, e: is_string(a["define"], e["define"]),
  692. actual["defines"], expected["defines"],
  693. check=check_define,
  694. check_exception=lambda a, e: "Define: %s" % a["define"],
  695. missing_exception=lambda e: "Define: %s" % e["define"],
  696. extra_exception=lambda a: "Define: %s" % a["define"])
  697. # FIXME: Properly test sysroot
  698. if "sysroot" in actual:
  699. expected_keys.append("sysroot")
  700. assert is_string(actual["sysroot"])
  701. assert sorted(actual.keys()) == sorted(expected_keys)
  702. check_list_match(lambda a, e: is_string(a["language"], e["language"]),
  703. obj["compileGroups"], expected["compileGroups"],
  704. check=check_compile_group,
  705. check_exception=lambda a, e: "Compile group: %s" % a["language"],
  706. missing_exception=lambda e: "Compile group: %s" % e["language"],
  707. extra_exception=lambda a: "Compile group: %s" % a["language"])
  708. assert sorted(obj.keys()) == sorted(expected_keys)
  709. return _check
  710. def check_project(c):
  711. def _check(actual, expected):
  712. assert is_dict(actual)
  713. expected_keys = ["name", "directoryIndexes"]
  714. check_list_match(lambda a, e: matches(c["directories"][a]["source"], e),
  715. actual["directoryIndexes"], expected["directorySources"],
  716. missing_exception=lambda e: "Directory source: %s" % e,
  717. extra_exception=lambda a: "Directory source: %s" % c["directories"][a]["source"])
  718. if expected["parentName"] is not None:
  719. expected_keys.append("parentIndex")
  720. assert is_int(actual["parentIndex"])
  721. assert is_string(c["projects"][actual["parentIndex"]]["name"], expected["parentName"])
  722. if expected["childNames"] is not None:
  723. expected_keys.append("childIndexes")
  724. check_list_match(lambda a, e: is_string(c["projects"][a]["name"], e),
  725. actual["childIndexes"], expected["childNames"],
  726. missing_exception=lambda e: "Child name: %s" % e,
  727. extra_exception=lambda a: "Child name: %s" % c["projects"][a]["name"])
  728. if expected["targetIds"] is not None:
  729. expected_keys.append("targetIndexes")
  730. check_list_match(lambda a, e: matches(c["targets"][a]["id"], e),
  731. actual["targetIndexes"], expected["targetIds"],
  732. missing_exception=lambda e: "Target ID: %s" % e,
  733. extra_exception=lambda a: "Target ID: %s" % c["targets"][a]["id"])
  734. if expected["abstractTargetIds"] is not None:
  735. expected_keys.append("abstractTargetIndexes")
  736. check_list_match(lambda a, e: matches(c["abstractTargets"][a]["id"], e),
  737. actual["abstractTargetIndexes"], expected["abstractTargetIds"],
  738. missing_exception=lambda e: "Abstract target ID: %s" % e,
  739. extra_exception=lambda a: "Abstract target ID: %s" % c["abstractTargets"][a]["id"])
  740. assert sorted(actual.keys()) == sorted(expected_keys)
  741. return _check
  742. def gen_check_directories(c, g):
  743. expected = [
  744. read_codemodel_json_data("directories/top.json"),
  745. read_codemodel_json_data("directories/alias.json"),
  746. read_codemodel_json_data("directories/custom.json"),
  747. read_codemodel_json_data("directories/cxx.json"),
  748. read_codemodel_json_data("directories/cxx.cross.json"),
  749. read_codemodel_json_data("directories/imported.json"),
  750. read_codemodel_json_data("directories/interface.json"),
  751. read_codemodel_json_data("directories/object.json"),
  752. read_codemodel_json_data("directories/dir.json"),
  753. read_codemodel_json_data("directories/dir_dir.json"),
  754. read_codemodel_json_data("directories/dir_very-long.json"),
  755. read_codemodel_json_data("directories/external.json"),
  756. read_codemodel_json_data("directories/fileset.json"),
  757. read_codemodel_json_data("directories/subdir.json"),
  758. read_codemodel_json_data("directories/framework.json"),
  759. read_codemodel_json_data("directories/direct.json"),
  760. ]
  761. if matches(g["name"], "^Visual Studio "):
  762. for e in expected:
  763. if e["parentSource"] is not None:
  764. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^ZERO_CHECK"), e["targetIds"])
  765. elif g["name"] == "Xcode":
  766. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  767. for e in expected:
  768. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(link_imported_object_exe)"), e["targetIds"])
  769. e["abstractTargetIds"] = filter_list(lambda t: not matches(t, "^\\^(imported_object_lib)"), e["abstractTargetIds"])
  770. else:
  771. for e in expected:
  772. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(ALL_BUILD|ZERO_CHECK)"), e["targetIds"])
  773. if sys.platform in ("win32", "cygwin", "msys") or "aix" in sys.platform:
  774. for e in expected:
  775. e["installers"] = list(filter(lambda i: i["targetInstallNamelink"] is None or i["targetInstallNamelink"] == "skip", e["installers"]))
  776. for i in e["installers"]:
  777. i["targetInstallNamelink"] = None
  778. if sys.platform not in ("win32", "cygwin", "msys"):
  779. for e in expected:
  780. e["installers"] = list(filter(lambda i: not i.get("_dllExtra", False), e["installers"]))
  781. if "aix" not in sys.platform:
  782. for i in e["installers"]:
  783. if "pathsNamelink" in i:
  784. i["paths"] = i["pathsNamelink"]
  785. if sys.platform not in ("win32", "darwin") and "linux" not in sys.platform:
  786. for e in expected:
  787. e["installers"] = list(filter(lambda i: i["type"] != "runtimeDependencySet", e["installers"]))
  788. if sys.platform != "darwin":
  789. for e in expected:
  790. e["installers"] = list(filter(lambda i: i.get("runtimeDependencySetType", None) != "framework", e["installers"]))
  791. return expected
  792. def check_directories(c, g, major, minor):
  793. check_list_match(lambda a, e: matches(a["source"], e["source"]), c["directories"], gen_check_directories(c, g),
  794. check=check_directory(c, major, minor),
  795. check_exception=lambda a, e: "Directory source: %s" % a["source"],
  796. missing_exception=lambda e: "Directory source: %s" % e["source"],
  797. extra_exception=lambda a: "Directory source: %s" % a["source"])
  798. def gen_check_build_system_targets(c, g, inSource):
  799. expected = [
  800. read_codemodel_json_data("targets/all_build_top.json"),
  801. read_codemodel_json_data("targets/zero_check_top.json"),
  802. read_codemodel_json_data("targets/interface_exe.json"),
  803. read_codemodel_json_data("targets/c_lib.json"),
  804. read_codemodel_json_data("targets/c_exe.json"),
  805. read_codemodel_json_data("targets/c_shared_lib.json"),
  806. read_codemodel_json_data("targets/c_shared_exe.json"),
  807. read_codemodel_json_data("targets/c_static_lib.json"),
  808. read_codemodel_json_data("targets/c_static_exe.json"),
  809. read_codemodel_json_data("targets/c_subdir.json"),
  810. read_codemodel_json_data("targets/all_build_cxx.json"),
  811. read_codemodel_json_data("targets/zero_check_cxx.json"),
  812. read_codemodel_json_data("targets/cxx_lib.json"),
  813. read_codemodel_json_data("targets/cxx_exe.json"),
  814. read_codemodel_json_data("targets/cxx_exe_cross_emulator.json"),
  815. read_codemodel_json_data("targets/cxx_exe_cross_emulator_args.json"),
  816. read_codemodel_json_data("targets/cxx_exe_test_launcher_and_cross_emulator.json"),
  817. read_codemodel_json_data("targets/cxx_exe_test_launcher.json"),
  818. read_codemodel_json_data("targets/cxx_standard_compile_feature_exe.json"),
  819. read_codemodel_json_data("targets/cxx_standard_exe.json"),
  820. read_codemodel_json_data("targets/cxx_shared_lib.json"),
  821. read_codemodel_json_data("targets/cxx_shared_exe.json"),
  822. read_codemodel_json_data("targets/cxx_static_lib.json"),
  823. read_codemodel_json_data("targets/cxx_static_exe.json"),
  824. read_codemodel_json_data("targets/all_build_alias.json"),
  825. read_codemodel_json_data("targets/zero_check_alias.json"),
  826. read_codemodel_json_data("targets/c_alias_exe.json"),
  827. read_codemodel_json_data("targets/cxx_alias_exe.json"),
  828. read_codemodel_json_data("targets/all_build_object.json"),
  829. read_codemodel_json_data("targets/zero_check_object.json"),
  830. read_codemodel_json_data("targets/c_object_lib.json"),
  831. read_codemodel_json_data("targets/c_object_exe.json"),
  832. read_codemodel_json_data("targets/cxx_object_lib.json"),
  833. read_codemodel_json_data("targets/cxx_object_exe.json"),
  834. read_codemodel_json_data("targets/all_build_framework.json"),
  835. read_codemodel_json_data("targets/zero_check_framework.json"),
  836. read_codemodel_json_data("targets/static_framework.json"),
  837. read_codemodel_json_data("targets/shared_framework.json"),
  838. read_codemodel_json_data("targets/exe_framework.json"),
  839. read_codemodel_json_data("targets/all_build_imported.json"),
  840. read_codemodel_json_data("targets/zero_check_imported.json"),
  841. read_codemodel_json_data("targets/link_imported_exe.json"),
  842. read_codemodel_json_data("targets/link_imported_shared_exe.json"),
  843. read_codemodel_json_data("targets/link_imported_static_exe.json"),
  844. read_codemodel_json_data("targets/link_imported_object_exe.json"),
  845. read_codemodel_json_data("targets/link_imported_interface_exe.json"),
  846. read_codemodel_json_data("targets/link_imported_interface_symbolic_exe.json"),
  847. read_codemodel_json_data("targets/all_build_interface.json"),
  848. read_codemodel_json_data("targets/zero_check_interface.json"),
  849. read_codemodel_json_data("targets/iface_srcs.json"),
  850. read_codemodel_json_data("targets/all_build_direct.json"),
  851. read_codemodel_json_data("targets/zero_check_direct.json"),
  852. read_codemodel_json_data("targets/link_transitive_direct_exe.json"),
  853. read_codemodel_json_data("targets/transitive_direct_lib.json"),
  854. read_codemodel_json_data("targets/inject_direct_lib_impl.json"),
  855. read_codemodel_json_data("targets/usage_lib.json"),
  856. read_codemodel_json_data("targets/link_usage_exe.json"),
  857. read_codemodel_json_data("targets/compile_usage_exe.json"),
  858. read_codemodel_json_data("targets/all_build_custom.json"),
  859. read_codemodel_json_data("targets/zero_check_custom.json"),
  860. read_codemodel_json_data("targets/custom_tgt.json"),
  861. read_codemodel_json_data("targets/custom_exe.json"),
  862. read_codemodel_json_data("targets/all_build_external.json"),
  863. read_codemodel_json_data("targets/zero_check_external.json"), # Must be the last zero_check_... because matches all ZERO_CHECK::@XXX target ids
  864. read_codemodel_json_data("targets/generated_exe.json"),
  865. read_codemodel_json_data("targets/c_headers_1.json"),
  866. read_codemodel_json_data("targets/c_headers_2.json"),
  867. ]
  868. if sys.platform == "darwin":
  869. for e in expected:
  870. if e["name"] == "static_framework":
  871. apple_static_framework = read_codemodel_json_data("targets/apple_static_framework.json")
  872. e["artifacts"] = apple_static_framework["artifacts"]
  873. e["nameOnDisk"] = apple_static_framework["nameOnDisk"]
  874. elif e["name"] == "shared_framework":
  875. apple_shared_framework = read_codemodel_json_data("targets/apple_shared_framework.json")
  876. e["artifacts"] = apple_shared_framework["artifacts"]
  877. e["nameOnDisk"] = apple_shared_framework["nameOnDisk"]
  878. elif e["name"] == "exe_framework":
  879. apple_exe_framework = read_codemodel_json_data("targets/apple_exe_framework.json")
  880. e["compileGroups"] = apple_exe_framework["compileGroups"]
  881. e["link"] = apple_exe_framework["link"]
  882. if args.cxx_compiler_id in ['Clang', 'AppleClang', 'LCC', 'GNU', 'Intel', 'IntelLLVM', 'MSVC', 'Embarcadero', 'CrayClang', 'IBMClang'] and g["name"] != "Xcode":
  883. for e in expected:
  884. if e["name"] == "cxx_exe":
  885. if matches(g["name"], "^(Visual Studio |Ninja Multi-Config)"):
  886. precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_multigen.json")
  887. else:
  888. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  889. precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_2arch.json")
  890. else:
  891. precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader.json")
  892. e["compileGroups"] = precompile_header_data["compileGroups"]
  893. e["sources"] = precompile_header_data["sources"]
  894. e["sourceGroups"] = precompile_header_data["sourceGroups"]
  895. if args.cxx_compiler_id != 'MSVC' and args.cxx_simulate_id != 'MSVC':
  896. for e in expected:
  897. if not e["compileGroups"]:
  898. continue
  899. for group in e["compileGroups"]:
  900. if not group["defines"]:
  901. continue
  902. # _WINDLL is expected for compilers targeting the MSVC ABI, but not for others.
  903. # And _MBCS too
  904. group["defines"] = [d for d in group["defines"] if d and d["define"] != "_WINDLL" and d["define"] != "_MBCS"]
  905. if len(group["defines"]) == 0:
  906. group["defines"] = None
  907. if os.path.exists(os.path.join(reply_dir, "..", "..", "..", "..", "cxx", "cxx_std_11.txt")):
  908. for e in expected:
  909. if e["name"] == "cxx_standard_compile_feature_exe":
  910. language_standard_data = read_codemodel_json_data("targets/cxx_standard_compile_feature_exe_languagestandard.json")
  911. e["compileGroups"][0]["languageStandard"] = language_standard_data["languageStandard"]
  912. if not os.path.exists(os.path.join(reply_dir, "..", "..", "..", "..", "ipo_enabled.txt")):
  913. for e in expected:
  914. try:
  915. e["link"]["lto"] = None
  916. except TypeError: # "link" is not a dict, no problem.
  917. pass
  918. try:
  919. e["archive"]["lto"] = None
  920. except TypeError: # "archive" is not a dict, no problem.
  921. pass
  922. if inSource:
  923. for e in expected:
  924. if e["sources"] is not None:
  925. for s in e["sources"]:
  926. s["path"] = s["path"].replace("^.*/Tests/RunCMake/FileAPI/", "^", 1)
  927. if e["sourceGroups"] is not None:
  928. for group in e["sourceGroups"]:
  929. group["sourcePaths"] = [p.replace("^.*/Tests/RunCMake/FileAPI/", "^", 1) for p in group["sourcePaths"]]
  930. if e["compileGroups"] is not None:
  931. for group in e["compileGroups"]:
  932. group["sourcePaths"] = [p.replace("^.*/Tests/RunCMake/FileAPI/", "^", 1) for p in group["sourcePaths"]]
  933. if matches(g["name"], "^Visual Studio "):
  934. expected = filter_list(lambda e: e["name"] not in ("ZERO_CHECK") or e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$", expected)
  935. for e in expected:
  936. if e["type"] == "UTILITY":
  937. if e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$":
  938. # The json files have data for Xcode. Substitute data for VS.
  939. e["sources"] = [
  940. {
  941. "path": "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
  942. "isGenerated": True,
  943. "fileSetName": None,
  944. "sourceGroupName": "CMake Rules",
  945. "compileGroupLanguage": None,
  946. "backtrace": [
  947. {
  948. "file": "^CMakeLists\\.txt$",
  949. "line": None,
  950. "command": None,
  951. "hasParent": False,
  952. },
  953. ],
  954. },
  955. ]
  956. e["sourceGroups"] = [
  957. {
  958. "name": "CMake Rules",
  959. "sourcePaths": [
  960. "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
  961. ],
  962. "interfaceSourcePaths": None,
  963. },
  964. ]
  965. elif e["name"] in ("ALL_BUILD"):
  966. e["sources"] = []
  967. e["sourceGroups"] = None
  968. if e["dependencies"] is not None:
  969. for d in e["dependencies"]:
  970. if matches(d["id"], "^\\^ZERO_CHECK::@"):
  971. d["id"] = "^ZERO_CHECK::@6890427a1f51a3e7e1df$"
  972. if e["name"] == "cxx_exe":
  973. e["debugger"]["workingDirectory"] = "^/test/debugger/workingDirectoryVS$"
  974. elif g["name"] == "Xcode":
  975. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  976. expected = filter_list(lambda e: e["name"] not in ("link_imported_object_exe"), expected)
  977. for e in expected:
  978. e["dependencies"] = filter_list(lambda d: not matches(d["id"], "^\\^link_imported_object_exe::@"), e["dependencies"])
  979. e["orderDependencies"] = filter_list(lambda d: not matches(d["id"], "^\\^link_imported_object_exe::@"), e["orderDependencies"])
  980. if e["name"] in ("c_object_lib", "cxx_object_lib", "inject_direct_lib_impl"):
  981. e["artifacts"] = None
  982. else:
  983. for e in expected:
  984. e["dependencies"] = filter_list(lambda d: not matches(d["id"], "^\\^ZERO_CHECK::@"), e["dependencies"])
  985. expected = filter_list(lambda t: t["name"] not in ("ALL_BUILD", "ZERO_CHECK"), expected)
  986. if sys.platform not in ("win32", "cygwin", "msys"):
  987. for e in expected:
  988. e["artifacts"] = filter_list(lambda a: not a["_dllExtra"], e["artifacts"])
  989. if e["install"] is not None:
  990. e["install"]["destinations"] = filter_list(lambda d: "_dllExtra" not in d or not d["_dllExtra"], e["install"]["destinations"])
  991. else:
  992. for e in expected:
  993. if e["install"] is not None:
  994. e["install"]["destinations"] = filter_list(lambda d: "_namelink" not in d or not d["_namelink"], e["install"]["destinations"])
  995. if "aix" not in sys.platform:
  996. for e in expected:
  997. e["artifacts"] = filter_list(lambda a: not a.get("_aixExtra", False), e["artifacts"])
  998. return expected
  999. def gen_check_abstract_targets(c, g, inSource):
  1000. expected = [
  1001. read_codemodel_json_data("targets/interface_lib.json"),
  1002. read_codemodel_json_data("targets/import_framework.json"),
  1003. read_codemodel_json_data("targets/imported_exe.json"),
  1004. read_codemodel_json_data("targets/imported_lib.json"),
  1005. read_codemodel_json_data("targets/imported_interface_lib.json"),
  1006. read_codemodel_json_data("targets/imported_interface_symbolic_lib.json"),
  1007. read_codemodel_json_data("targets/imported_object_lib.json"),
  1008. read_codemodel_json_data("targets/imported_shared_lib.json"),
  1009. read_codemodel_json_data("targets/imported_static_lib.json"),
  1010. read_codemodel_json_data("targets/unused_imported_shared_lib.json"),
  1011. read_codemodel_json_data("targets/iface_none.json"),
  1012. read_codemodel_json_data("targets/iface_symbolic.json"),
  1013. read_codemodel_json_data("targets/inject_direct_lib.json"),
  1014. ]
  1015. if sys.platform == "darwin":
  1016. for e in expected:
  1017. if e["name"] == "import_framework":
  1018. apple_import_framework = read_codemodel_json_data("targets/apple_import_framework.json")
  1019. e["artifacts"] = apple_import_framework["artifacts"]
  1020. e["nameOnDisk"] = apple_import_framework["nameOnDisk"]
  1021. if g["name"] == "Xcode":
  1022. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  1023. expected = filter_list(lambda e: e["name"] not in ("imported_object_lib"), expected)
  1024. if sys.platform not in ("win32", "cygwin", "msys"):
  1025. for e in expected:
  1026. e["artifacts"] = filter_list(lambda a: not a["_dllExtra"], e["artifacts"])
  1027. return expected
  1028. def check_build_system_targets(c, g, major, minor, inSource):
  1029. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  1030. c["targets"], gen_check_build_system_targets(c, g, inSource),
  1031. check=check_target(c, major, minor),
  1032. check_exception=lambda a, e: "Target ID: %s" % a["id"],
  1033. missing_exception=lambda e: "Target ID: %s" % e["id"],
  1034. extra_exception=lambda a: "Target ID: %s" % a["id"])
  1035. def check_abstract_targets(c, g, major, minor, inSource):
  1036. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  1037. c["abstractTargets"], gen_check_abstract_targets(c, g, inSource),
  1038. check=check_target(c, major, minor),
  1039. check_exception=lambda a, e: "Abstract target ID: %s" % a["id"],
  1040. missing_exception=lambda e: "Abstract target ID: %s" % e["id"],
  1041. extra_exception=lambda a: "Abstract target ID: %s" % a["id"])
  1042. def gen_check_projects(c, g):
  1043. expected = [
  1044. read_codemodel_json_data("projects/codemodel-v2.json"),
  1045. read_codemodel_json_data("projects/cxx.json"),
  1046. read_codemodel_json_data("projects/alias.json"),
  1047. read_codemodel_json_data("projects/object.json"),
  1048. read_codemodel_json_data("projects/imported.json"),
  1049. read_codemodel_json_data("projects/interface.json"),
  1050. read_codemodel_json_data("projects/custom.json"),
  1051. read_codemodel_json_data("projects/external.json"),
  1052. read_codemodel_json_data("projects/framework.json"),
  1053. read_codemodel_json_data("projects/direct.json"),
  1054. ]
  1055. if matches(g["name"], "^Visual Studio "):
  1056. for e in expected:
  1057. if e["parentName"] is not None:
  1058. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^ZERO_CHECK"), e["targetIds"])
  1059. elif g["name"] == "Xcode":
  1060. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  1061. for e in expected:
  1062. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(link_imported_object_exe)"), e["targetIds"])
  1063. e["abstractTargetIds"] = filter_list(lambda t: not matches(t, "^\\^(imported_object_lib)"), e["abstractTargetIds"])
  1064. else:
  1065. for e in expected:
  1066. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(ALL_BUILD|ZERO_CHECK)"), e["targetIds"])
  1067. return expected
  1068. def check_projects(c, g):
  1069. check_list_match(lambda a, e: is_string(a["name"], e["name"]), c["projects"], gen_check_projects(c, g),
  1070. check=check_project(c),
  1071. check_exception=lambda a, e: "Project name: %s" % a["name"],
  1072. missing_exception=lambda e: "Project name: %s" % e["name"],
  1073. extra_exception=lambda a: "Project name: %s" % a["name"])
  1074. def check_object_codemodel_configuration(c, g, major, minor, inSource):
  1075. assert sorted(c.keys()) == ["abstractTargets", "directories", "name", "projects", "targets"]
  1076. assert is_string(c["name"])
  1077. check_directories(c, g, major, minor)
  1078. check_build_system_targets(c, g, major, minor, inSource)
  1079. check_abstract_targets(c, g, major, minor, inSource)
  1080. check_projects(c, g)
  1081. def check_object_codemodel(g, major, minor):
  1082. def _check(o):
  1083. assert sorted(o.keys()) == ["configurations", "kind", "paths", "version"]
  1084. # The "kind" and "version" members are handled by check_index_object.
  1085. assert is_dict(o["paths"])
  1086. assert sorted(o["paths"].keys()) == ["build", "source"]
  1087. assert matches(o["paths"]["build"], "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build$")
  1088. assert matches(o["paths"]["source"], "^.*/Tests/RunCMake/FileAPI$")
  1089. inSource = os.path.dirname(o["paths"]["build"]) == o["paths"]["source"]
  1090. if g["multiConfig"]:
  1091. assert sorted([c["name"] for c in o["configurations"]]) == ["Debug", "MinSizeRel", "RelWithDebInfo", "Release"]
  1092. else:
  1093. assert len(o["configurations"]) == 1
  1094. assert o["configurations"][0]["name"] in ("", "Debug", "Release", "RelWithDebInfo", "MinSizeRel")
  1095. for c in o["configurations"]:
  1096. check_object_codemodel_configuration(c, g, major, minor, inSource)
  1097. return _check
  1098. assert is_dict(index)
  1099. assert sorted(index.keys()) == ["cmake", "objects", "reply"]
  1100. check_objects(index["objects"], index["cmake"]["generator"])