Skip to content

Commit f130119

Browse files
Always start Bloop under specific dir under home
Rather than in the current directory, which users might delete later on, which sometimes prevents Bloop from starting sub-processes (like javac…)
1 parent 52c3c93 commit f130119

File tree

7 files changed

+36
-10
lines changed

7 files changed

+36
-10
lines changed

modules/bloop-rifle/src/main/scala/scala/build/blooprifle/BloopRifle.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ object BloopRifle {
5454
bloopJava,
5555
config.javaOpts,
5656
cp.map(_.toPath),
57+
config.workingDir,
5758
scheduler,
5859
config.startCheckPeriod,
5960
config.startCheckTimeout,

modules/bloop-rifle/src/main/scala/scala/build/blooprifle/BloopRifleConfig.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final case class BloopRifleConfig(
1212
javaPath: String,
1313
javaOpts: Seq[String],
1414
classPath: String => Either[Throwable, Seq[File]],
15+
workingDir: File,
1516
bspSocketOrPort: Option[() => BspConnectionAddress],
1617
bspStdin: Option[InputStream],
1718
bspStdout: Option[OutputStream],
@@ -116,13 +117,15 @@ object BloopRifleConfig {
116117

117118
def default(
118119
address: Address,
119-
bloopClassPath: String => Either[Throwable, Seq[File]]
120+
bloopClassPath: String => Either[Throwable, Seq[File]],
121+
workingDir: File
120122
): BloopRifleConfig =
121123
BloopRifleConfig(
122124
address = address,
123125
javaPath = "java",
124126
javaOpts = defaultJavaOpts,
125127
classPath = bloopClassPath,
128+
workingDir = workingDir,
126129
bspSocketOrPort = None,
127130
bspStdin = None,
128131
bspStdout = None,

modules/bloop-rifle/src/main/scala/scala/build/blooprifle/internal/Operations.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ object Operations {
102102
javaPath: String,
103103
javaOpts: Seq[String],
104104
classPath: Seq[Path],
105+
workingDir: File,
105106
scheduler: ScheduledExecutorService,
106107
waitInterval: FiniteDuration,
107108
timeout: Duration,
@@ -124,6 +125,7 @@ object Operations {
124125
) ++
125126
addressArgs
126127
val b = new ProcessBuilder(command: _*)
128+
b.directory(workingDir)
127129
b.redirectInput(ProcessBuilder.Redirect.PIPE)
128130

129131
// https://stackoverflow.com/questions/55628999/java-processbuilder-how-to-suppress-output-instead-of-redirecting-it/55629297#55629297

modules/build/src/main/scala/scala/build/Directories.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ trait Directories {
1111
def virtualProjectsDir: os.Path
1212
def bspSocketDir: os.Path
1313
def bloopDaemonDir: os.Path
14+
def bloopWorkingDir: os.Path
1415
}
1516

1617
object Directories {
@@ -28,11 +29,13 @@ object Directories {
2829
// FIXME I would have preferred to use projDirs.dataLocalDir, but it seems named socket
2930
// support, or name sockets in general, aren't fine with it.
3031
os.Path(projDirs.cacheDir, Os.pwd) / "bsp-sockets"
31-
lazy val bloopDaemonDir: os.Path = {
32+
lazy val bloopDaemonDir: os.Path =
33+
bloopWorkingDir / "daemon"
34+
lazy val bloopWorkingDir: os.Path = {
3235
val baseDir =
3336
if (Properties.isMac) projDirs.cacheDir
3437
else projDirs.dataLocalDir
35-
os.Path(baseDir, Os.pwd) / "bloop" / "daemon"
38+
os.Path(baseDir, Os.pwd) / "bloop"
3639
}
3740
}
3841

@@ -48,7 +51,9 @@ object Directories {
4851
lazy val bspSocketDir: os.Path =
4952
dir / "data-local" / "bsp-sockets"
5053
lazy val bloopDaemonDir: os.Path =
51-
dir / "data-local" / "bloop" / "daemon"
54+
bloopWorkingDir / "daemon"
55+
lazy val bloopWorkingDir: os.Path =
56+
dir / "data-local" / "bloop"
5257
}
5358

5459
def default(): Directories = {

modules/build/src/test/scala/scala/build/tests/util/BloopServer.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ import scala.util.Properties
66

77
object BloopServer {
88

9+
private def directories = scala.build.Directories.default()
10+
911
// FIXME We could use a test-specific Bloop instance here.
1012
// Not sure how to properly shut it down or have it exit after a period
1113
// of inactivity, so we keep using our default global Bloop for now.
1214
private def bloopAddress =
1315
if (Properties.isWin)
1416
BloopRifleConfig.Address.Tcp(BloopRifleConfig.defaultHost, BloopRifleConfig.defaultPort)
15-
else {
16-
val directories = scala.build.Directories.default()
17+
else
1718
BloopRifleConfig.Address.DomainSocket(directories.bloopDaemonDir.toNIO)
18-
}
1919

2020
val bloopConfig = BloopRifleConfig.default(
2121
bloopAddress,
22-
v => Bloop.bloopClassPath(Logger.nop, v)
22+
v => Bloop.bloopClassPath(Logger.nop, v),
23+
directories.bloopWorkingDir.toIO
2324
)
2425

2526
}

modules/cli/src/main/scala/scala/cli/commands/SharedCompilationServerOptions.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ final case class SharedCompilationServerOptions(
8383
@Group("Compilation server")
8484
@HelpMessage("JVM to use to start Bloop (e.g. 'system|11', 'temurin:17', …)")
8585
@Hidden
86-
bloopJvm: Option[String] = None
86+
bloopJvm: Option[String] = None,
87+
88+
@Group("Compilation server")
89+
@HelpMessage("Working directory for Bloop, if it needs to be started")
90+
@Hidden
91+
bloopWorkingDir: Option[String] = None
8792
) {
8893
// format: on
8994

@@ -239,9 +244,14 @@ final case class SharedCompilationServerOptions(
239244
)
240245
}
241246

247+
val workingDir = bloopWorkingDir
248+
.filter(_.trim.nonEmpty)
249+
.map(os.Path(_, Os.pwd))
250+
.getOrElse(directories.bloopWorkingDir)
242251
val baseConfig = BloopRifleConfig.default(
243252
address,
244-
v => Bloop.bloopClassPath(logger, v)
253+
v => Bloop.bloopClassPath(logger, v),
254+
workingDir.toIO
245255
)
246256

247257
baseConfig.copy(

website/docs/reference/cli-options.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ Bloop global options file
151151

152152
JVM to use to start Bloop (e.g. 'system|11', 'temurin:17', …)
153153

154+
#### `--bloop-working-dir`
155+
156+
Working directory for Bloop, if it needs to be started
157+
154158
## Compile options
155159

156160
Available in commands:

0 commit comments

Comments
 (0)