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

Function dk_spawn

src/pipeline/pass_docker.c:1120–1191  ·  view source on GitHub ↗

SPAWNS from the Dockerfile to what its last stage runs. */

Source from the content-addressed store, hash-verified

1118
1119/* SPAWNS from the Dockerfile to what its last stage runs. */
1120static void dk_spawn(dk_t *d) {
1121 if (d->stage < 0 || d->stage >= DK_MAX_STAGES || (!d->entry.set && !d->cmd.set)) {
1122 return;
1123 }
1124 const dk_entry_t *e = d->entry.set ? &d->entry : &d->cmd;
1125 const char *argv[DK_MAX_WORDS];
1126 int argc = 0;
1127 for (int i = 0; i < e->argc; i++) {
1128 if (e->argv[i] && e->argv[i][0]) {
1129 argv[argc++] = e->argv[i];
1130 }
1131 }
1132 if (argc == 0 || strchr(argv[0], '$') || argv[0][0] == '-') {
1133 return; /* unknown, or arguments to an inherited ENTRYPOINT */
1134 }
1135 const char *prog = argv[0];
1136 const char *base = dk_base(prog);
1137 if ((strcmp(base, "sh") == 0 || strcmp(base, "bash") == 0) && argc > SKIP_ONE &&
1138 strcmp(argv[SKIP_ONE], "-c") == 0) {
1139 return;
1140 }
1141 dk_found_t f = {0};
1142 const char *path = NULL;
1143 const cbm_gbuf_node_t *main_fn = NULL;
1144 if (dk_interpreter(base)) {
1145 const char *script = NULL;
1146 for (int i = SKIP_ONE; i < argc && !script; i++) {
1147 script = argv[i][0] != '-' ? argv[i] : NULL;
1148 }
1149 if (script && !strchr(script, '$') &&
1150 dk_origin(d, d->stage, dk_absolute(d, script, e->workdir), DK_WANT_FILE, 0, &f)) {
1151 path = f.repo;
1152 }
1153 } else if (strchr(prog, '/')) {
1154 if (dk_origin(d, d->stage, dk_absolute(d, prog, e->workdir), DK_WANT_FILE, 0, &f)) {
1155 path = f.repo;
1156 main_fn = f.build ? dk_gomain(d, f.build, f.build_stage) : NULL;
1157 }
1158 } else if (!d->entry.set &&
1159 dk_origin(d, d->stage, dk_absolute(d, prog, e->workdir), DK_WANT_FILE, 0, &f)) {
1160 path = f.repo; /* a CMD file under an inherited ENTRYPOINT (distroless) */
1161 }
1162 int64_t tgt = 0;
1163 if (path) {
1164 const char *mqn = cbm_fqn_module(d->a, d->ctx->project_name, path);
1165 const cbm_gbuf_node_t *m = mqn ? cbm_gbuf_find_by_qn(d->ctx->gbuf, mqn) : NULL;
1166 const cbm_gbuf_node_t *file = m ? NULL : cbm_ht_get(d->ix->files, path);
1167 tgt = m ? m->id : file ? file->id : 0;
1168 } else if (main_fn) {
1169 tgt = main_fn->id;
1170 } else {
1171 char esc_base[CBM_SZ_512];
1172 cbm_json_escape(esc_base, (int)sizeof(esc_base), base);
1173 char qn[CBM_SZ_512];
1174 snprintf(qn, sizeof(qn), "__process__%s", base);
1175 char node_props[CBM_SZ_1K];
1176 snprintf(node_props, sizeof(node_props), "{\"program\":\"%s\"}", esc_base);
1177 tgt = cbm_gbuf_upsert_node(d->ctx->gbuf, "Process", base, qn, "", 0, 0, node_props);

Callers 1

dk_fileFunction · 0.85

Calls 11

dk_baseFunction · 0.85
dk_interpreterFunction · 0.85
dk_originFunction · 0.85
dk_absoluteFunction · 0.85
dk_gomainFunction · 0.85
cbm_fqn_moduleFunction · 0.85
cbm_gbuf_find_by_qnFunction · 0.85
cbm_ht_getFunction · 0.85
cbm_json_escapeFunction · 0.85
cbm_gbuf_upsert_nodeFunction · 0.85
cbm_gbuf_insert_edgeFunction · 0.85

Tested by

no test coverage detected