Skip to content

Commit bbafbf1

Browse files
committed
invoke via option
1 parent a4f1916 commit bbafbf1

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

project/src/build.runner.scala

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ import cats.effect.IO
2020
import cats.effect.ResourceIO
2121
import cats.syntax.all.*
2222

23-
sealed trait BuildTool
24-
class ScalaCli extends BuildTool
25-
class Mill extends BuildTool
23+
sealed trait BuildTool(val invokedVia: String)
24+
class ScalaCli
25+
extends BuildTool(
26+
if isWindows then "scala-cli.bat" else "scala-cli"
27+
)
28+
class Mill
29+
extends BuildTool(
30+
if isWindows then "mill.bat" else "mill"
31+
)
2632

2733
private lazy val isWindows: Boolean =
2834
System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")
@@ -33,23 +39,31 @@ def buildRunner(
3339
workDir: fs2.io.file.Path,
3440
outDir: fs2.io.file.Path,
3541
extraBuildArgs: List[String],
36-
millModuleName: Option[String]
42+
millModuleName: Option[String],
43+
buildToolInvocation: Option[String]
3744
)(
3845
logger: Scribe[IO]
39-
): ResourceIO[Unit] = tool match
40-
case scli: ScalaCli => buildRunnerScli(linkingTopic, workDir, outDir, extraBuildArgs)(logger)
41-
case m: Mill =>
42-
buildRunnerMill(
43-
linkingTopic,
44-
workDir,
45-
millModuleName.getOrElse(throw new Exception("must have a module name when running with mill")),
46-
extraBuildArgs
47-
)(logger)
46+
): ResourceIO[Unit] =
47+
val invokeVia = buildToolInvocation.getOrElse(tool.invokedVia)
48+
tool match
49+
case scli: ScalaCli =>
50+
buildRunnerScli(linkingTopic, workDir, outDir, invokeVia, extraBuildArgs)(logger)
51+
case m: Mill =>
52+
buildRunnerMill(
53+
linkingTopic,
54+
workDir,
55+
millModuleName.getOrElse(throw new Exception("must have a module name when running with mill")),
56+
invokeVia,
57+
extraBuildArgs
58+
)(logger)
59+
end match
60+
end buildRunner
4861

4962
def buildRunnerScli(
5063
linkingTopic: Topic[IO, Unit],
5164
workDir: fs2.io.file.Path,
5265
outDir: fs2.io.file.Path,
66+
invokeVia: String,
5367
extraBuildArgs: List[String]
5468
)(
5569
logger: Scribe[IO]
@@ -66,12 +80,12 @@ def buildRunnerScli(
6680
) ++ extraBuildArgs
6781

6882
logger
69-
.trace(scalaCliArgs.toString())
83+
.trace(s"Invoking via : $invokeVia with args : ${scalaCliArgs.toString()}")
7084
.toResource
7185
.flatMap(
7286
_ =>
7387
ProcessBuilder(
74-
if isWindows then "scala-cli.bat" else "scala-cli",
88+
invokeVia,
7589
scalaCliArgs
7690
).withWorkingDirectory(workDir)
7791
.spawn[IO]
@@ -103,6 +117,7 @@ def buildRunnerMill(
103117
linkingTopic: Topic[IO, Unit],
104118
workDir: fs2.io.file.Path,
105119
moduleName: String,
120+
invokeVia: String,
106121
extraBuildArgs: List[String]
107122
)(
108123
logger: Scribe[IO]
@@ -140,7 +155,7 @@ def buildRunnerMill(
140155
) ++ extraBuildArgs
141156
// TODO pipe this to stdout so that we can see linker progress / errors.
142157
val builder = ProcessBuilder(
143-
if isWindows then "mill.bat" else "mill",
158+
invokeVia,
144159
millargs
145160
).withWorkingDirectory(workDir)
146161
.spawn[IO]

project/src/live.server.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ object LiveServer extends IOApp:
175175
}
176176
.orNone
177177

178+
val buildToolInvocation: Opts[Option[String]] = Opts
179+
.option[String](
180+
"build-tool-invocation",
181+
"This string will be passed to an fs2 process which invokes the build tool. By default it's 'scala-cli', or `mill`, " +
182+
"and is assumed is on the path"
183+
)
184+
.orNone
185+
178186
case class LiveServerConfig(
179187
baseDir: Option[String],
180188
outDir: Option[String] = None,
@@ -189,7 +197,8 @@ object LiveServer extends IOApp:
189197
extraBuildArgs: List[String] = List.empty,
190198
millModuleName: Option[String] = None,
191199
stylesDir: Option[String] = None,
192-
indexHtmlTemplate: Option[String] = None
200+
indexHtmlTemplate: Option[String] = None,
201+
buildToolInvocation: Option[String] = None
193202
)
194203

195204
def parseOpts = (
@@ -206,7 +215,8 @@ object LiveServer extends IOApp:
206215
extraBuildArgsOpt,
207216
millModuleNameOpt,
208217
stylesDirOpt,
209-
indexHtmlTemplateOpt
218+
indexHtmlTemplateOpt,
219+
buildToolInvocation
210220
).mapN(LiveServerConfig.apply)
211221

212222
def main(lsc: LiveServerConfig): Resource[IO, Server] =
@@ -270,7 +280,8 @@ object LiveServer extends IOApp:
270280
baseDirPath,
271281
outDirPath,
272282
lsc.extraBuildArgs,
273-
lsc.millModuleName
283+
lsc.millModuleName,
284+
lsc.buildToolInvocation
274285
)(logger)
275286

276287
app <- routes(outDirString, refreshTopic, indexOpts, proxyRoutes, fileToHashRef, lsc.clientRoutingPrefix)(logger)

0 commit comments

Comments
 (0)