Skip to content

Commit 9fa4343

Browse files
ashi009alexeagle
authored andcommitted
feat: support --compilation_mode flag
1 parent 0648b97 commit 9fa4343

15 files changed

Lines changed: 54 additions & 37 deletions

File tree

.bazelci/presubmit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ tasks:
106106
name: ubuntu1804_debug
107107
platform: ubuntu1804
108108
test_flags:
109+
- "--compilation_mode=dbg"
109110
- "--define=VERBOSE_LOGS=1"
110-
- "--define=DEBUG=1"
111111
- "--test_tag_filters=-e2e,-examples,-no-bazelci,-no-bazelci-ubuntu,-manual"
112112
test_targets:
113113
- "//..."

common.bazelrc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ test --test_output=errors
4242
# --define=VERBOSE_LOGS=1
4343
# Rules will output verbose logs if the VERBOSE_LOGS environment variable is set. `VERBOSE_LOGS` will be passed to
4444
# `nodejs_binary` and `nodejs_test` via the default value of the `default_env_vars` attribute of those rules.
45-
# --define=DEBUG=1
46-
# Rules may change their build outputs if the DEBUG environment variable is set. For example,
47-
# mininfiers such as terser may make their output more human readable when this is set. `DEBUG` will be passed to
45+
# --compilation_mode=dbg
46+
# Rules may change their build outputs if the compilation mode is set to dbg. For example,
47+
# mininfiers such as terser may make their output more human readable when this is set. `COMPILATION_MODE` will be passed to
4848
# `nodejs_binary` and `nodejs_test` via the default value of the `default_env_vars` attribute of those rules.
49+
# See https://docs.bazel.build/versions/master/user-manual.html#flag--compilation_mode for more details.
4950
test:debug --test_output=streamed --test_strategy=exclusive --test_timeout=9999 --nocache_test_results --define=VERBOSE_LOGS=1
5051
# Use bazel run with `--config=debug` to turn on the NodeJS inspector agent.
5152
# The node process will break before user code starts and wait for the debugger to connect.
5253
run:debug --define=VERBOSE_LOGS=1 -- --node_options=--inspect-brk
5354
# The following option will change the build output of certain rules such as terser and may not be desirable in all cases
54-
build:debug --define=DEBUG=1
55+
build:debug --compilation_mode=dbg
5556

5657
# Turn off legacy external runfiles
5758
# This prevents accidentally depending on this feature, which Bazel will remove.

docs/Built-ins.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,13 @@ without losing the defaults that should be set in most cases.
226226

227227
The set of default environment variables is:
228228

229-
- `DEBUG`: rules use this environment variable to turn on debug information in their output artifacts
229+
- `COMPILATION_MODE`: rules use this environment variable to produce optimized (eg. mangled and minimized) or debugging output
230230
- `VERBOSE_LOGS`: rules use this environment variable to turn on debug output in their logs
231+
- `DEBUG`: used by some npm packages to print debugging logs
231232
- `NODE_DEBUG`: used by node.js itself to print more logs
232233

234+
Note that, `DEBUG` is derived from bazel compilation mode if not present in --define.
235+
233236

234237
#### `entry_point`
235238
(*[label], mandatory*): The script which should be executed first, usually containing a main function.
@@ -438,10 +441,13 @@ without losing the defaults that should be set in most cases.
438441

439442
The set of default environment variables is:
440443

441-
- `DEBUG`: rules use this environment variable to turn on debug information in their output artifacts
444+
- `COMPILATION_MODE`: rules use this environment variable to produce optimized (eg. mangled and minimized) or debugging output
442445
- `VERBOSE_LOGS`: rules use this environment variable to turn on debug output in their logs
446+
- `DEBUG`: used by some npm packages to print debugging logs
443447
- `NODE_DEBUG`: used by node.js itself to print more logs
444448

449+
Note that, `DEBUG` is derived from bazel compilation mode if not present in --define.
450+
445451

446452
#### `entry_point`
447453
(*[label], mandatory*): The script which should be executed first, usually containing a main function.

docs/Terser.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Bazel will make a copy of your config file, treating it as a template.
9696
9797
If you use the magic strings `"bazel_debug"` or `"bazel_no_debug"`, these will be
9898
replaced with `true` and `false` respecting the value of the `debug` attribute
99-
or the `--define=DEBUG=1` bazel flag.
99+
or the `--compilation_mode=dbg` bazel flag.
100100

101101
For example,
102102

@@ -115,8 +115,8 @@ If `config_file` isn't supplied, Bazel will use a default config file.
115115
#### `debug`
116116
(*Boolean*): Configure terser to produce more readable output.
117117

118-
Instead of setting this attribute, consider setting the DEBUG variable instead
119-
bazel build --define=DEBUG=1 //my/terser:target
118+
Instead of setting this attribute, consider using debugging compilation mode instead
119+
bazel build --compilation_mode=dbg //my/terser:target
120120
so that it only affects the current build.
121121

122122

@@ -126,7 +126,7 @@ so that it only affects the current build.
126126

127127
#### `src`
128128
(*[label], mandatory*): File(s) to minify.
129-
129+
130130
Can be a .js file, a rule producing .js files as its default output, or a rule producing a directory of .js files.
131131

132132
Note that you can pass multiple files to terser, which it will bundle together.

internal/bazel_integration_test/test_runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const fs = require('fs');
2424
const path = require('path');
2525
const tmp = require('tmp');
2626

27-
const DEBUG = !!process.env['DEBUG'];
27+
const DEBUG = process.env['COMPILATION_MODE'] === 'dbg';
2828
const VERBOSE_LOGS = !!process.env['VERBOSE_LOGS'];
2929

