codemodel-v2-check.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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, 1, 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_directory(c):
  36. def _check(actual, expected):
  37. assert is_dict(actual)
  38. expected_keys = ["build", "source", "projectIndex"]
  39. assert matches(actual["build"], expected["build"])
  40. assert is_int(actual["projectIndex"])
  41. assert is_string(c["projects"][actual["projectIndex"]]["name"], expected["projectName"])
  42. if expected["parentSource"] is not None:
  43. expected_keys.append("parentIndex")
  44. assert is_int(actual["parentIndex"])
  45. assert matches(c["directories"][actual["parentIndex"]]["source"], expected["parentSource"])
  46. if expected["childSources"] is not None:
  47. expected_keys.append("childIndexes")
  48. check_list_match(lambda a, e: matches(c["directories"][a]["source"], e),
  49. actual["childIndexes"], expected["childSources"],
  50. missing_exception=lambda e: "Child source: %s" % e,
  51. extra_exception=lambda a: "Child source: %s" % a["source"])
  52. if expected["targetIds"] is not None:
  53. expected_keys.append("targetIndexes")
  54. check_list_match(lambda a, e: matches(c["targets"][a]["id"], e),
  55. actual["targetIndexes"], expected["targetIds"],
  56. missing_exception=lambda e: "Target ID: %s" % e,
  57. extra_exception=lambda a: "Target ID: %s" % c["targets"][a]["id"])
  58. if expected["minimumCMakeVersion"] is not None:
  59. expected_keys.append("minimumCMakeVersion")
  60. assert is_dict(actual["minimumCMakeVersion"])
  61. assert sorted(actual["minimumCMakeVersion"].keys()) == ["string"]
  62. assert is_string(actual["minimumCMakeVersion"]["string"], expected["minimumCMakeVersion"])
  63. if expected["hasInstallRule"] is not None:
  64. expected_keys.append("hasInstallRule")
  65. assert is_bool(actual["hasInstallRule"], expected["hasInstallRule"])
  66. assert sorted(actual.keys()) == sorted(expected_keys)
  67. return _check
  68. def check_target_backtrace_graph(t):
  69. btg = t["backtraceGraph"]
  70. assert is_dict(btg)
  71. assert sorted(btg.keys()) == ["commands", "files", "nodes"]
  72. assert is_list(btg["commands"])
  73. for c in btg["commands"]:
  74. assert is_string(c)
  75. for f in btg["files"]:
  76. assert is_string(f)
  77. for n in btg["nodes"]:
  78. expected_keys = ["file"]
  79. assert is_dict(n)
  80. assert is_int(n["file"])
  81. assert 0 <= n["file"] < len(btg["files"])
  82. if "line" in n:
  83. expected_keys.append("line")
  84. assert is_int(n["line"])
  85. if "command" in n:
  86. expected_keys.append("command")
  87. assert is_int(n["command"])
  88. assert 0 <= n["command"] < len(btg["commands"])
  89. if "parent" in n:
  90. expected_keys.append("parent")
  91. assert is_int(n["parent"])
  92. assert 0 <= n["parent"] < len(btg["nodes"])
  93. assert sorted(n.keys()) == sorted(expected_keys)
  94. def check_target(c):
  95. def _check(actual, expected):
  96. assert is_dict(actual)
  97. assert sorted(actual.keys()) == ["directoryIndex", "id", "jsonFile", "name", "projectIndex"]
  98. assert is_int(actual["directoryIndex"])
  99. assert matches(c["directories"][actual["directoryIndex"]]["source"], expected["directorySource"])
  100. assert is_string(actual["name"], expected["name"])
  101. assert is_string(actual["jsonFile"])
  102. assert is_int(actual["projectIndex"])
  103. assert is_string(c["projects"][actual["projectIndex"]]["name"], expected["projectName"])
  104. filepath = os.path.join(reply_dir, actual["jsonFile"])
  105. with open(filepath) as f:
  106. obj = json.load(f)
  107. expected_keys = ["name", "id", "type", "backtraceGraph", "paths", "sources"]
  108. assert is_dict(obj)
  109. assert is_string(obj["name"], expected["name"])
  110. assert matches(obj["id"], expected["id"])
  111. assert is_string(obj["type"], expected["type"])
  112. check_target_backtrace_graph(obj)
  113. assert is_dict(obj["paths"])
  114. assert sorted(obj["paths"].keys()) == ["build", "source"]
  115. assert matches(obj["paths"]["build"], expected["build"])
  116. assert matches(obj["paths"]["source"], expected["source"])
  117. def check_source(actual, expected):
  118. assert is_dict(actual)
  119. expected_keys = ["path"]
  120. if expected["compileGroupLanguage"] is not None:
  121. expected_keys.append("compileGroupIndex")
  122. assert is_string(obj["compileGroups"][actual["compileGroupIndex"]]["language"], expected["compileGroupLanguage"])
  123. if expected["sourceGroupName"] is not None:
  124. expected_keys.append("sourceGroupIndex")
  125. assert is_string(obj["sourceGroups"][actual["sourceGroupIndex"]]["name"], expected["sourceGroupName"])
  126. if expected["isGenerated"] is not None:
  127. expected_keys.append("isGenerated")
  128. assert is_bool(actual["isGenerated"], expected["isGenerated"])
  129. if expected["backtrace"] is not None:
  130. expected_keys.append("backtrace")
  131. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  132. assert sorted(actual.keys()) == sorted(expected_keys)
  133. check_list_match(lambda a, e: matches(a["path"], e["path"]), obj["sources"],
  134. expected["sources"], check=check_source,
  135. check_exception=lambda a, e: "Source file: %s" % a["path"],
  136. missing_exception=lambda e: "Source file: %s" % e["path"],
  137. extra_exception=lambda a: "Source file: %s" % a["path"])
  138. if expected["backtrace"] is not None:
  139. expected_keys.append("backtrace")
  140. check_backtrace(obj, obj["backtrace"], expected["backtrace"])
  141. if expected["folder"] is not None:
  142. expected_keys.append("folder")
  143. assert is_dict(obj["folder"])
  144. assert sorted(obj["folder"].keys()) == ["name"]
  145. assert is_string(obj["folder"]["name"], expected["folder"])
  146. if expected["nameOnDisk"] is not None:
  147. expected_keys.append("nameOnDisk")
  148. assert matches(obj["nameOnDisk"], expected["nameOnDisk"])
  149. if expected["artifacts"] is not None:
  150. expected_keys.append("artifacts")
  151. def check_artifact(actual, expected):
  152. assert is_dict(actual)
  153. assert sorted(actual.keys()) == ["path"]
  154. check_list_match(lambda a, e: matches(a["path"], e["path"]),
  155. obj["artifacts"], expected["artifacts"],
  156. check=check_artifact,
  157. check_exception=lambda a, e: "Artifact: %s" % a["path"],
  158. missing_exception=lambda e: "Artifact: %s" % e["path"],
  159. extra_exception=lambda a: "Artifact: %s" % a["path"])
  160. if expected["isGeneratorProvided"] is not None:
  161. expected_keys.append("isGeneratorProvided")
  162. assert is_bool(obj["isGeneratorProvided"], expected["isGeneratorProvided"])
  163. if expected["install"] is not None:
  164. expected_keys.append("install")
  165. assert is_dict(obj["install"])
  166. assert sorted(obj["install"].keys()) == ["destinations", "prefix"]
  167. assert is_dict(obj["install"]["prefix"])
  168. assert sorted(obj["install"]["prefix"].keys()) == ["path"]
  169. assert matches(obj["install"]["prefix"]["path"], expected["install"]["prefix"])
  170. def check_install_destination(actual, expected):
  171. assert is_dict(actual)
  172. expected_keys = ["path"]
  173. if expected["backtrace"] is not None:
  174. expected_keys.append("backtrace")
  175. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  176. assert sorted(actual.keys()) == sorted(expected_keys)
  177. check_list_match(lambda a, e: matches(a["path"], e["path"]),
  178. obj["install"]["destinations"], expected["install"]["destinations"],
  179. check=check_install_destination,
  180. check_exception=lambda a, e: "Install path: %s" % a["path"],
  181. missing_exception=lambda e: "Install path: %s" % e["path"],
  182. extra_exception=lambda a: "Install path: %s" % a["path"])
  183. if expected["link"] is not None:
  184. expected_keys.append("link")
  185. assert is_dict(obj["link"])
  186. link_keys = ["language"]
  187. assert is_string(obj["link"]["language"], expected["link"]["language"])
  188. if "commandFragments" in obj["link"]:
  189. link_keys.append("commandFragments")
  190. assert is_list(obj["link"]["commandFragments"])
  191. for f in obj["link"]["commandFragments"]:
  192. assert is_dict(f)
  193. assert sorted(f.keys()) == ["fragment", "role"] or sorted(f.keys()) == ["backtrace", "fragment", "role"]
  194. assert is_string(f["fragment"])
  195. assert is_string(f["role"])
  196. assert f["role"] in ("flags", "libraries", "libraryPath", "frameworkPath")
  197. if expected["link"]["commandFragments"] is not None:
  198. def check_link_command_fragments(actual, expected):
  199. assert is_dict(actual)
  200. expected_keys = ["fragment", "role"]
  201. if expected["backtrace"] is not None:
  202. expected_keys.append("backtrace")
  203. assert matches(actual["fragment"], expected["fragment"])
  204. assert actual["role"] == expected["role"]
  205. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  206. assert sorted(actual.keys()) == sorted(expected_keys)
  207. check_list_match(lambda a, e: matches(a["fragment"], e["fragment"]),
  208. obj["link"]["commandFragments"], expected["link"]["commandFragments"],
  209. check=check_link_command_fragments,
  210. check_exception=lambda a, e: "Link fragment: %s" % a["fragment"],
  211. missing_exception=lambda e: "Link fragment: %s" % e["fragment"],
  212. extra_exception=lambda a: "Link fragment: %s" % a["fragment"],
  213. allow_extra=True)
  214. if expected["link"]["lto"] is not None:
  215. link_keys.append("lto")
  216. assert is_bool(obj["link"]["lto"], expected["link"]["lto"])
  217. # FIXME: Properly test sysroot
  218. if "sysroot" in obj["link"]:
  219. link_keys.append("sysroot")
  220. assert is_string(obj["link"]["sysroot"])
  221. assert sorted(obj["link"].keys()) == sorted(link_keys)
  222. if expected["archive"] is not None:
  223. expected_keys.append("archive")
  224. assert is_dict(obj["archive"])
  225. archive_keys = []
  226. # FIXME: Properly test commandFragments
  227. if "commandFragments" in obj["archive"]:
  228. archive_keys.append("commandFragments")
  229. assert is_list(obj["archive"]["commandFragments"])
  230. for f in obj["archive"]["commandFragments"]:
  231. assert is_dict(f)
  232. assert sorted(f.keys()) == ["fragment", "role"]
  233. assert is_string(f["fragment"])
  234. assert is_string(f["role"])
  235. assert f["role"] in ("flags")
  236. if expected["archive"]["lto"] is not None:
  237. archive_keys.append("lto")
  238. assert is_bool(obj["archive"]["lto"], expected["archive"]["lto"])
  239. assert sorted(obj["archive"].keys()) == sorted(archive_keys)
  240. if expected["dependencies"] is not None:
  241. expected_keys.append("dependencies")
  242. def check_dependency(actual, expected):
  243. assert is_dict(actual)
  244. expected_keys = ["id"]
  245. if expected["backtrace"] is not None:
  246. expected_keys.append("backtrace")
  247. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  248. assert sorted(actual.keys()) == sorted(expected_keys)
  249. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  250. obj["dependencies"], expected["dependencies"],
  251. check=check_dependency,
  252. check_exception=lambda a, e: "Dependency ID: %s" % a["id"],
  253. missing_exception=lambda e: "Dependency ID: %s" % e["id"],
  254. extra_exception=lambda a: "Dependency ID: %s" % a["id"])
  255. if expected["sourceGroups"] is not None:
  256. expected_keys.append("sourceGroups")
  257. def check_source_group(actual, expected):
  258. assert is_dict(actual)
  259. assert sorted(actual.keys()) == ["name", "sourceIndexes"]
  260. check_list_match(lambda a, e: matches(obj["sources"][a]["path"], e),
  261. actual["sourceIndexes"], expected["sourcePaths"],
  262. missing_exception=lambda e: "Source path: %s" % e,
  263. extra_exception=lambda a: "Source path: %s" % obj["sources"][a]["path"])
  264. check_list_match(lambda a, e: is_string(a["name"], e["name"]),
  265. obj["sourceGroups"], expected["sourceGroups"],
  266. check=check_source_group,
  267. check_exception=lambda a, e: "Source group: %s" % a["name"],
  268. missing_exception=lambda e: "Source group: %s" % e["name"],
  269. extra_exception=lambda a: "Source group: %s" % a["name"])
  270. if expected["compileGroups"] is not None:
  271. expected_keys.append("compileGroups")
  272. def check_compile_group(actual, expected):
  273. assert is_dict(actual)
  274. expected_keys = ["sourceIndexes", "language"]
  275. check_list_match(lambda a, e: matches(obj["sources"][a]["path"], e),
  276. actual["sourceIndexes"], expected["sourcePaths"],
  277. missing_exception=lambda e: "Source path: %s" % e,
  278. extra_exception=lambda a: "Source path: %s" % obj["sources"][a]["path"])
  279. if "compileCommandFragments" in actual:
  280. expected_keys.append("compileCommandFragments")
  281. assert is_list(actual["compileCommandFragments"])
  282. for f in actual["compileCommandFragments"]:
  283. assert is_dict(f)
  284. assert is_string(f["fragment"])
  285. if expected["compileCommandFragments"] is not None:
  286. def check_compile_command_fragments(actual, expected):
  287. assert is_dict(actual)
  288. expected_keys = ["fragment"]
  289. if expected["backtrace"] is not None:
  290. expected_keys.append("backtrace")
  291. assert actual["fragment"] == expected["fragment"]
  292. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  293. assert sorted(actual.keys()) == sorted(expected_keys)
  294. check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]),
  295. actual["compileCommandFragments"], expected["compileCommandFragments"],
  296. check=check_compile_command_fragments,
  297. check_exception=lambda a, e: "Compile fragment: %s" % a["fragment"],
  298. missing_exception=lambda e: "Compile fragment: %s" % e["fragment"],
  299. extra_exception=lambda a: "Compile fragment: %s" % a["fragment"],
  300. allow_extra=True)
  301. if expected["includes"] is not None:
  302. expected_keys.append("includes")
  303. def check_include(actual, expected):
  304. assert is_dict(actual)
  305. expected_keys = ["path"]
  306. if expected["isSystem"] is not None:
  307. expected_keys.append("isSystem")
  308. assert is_bool(actual["isSystem"], expected["isSystem"])
  309. if expected["backtrace"] is not None:
  310. expected_keys.append("backtrace")
  311. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  312. assert sorted(actual.keys()) == sorted(expected_keys)
  313. check_list_match(lambda a, e: matches(a["path"], e["path"]),
  314. actual["includes"], expected["includes"],
  315. check=check_include,
  316. check_exception=lambda a, e: "Include path: %s" % a["path"],
  317. missing_exception=lambda e: "Include path: %s" % e["path"],
  318. extra_exception=lambda a: "Include path: %s" % a["path"])
  319. if "precompileHeaders" in expected:
  320. expected_keys.append("precompileHeaders")
  321. def check_precompile_header(actual, expected):
  322. assert is_dict(actual)
  323. expected_keys = ["backtrace", "header"]
  324. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  325. assert sorted(actual.keys()) == sorted(expected_keys)
  326. check_list_match(lambda a, e: matches(a["header"], e["header"]),
  327. actual["precompileHeaders"], expected["precompileHeaders"],
  328. check=check_precompile_header,
  329. check_exception=lambda a, e: "Precompile header: %s" % a["header"],
  330. missing_exception=lambda e: "Precompile header: %s" % e["header"],
  331. extra_exception=lambda a: "Precompile header: %s" % a["header"])
  332. if expected["defines"] is not None:
  333. expected_keys.append("defines")
  334. def check_define(actual, expected):
  335. assert is_dict(actual)
  336. expected_keys = ["define"]
  337. if expected["backtrace"] is not None:
  338. expected_keys.append("backtrace")
  339. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  340. assert sorted(actual.keys()) == sorted(expected_keys)
  341. check_list_match(lambda a, e: is_string(a["define"], e["define"]),
  342. actual["defines"], expected["defines"],
  343. check=check_define,
  344. check_exception=lambda a, e: "Define: %s" % a["define"],
  345. missing_exception=lambda e: "Define: %s" % e["define"],
  346. extra_exception=lambda a: "Define: %s" % a["define"])
  347. # FIXME: Properly test sysroot
  348. if "sysroot" in actual:
  349. expected_keys.append("sysroot")
  350. assert is_string(actual["sysroot"])
  351. assert sorted(actual.keys()) == sorted(expected_keys)
  352. check_list_match(lambda a, e: is_string(a["language"], e["language"]),
  353. obj["compileGroups"], expected["compileGroups"],
  354. check=check_compile_group,
  355. check_exception=lambda a, e: "Compile group: %s" % a["language"],
  356. missing_exception=lambda e: "Compile group: %s" % e["language"],
  357. extra_exception=lambda a: "Compile group: %s" % a["language"])
  358. assert sorted(obj.keys()) == sorted(expected_keys)
  359. return _check
  360. def check_project(c):
  361. def _check(actual, expected):
  362. assert is_dict(actual)
  363. expected_keys = ["name", "directoryIndexes"]
  364. check_list_match(lambda a, e: matches(c["directories"][a]["source"], e),
  365. actual["directoryIndexes"], expected["directorySources"],
  366. missing_exception=lambda e: "Directory source: %s" % e,
  367. extra_exception=lambda a: "Directory source: %s" % c["directories"][a]["source"])
  368. if expected["parentName"] is not None:
  369. expected_keys.append("parentIndex")
  370. assert is_int(actual["parentIndex"])
  371. assert is_string(c["projects"][actual["parentIndex"]]["name"], expected["parentName"])
  372. if expected["childNames"] is not None:
  373. expected_keys.append("childIndexes")
  374. check_list_match(lambda a, e: is_string(c["projects"][a]["name"], e),
  375. actual["childIndexes"], expected["childNames"],
  376. missing_exception=lambda e: "Child name: %s" % e,
  377. extra_exception=lambda a: "Child name: %s" % c["projects"][a]["name"])
  378. if expected["targetIds"] is not None:
  379. expected_keys.append("targetIndexes")
  380. check_list_match(lambda a, e: matches(c["targets"][a]["id"], e),
  381. actual["targetIndexes"], expected["targetIds"],
  382. missing_exception=lambda e: "Target ID: %s" % e,
  383. extra_exception=lambda a: "Target ID: %s" % c["targets"][a]["id"])
  384. assert sorted(actual.keys()) == sorted(expected_keys)
  385. return _check
  386. def gen_check_directories(c, g):
  387. expected = [
  388. read_codemodel_json_data("directories/top.json"),
  389. read_codemodel_json_data("directories/alias.json"),
  390. read_codemodel_json_data("directories/custom.json"),
  391. read_codemodel_json_data("directories/cxx.json"),
  392. read_codemodel_json_data("directories/imported.json"),
  393. read_codemodel_json_data("directories/object.json"),
  394. read_codemodel_json_data("directories/dir.json"),
  395. read_codemodel_json_data("directories/dir_dir.json"),
  396. read_codemodel_json_data("directories/external.json"),
  397. ]
  398. if matches(g["name"], "^Visual Studio "):
  399. for e in expected:
  400. if e["parentSource"] is not None:
  401. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^ZERO_CHECK"), e["targetIds"])
  402. elif g["name"] == "Xcode":
  403. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  404. for e in expected:
  405. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(link_imported_object_exe)"), e["targetIds"])
  406. else:
  407. for e in expected:
  408. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(ALL_BUILD|ZERO_CHECK)"), e["targetIds"])
  409. return expected
  410. def check_directories(c, g):
  411. check_list_match(lambda a, e: matches(a["source"], e["source"]), c["directories"], gen_check_directories(c, g),
  412. check=check_directory(c),
  413. check_exception=lambda a, e: "Directory source: %s" % a["source"],
  414. missing_exception=lambda e: "Directory source: %s" % e["source"],
  415. extra_exception=lambda a: "Directory source: %s" % a["source"])
  416. def gen_check_targets(c, g, inSource):
  417. expected = [
  418. read_codemodel_json_data("targets/all_build_top.json"),
  419. read_codemodel_json_data("targets/zero_check_top.json"),
  420. read_codemodel_json_data("targets/interface_exe.json"),
  421. read_codemodel_json_data("targets/c_lib.json"),
  422. read_codemodel_json_data("targets/c_exe.json"),
  423. read_codemodel_json_data("targets/c_shared_lib.json"),
  424. read_codemodel_json_data("targets/c_shared_exe.json"),
  425. read_codemodel_json_data("targets/c_static_lib.json"),
  426. read_codemodel_json_data("targets/c_static_exe.json"),
  427. read_codemodel_json_data("targets/all_build_cxx.json"),
  428. read_codemodel_json_data("targets/zero_check_cxx.json"),
  429. read_codemodel_json_data("targets/cxx_lib.json"),
  430. read_codemodel_json_data("targets/cxx_exe.json"),
  431. read_codemodel_json_data("targets/cxx_shared_lib.json"),
  432. read_codemodel_json_data("targets/cxx_shared_exe.json"),
  433. read_codemodel_json_data("targets/cxx_static_lib.json"),
  434. read_codemodel_json_data("targets/cxx_static_exe.json"),
  435. read_codemodel_json_data("targets/all_build_alias.json"),
  436. read_codemodel_json_data("targets/zero_check_alias.json"),
  437. read_codemodel_json_data("targets/c_alias_exe.json"),
  438. read_codemodel_json_data("targets/cxx_alias_exe.json"),
  439. read_codemodel_json_data("targets/all_build_object.json"),
  440. read_codemodel_json_data("targets/zero_check_object.json"),
  441. read_codemodel_json_data("targets/c_object_lib.json"),
  442. read_codemodel_json_data("targets/c_object_exe.json"),
  443. read_codemodel_json_data("targets/cxx_object_lib.json"),
  444. read_codemodel_json_data("targets/cxx_object_exe.json"),
  445. read_codemodel_json_data("targets/all_build_imported.json"),
  446. read_codemodel_json_data("targets/zero_check_imported.json"),
  447. read_codemodel_json_data("targets/link_imported_exe.json"),
  448. read_codemodel_json_data("targets/link_imported_shared_exe.json"),
  449. read_codemodel_json_data("targets/link_imported_static_exe.json"),
  450. read_codemodel_json_data("targets/link_imported_object_exe.json"),
  451. read_codemodel_json_data("targets/link_imported_interface_exe.json"),
  452. read_codemodel_json_data("targets/all_build_custom.json"),
  453. read_codemodel_json_data("targets/zero_check_custom.json"),
  454. read_codemodel_json_data("targets/custom_tgt.json"),
  455. read_codemodel_json_data("targets/custom_exe.json"),
  456. read_codemodel_json_data("targets/all_build_external.json"),
  457. read_codemodel_json_data("targets/zero_check_external.json"),
  458. read_codemodel_json_data("targets/generated_exe.json"),
  459. ]
  460. if cxx_compiler_id in ['Clang', 'AppleClang', 'GNU', 'Intel', 'MSVC', 'Embarcadero'] and g["name"] != "Xcode":
  461. for e in expected:
  462. if e["name"] == "cxx_exe":
  463. if matches(g["name"], "^(Visual Studio |Ninja Multi-Config)"):
  464. precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_multigen.json")
  465. else:
  466. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  467. precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_2arch.json")
  468. else:
  469. precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader.json")
  470. e["compileGroups"] = precompile_header_data["compileGroups"]
  471. e["sources"] = precompile_header_data["sources"]
  472. e["sourceGroups"] = precompile_header_data["sourceGroups"]
  473. if not os.path.exists(os.path.join(reply_dir, "..", "..", "..", "..", "ipo_enabled.txt")):
  474. for e in expected:
  475. try:
  476. e["link"]["lto"] = None
  477. except TypeError: # "link" is not a dict, no problem.
  478. pass
  479. try:
  480. e["archive"]["lto"] = None
  481. except TypeError: # "archive" is not a dict, no problem.
  482. pass
  483. if inSource:
  484. for e in expected:
  485. if e["sources"] is not None:
  486. for s in e["sources"]:
  487. s["path"] = s["path"].replace("^.*/Tests/RunCMake/FileAPI/", "^", 1)
  488. if e["sourceGroups"] is not None:
  489. for group in e["sourceGroups"]:
  490. group["sourcePaths"] = [p.replace("^.*/Tests/RunCMake/FileAPI/", "^", 1) for p in group["sourcePaths"]]
  491. if e["compileGroups"] is not None:
  492. for group in e["compileGroups"]:
  493. group["sourcePaths"] = [p.replace("^.*/Tests/RunCMake/FileAPI/", "^", 1) for p in group["sourcePaths"]]
  494. if matches(g["name"], "^Visual Studio "):
  495. expected = filter_list(lambda e: e["name"] not in ("ZERO_CHECK") or e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$", expected)
  496. for e in expected:
  497. if e["type"] == "UTILITY":
  498. if e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$":
  499. e["sources"] = [
  500. {
  501. "path": "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
  502. "isGenerated": True,
  503. "sourceGroupName": "CMake Rules",
  504. "compileGroupLanguage": None,
  505. "backtrace": [
  506. {
  507. "file": "^CMakeLists\\.txt$",
  508. "line": None,
  509. "command": None,
  510. "hasParent": False,
  511. },
  512. ],
  513. },
  514. ]
  515. e["sourceGroups"] = [
  516. {
  517. "name": "CMake Rules",
  518. "sourcePaths": [
  519. "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
  520. ],
  521. },
  522. ]
  523. elif e["name"] in ("ALL_BUILD"):
  524. e["sources"] = []
  525. e["sourceGroups"] = None
  526. if e["dependencies"] is not None:
  527. for d in e["dependencies"]:
  528. if matches(d["id"], "^\\^ZERO_CHECK::@"):
  529. d["id"] = "^ZERO_CHECK::@6890427a1f51a3e7e1df$"
  530. elif g["name"] == "Xcode":
  531. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  532. expected = filter_list(lambda e: e["name"] not in ("link_imported_object_exe"), expected)
  533. for e in expected:
  534. e["dependencies"] = filter_list(lambda d: not matches(d["id"], "^\\^link_imported_object_exe::@"), e["dependencies"])
  535. if e["name"] in ("c_object_lib", "cxx_object_lib"):
  536. e["artifacts"] = None
  537. else:
  538. for e in expected:
  539. e["dependencies"] = filter_list(lambda d: not matches(d["id"], "^\\^ZERO_CHECK::@"), e["dependencies"])
  540. expected = filter_list(lambda t: t["name"] not in ("ALL_BUILD", "ZERO_CHECK"), expected)
  541. if sys.platform not in ("win32", "cygwin", "msys"):
  542. for e in expected:
  543. e["artifacts"] = filter_list(lambda a: not a["_dllExtra"], e["artifacts"])
  544. if "aix" not in sys.platform:
  545. for e in expected:
  546. e["artifacts"] = filter_list(lambda a: not a.get("_aixExtra", False), e["artifacts"])
  547. return expected
  548. def check_targets(c, g, inSource):
  549. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  550. c["targets"], gen_check_targets(c, g, inSource),
  551. check=check_target(c),
  552. check_exception=lambda a, e: "Target ID: %s" % a["id"],
  553. missing_exception=lambda e: "Target ID: %s" % e["id"],
  554. extra_exception=lambda a: "Target ID: %s" % a["id"])
  555. def gen_check_projects(c, g):
  556. expected = [
  557. read_codemodel_json_data("projects/codemodel-v2.json"),
  558. read_codemodel_json_data("projects/cxx.json"),
  559. read_codemodel_json_data("projects/alias.json"),
  560. read_codemodel_json_data("projects/object.json"),
  561. read_codemodel_json_data("projects/imported.json"),
  562. read_codemodel_json_data("projects/custom.json"),
  563. read_codemodel_json_data("projects/external.json"),
  564. ]
  565. if matches(g["name"], "^Visual Studio "):
  566. for e in expected:
  567. if e["parentName"] is not None:
  568. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^ZERO_CHECK"), e["targetIds"])
  569. elif g["name"] == "Xcode":
  570. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  571. for e in expected:
  572. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(link_imported_object_exe)"), e["targetIds"])
  573. else:
  574. for e in expected:
  575. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(ALL_BUILD|ZERO_CHECK)"), e["targetIds"])
  576. return expected
  577. def check_projects(c, g):
  578. check_list_match(lambda a, e: is_string(a["name"], e["name"]), c["projects"], gen_check_projects(c, g),
  579. check=check_project(c),
  580. check_exception=lambda a, e: "Project name: %s" % a["name"],
  581. missing_exception=lambda e: "Project name: %s" % e["name"],
  582. extra_exception=lambda a: "Project name: %s" % a["name"])
  583. def check_object_codemodel_configuration(c, g, inSource):
  584. assert sorted(c.keys()) == ["directories", "name", "projects", "targets"]
  585. assert is_string(c["name"])
  586. check_directories(c, g)
  587. check_targets(c, g, inSource)
  588. check_projects(c, g)
  589. def check_object_codemodel(g):
  590. def _check(o):
  591. assert sorted(o.keys()) == ["configurations", "kind", "paths", "version"]
  592. # The "kind" and "version" members are handled by check_index_object.
  593. assert is_dict(o["paths"])
  594. assert sorted(o["paths"].keys()) == ["build", "source"]
  595. assert matches(o["paths"]["build"], "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build$")
  596. assert matches(o["paths"]["source"], "^.*/Tests/RunCMake/FileAPI$")
  597. inSource = os.path.dirname(o["paths"]["build"]) == o["paths"]["source"]
  598. if g["multiConfig"]:
  599. assert sorted([c["name"] for c in o["configurations"]]) == ["Debug", "MinSizeRel", "RelWithDebInfo", "Release"]
  600. else:
  601. assert len(o["configurations"]) == 1
  602. assert o["configurations"][0]["name"] in ("", "Debug", "Release", "RelWithDebInfo", "MinSizeRel")
  603. for c in o["configurations"]:
  604. check_object_codemodel_configuration(c, g, inSource)
  605. return _check
  606. cxx_compiler_id = sys.argv[2]
  607. assert is_dict(index)
  608. assert sorted(index.keys()) == ["cmake", "objects", "reply"]
  609. check_objects(index["objects"], index["cmake"]["generator"])