codemodel-v2-check.py 38 KB

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