1 from check_index import *
7 def read_codemodel_json_data(filename):
8 abs_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "codemodel-v2-data", filename)
9 with open(abs_filename, "r") as f:
12 def check_objects(o, g):
15 check_index_object(o[0], "codemodel", 2, 4, check_object_codemodel(g))
17 def check_backtrace(t, b, backtrace):
18 btg = t["backtraceGraph"]
19 for expected in backtrace:
21 node = btg["nodes"][b]
22 expected_keys = ["file"]
23 assert matches(btg["files"][node["file"]], expected["file"])
25 if expected["line"] is not None:
26 expected_keys.append("line")
27 assert is_int(node["line"], expected["line"])
29 if expected["command"] is not None:
30 expected_keys.append("command")
31 assert is_int(node["command"])
32 assert is_string(btg["commands"][node["command"]], expected["command"])
34 if expected["hasParent"]:
35 expected_keys.append("parent")
36 assert is_int(node["parent"])
41 assert sorted(node.keys()) == sorted(expected_keys)
45 def check_backtraces(t, actual, expected):
46 assert is_list(actual)
47 assert is_list(expected)
48 assert len(actual) == len(expected)
51 while i < len(actual):
52 check_backtrace(t, actual[i], expected[i])
55 def check_directory(c):
56 def _check(actual, expected):
57 assert is_dict(actual)
58 expected_keys = ["build", "jsonFile", "source", "projectIndex"]
59 assert matches(actual["build"], expected["build"])
61 assert is_int(actual["projectIndex"])
62 assert is_string(c["projects"][actual["projectIndex"]]["name"], expected["projectName"])
64 if expected["parentSource"] is not None:
65 expected_keys.append("parentIndex")
66 assert is_int(actual["parentIndex"])
67 assert matches(c["directories"][actual["parentIndex"]]["source"], expected["parentSource"])
69 if expected["childSources"] is not None:
70 expected_keys.append("childIndexes")
71 check_list_match(lambda a, e: matches(c["directories"][a]["source"], e),
72 actual["childIndexes"], expected["childSources"],
73 missing_exception=lambda e: "Child source: %s" % e,
74 extra_exception=lambda a: "Child source: %s" % a["source"])
76 if expected["targetIds"] is not None:
77 expected_keys.append("targetIndexes")
78 check_list_match(lambda a, e: matches(c["targets"][a]["id"], e),
79 actual["targetIndexes"], expected["targetIds"],
80 missing_exception=lambda e: "Target ID: %s" % e,
81 extra_exception=lambda a: "Target ID: %s" % c["targets"][a]["id"])
83 if expected["minimumCMakeVersion"] is not None:
84 expected_keys.append("minimumCMakeVersion")
85 assert is_dict(actual["minimumCMakeVersion"])
86 assert sorted(actual["minimumCMakeVersion"].keys()) == ["string"]
87 assert is_string(actual["minimumCMakeVersion"]["string"], expected["minimumCMakeVersion"])
89 if expected["hasInstallRule"] is not None:
90 expected_keys.append("hasInstallRule")
91 assert is_bool(actual["hasInstallRule"], expected["hasInstallRule"])
93 assert sorted(actual.keys()) == sorted(expected_keys)
95 assert is_string(actual["jsonFile"])
96 filepath = os.path.join(reply_dir, actual["jsonFile"])
97 with open(filepath) as f:
101 assert sorted(d.keys()) == ["backtraceGraph", "installers", "paths"]
103 assert is_string(d["paths"]["source"], actual["source"])
104 assert is_string(d["paths"]["build"], actual["build"])
106 check_backtrace_graph(d["backtraceGraph"])
108 assert is_list(d["installers"])
109 assert len(d["installers"]) == len(expected["installers"])
110 for a, e in zip(d["installers"], expected["installers"]):
112 expected_keys = ["component", "type"]
114 assert is_string(a["component"], e["component"])
115 assert is_string(a["type"], e["type"])
117 if e["destination"] is not None:
118 expected_keys.append("destination")
119 assert is_string(a["destination"], e["destination"])
121 if e["paths"] is not None:
122 expected_keys.append("paths")
123 assert is_list(a["paths"])
124 assert len(a["paths"]) == len(e["paths"])
126 for ap, ep in zip(a["paths"], e["paths"]):
128 assert matches(ap, ep)
131 assert sorted(ap.keys()) == ["from", "to"]
132 assert matches(ap["from"], ep["from"])
133 assert matches(ap["to"], ep["to"])
135 if e["isExcludeFromAll"] is not None:
136 expected_keys.append("isExcludeFromAll")
137 assert is_bool(a["isExcludeFromAll"], e["isExcludeFromAll"])
139 if e["isForAllComponents"] is not None:
140 expected_keys.append("isForAllComponents")
141 assert is_bool(a["isForAllComponents"], e["isForAllComponents"])
143 if e["isOptional"] is not None:
144 expected_keys.append("isOptional")
145 assert is_bool(a["isOptional"], e["isOptional"])
147 if e["targetId"] is not None:
148 expected_keys.append("targetId")
149 assert matches(a["targetId"], e["targetId"])
151 if e["targetIndex"] is not None:
152 expected_keys.append("targetIndex")
153 assert is_int(a["targetIndex"])
154 assert c["targets"][a["targetIndex"]]["name"] == e["targetIndex"]
156 if e["targetIsImportLibrary"] is not None:
157 expected_keys.append("targetIsImportLibrary")
158 assert is_bool(a["targetIsImportLibrary"], e["targetIsImportLibrary"])
160 if e["targetInstallNamelink"] is not None:
161 expected_keys.append("targetInstallNamelink")
162 assert is_string(a["targetInstallNamelink"], e["targetInstallNamelink"])
164 if e["exportName"] is not None:
165 expected_keys.append("exportName")
166 assert is_string(a["exportName"], e["exportName"])
168 if e["exportTargets"] is not None:
169 expected_keys.append("exportTargets")
170 assert is_list(a["exportTargets"])
171 assert len(a["exportTargets"]) == len(e["exportTargets"])
172 for at, et in zip(a["exportTargets"], e["exportTargets"]):
174 assert sorted(at.keys()) == ["id", "index"]
175 assert matches(at["id"], et["id"])
176 assert is_int(at["index"])
177 assert c["targets"][at["index"]]["name"] == et["index"]
179 if e["scriptFile"] is not None:
180 expected_keys.append("scriptFile")
181 assert is_string(a["scriptFile"], e["scriptFile"])
183 if e.get("runtimeDependencySetName", None) is not None:
184 expected_keys.append("runtimeDependencySetName")
185 assert is_string(a["runtimeDependencySetName"], e["runtimeDependencySetName"])
187 if e.get("runtimeDependencySetType", None) is not None:
188 expected_keys.append("runtimeDependencySetType")
189 assert is_string(a["runtimeDependencySetType"], e["runtimeDependencySetType"])
191 if e.get("fileSetName", None) is not None:
192 expected_keys.append("fileSetName")
193 assert is_string(a["fileSetName"], e["fileSetName"])
195 if e.get("fileSetType", None) is not None:
196 expected_keys.append("fileSetType")
197 assert is_string(a["fileSetType"], e["fileSetType"])
199 if e.get("fileSetDirectories", None) is not None:
200 expected_keys.append("fileSetDirectories")
201 assert is_list(a["fileSetDirectories"])
202 assert len(a["fileSetDirectories"]) == len(e["fileSetDirectories"])
203 for ad, ed in zip(a["fileSetDirectories"], e["fileSetDirectories"]):
204 assert matches(ad, ed)
206 if e.get("fileSetTarget", None) is not None:
207 expected_keys.append("fileSetTarget")
208 et = e["fileSetTarget"]
209 at = a["fileSetTarget"]
211 assert sorted(at.keys()) == ["id", "index"]
212 assert matches(at["id"], et["id"])
213 assert is_int(at["index"])
214 assert c["targets"][at["index"]]["name"] == et["index"]
216 if e["backtrace"] is not None:
217 expected_keys.append("backtrace")
218 check_backtrace(d, a["backtrace"], e["backtrace"])
220 assert sorted(a.keys()) == sorted(expected_keys)
224 def check_backtrace_graph(btg):
226 assert sorted(btg.keys()) == ["commands", "files", "nodes"]
227 assert is_list(btg["commands"])
229 for c in btg["commands"]:
232 for f in btg["files"]:
235 for n in btg["nodes"]:
236 expected_keys = ["file"]
238 assert is_int(n["file"])
239 assert 0 <= n["file"] < len(btg["files"])
242 expected_keys.append("line")
243 assert is_int(n["line"])
246 expected_keys.append("command")
247 assert is_int(n["command"])
248 assert 0 <= n["command"] < len(btg["commands"])
251 expected_keys.append("parent")
252 assert is_int(n["parent"])
253 assert 0 <= n["parent"] < len(btg["nodes"])
255 assert sorted(n.keys()) == sorted(expected_keys)
258 def _check(actual, expected):
259 assert is_dict(actual)
260 assert sorted(actual.keys()) == ["directoryIndex", "id", "jsonFile", "name", "projectIndex"]
261 assert is_int(actual["directoryIndex"])
262 assert matches(c["directories"][actual["directoryIndex"]]["source"], expected["directorySource"])
263 assert is_string(actual["name"], expected["name"])
264 assert is_string(actual["jsonFile"])
265 assert is_int(actual["projectIndex"])
266 assert is_string(c["projects"][actual["projectIndex"]]["name"], expected["projectName"])
268 filepath = os.path.join(reply_dir, actual["jsonFile"])
269 with open(filepath) as f:
272 expected_keys = ["name", "id", "type", "backtraceGraph", "paths", "sources"]
274 assert is_string(obj["name"], expected["name"])
275 assert matches(obj["id"], expected["id"])
276 assert is_string(obj["type"], expected["type"])
277 check_backtrace_graph(obj["backtraceGraph"])
279 assert is_dict(obj["paths"])
280 assert sorted(obj["paths"].keys()) == ["build", "source"]
281 assert matches(obj["paths"]["build"], expected["build"])
282 assert matches(obj["paths"]["source"], expected["source"])
284 def check_source(actual, expected):
285 assert is_dict(actual)
286 expected_keys = ["path"]
288 if expected["compileGroupLanguage"] is not None:
289 expected_keys.append("compileGroupIndex")
290 assert is_string(obj["compileGroups"][actual["compileGroupIndex"]]["language"], expected["compileGroupLanguage"])
292 if expected["sourceGroupName"] is not None:
293 expected_keys.append("sourceGroupIndex")
294 assert is_string(obj["sourceGroups"][actual["sourceGroupIndex"]]["name"], expected["sourceGroupName"])
296 if expected["isGenerated"] is not None:
297 expected_keys.append("isGenerated")
298 assert is_bool(actual["isGenerated"], expected["isGenerated"])
300 if expected["backtrace"] is not None:
301 expected_keys.append("backtrace")
302 check_backtrace(obj, actual["backtrace"], expected["backtrace"])
304 assert sorted(actual.keys()) == sorted(expected_keys)
306 check_list_match(lambda a, e: matches(a["path"], e["path"]), obj["sources"],
307 expected["sources"], check=check_source,
308 check_exception=lambda a, e: "Source file: %s" % a["path"],
309 missing_exception=lambda e: "Source file: %s" % e["path"],
310 extra_exception=lambda a: "Source file: %s" % a["path"])
312 if expected["backtrace"] is not None:
313 expected_keys.append("backtrace")
314 check_backtrace(obj, obj["backtrace"], expected["backtrace"])
316 if expected["folder"] is not None:
317 expected_keys.append("folder")
318 assert is_dict(obj["folder"])
319 assert sorted(obj["folder"].keys()) == ["name"]
320 assert is_string(obj["folder"]["name"], expected["folder"])
322 if expected["nameOnDisk"] is not None:
323 expected_keys.append("nameOnDisk")
324 assert matches(obj["nameOnDisk"], expected["nameOnDisk"])
326 if expected["artifacts"] is not None:
327 expected_keys.append("artifacts")
329 def check_artifact(actual, expected):
330 assert is_dict(actual)
331 assert sorted(actual.keys()) == ["path"]
333 check_list_match(lambda a, e: matches(a["path"], e["path"]),
334 obj["artifacts"], expected["artifacts"],
335 check=check_artifact,
336 check_exception=lambda a, e: "Artifact: %s" % a["path"],
337 missing_exception=lambda e: "Artifact: %s" % e["path"],
338 extra_exception=lambda a: "Artifact: %s" % a["path"])
340 if expected["isGeneratorProvided"] is not None:
341 expected_keys.append("isGeneratorProvided")
342 assert is_bool(obj["isGeneratorProvided"], expected["isGeneratorProvided"])
344 if expected["install"] is not None:
345 expected_keys.append("install")
346 assert is_dict(obj["install"])
347 assert sorted(obj["install"].keys()) == ["destinations", "prefix"]
349 assert is_dict(obj["install"]["prefix"])
350 assert sorted(obj["install"]["prefix"].keys()) == ["path"]
351 assert matches(obj["install"]["prefix"]["path"], expected["install"]["prefix"])
353 def check_install_destination(actual, expected):
354 assert is_dict(actual)
355 expected_keys = ["path"]
357 if expected["backtrace"] is not None:
358 expected_keys.append("backtrace")
359 check_backtrace(obj, actual["backtrace"], expected["backtrace"])
361 assert sorted(actual.keys()) == sorted(expected_keys)
363 check_list_match(lambda a, e: matches(a["path"], e["path"]),
364 obj["install"]["destinations"], expected["install"]["destinations"],
365 check=check_install_destination,
366 check_exception=lambda a, e: "Install path: %s" % a["path"],
367 missing_exception=lambda e: "Install path: %s" % e["path"],
368 extra_exception=lambda a: "Install path: %s" % a["path"])
370 if expected["link"] is not None:
371 expected_keys.append("link")
372 assert is_dict(obj["link"])
373 link_keys = ["language"]
375 assert is_string(obj["link"]["language"], expected["link"]["language"])
377 if "commandFragments" in obj["link"]:
378 link_keys.append("commandFragments")
379 assert is_list(obj["link"]["commandFragments"])
380 for f in obj["link"]["commandFragments"]:
382 assert sorted(f.keys()) == ["fragment", "role"] or sorted(f.keys()) == ["backtrace", "fragment", "role"]
383 assert is_string(f["fragment"])
384 assert is_string(f["role"])
385 assert f["role"] in ("flags", "libraries", "libraryPath", "frameworkPath")
387 if expected["link"]["commandFragments"] is not None:
388 def check_link_command_fragments(actual, expected):
389 assert is_dict(actual)
390 expected_keys = ["fragment", "role"]
392 if expected["backtrace"] is not None:
393 expected_keys.append("backtrace")
394 assert matches(actual["fragment"], expected["fragment"])
395 assert actual["role"] == expected["role"]
396 check_backtrace(obj, actual["backtrace"], expected["backtrace"])
398 assert sorted(actual.keys()) == sorted(expected_keys)
400 check_list_match(lambda a, e: matches(a["fragment"], e["fragment"]),
401 obj["link"]["commandFragments"], expected["link"]["commandFragments"],
402 check=check_link_command_fragments,
403 check_exception=lambda a, e: "Link fragment: %s" % a["fragment"],
404 missing_exception=lambda e: "Link fragment: %s" % e["fragment"],
405 extra_exception=lambda a: "Link fragment: %s" % a["fragment"],
408 if expected["link"]["lto"] is not None:
409 link_keys.append("lto")
410 assert is_bool(obj["link"]["lto"], expected["link"]["lto"])
412 # FIXME: Properly test sysroot
413 if "sysroot" in obj["link"]:
414 link_keys.append("sysroot")
415 assert is_string(obj["link"]["sysroot"])
417 assert sorted(obj["link"].keys()) == sorted(link_keys)
419 if expected["archive"] is not None:
420 expected_keys.append("archive")
421 assert is_dict(obj["archive"])
424 # FIXME: Properly test commandFragments
425 if "commandFragments" in obj["archive"]:
426 archive_keys.append("commandFragments")
427 assert is_list(obj["archive"]["commandFragments"])
428 for f in obj["archive"]["commandFragments"]:
430 assert sorted(f.keys()) == ["fragment", "role"]
431 assert is_string(f["fragment"])
432 assert is_string(f["role"])
433 assert f["role"] in ("flags")
435 if expected["archive"]["lto"] is not None:
436 archive_keys.append("lto")
437 assert is_bool(obj["archive"]["lto"], expected["archive"]["lto"])
439 assert sorted(obj["archive"].keys()) == sorted(archive_keys)
441 if expected["dependencies"] is not None:
442 expected_keys.append("dependencies")
444 def check_dependency(actual, expected):
445 assert is_dict(actual)
446 expected_keys = ["id"]
448 if expected["backtrace"] is not None:
449 expected_keys.append("backtrace")
450 check_backtrace(obj, actual["backtrace"], expected["backtrace"])
452 assert sorted(actual.keys()) == sorted(expected_keys)
454 check_list_match(lambda a, e: matches(a["id"], e["id"]),
455 obj["dependencies"], expected["dependencies"],
456 check=check_dependency,
457 check_exception=lambda a, e: "Dependency ID: %s" % a["id"],
458 missing_exception=lambda e: "Dependency ID: %s" % e["id"],
459 extra_exception=lambda a: "Dependency ID: %s" % a["id"])
461 if expected["sourceGroups"] is not None:
462 expected_keys.append("sourceGroups")
464 def check_source_group(actual, expected):
465 assert is_dict(actual)
466 assert sorted(actual.keys()) == ["name", "sourceIndexes"]
468 check_list_match(lambda a, e: matches(obj["sources"][a]["path"], e),
469 actual["sourceIndexes"], expected["sourcePaths"],
470 missing_exception=lambda e: "Source path: %s" % e,
471 extra_exception=lambda a: "Source path: %s" % obj["sources"][a]["path"])
473 check_list_match(lambda a, e: is_string(a["name"], e["name"]),
474 obj["sourceGroups"], expected["sourceGroups"],
475 check=check_source_group,
476 check_exception=lambda a, e: "Source group: %s" % a["name"],
477 missing_exception=lambda e: "Source group: %s" % e["name"],
478 extra_exception=lambda a: "Source group: %s" % a["name"])
480 if expected["compileGroups"] is not None:
481 expected_keys.append("compileGroups")
483 def check_compile_group(actual, expected):
484 assert is_dict(actual)
485 expected_keys = ["sourceIndexes", "language"]
487 check_list_match(lambda a, e: matches(obj["sources"][a]["path"], e),
488 actual["sourceIndexes"], expected["sourcePaths"],
489 missing_exception=lambda e: "Source path: %s" % e,
490 extra_exception=lambda a: "Source path: %s" % obj["sources"][a]["path"])
492 if "compileCommandFragments" in actual:
493 expected_keys.append("compileCommandFragments")
494 assert is_list(actual["compileCommandFragments"])
495 for f in actual["compileCommandFragments"]:
497 assert is_string(f["fragment"])
499 if expected["compileCommandFragments"] is not None:
500 def check_compile_command_fragments(actual, expected):
501 assert is_dict(actual)
502 expected_keys = ["fragment"]
504 if expected["backtrace"] is not None:
505 expected_keys.append("backtrace")
506 assert actual["fragment"] == expected["fragment"]
507 check_backtrace(obj, actual["backtrace"], expected["backtrace"])
509 assert sorted(actual.keys()) == sorted(expected_keys)
511 check_list_match(lambda a, e: is_string(a["fragment"], e["fragment"]),
512 actual["compileCommandFragments"], expected["compileCommandFragments"],
513 check=check_compile_command_fragments,
514 check_exception=lambda a, e: "Compile fragment: %s" % a["fragment"],
515 missing_exception=lambda e: "Compile fragment: %s" % e["fragment"],
516 extra_exception=lambda a: "Compile fragment: %s" % a["fragment"],
519 if expected["includes"] is not None:
520 expected_keys.append("includes")
522 def check_include(actual, expected):
523 assert is_dict(actual)
524 expected_keys = ["path"]
526 if expected["isSystem"] is not None:
527 expected_keys.append("isSystem")
528 assert is_bool(actual["isSystem"], expected["isSystem"])
530 if expected["backtrace"] is not None:
531 expected_keys.append("backtrace")
532 check_backtrace(obj, actual["backtrace"], expected["backtrace"])
534 assert sorted(actual.keys()) == sorted(expected_keys)
536 check_list_match(lambda a, e: matches(a["path"], e["path"]),
537 actual["includes"], expected["includes"],
539 check_exception=lambda a, e: "Include path: %s" % a["path"],
540 missing_exception=lambda e: "Include path: %s" % e["path"],
541 extra_exception=lambda a: "Include path: %s" % a["path"])
543 if "precompileHeaders" in expected:
544 expected_keys.append("precompileHeaders")
546 def check_precompile_header(actual, expected):
547 assert is_dict(actual)
548 expected_keys = ["backtrace", "header"]
549 check_backtrace(obj, actual["backtrace"], expected["backtrace"])
551 assert sorted(actual.keys()) == sorted(expected_keys)
553 check_list_match(lambda a, e: matches(a["header"], e["header"]),
554 actual["precompileHeaders"], expected["precompileHeaders"],
555 check=check_precompile_header,
556 check_exception=lambda a, e: "Precompile header: %s" % a["header"],
557 missing_exception=lambda e: "Precompile header: %s" % e["header"],
558 extra_exception=lambda a: "Precompile header: %s" % a["header"])
560 if "languageStandard" in expected:
561 expected_keys.append("languageStandard")
563 def check_language_standard(actual, expected):
564 assert is_dict(actual)
565 expected_keys = ["backtraces", "standard"]
566 assert actual["standard"] == expected["standard"]
567 check_backtraces(obj, actual["backtraces"], expected["backtraces"])
569 assert sorted(actual.keys()) == sorted(expected_keys)
571 check_language_standard(actual["languageStandard"], expected["languageStandard"])
573 if expected["defines"] is not None:
574 expected_keys.append("defines")
576 def check_define(actual, expected):
577 assert is_dict(actual)
578 expected_keys = ["define"]
580 if expected["backtrace"] is not None:
581 expected_keys.append("backtrace")
582 check_backtrace(obj, actual["backtrace"], expected["backtrace"])
584 assert sorted(actual.keys()) == sorted(expected_keys)
586 check_list_match(lambda a, e: is_string(a["define"], e["define"]),
587 actual["defines"], expected["defines"],
589 check_exception=lambda a, e: "Define: %s" % a["define"],
590 missing_exception=lambda e: "Define: %s" % e["define"],
591 extra_exception=lambda a: "Define: %s" % a["define"])
593 # FIXME: Properly test sysroot
594 if "sysroot" in actual:
595 expected_keys.append("sysroot")
596 assert is_string(actual["sysroot"])
598 assert sorted(actual.keys()) == sorted(expected_keys)
600 check_list_match(lambda a, e: is_string(a["language"], e["language"]),
601 obj["compileGroups"], expected["compileGroups"],
602 check=check_compile_group,
603 check_exception=lambda a, e: "Compile group: %s" % a["language"],
604 missing_exception=lambda e: "Compile group: %s" % e["language"],
605 extra_exception=lambda a: "Compile group: %s" % a["language"])
607 assert sorted(obj.keys()) == sorted(expected_keys)
611 def check_project(c):
612 def _check(actual, expected):
613 assert is_dict(actual)
614 expected_keys = ["name", "directoryIndexes"]
616 check_list_match(lambda a, e: matches(c["directories"][a]["source"], e),
617 actual["directoryIndexes"], expected["directorySources"],
618 missing_exception=lambda e: "Directory source: %s" % e,
619 extra_exception=lambda a: "Directory source: %s" % c["directories"][a]["source"])
621 if expected["parentName"] is not None:
622 expected_keys.append("parentIndex")
623 assert is_int(actual["parentIndex"])
624 assert is_string(c["projects"][actual["parentIndex"]]["name"], expected["parentName"])
626 if expected["childNames"] is not None:
627 expected_keys.append("childIndexes")
628 check_list_match(lambda a, e: is_string(c["projects"][a]["name"], e),
629 actual["childIndexes"], expected["childNames"],
630 missing_exception=lambda e: "Child name: %s" % e,
631 extra_exception=lambda a: "Child name: %s" % c["projects"][a]["name"])
633 if expected["targetIds"] is not None:
634 expected_keys.append("targetIndexes")
635 check_list_match(lambda a, e: matches(c["targets"][a]["id"], e),
636 actual["targetIndexes"], expected["targetIds"],
637 missing_exception=lambda e: "Target ID: %s" % e,
638 extra_exception=lambda a: "Target ID: %s" % c["targets"][a]["id"])
640 assert sorted(actual.keys()) == sorted(expected_keys)
644 def gen_check_directories(c, g):
646 read_codemodel_json_data("directories/top.json"),
647 read_codemodel_json_data("directories/alias.json"),
648 read_codemodel_json_data("directories/custom.json"),
649 read_codemodel_json_data("directories/cxx.json"),
650 read_codemodel_json_data("directories/imported.json"),
651 read_codemodel_json_data("directories/interface.json"),
652 read_codemodel_json_data("directories/object.json"),
653 read_codemodel_json_data("directories/dir.json"),
654 read_codemodel_json_data("directories/dir_dir.json"),
655 read_codemodel_json_data("directories/external.json"),
656 read_codemodel_json_data("directories/fileset.json"),
659 if matches(g["name"], "^Visual Studio "):
661 if e["parentSource"] is not None:
662 e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^ZERO_CHECK"), e["targetIds"])
664 elif g["name"] == "Xcode":
665 if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
667 e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(link_imported_object_exe)"), e["targetIds"])
671 e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(ALL_BUILD|ZERO_CHECK)"), e["targetIds"])
673 if sys.platform in ("win32", "cygwin", "msys") or "aix" in sys.platform:
675 e["installers"] = list(filter(lambda i: i["targetInstallNamelink"] is None or i["targetInstallNamelink"] == "skip", e["installers"]))
676 for i in e["installers"]:
677 i["targetInstallNamelink"] = None
679 if sys.platform not in ("win32", "cygwin", "msys"):
681 e["installers"] = list(filter(lambda i: not i.get("_dllExtra", False), e["installers"]))
682 if "aix" not in sys.platform:
683 for i in e["installers"]:
684 if "pathsNamelink" in i:
685 i["paths"] = i["pathsNamelink"]
687 if sys.platform not in ("win32", "darwin") and "linux" not in sys.platform:
689 e["installers"] = list(filter(lambda i: i["type"] != "runtimeDependencySet", e["installers"]))
691 if sys.platform != "darwin":
693 e["installers"] = list(filter(lambda i: i.get("runtimeDependencySetType", None) != "framework", e["installers"]))
697 def check_directories(c, g):
698 check_list_match(lambda a, e: matches(a["source"], e["source"]), c["directories"], gen_check_directories(c, g),
699 check=check_directory(c),
700 check_exception=lambda a, e: "Directory source: %s" % a["source"],
701 missing_exception=lambda e: "Directory source: %s" % e["source"],
702 extra_exception=lambda a: "Directory source: %s" % a["source"])
704 def gen_check_targets(c, g, inSource):
706 read_codemodel_json_data("targets/all_build_top.json"),
707 read_codemodel_json_data("targets/zero_check_top.json"),
708 read_codemodel_json_data("targets/interface_exe.json"),
709 read_codemodel_json_data("targets/c_lib.json"),
710 read_codemodel_json_data("targets/c_exe.json"),
711 read_codemodel_json_data("targets/c_shared_lib.json"),
712 read_codemodel_json_data("targets/c_shared_exe.json"),
713 read_codemodel_json_data("targets/c_static_lib.json"),
714 read_codemodel_json_data("targets/c_static_exe.json"),
716 read_codemodel_json_data("targets/all_build_cxx.json"),
717 read_codemodel_json_data("targets/zero_check_cxx.json"),
718 read_codemodel_json_data("targets/cxx_lib.json"),
719 read_codemodel_json_data("targets/cxx_exe.json"),
720 read_codemodel_json_data("targets/cxx_standard_compile_feature_exe.json"),
721 read_codemodel_json_data("targets/cxx_standard_exe.json"),
722 read_codemodel_json_data("targets/cxx_shared_lib.json"),
723 read_codemodel_json_data("targets/cxx_shared_exe.json"),
724 read_codemodel_json_data("targets/cxx_static_lib.json"),
725 read_codemodel_json_data("targets/cxx_static_exe.json"),
727 read_codemodel_json_data("targets/all_build_alias.json"),
728 read_codemodel_json_data("targets/zero_check_alias.json"),
729 read_codemodel_json_data("targets/c_alias_exe.json"),
730 read_codemodel_json_data("targets/cxx_alias_exe.json"),
732 read_codemodel_json_data("targets/all_build_object.json"),
733 read_codemodel_json_data("targets/zero_check_object.json"),
734 read_codemodel_json_data("targets/c_object_lib.json"),
735 read_codemodel_json_data("targets/c_object_exe.json"),
736 read_codemodel_json_data("targets/cxx_object_lib.json"),
737 read_codemodel_json_data("targets/cxx_object_exe.json"),
739 read_codemodel_json_data("targets/all_build_imported.json"),
740 read_codemodel_json_data("targets/zero_check_imported.json"),
741 read_codemodel_json_data("targets/link_imported_exe.json"),
742 read_codemodel_json_data("targets/link_imported_shared_exe.json"),
743 read_codemodel_json_data("targets/link_imported_static_exe.json"),
744 read_codemodel_json_data("targets/link_imported_object_exe.json"),
745 read_codemodel_json_data("targets/link_imported_interface_exe.json"),
747 read_codemodel_json_data("targets/all_build_interface.json"),
748 read_codemodel_json_data("targets/zero_check_interface.json"),
749 read_codemodel_json_data("targets/iface_srcs.json"),
751 read_codemodel_json_data("targets/all_build_custom.json"),
752 read_codemodel_json_data("targets/zero_check_custom.json"),
753 read_codemodel_json_data("targets/custom_tgt.json"),
754 read_codemodel_json_data("targets/custom_exe.json"),
755 read_codemodel_json_data("targets/all_build_external.json"),
756 read_codemodel_json_data("targets/zero_check_external.json"),
757 read_codemodel_json_data("targets/generated_exe.json"),
759 read_codemodel_json_data("targets/c_headers_1.json"),
760 read_codemodel_json_data("targets/c_headers_2.json"),
763 if cxx_compiler_id in ['Clang', 'AppleClang', 'LCC', 'GNU', 'Intel', 'IntelLLVM', 'MSVC', 'Embarcadero', 'IBMClang'] and g["name"] != "Xcode":
765 if e["name"] == "cxx_exe":
766 if matches(g["name"], "^(Visual Studio |Ninja Multi-Config)"):
767 precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_multigen.json")
769 if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
770 precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_2arch.json")
772 precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader.json")
773 e["compileGroups"] = precompile_header_data["compileGroups"]
774 e["sources"] = precompile_header_data["sources"]
775 e["sourceGroups"] = precompile_header_data["sourceGroups"]
777 if os.path.exists(os.path.join(reply_dir, "..", "..", "..", "..", "cxx", "cxx_std_11.txt")):
779 if e["name"] == "cxx_standard_compile_feature_exe":
780 language_standard_data = read_codemodel_json_data("targets/cxx_standard_compile_feature_exe_languagestandard.json")
781 e["compileGroups"][0]["languageStandard"] = language_standard_data["languageStandard"]
783 if not os.path.exists(os.path.join(reply_dir, "..", "..", "..", "..", "ipo_enabled.txt")):
786 e["link"]["lto"] = None
787 except TypeError: # "link" is not a dict, no problem.
790 e["archive"]["lto"] = None
791 except TypeError: # "archive" is not a dict, no problem.
796 if e["sources"] is not None:
797 for s in e["sources"]:
798 s["path"] = s["path"].replace("^.*/Tests/RunCMake/FileAPI/", "^", 1)
799 if e["sourceGroups"] is not None:
800 for group in e["sourceGroups"]:
801 group["sourcePaths"] = [p.replace("^.*/Tests/RunCMake/FileAPI/", "^", 1) for p in group["sourcePaths"]]
802 if e["compileGroups"] is not None:
803 for group in e["compileGroups"]:
804 group["sourcePaths"] = [p.replace("^.*/Tests/RunCMake/FileAPI/", "^", 1) for p in group["sourcePaths"]]
806 if matches(g["name"], "^Visual Studio "):
807 expected = filter_list(lambda e: e["name"] not in ("ZERO_CHECK") or e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$", expected)
809 if e["type"] == "UTILITY":
810 if e["id"] == "^ZERO_CHECK::@6890427a1f51a3e7e1df$":
813 "path": "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
815 "sourceGroupName": "CMake Rules",
816 "compileGroupLanguage": None,
819 "file": "^CMakeLists\\.txt$",
827 e["sourceGroups"] = [
829 "name": "CMake Rules",
831 "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build/CMakeFiles/([0-9a-f]+/)?generate\\.stamp\\.rule$",
835 elif e["name"] in ("ALL_BUILD"):
837 e["sourceGroups"] = None
838 if e["dependencies"] is not None:
839 for d in e["dependencies"]:
840 if matches(d["id"], "^\\^ZERO_CHECK::@"):
841 d["id"] = "^ZERO_CHECK::@6890427a1f51a3e7e1df$"
843 elif g["name"] == "Xcode":
844 if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
845 expected = filter_list(lambda e: e["name"] not in ("link_imported_object_exe"), expected)
847 e["dependencies"] = filter_list(lambda d: not matches(d["id"], "^\\^link_imported_object_exe::@"), e["dependencies"])
848 if e["name"] in ("c_object_lib", "cxx_object_lib"):
849 e["artifacts"] = None
853 e["dependencies"] = filter_list(lambda d: not matches(d["id"], "^\\^ZERO_CHECK::@"), e["dependencies"])
855 expected = filter_list(lambda t: t["name"] not in ("ALL_BUILD", "ZERO_CHECK"), expected)
857 if sys.platform not in ("win32", "cygwin", "msys"):
859 e["artifacts"] = filter_list(lambda a: not a["_dllExtra"], e["artifacts"])
860 if e["install"] is not None:
861 e["install"]["destinations"] = filter_list(lambda d: "_dllExtra" not in d or not d["_dllExtra"], e["install"]["destinations"])
865 if e["install"] is not None:
866 e["install"]["destinations"] = filter_list(lambda d: "_namelink" not in d or not d["_namelink"], e["install"]["destinations"])
868 if "aix" not in sys.platform:
870 e["artifacts"] = filter_list(lambda a: not a.get("_aixExtra", False), e["artifacts"])
874 def check_targets(c, g, inSource):
875 check_list_match(lambda a, e: matches(a["id"], e["id"]),
876 c["targets"], gen_check_targets(c, g, inSource),
877 check=check_target(c),
878 check_exception=lambda a, e: "Target ID: %s" % a["id"],
879 missing_exception=lambda e: "Target ID: %s" % e["id"],
880 extra_exception=lambda a: "Target ID: %s" % a["id"])
882 def gen_check_projects(c, g):
884 read_codemodel_json_data("projects/codemodel-v2.json"),
885 read_codemodel_json_data("projects/cxx.json"),
886 read_codemodel_json_data("projects/alias.json"),
887 read_codemodel_json_data("projects/object.json"),
888 read_codemodel_json_data("projects/imported.json"),
889 read_codemodel_json_data("projects/interface.json"),
890 read_codemodel_json_data("projects/custom.json"),
891 read_codemodel_json_data("projects/external.json"),
894 if matches(g["name"], "^Visual Studio "):
896 if e["parentName"] is not None:
897 e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^ZERO_CHECK"), e["targetIds"])
899 elif g["name"] == "Xcode":
900 if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""):
902 e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(link_imported_object_exe)"), e["targetIds"])
906 e["targetIds"] = filter_list(lambda t: not matches(t, "^\\^(ALL_BUILD|ZERO_CHECK)"), e["targetIds"])
910 def check_projects(c, g):
911 check_list_match(lambda a, e: is_string(a["name"], e["name"]), c["projects"], gen_check_projects(c, g),
912 check=check_project(c),
913 check_exception=lambda a, e: "Project name: %s" % a["name"],
914 missing_exception=lambda e: "Project name: %s" % e["name"],
915 extra_exception=lambda a: "Project name: %s" % a["name"])
917 def check_object_codemodel_configuration(c, g, inSource):
918 assert sorted(c.keys()) == ["directories", "name", "projects", "targets"]
919 assert is_string(c["name"])
920 check_directories(c, g)
921 check_targets(c, g, inSource)
924 def check_object_codemodel(g):
926 assert sorted(o.keys()) == ["configurations", "kind", "paths", "version"]
927 # The "kind" and "version" members are handled by check_index_object.
928 assert is_dict(o["paths"])
929 assert sorted(o["paths"].keys()) == ["build", "source"]
930 assert matches(o["paths"]["build"], "^.*/Tests/RunCMake/FileAPI/codemodel-v2-build$")
931 assert matches(o["paths"]["source"], "^.*/Tests/RunCMake/FileAPI$")
933 inSource = os.path.dirname(o["paths"]["build"]) == o["paths"]["source"]
936 assert sorted([c["name"] for c in o["configurations"]]) == ["Debug", "MinSizeRel", "RelWithDebInfo", "Release"]
938 assert len(o["configurations"]) == 1
939 assert o["configurations"][0]["name"] in ("", "Debug", "Release", "RelWithDebInfo", "MinSizeRel")
941 for c in o["configurations"]:
942 check_object_codemodel_configuration(c, g, inSource)
945 cxx_compiler_id = sys.argv[2]
946 assert is_dict(index)
947 assert sorted(index.keys()) == ["cmake", "objects", "reply"]
948 check_objects(index["objects"], index["cmake"]["generator"])