From dc751fd949e119d2b0b4a2a2d7e6928a2b1a5a37 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 10 Jan 2022 23:28:30 -0800 Subject: [PATCH] fix: change all cfg=host and cfg=target executable attributes to cfg=exec --- examples/angular/src/tsconfig.json | 3 +- examples/angular/tools/karma.bzl | 2 +- examples/parcel/parcel.bzl | 2 +- examples/worker/uses_workers.bzl | 2 +- .../bazel_integration_test.bzl | 2 +- internal/linker/test/integration/rule.bzl | 2 +- .../linker/test/no_npm_deps/no_npm_deps.bzl | 2 +- internal/node/node.bzl | 2 +- internal/node/npm_package_bin.bzl | 2 +- internal/npm_install/npm_umd_bundle.bzl | 2 +- internal/pkg_web/pkg_web.bzl | 2 +- internal/providers/test/run_node_test.bzl | 6 +-- .../concatjs/devserver/concatjs_devserver.bzl | 4 +- packages/concatjs/internal/build_defs.bzl | 2 +- .../test/some_module/run_node_test.bzl | 2 +- packages/concatjs/web_test/karma_web_test.bzl | 2 +- packages/protractor/protractor_web_test.bzl | 4 +- packages/rollup/rollup_bundle.bzl | 4 +- packages/terser/index.js | 45 ++++++++++++++++++- packages/terser/terser_minified.bzl | 4 +- packages/typescript/internal/ts_project.bzl | 2 +- .../typescript/internal/validate_options.bzl | 2 +- 22 files changed, 72 insertions(+), 28 deletions(-) diff --git a/examples/angular/src/tsconfig.json b/examples/angular/src/tsconfig.json index ff86b826df..f26532e8c5 100644 --- a/examples/angular/src/tsconfig.json +++ b/examples/angular/src/tsconfig.json @@ -25,11 +25,12 @@ // Add all possible bazel-out directories // See https://github.com/microsoft/TypeScript/issues/37257 + "../bazel-out/darwin_arm64-fastbuild/bin/src", "../bazel-out/darwin-dbg/bin/src", "../bazel-out/darwin-fastbuild/bin/src", - "../bazel-out/darwin_arm64-fastbuild/bin/src", "../bazel-out/k8-dbg/bin/src", "../bazel-out/k8-fastbuild/bin/src", + "../bazel-out/k8-opt-exec-2B5CBBC6/bin/src", "../bazel-out/x64_windows-dbg/bin/src", "../bazel-out/x64_windows-fastbuild/bin/src" ] diff --git a/examples/angular/tools/karma.bzl b/examples/angular/tools/karma.bzl index cec19c0541..501b2dbe7f 100644 --- a/examples/angular/tools/karma.bzl +++ b/examples/angular/tools/karma.bzl @@ -70,7 +70,7 @@ _generate_karma_config = rule( # https://github.com/bazelbuild/rules_nodejs/blob/3.3.0/packages/concatjs/web_test/karma_web_test.bzl#L88-L91 "_conf_tmpl": attr.label( doc = """the karma config template""", - cfg = "host", + cfg = "exec", allow_single_file = True, default = Label("//tools:karma.conf.js"), ), diff --git a/examples/parcel/parcel.bzl b/examples/parcel/parcel.bzl index 707ea4fc8f..68c57bef94 100644 --- a/examples/parcel/parcel.bzl +++ b/examples/parcel/parcel.bzl @@ -57,7 +57,7 @@ parcel = rule( # This default assumes that users name their install "npm" default = Label("@npm//parcel-bundler/bin:parcel"), executable = True, - cfg = "host", + cfg = "exec", ), "srcs": attr.label_list(allow_files = True), }, diff --git a/examples/worker/uses_workers.bzl b/examples/worker/uses_workers.bzl index 609d940b70..32f6f91f69 100644 --- a/examples/worker/uses_workers.bzl +++ b/examples/worker/uses_workers.bzl @@ -34,7 +34,7 @@ work = rule( "tool": attr.label( default = Label("//:tool"), executable = True, - cfg = "host", + cfg = "exec", ), }, ) diff --git a/internal/bazel_integration_test/bazel_integration_test.bzl b/internal/bazel_integration_test/bazel_integration_test.bzl index 78abf25620..088fa1439b 100644 --- a/internal/bazel_integration_test/bazel_integration_test.bzl +++ b/internal/bazel_integration_test/bazel_integration_test.bzl @@ -244,7 +244,7 @@ is published on GitHub. ), "_test_runner": attr.label( executable = True, - cfg = "host", + cfg = "exec", default = Label("@build_bazel_rules_nodejs//internal/bazel_integration_test:test_runner"), ), } diff --git a/internal/linker/test/integration/rule.bzl b/internal/linker/test/integration/rule.bzl index d146c78d59..75346dfbef 100644 --- a/internal/linker/test/integration/rule.bzl +++ b/internal/linker/test/integration/rule.bzl @@ -20,5 +20,5 @@ linked = rule(_linked, attrs = { aspects = [module_mappings_aspect], ), "out": attr.output(), - "program": attr.label(executable = True, cfg = "host", mandatory = True), + "program": attr.label(executable = True, cfg = "exec", mandatory = True), }) diff --git a/internal/linker/test/no_npm_deps/no_npm_deps.bzl b/internal/linker/test/no_npm_deps/no_npm_deps.bzl index 7328acc931..c29fbc8e69 100644 --- a/internal/linker/test/no_npm_deps/no_npm_deps.bzl +++ b/internal/linker/test/no_npm_deps/no_npm_deps.bzl @@ -11,7 +11,7 @@ _ATTRS = { ), "terser": attr.label( executable = True, - cfg = "host", + cfg = "exec", default = Label("@npm//terser/bin:terser"), ), } diff --git a/internal/node/node.bzl b/internal/node/node.bzl index 187098657f..98c3df2107 100644 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -665,7 +665,7 @@ nodejs_test_kwargs = dict( "_lcov_merger": attr.label( executable = True, default = Label("@build_bazel_rules_nodejs//internal/coverage:lcov_merger_sh"), - cfg = "target", + cfg = "exec", ), }), doc = """ diff --git a/internal/node/npm_package_bin.bzl b/internal/node/npm_package_bin.bzl index 580ae69d12..dc31674362 100644 --- a/internal/node/npm_package_bin.bzl +++ b/internal/node/npm_package_bin.bzl @@ -21,7 +21,7 @@ _ATTRS = { "stdout": attr.output(), "tool": attr.label( executable = True, - cfg = "host", + cfg = "exec", mandatory = True, ), "stamp": STAMP_ATTR, diff --git a/internal/npm_install/npm_umd_bundle.bzl b/internal/npm_install/npm_umd_bundle.bzl index bc6d7b094f..cb00b12a97 100644 --- a/internal/npm_install/npm_umd_bundle.bzl +++ b/internal/npm_install/npm_umd_bundle.bzl @@ -114,7 +114,7 @@ This target would be then be used instead of the generated `@npm//typeorm:typeor ), "_browserify_wrapped": attr.label( executable = True, - cfg = "host", + cfg = "exec", default = Label("@build_bazel_rules_nodejs//internal/npm_install:browserify-wrapped"), ), } diff --git a/internal/pkg_web/pkg_web.bzl b/internal/pkg_web/pkg_web.bzl index 90db407e37..dbb2f23091 100644 --- a/internal/pkg_web/pkg_web.bzl +++ b/internal/pkg_web/pkg_web.bzl @@ -38,7 +38,7 @@ See the section on stamping in the README.""", "_assembler": attr.label( default = "@build_bazel_rules_nodejs//internal/pkg_web:assembler", executable = True, - cfg = "host", + cfg = "exec", ), } diff --git a/internal/providers/test/run_node_test.bzl b/internal/providers/test/run_node_test.bzl index 07161cb162..a011918e75 100644 --- a/internal/providers/test/run_node_test.bzl +++ b/internal/providers/test/run_node_test.bzl @@ -75,17 +75,17 @@ js_write_file = rule( "content": attr.string(), "_clone": attr.label( default = Label("//internal/providers/test:cloner_bin"), - cfg = "host", + cfg = "exec", executable = True, ), "_writer": attr.label( default = Label("//internal/providers/test:writer_bin"), - cfg = "host", + cfg = "exec", executable = True, ), "_writer2": attr.label( default = Label("//internal/providers/test:writer_bin2"), - cfg = "host", + cfg = "exec", executable = True, ), }, diff --git a/packages/concatjs/devserver/concatjs_devserver.bzl b/packages/concatjs/devserver/concatjs_devserver.bzl index 75ada3140a..8f5d1bab72 100644 --- a/packages/concatjs/devserver/concatjs_devserver.bzl +++ b/packages/concatjs/devserver/concatjs_devserver.bzl @@ -152,14 +152,14 @@ concatjs_devserver = rule( Defaults to precompiled go binary setup by @bazel/typescript npm package""", default = Label("//packages/concatjs/devserver"), executable = True, - cfg = "host", + cfg = "exec", ), "devserver_host": attr.label( doc = """Go based devserver executable for the host platform. Defaults to precompiled go binary setup by @bazel/typescript npm package""", default = Label("//packages/concatjs/devserver"), executable = True, - cfg = "host", + cfg = "exec", ), "entry_module": attr.string( doc = """The `entry_module` should be the AMD module name of the entry module such as `"__main__/src/index".` diff --git a/packages/concatjs/internal/build_defs.bzl b/packages/concatjs/internal/build_defs.bzl index 971fb80d0d..05792c818e 100644 --- a/packages/concatjs/internal/build_defs.bzl +++ b/packages/concatjs/internal/build_defs.bzl @@ -407,7 +407,7 @@ then it needs to be a data dependency of `tsc_wrapped` so that it can be loaded default = Label(_DEFAULT_COMPILER), allow_files = True, executable = True, - cfg = "host", + cfg = "exec", ), "deps": attr.label_list( aspects = DEPS_ASPECTS + [node_modules_aspect], diff --git a/packages/concatjs/test/some_module/run_node_test.bzl b/packages/concatjs/test/some_module/run_node_test.bzl index 863cdae0ff..84904c2996 100644 --- a/packages/concatjs/test/some_module/run_node_test.bzl +++ b/packages/concatjs/test/some_module/run_node_test.bzl @@ -23,7 +23,7 @@ ts_write_file = rule( "content": attr.string(), "_writer": attr.label( default = Label("//packages/concatjs/test/some_module:writer_bin"), - cfg = "host", + cfg = "exec", executable = True, ), }, diff --git a/packages/concatjs/web_test/karma_web_test.bzl b/packages/concatjs/web_test/karma_web_test.bzl index 5d0a1aec96..f45aced58c 100644 --- a/packages/concatjs/web_test/karma_web_test.bzl +++ b/packages/concatjs/web_test/karma_web_test.bzl @@ -65,7 +65,7 @@ KARMA_WEB_TEST_ATTRS = { # NB: replaced during pkg_npm with "@npm//karma/bin:karma" default = "//packages/concatjs/web_test:karma_bin", executable = True, - cfg = "target", + cfg = "exec", allow_files = True, ), "runtime_deps": attr.label_list( diff --git a/packages/protractor/protractor_web_test.bzl b/packages/protractor/protractor_web_test.bzl index 629fea7c57..ccee5de25e 100644 --- a/packages/protractor/protractor_web_test.bzl +++ b/packages/protractor/protractor_web_test.bzl @@ -213,13 +213,13 @@ _protractor_web_test = rule( "protractor": attr.label( doc = "Protractor executable target", executable = True, - cfg = "target", + cfg = "exec", allow_files = True, ), "server": attr.label( doc = "Optional server executable target", executable = True, - cfg = "target", + cfg = "exec", allow_files = True, ), "srcs": attr.label_list( diff --git a/packages/rollup/rollup_bundle.bzl b/packages/rollup/rollup_bundle.bzl index fd70a53f26..3cdbd565a3 100644 --- a/packages/rollup/rollup_bundle.bzl +++ b/packages/rollup/rollup_bundle.bzl @@ -118,7 +118,7 @@ Otherwise, the outputs are assumed to be a single file. "rollup_bin": attr.label( doc = "Target that executes the rollup binary", executable = True, - cfg = "host", + cfg = "exec", default = ( # BEGIN-INTERNAL "@npm" + @@ -129,7 +129,7 @@ Otherwise, the outputs are assumed to be a single file. "rollup_worker_bin": attr.label( doc = "Internal use only", executable = True, - cfg = "host", + cfg = "exec", default = "//packages/rollup/bin:rollup-worker", ), "silent": attr.bool( diff --git a/packages/terser/index.js b/packages/terser/index.js index 682550b083..3819a1523d 100644 --- a/packages/terser/index.js +++ b/packages/terser/index.js @@ -26,6 +26,45 @@ function isDirectory(input) { return fs.lstatSync(path.join(process.cwd(), input)).isDirectory(); } +// Returns a single quotes version of str +function singleQuotes(str) { + return `'${str.replace(/'/g, '').replace(/"/g, '')}'`; +} + +// Ensures that args are well formed. +// Work-around for an issue on Windows when exec bin path is not quoted. +// In --source-map, base=bazel-out/x64_windows-opt-exec-2B5CBBC6/bin must +// be quoted such as base='bazel-out/x64_windows-opt-exec-2B5CBBC6/bin' pr +// terser fails with +// ERROR: `includeSources,base=bazel-out/x64_windows-opt-exec-2B5CBBC6/bin,content=inline,url=bundle.min.js.map` is not a supported option +function fixArgs(args) { + const sourceMapIndex = args.indexOf('--source-map'); + if (sourceMapIndex === -1) { + return args; + } + let sourceMapOptions = args[sourceMapIndex + 1].split(','); + sourceMapOptions = sourceMapOptions.map(o => { + const s = o.split('='); + if (s.length == 1) { + return o; + } + switch (s[0]) { + case 'base': + case 'content': + case 'url': + return `${s[0]}=${singleQuotes(s[1])}`; + default: + return o; + } + }); + + return [ + ...args.slice(0, sourceMapIndex + 1), + sourceMapOptions.join(','), + ...args.slice(sourceMapIndex + 2), + ]; +} + /** * Replaces directory url with the outputFile name in the url option of source-map argument */ @@ -35,8 +74,10 @@ function directoryArgs(residualArgs, inputFile, outputFile) { return residualArgs; } + let sourceMapOptions = residualArgs[sourceMapIndex + 1].split(','); + // set the correct sourcemap url for this output file - let sourceMapOptions = residualArgs[sourceMapIndex + 1].split(',').map( + sourceMapOptions = sourceMapOptions.map( o => o.startsWith('url=') ? `url='${path.basename(outputFile)}.map'` : o); // if an input .map file exists then set the correct sourcemap content option @@ -143,6 +184,8 @@ function spawn(cmd, args) { } function main() { + process.argv = fixArgs(process.argv) + // Peek at the arguments to find any directories declared as inputs let argv = process.argv.slice(2); // terser_minified.bzl always passes the inputs first, diff --git a/packages/terser/terser_minified.bzl b/packages/terser/terser_minified.bzl index 8f95fe59ba..850bbd28e3 100644 --- a/packages/terser/terser_minified.bzl +++ b/packages/terser/terser_minified.bzl @@ -104,7 +104,7 @@ If you want to do this, you can pass a filegroup here.""", doc = "An executable target that runs Terser", default = Label("//packages/terser/bin:terser"), executable = True, - cfg = "host", + cfg = "exec", ), } @@ -149,7 +149,7 @@ def _terser(ctx): if ctx.attr.sourcemap: # Source mapping options are comma-packed into one argv # see https://github.com/terser-js/terser#command-line-usage - source_map_opts = ["includeSources", "base=" + ctx.bin_dir.path] + source_map_opts = ["includeSources", "base='%s'" % ctx.bin_dir.path] if len(sourcemaps) == 0: source_map_opts.append("content=inline") diff --git a/packages/typescript/internal/ts_project.bzl b/packages/typescript/internal/ts_project.bzl index 8e5b8c4354..ebc3735599 100644 --- a/packages/typescript/internal/ts_project.bzl +++ b/packages/typescript/internal/ts_project.bzl @@ -35,7 +35,7 @@ _ATTRS = { # that compiler might allow more sources than tsc does. "srcs": attr.label_list(allow_files = True, mandatory = True), "supports_workers": attr.bool(default = False), - "tsc": attr.label(default = Label(_DEFAULT_TSC), executable = True, cfg = "host"), + "tsc": attr.label(default = Label(_DEFAULT_TSC), executable = True, cfg = "exec"), "transpile": attr.bool(doc = "whether tsc should be used to produce .js outputs"), "tsconfig": attr.label(mandatory = True, allow_single_file = [".json"]), } diff --git a/packages/typescript/internal/validate_options.bzl b/packages/typescript/internal/validate_options.bzl index 31d6edc363..e35acd09a8 100644 --- a/packages/typescript/internal/validate_options.bzl +++ b/packages/typescript/internal/validate_options.bzl @@ -68,7 +68,7 @@ validate_options = rule( "target": attr.string(), "ts_build_info_file": attr.string(), "tsconfig": attr.label(mandatory = True, allow_single_file = [".json"]), - "validator": attr.label(default = Label("//packages/typescript/bin:ts_project_options_validator"), executable = True, cfg = "host"), + "validator": attr.label(default = Label("//packages/typescript/bin:ts_project_options_validator"), executable = True, cfg = "exec"), }, )