MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / process_compile_entry

Function process_compile_entry

src/pipeline/pass_compile_commands.c:184–236  ·  view source on GitHub ↗

Process a single compile_commands.json entry. Returns 1 if added, 0 otherwise. */

Source from the content-addressed store, hash-verified

182
183/* Process a single compile_commands.json entry. Returns 1 if added, 0 otherwise. */
184static int process_compile_entry(yyjson_val *entry, const char *repo_path, char **out_path,
185 cbm_compile_flags_t **out_flag) {
186 yyjson_val *dir_val = yyjson_obj_get(entry, "directory");
187 yyjson_val *file_val = yyjson_obj_get(entry, "file");
188 yyjson_val *cmd_val = yyjson_obj_get(entry, "command");
189 yyjson_val *args_val = yyjson_obj_get(entry, "arguments");
190
191 if (!file_val) {
192 return 0;
193 }
194 const char *directory = dir_val ? yyjson_get_str(dir_val) : "";
195 const char *file_path = yyjson_get_str(file_val);
196 if (!file_path) {
197 return 0;
198 }
199
200 char *split_args[CBM_SZ_256] = {NULL};
201 const char *flag_args[CBM_SZ_256];
202 int flag_argc = extract_flag_args(args_val, cmd_val, flag_args, split_args, CBM_SZ_256);
203
204 if (flag_argc == 0) {
205 return 0;
206 }
207
208 cbm_compile_flags_t *f = cbm_extract_flags(flag_args, flag_argc, directory);
209
210 if (cmd_val && yyjson_is_str(cmd_val)) {
211 for (int j = 0; j < flag_argc; j++) {
212 free(split_args[j]);
213 }
214 }
215
216 if (!f) {
217 return 0;
218 }
219
220 char abs_path[CBM_SZ_4K];
221 if (file_path[0] != '/' && directory && directory[0]) {
222 snprintf(abs_path, sizeof(abs_path), "%s/%s", directory, file_path);
223 } else {
224 snprintf(abs_path, sizeof(abs_path), "%s", file_path);
225 }
226
227 size_t repo_len = strlen(repo_path);
228 if (strncmp(abs_path, repo_path, repo_len) != 0 || abs_path[repo_len] != '/') {
229 cbm_compile_flags_free(f);
230 return 0;
231 }
232
233 *out_path = strdup(abs_path + repo_len + SKIP_ONE);
234 *out_flag = f;
235 return SKIP_ONE;
236}
237
238int cbm_parse_compile_commands(const char *json_data, const char *repo_path, char ***out_paths,
239 cbm_compile_flags_t ***out_flags) {

Callers 1

Calls 3

extract_flag_argsFunction · 0.85
cbm_extract_flagsFunction · 0.85
cbm_compile_flags_freeFunction · 0.85

Tested by

no test coverage detected