codemodel-v2-check.py 56 KB

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