Skip to content

Commit

Permalink
perf: use shared args for source_root param
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Sep 9, 2024
1 parent 463c7a5 commit 9498a51
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions swc/private/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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,
Expand All @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit 9498a51

Please sign in to comment.