| 1817 | } |
| 1818 | |
| 1819 | static int ap_render(ap_context *c, const char *project, char **out_json) { |
| 1820 | memset(c->evidence_bytes, 0, sizeof(c->evidence_bytes)); |
| 1821 | c->evidence_scope = AP_EVIDENCE_CONTEXT; |
| 1822 | c->evidence_omitted = false; |
| 1823 | c->cycle_count = c->omitted_cycles = 0; |
| 1824 | ap_json_budget budget = {0}; |
| 1825 | yyjson_alc allocator = {ap_json_malloc, ap_json_realloc, ap_json_free, &budget}; |
| 1826 | yyjson_mut_doc *doc = yyjson_mut_doc_new(&allocator); |
| 1827 | if (!doc) |
| 1828 | return CBM_STORE_ERR; |
| 1829 | yyjson_mut_val *root = yyjson_mut_obj(doc); |
| 1830 | yyjson_mut_doc_set_root(doc, root); |
| 1831 | yyjson_mut_val *parts = yyjson_mut_arr(doc), *dependencies = yyjson_mut_arr(doc), |
| 1832 | *cycles = yyjson_mut_arr(doc), *entries = yyjson_mut_arr(doc), |
| 1833 | *paths = yyjson_mut_arr(doc), *warnings = yyjson_mut_arr(doc), |
| 1834 | *totals = yyjson_mut_obj(doc), *limits = yyjson_mut_obj(doc); |
| 1835 | yyjson_mut_obj_add_int(doc, root, "schema_version", 1); |
| 1836 | yyjson_mut_obj_add_str(doc, root, "kind", "static_projection"); |
| 1837 | yyjson_mut_obj_add_strcpy(doc, root, "project", project); |
| 1838 | yyjson_mut_obj_add_val(doc, root, "components", parts); |
| 1839 | yyjson_mut_obj_add_val(doc, root, "dependencies", dependencies); |
| 1840 | yyjson_mut_obj_add_val(doc, root, "cycles", cycles); |
| 1841 | yyjson_mut_obj_add_val(doc, root, "entrypoints", entries); |
| 1842 | yyjson_mut_obj_add_val(doc, root, "paths", paths); |
| 1843 | yyjson_mut_obj_add_val(doc, root, "warnings", warnings); |
| 1844 | yyjson_mut_obj_add_val(doc, root, "totals", totals); |
| 1845 | yyjson_mut_obj_add_val(doc, root, "limits", limits); |
| 1846 | int shown = 0, dependency_count = 0, dependency_shown = 0, entry_count = 0, entry_total = 0; |
| 1847 | int entry_indexes[AP_ENTRYPOINTS]; |
| 1848 | bool paths_truncated = false; |
| 1849 | int rc = CBM_STORE_OK; |
| 1850 | ap_dep *deps = NULL; |
| 1851 | if (!c->limited) { |
| 1852 | /* Prefer the largest connected candidates, retaining deterministic IDs. |
| 1853 | * Never relabel discarded components as a single invented component. |
| 1854 | * The same rank picks the overview entries, before they render. */ |
| 1855 | ap_rank *ranks = |
| 1856 | cbm_alloc(CBM_MEM_CLASS_OTHER, ((size_t)c->component_count + 1) * sizeof(*ranks)); |
| 1857 | if (!ranks) { |
| 1858 | rc = CBM_STORE_ERR; |
| 1859 | goto done; |
| 1860 | } |
| 1861 | for (int i = 0; i < c->component_count; i++) { |
| 1862 | c->components[i].displayed = -1; |
| 1863 | ranks[i] = (ap_rank){i, c->components[i].members, c->components[i].degree}; |
| 1864 | } |
| 1865 | qsort(ranks, (size_t)c->component_count, sizeof(*ranks), ap_rank_compare); |
| 1866 | for (int pick = 0; pick < c->options.max_components && pick < c->component_count; pick++) |
| 1867 | c->components[ranks[pick].index].displayed = shown++; |
| 1868 | ap_list_overview(c, ranks); |
| 1869 | cbm_free(CBM_MEM_CLASS_OTHER, ranks); |
| 1870 | if (ap_stopped(c)) { |
| 1871 | rc = CBM_STORE_ERR; |
| 1872 | goto done; |
| 1873 | } |
| 1874 | } |
| 1875 | if (ap_overview(c, doc, root) != CBM_STORE_OK) { |
| 1876 | rc = CBM_STORE_ERR; |
no test coverage detected