Skip to content

Commit 33a4785

Browse files
committed
Reuse formatter
1 parent 0941a60 commit 33a4785

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

scala/private/phases/phase_scalafmt.bzl

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
def phase_scalafmt(ctx, p):
77
if ctx.attr.format:
88
manifest, files = _build_format(ctx)
9-
_format_runner(ctx, manifest, files)
10-
_format_tester(ctx, manifest, files)
9+
_formatter(ctx, manifest, files, ctx.file._runner, ctx.outputs.scalafmt_runner)
10+
_formatter(ctx, manifest, files, ctx.file._testrunner, ctx.outputs.scalafmt_testrunner)
1111
else:
1212
ctx.actions.write(
1313
output = ctx.outputs.scalafmt_runner,
@@ -52,30 +52,16 @@ def _build_format(ctx):
5252

5353
return manifest, files
5454

55-
def _format_runner(ctx, manifest, files):
55+
def _formatter(ctx, manifest, files, input_runner, output_runner):
5656
ctx.actions.run_shell(
57-
inputs = [ctx.file._runner, manifest] + files,
58-
outputs = [ctx.outputs.scalafmt_runner],
57+
inputs = [input_runner, manifest] + files,
58+
outputs = [output_runner],
5959
command = "cat $1 | sed -e s#%workspace%#$2# -e s#%manifest%#$3# > $4",
6060
arguments = [
61-
ctx.file._runner.path,
61+
input_runner.path,
6262
ctx.workspace_name,
6363
manifest.short_path,
64-
ctx.outputs.scalafmt_runner.path,
65-
],
66-
execution_requirements = {},
67-
)
68-
69-
def _format_tester(ctx, manifest, files):
70-
ctx.actions.run_shell(
71-
inputs = [ctx.file._testrunner, manifest] + files,
72-
outputs = [ctx.outputs.scalafmt_testrunner],
73-
command = "cat $1 | sed -e s#%workspace%#$2# -e s#%manifest%#$3# > $4",
74-
arguments = [
75-
ctx.file._testrunner.path,
76-
ctx.workspace_name,
77-
manifest.short_path,
78-
ctx.outputs.scalafmt_testrunner.path,
64+
output_runner.path,
7965
],
8066
execution_requirements = {},
8167
)

0 commit comments

Comments
 (0)