3030
function log(...m) {

internal/golden_file_test/bin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require('path');
33

44
function main(args) {
55
const [mode, golden_no_debug, golden_debug, actual] = args;
6-
const debug = !!process.env['DEBUG'];
6+
const debug = process.env['COMPILATION_MODE'] === 'dbg';
77
const golden = debug ? golden_debug : golden_no_debug;
88
const actualContents = fs.readFileSync(require.resolve(actual), 'utf-8').replace(/\r\n/g, '\n');
99
const goldenContents = fs.readFileSync(require.resolve(golden), 'utf-8').replace(/\r\n/g, '\n');
@@ -22,12 +22,12 @@ function main(args) {
2222
prettyDiff = prettyDiff.substr(0, 5000) + '/n...elided...';
2323
}
2424
throw new Error(`Actual output doesn't match golden file:
25-
25+
2626
${prettyDiff}
27-
27+
2828
Update the golden file:
2929
30-
bazel run ${debug ? '--define=DEBUG=1 ' : ''}${
30+
bazel run ${debug ? '--compilation_mode=dbg ' : ''}${
3131
process.env['BAZEL_TARGET'].replace(/_bin$/, '')}.accept
3232
`);
3333
} else {

internal/node/node.bzl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ def _nodejs_binary_impl(ctx):
171171
if k in ctx.var.keys():
172172
env_vars += "export %s=\"%s\"\n" % (k, ctx.var[k])
173173

174+
if "DEBUG" in ctx.var and ctx.var["COMPILATION_MODE"] != "dbg":
175+
print("""
176+
WARNING: `--define DEBUG` no longer triggers a debugging build, use
177+
`--compilation_mode=dbg` instead.
178+
179+
""")
180+
174181
expected_exit_code = 0
175182
if hasattr(ctx.attr, "expected_exit_code"):
176183
expected_exit_code = ctx.attr.expected_exit_code
@@ -303,11 +310,12 @@ without losing the defaults that should be set in most cases.
303310
304311
The set of default environment variables is:
305312
306-
- `DEBUG`: rules use this environment variable to turn on debug information in their output artifacts
313+
- `COMPILATION_MODE`: rules use this environment variable to produce optimized (eg. mangled and minimized) or debugging output
307314
- `VERBOSE_LOGS`: rules use this environment variable to turn on debug output in their logs
315+
- `DEBUG`: used by some npm packages to print debugging logs
308316
- `NODE_DEBUG`: used by node.js itself to print more logs
309317
""",
310-
default = ["DEBUG", "VERBOSE_LOGS", "NODE_DEBUG"],
318+
default = ["COMPILATION_MODE", "VERBOSE_LOGS", "DEBUG", "NODE_DEBUG"],
311319
),
312320
"entry_point": attr.label(
313321
doc = """The script which should be executed first, usually containing a main function.

internal/providers/js_providers.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ subscribes to these by having a (possibly transitive) dependency on the publishe
2929
Debug output is considered orthogonal to these providers.
3030
Any output may or may not have user debugging affordances provided, such as
3131
readable minification.
32-
We expect that rules will have a boolean `debug` attribute, and/or accept the `DEBUG`
33-
environment variable.
32+
We expect that rules will have a boolean `debug` attribute, and/or accept the
33+
`COMPILATION_MODE` environment variable.
3434
Note that this means a given build either produces debug or non-debug output.
3535
If users really need to produce both in a single build, they'll need two rules with
3636
differing 'debug' attributes.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"test_e2e": "bazel --host_jvm_args=-Xms256m --host_jvm_args=-Xmx1280m test --test_tag_filters=e2e --local_resources=792,1.0,1.0 --test_arg=--local_resources=13288,1.0,1.0 ...",
8484
"test_examples": "bazel --host_jvm_args=-Xms256m --host_jvm_args=-Xmx1280m test --test_tag_filters=examples --local_resources=792,1.0,1.0 --test_arg=--local_resources=13288,1.0,1.0 ...",
8585
"run_integration_test": "bazel --host_jvm_args=-Xms256m --host_jvm_args=-Xmx1280m run --local_resources=792,1.0,1.0 --test_arg=--local_resources=13288,1.0,1.0",
86-
"run_integration_test_debug": "yarn run_integration_test --define=DEBUG=1",
86+
"run_integration_test_debug": "yarn run_integration_test --compilation_mode=dbg",
8787
"test_all": "./scripts/test_all.sh",
8888
"clean_all": "./scripts/clean_all.sh",
8989
"// Unchecked warnings": "The following warnings are not checked as disabling them locally is broken",

packages/create/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const fs = require('fs');
44
const path = require('path');
5-
const DEBUG = !!process.env['DEBUG'];
5+
const DEBUG = process.env['COMPILATION_MODE'] === 'dbg';
66

77
/**
88
* Detect if the user ran `yarn create @bazel` so we can default
@@ -26,7 +26,7 @@ function validateWorkspaceName(name, error) {
2626
return true;
2727
}
2828
error(`ERROR: ${name} is not a valid Bazel workspace name.
29-
29+
3030
A workspace name must start with a letter and can contain letters, numbers, and underscores
3131
(this is to maximize the number of languages for which this string can be a valid package/module name).
3232
It should describe the project in reverse-DNS form, with elements separated by underscores.
@@ -167,7 +167,7 @@ install_bazel_dependencies()`;
167167
if (args['typescript']) {
168168
workspaceContent += `
169169
170-
# Setup TypeScript toolchain
170+
# Setup TypeScript toolchain
171171
load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")
172172
ts_setup_workspace()`;
173173
}

0 commit comments

Comments
 (0)