| 5660 | } |
| 5661 | |
| 5662 | static int arch_entry_points(cbm_store_t *s, const char *project, const char *path, |
| 5663 | cbm_architecture_info_t *out) { |
| 5664 | char norm[CBM_SZ_512]; |
| 5665 | char like[CBM_SZ_512]; |
| 5666 | bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like)); |
| 5667 | char sqlbuf[ST_SQL_BUF]; |
| 5668 | const char *base = "SELECT name, qualified_name, file_path FROM nodes " |
| 5669 | "WHERE project=?1 AND json_extract(properties, '$.is_entry_point') = 1 " |
| 5670 | "AND (json_extract(properties, '$.is_test') IS NULL OR " |
| 5671 | "json_extract(properties, '$.is_test') != 1) " |
| 5672 | "AND file_path NOT LIKE '%test%'"; |
| 5673 | if (scoped) { |
| 5674 | snprintf(sqlbuf, sizeof(sqlbuf), "%s%s LIMIT 20", base, arch_path_scope_sql()); |
| 5675 | } else { |
| 5676 | snprintf(sqlbuf, sizeof(sqlbuf), "%s LIMIT 20", base); |
| 5677 | } |
| 5678 | sqlite3_stmt *stmt = NULL; |
| 5679 | if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) { |
| 5680 | store_set_error_sqlite(s, "arch_entry_points"); |
| 5681 | return CBM_STORE_ERR; |
| 5682 | } |
| 5683 | bind_text(stmt, SKIP_ONE, project); |
| 5684 | if (scoped) { |
| 5685 | arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like); |
| 5686 | } |
| 5687 | |
| 5688 | int cap = ST_INIT_CAP_8; |
| 5689 | int n = 0; |
| 5690 | cbm_entry_point_t *arr = calloc(cap, sizeof(cbm_entry_point_t)); |
| 5691 | int scan_rc21; |
| 5692 | while ((scan_rc21 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 5693 | if (n >= cap) { |
| 5694 | cap *= ST_GROWTH; |
| 5695 | arr = safe_realloc(arr, cap * sizeof(cbm_entry_point_t)); |
| 5696 | } |
| 5697 | arr[n].name = heap_strdup((const char *)sqlite3_column_text(stmt, 0)); |
| 5698 | arr[n].qualified_name = heap_strdup((const char *)sqlite3_column_text(stmt, SKIP_ONE)); |
| 5699 | arr[n].file = heap_strdup((const char *)sqlite3_column_text(stmt, CBM_SZ_2)); |
| 5700 | n++; |
| 5701 | } |
| 5702 | if (scan_rc21 != SQLITE_DONE) { /* SCANCHK:21:stmt */ |
| 5703 | store_set_error_sqlite(s, "row scan aborted"); |
| 5704 | sqlite3_finalize(stmt); |
| 5705 | out->entry_points = arr; |
| 5706 | out->entry_point_count = n; |
| 5707 | return CBM_STORE_ERR; |
| 5708 | } |
| 5709 | sqlite3_finalize(stmt); |
| 5710 | out->entry_points = arr; |
| 5711 | out->entry_point_count = n; |
| 5712 | return CBM_STORE_OK; |
| 5713 | } |
| 5714 | |
| 5715 | /* Extract a JSON string value from a simple JSON object by key name. */ |
| 5716 | static char *extract_json_string_prop(const char *json, const char *key, int key_len) { |
no test coverage detected