codemodel-v2-check.py 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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, 6, 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 expected["frameworks"] is not None:
  458. expected_keys.append("frameworks")
  459. def check_include(actual, expected):
  460. assert is_dict(actual)
  461. expected_keys = ["path"]
  462. if expected["isSystem"] is not None:
  463. expected_keys.append("isSystem")
  464. assert is_bool(actual["isSystem"], expected["isSystem"])
  465. if expected["backtrace"] is not None:
  466. expected_keys.append("backtrace")
  467. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  468. assert sorted(actual.keys()) == sorted(expected_keys)
  469. check_list_match(lambda a, e: matches(a["path"], e["path"]),
  470. actual["frameworks"], expected["frameworks"],
  471. check=check_include,
  472. check_exception=lambda a, e: "Framework path: %s" % a["path"],
  473. missing_exception=lambda e: "Framework path: %s" % e["path"],
  474. extra_exception=lambda a: "Framework path: %s" % a["path"])
  475. if "precompileHeaders" in expected:
  476. expected_keys.append("precompileHeaders")
  477. def check_precompile_header(actual, expected):
  478. assert is_dict(actual)
  479. expected_keys = ["backtrace", "header"]
  480. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  481. assert sorted(actual.keys()) == sorted(expected_keys)
  482. check_list_match(lambda a, e: matches(a["header"], e["header"]),
  483. actual["precompileHeaders"], expected["precompileHeaders"],
  484. check=check_precompile_header,
  485. check_exception=lambda a, e: "Precompile header: %s" % a["header"],
  486. missing_exception=lambda e: "Precompile header: %s" % e["header"],
  487. extra_exception=lambda a: "Precompile header: %s" % a["header"])
  488. if "languageStandard" in expected:
  489. expected_keys.append("languageStandard")
  490. def check_language_standard(actual, expected):
  491. assert is_dict(actual)
  492. expected_keys = ["backtraces", "standard"]
  493. assert actual["standard"] == expected["standard"]
  494. check_backtraces(obj, actual["backtraces"], expected["backtraces"])
  495. assert sorted(actual.keys()) == sorted(expected_keys)
  496. check_language_standard(actual["languageStandard"], expected["languageStandard"])
  497. if expected["defines"] is not None:
  498. expected_keys.append("defines")
  499. def check_define(actual, expected):
  500. assert is_dict(actual)
  501. expected_keys = ["define"]
  502. if expected["backtrace"] is not None:
  503. expected_keys.append("backtrace")
  504. check_backtrace(obj, actual["backtrace"], expected["backtrace"])
  505. assert sorted(actual.keys()) == sorted(expected_keys)
  506. check_list_match(lambda a, e: is_string(a["define"], e["define"]),
  507. actual["defines"], expected["defines"],
  508. check=check_define,
  509. check_exception=lambda a, e: "Define: %s" % a["define"],
  510. missing_exception=lambda e: "Define: %s" % e["define"],
  511. extra_exception=lambda a: "Define: %s" % a["define"])
  512. # FIXME: Properly test sysroot
  513. if "sysroot" in actual:
  514. expected_keys.append("sysroot")
  515. assert is_string(actual["sysroot"])
  516. assert sorted(actual.keys()) == sorted(expected_keys)
  517. check_list_match(lambda a, e: is_string(a["language"], e["language"]),
  518. obj["compileGroups"], expected["compileGroups"],
  519. check=check_compile_group,
  520. check_exception=lambda a, e: "Compile group: %s" % a["language"],
  521. missing_exception=lambda e: "Compile group: %s" % e["language"],
  522. extra_exception=lambda a: "Compile group: %s" % a["language"])
  523. assert sorted(obj.keys()) == sorted(expected_keys)
  524. return _check
  525. def check_project(c):
  526. def _check(actual, expected):
  527. assert is_dict(actual)
  528. expected_keys = ["name", "directoryIndexes"]
  529. check_list_match(lambda a, e: matches(c["directories"][a]["source"], e),
  530. actual["directoryIndexes"], expected["directorySources"],
  531. missing_exception=lambda e: "Directory source: %s" % e,
  532. extra_exception=lambda a: "Directory source: %s" % c["directories"][a]["source"])
  533. if expected["parentName"] is not None:
  534. expected_keys.append("parentIndex")
  535. assert is_int(actual["parentIndex"])
  536. assert is_string(c["projects"][actual["parentIndex"]]["name"], expected["parentName"])
  537. if expected["childNames"] is not None:
  538. expected_keys.append("childIndexes")
  539. check_list_match(lambda a, e: is_string(c["projects"][a]["name"], e),
  540. actual["childIndexes"], expected["childNames"],
  541. missing_exception=lambda e: "Child name: %s" % e,
  542. extra_exception=lambda a: "Child name: %s" % c["projects"][a]["name"])
  543. if expected["targetIds"] is not None:
  544. expected_keys.append("targetIndexes")
  545. check_list_match(lambda a, e: matches(c["targets"][a]["id"], e),
  546. actual["targetIndexes"], expected["targetIds"],
  547. missing_exception=lambda e: "Target ID: %s" % e,
  548. extra_exception=lambda a: "Target ID: %s" % c["targets"][a]["id"])
  549. assert sorted(actual.keys()) == sorted(expected_keys)
  550. return _check
  551. def gen_check_directories(c, g):
  552. expected = [
  553. read_codemodel_json_data("directories/top.json"),
  554. read_codemodel_json_data("directories/alias.json"),
  555. read_codemodel_json_data("directories/custom.json"),
  556. read_codemodel_json_data("directories/cxx.json"),
  557. read_codemodel_json_data("directories/imported.json"),
  558. read_codemodel_json_data("directories/interface.json"),
  559. read_codemodel_json_data("directories/object.json"),
  560. read_codemodel_json_data("directories/dir.json"),
  561. read_codemodel_json_data("directories/dir_dir.json"),
  562. read_codemodel_json_data("directories/external.json"),
  563. read_codemodel_json_data("directories/fileset.json"),
  564. read_codemodel_json_data("directories/subdir.json"),
  565. read_codemodel_json_data("directories/framework.json"),
  566. ]
  567. if matches(g["name"], "^Visual Studio "):
  568. for e in expected:
  569. if e["parentSource"] is not None:
  570. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^ZERO_CHECK"), e["targetIds"])
  571. elif g["name"] == "Xcode":
  572. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  573. for e in expected:
  574. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(link_imported_object_exe)"), e["targetIds"])
  575. else:
  576. for e in expected:
  577. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(ALL_BUILD|ZERO_CHECK)"), e["targetIds"])
  578. if sys.platform in ("win32", "cygwin", "msys") or "aix" in sys.platform:
  579. for e in expected:
  580. e["installers"] = list(filter(lambda i: i["targetInstallNamelink"] is None or i["targetInstallNamelink"] == "skip", e["installers"]))
  581. for i in e["installers"]:
  582. i["targetInstallNamelink"] = None
  583. if sys.platform not in ("win32", "cygwin", "msys"):
  584. for e in expected:
  585. e["installers"] = list(filter(lambda i: not i.get("_dllExtra", False), e["installers"]))
  586. if "aix" not in sys.platform:
  587. for i in e["installers"]:
  588. if "pathsNamelink" in i:
  589. i["paths"] = i["pathsNamelink"]
  590. if sys.platform not in ("win32", "darwin") and "linux" not in sys.platform:
  591. for e in expected:
  592. e["installers"] = list(filter(lambda i: i["type"] != "runtimeDependencySet", e["installers"]))
  593. if sys.platform != "darwin":
  594. for e in expected:
  595. e["installers"] = list(filter(lambda i: i.get("runtimeDependencySetType", None) != "framework", e["installers"]))
  596. return expected
  597. def check_directories(c, g):
  598. check_list_match(lambda a, e: matches(a["source"], e["source"]), c["directories"], gen_check_directories(c, g),
  599. check=check_directory(c),
  600. check_exception=lambda a, e: "Directory source: %s" % a["source"],
  601. missing_exception=lambda e: "Directory source: %s" % e["source"],
  602. extra_exception=lambda a: "Directory source: %s" % a["source"])
  603. def gen_check_targets(c, g, inSource):
  604. expected = [
  605. read_codemodel_json_data("targets/all_build_top.json"),
  606. read_codemodel_json_data("targets/zero_check_top.json"),
  607. read_codemodel_json_data("targets/interface_exe.json"),
  608. read_codemodel_json_data("targets/c_lib.json"),
  609. read_codemodel_json_data("targets/c_exe.json"),
  610. read_codemodel_json_data("targets/c_shared_lib.json"),
  611. read_codemodel_json_data("targets/c_shared_exe.json"),
  612. read_codemodel_json_data("targets/c_static_lib.json"),
  613. read_codemodel_json_data("targets/c_static_exe.json"),
  614. read_codemodel_json_data("targets/c_subdir.json"),
  615. read_codemodel_json_data("targets/all_build_cxx.json"),
  616. read_codemodel_json_data("targets/zero_check_cxx.json"),
  617. read_codemodel_json_data("targets/cxx_lib.json"),
  618. read_codemodel_json_data("targets/cxx_exe.json"),
  619. read_codemodel_json_data("targets/cxx_standard_compile_feature_exe.json"),
  620. read_codemodel_json_data("targets/cxx_standard_exe.json"),
  621. read_codemodel_json_data("targets/cxx_shared_lib.json"),
  622. read_codemodel_json_data("targets/cxx_shared_exe.json"),
  623. read_codemodel_json_data("targets/cxx_static_lib.json"),
  624. read_codemodel_json_data("targets/cxx_static_exe.json"),
  625. read_codemodel_json_data("targets/all_build_alias.json"),
  626. read_codemodel_json_data("targets/zero_check_alias.json"),
  627. read_codemodel_json_data("targets/c_alias_exe.json"),
  628. read_codemodel_json_data("targets/cxx_alias_exe.json"),
  629. read_codemodel_json_data("targets/all_build_object.json"),
  630. read_codemodel_json_data("targets/zero_check_object.json"),
  631. read_codemodel_json_data("targets/c_object_lib.json"),
  632. read_codemodel_json_data("targets/c_object_exe.json"),
  633. read_codemodel_json_data("targets/cxx_object_lib.json"),
  634. read_codemodel_json_data("targets/cxx_object_exe.json"),
  635. read_codemodel_json_data("targets/all_build_framework.json"),
  636. read_codemodel_json_data("targets/zero_check_framework.json"),
  637. read_codemodel_json_data("targets/static_framework.json"),
  638. read_codemodel_json_data("targets/shared_framework.json"),
  639. read_codemodel_json_data("targets/exe_framework.json"),
  640. read_codemodel_json_data("targets/all_build_imported.json"),
  641. read_codemodel_json_data("targets/zero_check_imported.json"),
  642. read_codemodel_json_data("targets/link_imported_exe.json"),
  643. read_codemodel_json_data("targets/link_imported_shared_exe.json"),
  644. read_codemodel_json_data("targets/link_imported_static_exe.json"),
  645. read_codemodel_json_data("targets/link_imported_object_exe.json"),
  646. read_codemodel_json_data("targets/link_imported_interface_exe.json"),
  647. read_codemodel_json_data("targets/all_build_interface.json"),
  648. read_codemodel_json_data("targets/zero_check_interface.json"),
  649. read_codemodel_json_data("targets/iface_srcs.json"),
  650. read_codemodel_json_data("targets/all_build_custom.json"),
  651. read_codemodel_json_data("targets/zero_check_custom.json"),
  652. read_codemodel_json_data("targets/custom_tgt.json"),
  653. read_codemodel_json_data("targets/custom_exe.json"),
  654. read_codemodel_json_data("targets/all_build_external.json"),
  655. read_codemodel_json_data("targets/zero_check_external.json"),
  656. read_codemodel_json_data("targets/generated_exe.json"),
  657. read_codemodel_json_data("targets/c_headers_1.json"),
  658. read_codemodel_json_data("targets/c_headers_2.json"),
  659. ]
  660. if sys.platform == "darwin":
  661. for e in expected:
  662. if e["name"] == "static_framework":
  663. apple_static_framework = read_codemodel_json_data("targets/apple_static_framework.json")
  664. e["artifacts"] = apple_static_framework["artifacts"]
  665. e["nameOnDisk"] = apple_static_framework["nameOnDisk"]
  666. elif e["name"] == "shared_framework":
  667. apple_shared_framework = read_codemodel_json_data("targets/apple_shared_framework.json")
  668. e["artifacts"] = apple_shared_framework["artifacts"]
  669. e["nameOnDisk"] = apple_shared_framework["nameOnDisk"]
  670. elif e["name"] == "exe_framework":
  671. apple_exe_framework = read_codemodel_json_data("targets/apple_exe_framework.json")
  672. e["compileGroups"] = apple_exe_framework["compileGroups"]
  673. e["link"] = apple_exe_framework["link"]
  674. if cxx_compiler_id in ['Clang', 'AppleClang', 'LCC', 'GNU', 'Intel', 'IntelLLVM', 'MSVC', 'Embarcadero', 'IBMClang'] and g["name"] != "Xcode":
  675. for e in expected:
  676. if e["name"] == "cxx_exe":
  677. if matches(g["name"], "^(Visual Studio |Ninja Multi-Config)"):
  678. precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_multigen.json")
  679. else:
  680. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  681. precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_2arch.json")
  682. else:
  683. precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader.json")
  684. e["compileGroups"] = precompile_header_data["compileGroups"]
  685. e["sources"] = precompile_header_data["sources"]
  686. e["sourceGroups"] = precompile_header_data["sourceGroups"]
  687. if os.path.exists(os.path.join(reply_dir, "..", "..", "..", "..", "cxx", "cxx_std_11.txt")):
  688. for e in expected:
  689. if e["name"] == "cxx_standard_compile_feature_exe":
  690. language_standard_data = read_codemodel_json_data("targets/cxx_standard_compile_feature_exe_languagestandard.json")
  691. e["compileGroups"][0]["languageStandard"] = language_standard_data["languageStandard"]
  692. if not os.path.exists(os.path.join(reply_dir, "..", "..", "..", "..", "ipo_enabled.txt")):
  693. for e in expected:
  694. try:
  695. e["link"]["lto"] = None
  696. except TypeError: # "link" is not a dict, no problem.
  697. pass
  698. try:
  699. e["archive"]["lto"] = None
  700. except TypeError: # "archive" is not a dict, no problem.
  701. pass
  702. if inSource:
  703. for e in expected:
  704. if e["sources"] is not None:
  705. for s in e["sources"]:
  706. s["path"] = s["path"].replace("^.*/Tests/RunCMake/FileAPI/", "^", 1)
  707. if e["sourceGroups"] is not None:
  708. for group in e["sourceGroups"]:
  709. group["sourcePaths"] = [p.replace("^.*/Tests/RunCMake/FileAPI/", "^", 1) for p in group["sourcePaths"]]
  710. if e["compileGroups"] is not None:
  711. for group in e["compileGroups"]:
  712. group["sourcePaths"] = [p.replace("^.*/Tests/RunCMake/FileAPI/", "^", 1) for p in group["sourcePaths"]]
  713. if matches(g["name"], "^Visual Studio "):
  714. expected = filter_list(lambda e: e["name"] not in ("ZERO_CHECK") or e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$", expected)
  715. for e in expected:
  716. if e["type"] == "UTILITY":
  717. if e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$":
  718. # The json files have data for Xcode. Substitute data for VS.
  719. e["sources"] = [
  720. {
  721. "path": "^CMakeLists\\.txt$",
  722. "isGenerated": None,
  723. "fileSetName": None,
  724. "sourceGroupName": "",
  725. "compileGroupLanguage": None,
  726. "backtrace": [
  727. {
  728. "file": "^CMakeLists\\.txt$",
  729. "line": None,
  730. "command": None,
  731. "hasParent": False,
  732. },
  733. ],
  734. },
  735. {
  736. "path": "^alias/CMakeLists\\.txt$",
  737. "isGenerated": None,
  738. "fileSetName": None,
  739. "sourceGroupName": "",
  740. "compileGroupLanguage": None,
  741. "backtrace": [
  742. {
  743. "file": "^CMakeLists\\.txt$",
  744. "line": None,
  745. "command": None,
  746. "hasParent": False,
  747. },
  748. ],
  749. },
  750. {
  751. "path": "^codemodel-v2\\.cmake$",
  752. "isGenerated": None,
  753. "fileSetName": None,
  754. "sourceGroupName": "",
  755. "compileGroupLanguage": None,
  756. "backtrace": [
  757. {
  758. "file": "^CMakeLists\\.txt$",
  759. "line": None,
  760. "command": None,
  761. "hasParent": False,
  762. },
  763. ],
  764. },
  765. {
  766. "path": "^custom/CMakeLists\\.txt$",
  767. "isGenerated": None,
  768. "fileSetName": None,
  769. "sourceGroupName": "",
  770. "compileGroupLanguage": None,
  771. "backtrace": [
  772. {
  773. "file": "^CMakeLists\\.txt$",
  774. "line": None,
  775. "command": None,
  776. "hasParent": False,
  777. },
  778. ],
  779. },
  780. {
  781. "path": "^cxx/CMakeLists\\.txt$",
  782. "isGenerated": None,
  783. "fileSetName": None,
  784. "sourceGroupName": "",
  785. "compileGroupLanguage": None,
  786. "backtrace": [
  787. {
  788. "file": "^CMakeLists\\.txt$",
  789. "line": None,
  790. "command": None,
  791. "hasParent": False,
  792. },
  793. ],
  794. },
  795. {
  796. "path": "^framework/CMakeLists\\.txt$",
  797. "isGenerated": None,
  798. "fileSetName": None,
  799. "sourceGroupName": "",
  800. "compileGroupLanguage": None,
  801. "backtrace": [
  802. {
  803. "file": "^CMakeLists\\.txt$",
  804. "line": None,
  805. "command": None,
  806. "hasParent": False,
  807. },
  808. ],
  809. },
  810. {
  811. "path": "^dir/CMakeLists\\.txt$",
  812. "isGenerated": None,
  813. "fileSetName": None,
  814. "sourceGroupName": "",
  815. "compileGroupLanguage": None,
  816. "backtrace": [
  817. {
  818. "file": "^CMakeLists\\.txt$",
  819. "line": None,
  820. "command": None,
  821. "hasParent": False,
  822. },
  823. ],
  824. },
  825. {
  826. "path": "^dir/dir/CMakeLists\\.txt$",
  827. "isGenerated": None,
  828. "fileSetName": None,
  829. "sourceGroupName": "",
  830. "compileGroupLanguage": None,
  831. "backtrace": [
  832. {
  833. "file": "^CMakeLists\\.txt$",
  834. "line": None,
  835. "command": None,
  836. "hasParent": False,
  837. },
  838. ],
  839. },
  840. {
  841. "path": "^fileset/CMakeLists\\.txt$",
  842. "isGenerated": None,
  843. "fileSetName": None,
  844. "sourceGroupName": "",
  845. "compileGroupLanguage": None,
  846. "backtrace": [
  847. {
  848. "file": "^CMakeLists\\.txt$",
  849. "line": None,
  850. "command": None,
  851. "hasParent": False,
  852. },
  853. ],
  854. },
  855. {
  856. "path": "^imported/CMakeLists\\.txt$",
  857. "isGenerated": None,
  858. "fileSetName": None,
  859. "sourceGroupName": "",
  860. "compileGroupLanguage": None,
  861. "backtrace": [
  862. {
  863. "file": "^CMakeLists\\.txt$",
  864. "line": None,
  865. "command": None,
  866. "hasParent": False,
  867. },
  868. ],
  869. },
  870. {
  871. "path": "^include_test\\.cmake$",
  872. "isGenerated": None,
  873. "fileSetName": None,
  874. "sourceGroupName": "",
  875. "compileGroupLanguage": None,
  876. "backtrace": [
  877. {
  878. "file": "^CMakeLists\\.txt$",
  879. "line": None,
  880. "command": None,
  881. "hasParent": False,
  882. },
  883. ],
  884. },
  885. {
  886. "path": "^interface/CMakeLists\\.txt$",
  887. "isGenerated": None,
  888. "fileSetName": None,
  889. "sourceGroupName": "",
  890. "compileGroupLanguage": None,
  891. "backtrace": [
  892. {
  893. "file": "^CMakeLists\\.txt$",
  894. "line": None,
  895. "command": None,
  896. "hasParent": False,
  897. },
  898. ],
  899. },
  900. {
  901. "path": "^object/CMakeLists\\.txt$",
  902. "isGenerated": None,
  903. "fileSetName": None,
  904. "sourceGroupName": "",
  905. "compileGroupLanguage": None,
  906. "backtrace": [
  907. {
  908. "file": "^CMakeLists\\.txt$",
  909. "line": None,
  910. "command": None,
  911. "hasParent": False,
  912. },
  913. ],
  914. },
  915. {
  916. "path": "^subdir/CMakeLists\\.txt$",
  917. "isGenerated": None,
  918. "fileSetName": None,
  919. "sourceGroupName": "",
  920. "compileGroupLanguage": None,
  921. "backtrace": [
  922. {
  923. "file": "^CMakeLists\\.txt$",
  924. "line": None,
  925. "command": None,
  926. "hasParent": False,
  927. },
  928. ],
  929. },
  930. {
  931. "path": "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
  932. "isGenerated": True,
  933. "fileSetName": None,
  934. "sourceGroupName": "CMake Rules",
  935. "compileGroupLanguage": None,
  936. "backtrace": [
  937. {
  938. "file": "^CMakeLists\\.txt$",
  939. "line": None,
  940. "command": None,
  941. "hasParent": False,
  942. },
  943. ],
  944. },
  945. ]
  946. e["sourceGroups"] = [
  947. {
  948. "name": "",
  949. "sourcePaths": [
  950. "^CMakeLists\\.txt$",
  951. "^alias/CMakeLists\\.txt$",
  952. "^codemodel-v2\\.cmake$",
  953. "^custom/CMakeLists\\.txt$",
  954. "^cxx/CMakeLists\\.txt$",
  955. "^framework/CMakeLists\\.txt$",
  956. "^dir/CMakeLists\\.txt$",
  957. "^dir/dir/CMakeLists\\.txt$",
  958. "^fileset/CMakeLists\\.txt$",
  959. "^imported/CMakeLists\\.txt$",
  960. "^include_test\\.cmake$",
  961. "^interface/CMakeLists\\.txt$",
  962. "^object/CMakeLists\\.txt$",
  963. "^subdir/CMakeLists\\.txt$",
  964. ],
  965. },
  966. {
  967. "name": "CMake Rules",
  968. "sourcePaths": [
  969. "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
  970. ],
  971. },
  972. ]
  973. elif e["name"] in ("ALL_BUILD"):
  974. e["sources"] = []
  975. e["sourceGroups"] = None
  976. if e["dependencies"] is not None:
  977. for d in e["dependencies"]:
  978. if matches(d["id"], "^\\^ZERO_CHECK::@"):
  979. d["id"] = "^ZERO_CHECK::@6890427a1f51a3e7e1df$"
  980. elif g["name"] == "Xcode":
  981. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  982. expected = filter_list(lambda e: e["name"] not in ("link_imported_object_exe"), expected)
  983. for e in expected:
  984. e["dependencies"] = filter_list(lambda d: not matches(d["id"], "^\\^link_imported_object_exe::@"), e["dependencies"])
  985. if e["name"] in ("c_object_lib", "cxx_object_lib"):
  986. e["artifacts"] = None
  987. else:
  988. for e in expected:
  989. e["dependencies"] = filter_list(lambda d: not matches(d["id"], "^\\^ZERO_CHECK::@"), e["dependencies"])
  990. expected = filter_list(lambda t: t["name"] not in ("ALL_BUILD", "ZERO_CHECK"), expected)
  991. if sys.platform not in ("win32", "cygwin", "msys"):
  992. for e in expected:
  993. e["artifacts"] = filter_list(lambda a: not a["_dllExtra"], e["artifacts"])
  994. if e["install"] is not None:
  995. e["install"]["destinations"] = filter_list(lambda d: "_dllExtra" not in d or not d["_dllExtra"], e["install"]["destinations"])
  996. else:
  997. for e in expected:
  998. if e["install"] is not None:
  999. e["install"]["destinations"] = filter_list(lambda d: "_namelink" not in d or not d["_namelink"], e["install"]["destinations"])
  1000. if "aix" not in sys.platform:
  1001. for e in expected:
  1002. e["artifacts"] = filter_list(lambda a: not a.get("_aixExtra", False), e["artifacts"])
  1003. return expected
  1004. def check_targets(c, g, inSource):
  1005. check_list_match(lambda a, e: matches(a["id"], e["id"]),
  1006. c["targets"], gen_check_targets(c, g, inSource),
  1007. check=check_target(c),
  1008. check_exception=lambda a, e: "Target ID: %s" % a["id"],
  1009. missing_exception=lambda e: "Target ID: %s" % e["id"],
  1010. extra_exception=lambda a: "Target ID: %s" % a["id"])
  1011. def gen_check_projects(c, g):
  1012. expected = [
  1013. read_codemodel_json_data("projects/codemodel-v2.json"),
  1014. read_codemodel_json_data("projects/cxx.json"),
  1015. read_codemodel_json_data("projects/alias.json"),
  1016. read_codemodel_json_data("projects/object.json"),
  1017. read_codemodel_json_data("projects/imported.json"),
  1018. read_codemodel_json_data("projects/interface.json"),
  1019. read_codemodel_json_data("projects/custom.json"),
  1020. read_codemodel_json_data("projects/external.json"),
  1021. read_codemodel_json_data("projects/framework.json"),
  1022. ]
  1023. if matches(g["name"], "^Visual Studio "):
  1024. for e in expected:
  1025. if e["parentName"] is not None:
  1026. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^ZERO_CHECK"), e["targetIds"])
  1027. elif g["name"] == "Xcode":
  1028. if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
  1029. for e in expected:
  1030. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(link_imported_object_exe)"), e["targetIds"])
  1031. else:
  1032. for e in expected:
  1033. e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(ALL_BUILD|ZERO_CHECK)"), e["targetIds"])
  1034. return expected
  1035. def check_projects(c, g):
  1036. check_list_match(lambda a, e: is_string(a["name"], e["name"]), c["projects"], gen_check_projects(c, g),
  1037. check=check_project(c),
  1038. check_exception=lambda a, e: "Project name: %s" % a["name"],
  1039. missing_exception=lambda e: "Project name: %s" % e["name"],
  1040. extra_exception=lambda a: "Project name: %s" % a["name"])
  1041. def check_object_codemodel_configuration(c, g, inSource):
  1042. assert sorted(c.keys()) == ["directories", "name", "projects", "targets"]
  1043. assert is_string(c["name"])
  1044. check_directories(c, g)
  1045. check_targets(c, g, inSource)
  1046. check_projects(c, g)
  1047. def check_object_codemodel(g):
  1048. def _check(o):
  1049. assert sorted(o.keys()) == ["configurations", "kind", "paths", "version"]
  1050. # The "kind" and "version" members are handled by check_index_object.
  1051. assert is_dict(o["paths"])
  1052. assert sorted(o["paths"].keys()) == ["build", "source"]
  1053. assert matches(o["paths"]["build"], "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build$")
  1054. assert matches(o["paths"]["source"], "^.*/Tests/RunCMake/FileAPI$")
  1055. inSource = os.path.dirname(o["paths"]["build"]) == o["paths"]["source"]
  1056. if g["multiConfig"]:
  1057. assert sorted([c["name"] for c in o["configurations"]]) == ["Debug", "MinSizeRel", "RelWithDebInfo", "Release"]
  1058. else:
  1059. assert len(o["configurations"]) == 1
  1060. assert o["configurations"][0]["name"] in ("", "Debug", "Release", "RelWithDebInfo", "MinSizeRel")
  1061. for c in o["configurations"]:
  1062. check_object_codemodel_configuration(c, g, inSource)
  1063. return _check
  1064. cxx_compiler_id = sys.argv[2]
  1065. assert is_dict(index)
  1066. assert sorted(index.keys()) == ["cmake", "objects", "reply"]
  1067. check_objects(index["objects"], index["cmake"]["generator"])