F1: the files the image is made of -- the context sources its stages COPY * / ADD, resolved in the build context: the Dockerfile's directory or the * repository root, the one more of the literal sources exist under (a tie: * the directory) -- and the context's ignore patterns, kept on the * Dockerfile's Module (image_context, image_files, image_ignore) for the env * join, which reads them bac
| 1371 | * Dockerfile's Module (image_context, image_files, image_ignore) for the env |
| 1372 | * join, which reads them back in an incremental run. */ |
| 1373 | static void dk_image_set(dk_t *d) { |
| 1374 | cbm_gbuf_node_t *mod = (cbm_gbuf_node_t *)cbm_gbuf_find_by_id(d->ctx->gbuf, d->module); |
| 1375 | if (!mod || d->stage < 0 || d->stage >= DK_MAX_STAGES) { |
| 1376 | return; |
| 1377 | } |
| 1378 | bool in[DK_MAX_STAGES] = {false}; |
| 1379 | dk_image_stages(d, in); |
| 1380 | dk_ctx_vote_t v = {.cands = {d->dir, ""}, .ncand = d->dir[0] ? DK_SET_CANDS : SKIP_ONE}; |
| 1381 | dk_image_sources(d, in, dk_ctx_vote, &v); |
| 1382 | const char *ctx = v.ncand > SKIP_ONE && v.hits[SKIP_ONE] > v.hits[0] ? "" : d->dir; |
| 1383 | dk_json_list_t files = {.ctx = ctx, .json = "[", .seen = cbm_ht_create(0)}; |
| 1384 | dk_json_list_t ignore = {.ctx = ctx, .json = "[", .seen = cbm_ht_create(0)}; |
| 1385 | if (files.seen && ignore.seen) { |
| 1386 | dk_image_sources(d, in, dk_file_add, &files); |
| 1387 | dk_ignore_add(d, &ignore); |
| 1388 | } |
| 1389 | const char *props = |
| 1390 | mod->properties_json && mod->properties_json[0] ? mod->properties_json : "{}"; |
| 1391 | size_t pl = strlen(props); |
| 1392 | if (files.seen && ignore.seen && files.json && files.json[SKIP_ONE] && ignore.json && |
| 1393 | pl >= PAIR_LEN && props[pl - SKIP_ONE] == '}') { |
| 1394 | char cesc[CBM_SZ_4K]; |
| 1395 | cbm_json_escape(cesc, (int)sizeof(cesc), ctx); |
| 1396 | bool empty = strspn(props + SKIP_ONE, " \t\r\n") == pl - PAIR_LEN; |
| 1397 | const char *out = cbm_arena_sprintf( |
| 1398 | d->a, "%.*s%s\"image_context\":\"%s\",\"image_files\":%s],\"image_ignore\":%s]}", |
| 1399 | (int)(pl - SKIP_ONE), props, empty ? "" : ",", cesc, files.json, ignore.json); |
| 1400 | if (out) { |
| 1401 | (void)cbm_gbuf_node_set_properties_json(mod, out); |
| 1402 | } |
| 1403 | } |
| 1404 | if (files.seen) { |
| 1405 | cbm_ht_free(files.seen); |
| 1406 | } |
| 1407 | if (ignore.seen) { |
| 1408 | cbm_ht_free(ignore.seen); |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | static void dk_file(dk_t *d, TSNode root) { |
| 1413 | for (uint32_t i = 0; i < ts_node_named_child_count(root); i++) { |
no test coverage detected