| 1008 | } |
| 1009 | |
| 1010 | CBMHashTable *cbm_pkgmap_build(cbm_pkg_entries_t *worker_entries, int worker_count, |
| 1011 | const char *project_name) { |
| 1012 | /* Count total entries */ |
| 1013 | int total = 0; |
| 1014 | for (int w = 0; w < worker_count; w++) { |
| 1015 | total += worker_entries[w].count; |
| 1016 | } |
| 1017 | if (total == 0) { |
| 1018 | return NULL; |
| 1019 | } |
| 1020 | |
| 1021 | CBMHashTable *map = cbm_ht_create(PKGMAP_HT_INIT); |
| 1022 | int merged = 0; |
| 1023 | |
| 1024 | for (int w = 0; w < worker_count; w++) { |
| 1025 | cbm_pkg_entries_t *we = &worker_entries[w]; |
| 1026 | for (int i = 0; i < we->count; i++) { |
| 1027 | /* Convert entry_rel to QN: project.dir.parts. A PSR-4 namespace |
| 1028 | * prefix (key ends in '\\') keeps its repo-relative DIRECTORY |
| 1029 | * instead: its readers map `Prefix\Sub\Class` onto a file path |
| 1030 | * (<dir>/Sub/Class.php), which a dotted QN cannot express (#1186). */ |
| 1031 | const char *entry_rel = we->items[i].entry_rel; |
| 1032 | char *qn = pkgmap_is_psr4_prefix(we->items[i].pkg_name) |
| 1033 | ? cbm_strndup(entry_rel, strlen(entry_rel)) |
| 1034 | : cbm_pipeline_fqn_module(project_name, entry_rel); |
| 1035 | if (!qn) { |
| 1036 | continue; |
| 1037 | } |
| 1038 | |
| 1039 | /* Check for duplicate — first wins */ |
| 1040 | if (cbm_ht_has(map, we->items[i].pkg_name)) { |
| 1041 | free(qn); |
| 1042 | continue; |
| 1043 | } |
| 1044 | |
| 1045 | /* Transfer ownership: key = strdup'd pkg_name, value = qn */ |
| 1046 | char *key = strdup(we->items[i].pkg_name); |
| 1047 | cbm_ht_set(map, key, qn); |
| 1048 | merged++; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | if (merged == 0) { |
| 1053 | cbm_ht_free(map); |
| 1054 | return NULL; |
| 1055 | } |
| 1056 | cbm_log_info("pkgmap.build", "entries", pkgmap_itoa(merged)); |
| 1057 | return map; |
| 1058 | } |
| 1059 | |
| 1060 | /* Returns true if basename is a package manifest we know how to parse. |
| 1061 | * Used by the filesystem walker; cbm_pkgmap_try_parse is the source of |
no test coverage detected