From 9498a51454efc51ec5c2da9bac9fad610a3f4eab Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Wed, 28 Aug 2024 16:53:00 -0700 Subject: [PATCH] perf: use shared args for source_root param --- swc/private/swc.bzl | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/swc/private/swc.bzl b/swc/private/swc.bzl index d6e1ddb..3331bdd 100644 --- a/swc/private/swc.bzl +++ b/swc/private/swc.bzl @@ -218,10 +218,17 @@ def _swc_impl(ctx): args = ctx.actions.args() args.add("compile") + # The root config file. Config options may be overridden by additional args. + if ctx.attr.swcrc: + args.add("--config-file", ctx.file.swcrc) + inputs.append(ctx.file.swcrc) + # Add user specified arguments *before* rule supplied arguments args.add_all(ctx.attr.args) args.add("--source-maps", ctx.attr.source_maps) + if ctx.attr.source_maps != "false" and ctx.attr.source_root: + args.add("--source-root", ctx.attr.source_root) if ctx.attr.plugins: plugin_cache = [ctx.actions.declare_directory("{}_plugin_cache".format(ctx.label.name))] @@ -262,18 +269,12 @@ def _swc_impl(ctx): args.add("--out-dir", output_dir.path) - src_args = ctx.actions.args() - if ctx.attr.swcrc: - src_args.add("--config-file", ctx.file.swcrc) - inputs.append(ctx.file.swcrc) - _swc_action( ctx, swc_toolchain.swcinfo.swc_binary, inputs = inputs, arguments = [ args, - src_args, ctx.files.srcs[0].path, ], outputs = output_sources, @@ -296,8 +297,6 @@ def _swc_impl(ctx): if ctx.attr.source_maps != "false": src_args.add("--source-file-name", _calculate_source_file(ctx, src)) - if ctx.attr.source_root: - src_args.add("--source-root", ctx.attr.source_root) src_path = _relative_to_package(src.path, ctx) @@ -315,10 +314,6 @@ def _swc_impl(ctx): src_inputs = [src] + inputs - if ctx.attr.swcrc: - src_args.add("--config-file", ctx.file.swcrc) - src_inputs.append(ctx.file.swcrc) - src_args.add("--out-file", js_out) output_sources.extend(outputs)