Skip to content

Commit 77039b1

Browse files
committed
fix(builtin): use correct genrule-style make vars
https://docs.bazel.build/versions/master/be/make-variables.html documents that $@ is for the output location of a single out and $(RULEDIR) is the preferred way to refer to the output directory of the package BREAKING CHANGE: Usage of the $@ shortcut in npm_package_bin-generated rules should now be $(RULEDIR) and you can now use $@ to refer to the location of a single output
1 parent 8f44bea commit 77039b1

12 files changed

Lines changed: 36 additions & 22 deletions

File tree

e2e/ts_devserver/subpackage/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ html_insert_assets(
2323
"--html",
2424
"$(location index.tmpl.html)",
2525
"--out",
26-
"$(location index.html)",
26+
"$@",
2727
"--assets",
2828
"$(location //:red-body-style.css)",
2929
],

examples/angular/src/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ html_insert_assets(
9393
"--html",
9494
"$(location //src:example/index.html)",
9595
"--out",
96-
"$(location index.html)",
96+
"$@",
9797
"--assets",
9898
] + ["$(location %s)" % s for s in _ASSETS] + [
9999
# This file doesn't exist during the build, but will be served by ts_devserver
@@ -154,7 +154,7 @@ babel(
154154
"--source-maps",
155155
"--presets=@babel/preset-env",
156156
"--out-dir",
157-
"$@",
157+
"$(RULEDIR)",
158158
],
159159
data = [
160160
":bundle-es2015",
@@ -184,7 +184,7 @@ html_insert_assets(
184184
"--html",
185185
"$(location //src:example/index.prod.html)",
186186
"--out",
187-
"$(location _prodapp/src/example/index.html)",
187+
"$@",
188188
"--assets",
189189
] + ["$(location %s)" % s for s in _ASSETS],
190190
data = ["//src:example/index.prod.html"] + _ASSETS,

examples/angular_view_engine/src/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ html_insert_assets(
9191
"--html",
9292
"$(location //src:example/index.html)",
9393
"--out",
94-
"$(location index.html)",
94+
"$@",
9595
"--assets",
9696
] + ["$(location %s)" % s for s in _ASSETS] + [
9797
# This file doesn't exist during the build, but will be served by ts_devserver
@@ -154,7 +154,7 @@ babel(
154154
"--source-maps",
155155
"--presets=@babel/preset-env",
156156
"--out-dir",
157-
"$@",
157+
"$(RULEDIR)",
158158
],
159159
data = [
160160
":bundle-es2015",
@@ -184,7 +184,7 @@ html_insert_assets(
184184
"--html",
185185
"$(location //src:example/index.prod.html)",
186186
"--out",
187-
"$(location _prodapp/src/example/index.html)",
187+
"$@",
188188
"--assets",
189189
] + ["$(location %s)" % s for s in _ASSETS],
190190
data = ["//src:example/index.prod.html"] + _ASSETS,

examples/app/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ html_insert_assets(
4343
outs = ["index.html"],
4444
args = [
4545
"--out",
46-
"$(location index.html)",
46+
"$@",
4747
"--html",
4848
"$(location :index.tmpl.html)",
4949
"--roots",
50-
"$@",
50+
"$(RULEDIR)",
5151
"--assets",
5252
] + ["$(locations %s)" % a for a in _ASSETS],
5353
data = [":index.tmpl.html"] + _ASSETS,
@@ -77,8 +77,8 @@ tsc(
7777
"-p",
7878
"$(location tsconfig-test.json)",
7979
"--outDir",
80-
# $@ is a shorthand for the dist/bin directory where Bazel requires we write outputs
81-
"$@",
80+
# $(RULEDIR) is a shorthand for the dist/bin directory where Bazel requires we write outputs
81+
"$(RULEDIR)",
8282
],
8383
data = [
8484
"app.e2e-spec.ts",

examples/closure/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ google_closure_compiler(
99
# --platform native would be faster but is failing on Windows
1010
"--platform=javascript",
1111
"--js=$(location hello.js)",
12-
"--js_output_file=$(location bundle.js)",
12+
"--js_output_file=$@",
1313
],
1414
data = ["hello.js"],
1515
)

examples/protocol_buffers/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,11 @@ requirejs@2.3.5:
24192419
resolved "https://registry.yarnpkg.com/requirejs/-/requirejs-2.3.5.tgz#617b9acbbcb336540ef4914d790323a8d4b861b0"
24202420
integrity sha512-svnO+aNcR/an9Dpi44C7KSAy5fFGLtmPbaaCeQaklUz8BQhS64tWWIIlvEA5jrWICzlO/X9KSzSeXFnZdBu8nw==
24212421

2422+
requirejs@2.3.6:
2423+
version "2.3.6"
2424+
resolved "https://registry.yarnpkg.com/requirejs/-/requirejs-2.3.6.tgz#e5093d9601c2829251258c0b9445d4d19fa9e7c9"
2425+
integrity sha512-ipEzlWQe6RK3jkzikgCupiTbTvm4S0/CAU5GlgptkN5SO6F3u0UD0K18wy6ErDqiCyP4J4YYe1HuAShvsxePLg==
2426+
24222427
requires-port@^1.0.0:
24232428
version "1.0.0"
24242429
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"

examples/react_webpack/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tsc(
2020
"$(location index.tsx)",
2121
"$(location types.d.ts)",
2222
"--outDir",
23-
"$@",
23+
"$(RULEDIR)",
2424
"--lib",
2525
"es2015,dom",
2626
"--jsx",
@@ -42,7 +42,7 @@ webpack(
4242
"--config",
4343
"$(location webpack.config.js)",
4444
"-o",
45-
"$(location app.bundle.js)",
45+
"$@",
4646
],
4747
data = [
4848
"index.js",

examples/webapp/differential_loading.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def differential_loading(name, entry_point, srcs):
3838
"--config-file",
3939
"$(location es5.babelrc)",
4040
"--out-dir",
41-
"$@",
41+
"$(RULEDIR)",
4242
],
4343
)
4444

internal/node/npm_package_bin.bzl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@ def _expand_location(ctx, s):
2626
# We'll write into a newly created directory named after the rule
2727
outdir_segments.append(ctx.attr.name)
2828

29+
if not ctx.attr.output_dir:
30+
if s.find("$@") != -1 and len(ctx.outputs.outs) > 1:
31+
fail("""$@ substitution may only be used with a single out
32+
Upgrading rules_nodejs? Maybe you need to switch from $@ to $(RULEDIR)
33+
See https://github.com/bazelbuild/rules_nodejs/releases/tag/0.42.0""")
34+
s = s.replace("$@", ctx.outputs.outs[0].path)
35+
2936
# The list comprehension removes empty segments like if we are in the root package
30-
s = s.replace("$@", "/".join([o for o in outdir_segments if o]))
37+
s = s.replace("$(RULEDIR)", "/".join([o for o in outdir_segments if o]))
3138
return ctx.expand_location(s, targets = ctx.attr.data)
3239

3340
def _inputs(ctx):
@@ -95,8 +102,10 @@ def npm_package_bin(tool = None, package = None, package_bin = None, data = [],
95102
96103
Subject to 'Make variable' substitution.
97104
Can use $(location) expansion. See https://docs.bazel.build/versions/master/be/make-variables.html
98-
You may also refer to the location of the output_dir with the special `$@` replacement, like genrule.
99-
If output_dir=False then $@ will refer to the output directory for this package.
105+
Like genrule, you may also use some syntax sugar for locations:
106+
- `$@`: if you have only one output file, the location of the output
107+
- `$(RULEDIR)`: the output directory of the rule, corresponding with its package
108+
(can be used with output_dir=True or False)
100109
101110
package: an npm package whose binary to run, like "terser". Assumes your node_modules are installed in a workspace called "npm"
102111
package_bin: the "bin" entry from `package` that should be run. By default package_bin is the same string as `package`

internal/node/test/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ npm_package_bin(
151151
args = [
152152
"$(location terser_input.js)",
153153
"--output",
154-
"$(location minified.js)",
154+
"$@",
155155
],
156156
data = ["terser_input.js"],
157157
package = "terser",
@@ -166,7 +166,7 @@ npm_package_bin(
166166
name = "dir_output",
167167
args = [
168168
"--output-dir",
169-
"$@",
169+
"$(RULEDIR)",
170170
"$(location terser_input.js)",
171171
],
172172
data = ["terser_input.js"],

0 commit comments

Comments
 (0)