| 8930 | } |
| 8931 | |
| 8932 | static int arch_entry_points(cbm_store_t *s, const char *project, const char *path, |
| 8933 | cbm_architecture_info_t *out) { |
| 8934 | char norm[CBM_SZ_512]; |
| 8935 | char like[CBM_SZ_512]; |
| 8936 | bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like)); |
| 8937 | char sqlbuf[ST_SQL_BUF]; |
| 8938 | const char *base = "SELECT name, qualified_name, file_path FROM nodes " |
| 8939 | "WHERE project=?1 AND json_extract(properties, '$.is_entry_point') = 1 " |
| 8940 | "AND (json_extract(properties, '$.is_test') IS NULL OR " |
| 8941 | "json_extract(properties, '$.is_test') != 1) " |
| 8942 | "AND file_path NOT LIKE '%test%'"; |
| 8943 | if (scoped) { |
| 8944 | snprintf(sqlbuf, sizeof(sqlbuf), "%s%s LIMIT 20", base, arch_path_scope_sql()); |
| 8945 | } else { |
| 8946 | snprintf(sqlbuf, sizeof(sqlbuf), "%s LIMIT 20", base); |
| 8947 | } |
| 8948 | sqlite3_stmt *stmt = NULL; |
| 8949 | if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) { |
| 8950 | store_set_error_sqlite(s, "arch_entry_points"); |
| 8951 | return CBM_STORE_ERR; |
| 8952 | } |
| 8953 | bind_text(stmt, SKIP_ONE, project); |
| 8954 | if (scoped) { |
| 8955 | arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like); |
| 8956 | } |
| 8957 | |
| 8958 | int cap = ST_INIT_CAP_8; |
| 8959 | int n = 0; |
| 8960 | cbm_entry_point_t *arr = calloc(cap, sizeof(cbm_entry_point_t)); |
| 8961 | int scan_rc21; |
| 8962 | while ((scan_rc21 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 8963 | if (n >= cap) { |
| 8964 | cap *= ST_GROWTH; |
| 8965 | arr = safe_realloc(arr, cap * sizeof(cbm_entry_point_t)); |
| 8966 | } |
| 8967 | arr[n].name = heap_strdup((const char *)sqlite3_column_text(stmt, 0)); |
| 8968 | arr[n].qualified_name = heap_strdup((const char *)sqlite3_column_text(stmt, SKIP_ONE)); |
| 8969 | arr[n].file = heap_strdup((const char *)sqlite3_column_text(stmt, CBM_SZ_2)); |
| 8970 | n++; |
| 8971 | } |
| 8972 | if (scan_rc21 != SQLITE_DONE) { /* SCANCHK:21:stmt */ |
| 8973 | store_set_error_sqlite(s, "row scan aborted"); |
| 8974 | sqlite3_finalize(stmt); |
| 8975 | out->entry_points = arr; |
| 8976 | out->entry_point_count = n; |
| 8977 | return CBM_STORE_ERR; |
| 8978 | } |
| 8979 | sqlite3_finalize(stmt); |
| 8980 | out->entry_points = arr; |
| 8981 | out->entry_point_count = n; |
| 8982 | return CBM_STORE_OK; |
| 8983 | } |
| 8984 | |
| 8985 | /* Extract a JSON string value from a simple JSON object by key name. */ |
| 8986 | static char *extract_json_string_prop(const char *json, const char *key, int key_len) { |
no test coverage detected