@@ -13,6 +13,7 @@ import java.util.Random
13
13
14
14
import scala .build .blooprifle .internal .Constants
15
15
import scala .build .blooprifle .{BloopRifleConfig , BloopVersion , BspConnectionAddress }
16
+ import scala .build .internal .Util
16
17
import scala .build .{Bloop , Logger , Os }
17
18
import scala .cli .internal .Pid
18
19
import scala .concurrent .duration .{Duration , FiniteDuration }
@@ -80,7 +81,7 @@ final case class SharedCompilationServerOptions(
80
81
@ Group (" Compilation server" )
81
82
@ HelpMessage (" Bloop global options file" )
82
83
@ Hidden
83
- bloopGlobalOptionsFile : String = (os.home / " .bloop " / " bloop.json " ).toString ,
84
+ bloopGlobalOptionsFile : Option [ String ] = None ,
84
85
85
86
@ Group (" Compilation server" )
86
87
@ HelpMessage (" JVM to use to start Bloop (e.g. 'system|11', 'temurin:17', …)" )
@@ -187,26 +188,28 @@ final case class SharedCompilationServerOptions(
187
188
BloopVersion (Constants .bloopVersion)
188
189
))(v => BloopRifleConfig .Strict (BloopVersion (v)))
189
190
190
- def bloopDefaultJvmOptions (logger : Logger ): List [String ] = {
191
- val filePath = os.Path (bloopGlobalOptionsFile, Os .pwd)
192
- if (os.exists(filePath) && os.isFile(filePath))
193
- try {
194
- val json = ujson.read(
195
- os.read(filePath : os.ReadablePath , charSet = Codec (Charset .defaultCharset()))
196
- )
197
- val bloopJson = upickle.default.read(json)(BloopJson .jsonCodec)
198
- bloopJson.javaOptions
199
- }
200
- catch {
201
- case e : Throwable =>
202
- System .err.println(s " Error parsing global bloop config in ' $filePath': " )
203
- e.printStackTrace()
191
+ def bloopDefaultJvmOptions (logger : Logger ): Option [List [String ]] = {
192
+ val filePathOpt = bloopGlobalOptionsFile.filter(_.trim.nonEmpty).map(os.Path (_, Os .pwd))
193
+ for (filePath <- filePathOpt)
194
+ yield
195
+ if (os.exists(filePath) && os.isFile(filePath))
196
+ try {
197
+ val json = ujson.read(
198
+ os.read(filePath : os.ReadablePath , charSet = Codec (Charset .defaultCharset()))
199
+ )
200
+ val bloopJson = upickle.default.read(json)(BloopJson .jsonCodec)
201
+ bloopJson.javaOptions
202
+ }
203
+ catch {
204
+ case e : Throwable =>
205
+ logger.message(s " Error parsing global bloop config in ' $filePath': " )
206
+ Util .printException(e)
207
+ List .empty
208
+ }
209
+ else {
210
+ logger.message(s " Bloop global options file ' $filePath' not found. " )
204
211
List .empty
205
- }
206
- else {
207
- logger.debug(s " Bloop global options file ' $filePath' not found. " )
208
- List .empty
209
- }
212
+ }
210
213
}
211
214
212
215
def bloopRifleConfig (
@@ -267,7 +270,7 @@ final case class SharedCompilationServerOptions(
267
270
initTimeout = bloopStartupTimeoutDuration.getOrElse(baseConfig.initTimeout),
268
271
javaOpts =
269
272
(if (bloopDefaultJavaOpts) baseConfig.javaOpts
270
- else Nil ) ++ bloopJavaOpt ++ bloopDefaultJvmOptions(logger),
273
+ else Nil ) ++ bloopJavaOpt ++ bloopDefaultJvmOptions(logger).getOrElse( Nil ) ,
271
274
minimumBloopJvm = javaV.getOrElse(8 ),
272
275
retainedBloopVersion = retainedBloopVersion
273
276
)
0 commit comments