Skip to content

Commit df99ca1

Browse files
authored
fix: js_image_layer files matching no layer (#2143)
1 parent ba38f3a commit df99ca1

9 files changed

+216
-1
lines changed

js/private/js_image_layer.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@ def _run_splitter(ctx, runfiles_dir, files, entries_json, layer_groups):
367367

368368
expected_layer_groups.append((name, mtree, unused_inputs))
369369

370+
# Final else {} to discard a file if it doesn't match any of the layer groups.
371+
PICK_STATEMENTS += """
372+
else {
373+
%s
374+
continue
375+
}""" % (
376+
"\n".join([
377+
" %sunusedinputs.write(destBuf);" % oname
378+
for oname in layer_groups.keys()
379+
])
380+
)
381+
370382
unused_inputs = ctx.actions.declare_file("{}_splitter_unused_inputs.txt".format(ctx.label.name))
371383
splitter_outputs.append(unused_inputs)
372384

js/private/test/image/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,18 @@ assert_js_image_layer_listings(
9292
additional_layers = ["odd_characters"],
9393
js_image_layer = ":regex_edge_cases",
9494
)
95+
96+
# Case 4: overwrite layer so some files have no matches
97+
# bazel run :custom_owner_test_update_all
98+
make_js_image_layer(
99+
name = "custom_layers_nomatch",
100+
binary = ":bin",
101+
layer_groups = {"app": "no app for you"},
102+
platform = ":linux_amd64",
103+
root = "/app",
104+
)
105+
106+
assert_js_image_layer_listings(
107+
name = "custom_layers_nomatch_test",
108+
js_image_layer = ":custom_layers_nomatch",
109+
)

js/private/test/image/asserts.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def make_js_image_layer(name, layer_groups = {}, **kwargs):
6969
**kwargs
7070
)
7171

72-
for layer in layers + layer_groups.keys():
72+
for layer in layers + [k for k in layer_groups.keys() if k not in layers]:
7373
native.filegroup(
7474
name = name + "_" + layer,
7575
srcs = [name],

js/private/test/image/custom_layers_nomatch_test_app.bzlmod.listing

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/
2+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/
3+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/
4+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/
5+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/
6+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/
7+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/
8+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/
9+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/
10+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/node-patches/
11+
-r-xr-xr-x 0 0 0 32555 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/node-patches/fs.cjs
12+
-r-xr-xr-x 0 0 0 1702 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/node-patches/register.cjs
13+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/
14+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/bin/
15+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/bin/nodejs/
16+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/bin/nodejs/bin/
17+
-r-xr-xr-x 0 0 0 80316256 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/bin/nodejs/bin/node
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/
2+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/
3+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/
4+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/
5+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/
6+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/
7+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/
8+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/
9+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/
10+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/
11+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/
12+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/node_modules/
13+
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/node_modules/acorn -> ../../../../../node_modules/.aspect_rules_js/[email protected]/node_modules/acorn
14+
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/node_modules/uuid -> ../../../../../node_modules/.aspect_rules_js/[email protected]/node_modules/uuid
15+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/
16+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/
17+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/
18+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/
19+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/node_modules/
20+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/node_modules/@mycorp/
21+
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/node_modules/@mycorp/pkg-d -> ../../../../../../node_modules/.aspect_rules_js/@[email protected]/node_modules/@mycorp/pkg-d
22+
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/node_modules/acorn -> ../../../../../node_modules/.aspect_rules_js/[email protected]/node_modules/acorn
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/
2+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/
3+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/
4+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/
5+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/
6+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/
7+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/
8+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/
9+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/
10+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@[email protected]/
11+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@[email protected]/node_modules/
12+
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@[email protected]/node_modules/@mycorp/
13+
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@[email protected]/node_modules/@mycorp/pkg-d -> ../../../../../examples/npm_package/packages/pkg_d

0 commit comments

Comments
 (0)