| 5753 | } |
| 5754 | |
| 5755 | static int arch_entry_points(cbm_store_t *s, const char *project, const char *path, |
| 5756 | cbm_architecture_info_t *out) { |
| 5757 | char norm[CBM_SZ_512]; |
| 5758 | char like[CBM_SZ_512]; |
| 5759 | bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like)); |
| 5760 | char sqlbuf[ST_SQL_BUF]; |
| 5761 | const char *base = "SELECT name, qualified_name, file_path FROM nodes " |
| 5762 | "WHERE project=?1 AND json_extract(properties, '$.is_entry_point') = 1 " |
| 5763 | "AND (json_extract(properties, '$.is_test') IS NULL OR " |
| 5764 | "json_extract(properties, '$.is_test') != 1) " |
| 5765 | "AND file_path NOT LIKE '%test%'"; |
| 5766 | if (scoped) { |
| 5767 | snprintf(sqlbuf, sizeof(sqlbuf), "%s%s LIMIT 20", base, arch_path_scope_sql()); |
| 5768 | } else { |
| 5769 | snprintf(sqlbuf, sizeof(sqlbuf), "%s LIMIT 20", base); |
| 5770 | } |
| 5771 | sqlite3_stmt *stmt = NULL; |
| 5772 | if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) { |
| 5773 | store_set_error_sqlite(s, "arch_entry_points"); |
| 5774 | return CBM_STORE_ERR; |
| 5775 | } |
| 5776 | bind_text(stmt, SKIP_ONE, project); |
| 5777 | if (scoped) { |
| 5778 | arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like); |
| 5779 | } |
| 5780 | |
| 5781 | int cap = ST_INIT_CAP_8; |
| 5782 | int n = 0; |
| 5783 | cbm_entry_point_t *arr = calloc(cap, sizeof(cbm_entry_point_t)); |
| 5784 | int scan_rc21; |
| 5785 | while ((scan_rc21 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 5786 | if (n >= cap) { |
| 5787 | cap *= ST_GROWTH; |
| 5788 | arr = safe_realloc(arr, cap * sizeof(cbm_entry_point_t)); |
| 5789 | } |
| 5790 | arr[n].name = heap_strdup((const char *)sqlite3_column_text(stmt, 0)); |
| 5791 | arr[n].qualified_name = heap_strdup((const char *)sqlite3_column_text(stmt, SKIP_ONE)); |
| 5792 | arr[n].file = heap_strdup((const char *)sqlite3_column_text(stmt, CBM_SZ_2)); |
| 5793 | n++; |
| 5794 | } |
| 5795 | if (scan_rc21 != SQLITE_DONE) { /* SCANCHK:21:stmt */ |
| 5796 | store_set_error_sqlite(s, "row scan aborted"); |
| 5797 | sqlite3_finalize(stmt); |
| 5798 | out->entry_points = arr; |
| 5799 | out->entry_point_count = n; |
| 5800 | return CBM_STORE_ERR; |
| 5801 | } |
| 5802 | sqlite3_finalize(stmt); |
| 5803 | out->entry_points = arr; |
| 5804 | out->entry_point_count = n; |
| 5805 | return CBM_STORE_OK; |
| 5806 | } |
| 5807 | |
| 5808 | /* Extract a JSON string value from a simple JSON object by key name. */ |
| 5809 | static char *extract_json_string_prop(const char *json, const char *key, int key_len) { |
no test coverage detected