/
SharedOptions.scala
659 lines (611 loc) · 22.6 KB
/
SharedOptions.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
package scala.cli.commands.shared
import caseapp.*
import caseapp.core.help.Help
import com.github.plokhotnyuk.jsoniter_scala.core.*
import com.github.plokhotnyuk.jsoniter_scala.macros.*
import coursier.cache.FileCache
import coursier.util.{Artifact, Task}
import dependency.AnyDependency
import dependency.parser.DependencyParser
import java.io.{File, InputStream}
import java.nio.file.Paths
import scala.build.EitherCps.{either, value}
import scala.build.*
import scala.build.blooprifle.BloopRifleConfig
import scala.build.compiler.{BloopCompilerMaker, ScalaCompilerMaker, SimpleScalaCompilerMaker}
import scala.build.directives.DirectiveDescription
import scala.build.errors.{AmbiguousPlatformError, BuildException}
import scala.build.input.{Element, Inputs, ResourceDirectory}
import scala.build.interactive.Interactive
import scala.build.interactive.Interactive.{InteractiveAsk, InteractiveNop}
import scala.build.internal.CsLoggerUtil.*
import scala.build.internal.{Constants, FetchExternalBinary, OsLibc, Util}
import scala.build.options.ScalaVersionUtil.fileWithTtl0
import scala.build.options.{Platform, ScalacOpt, ShadowingSeq}
import scala.build.preprocessing.directives.Toolkit
import scala.build.options as bo
import scala.cli.ScalaCli
import scala.cli.commands.publish.ConfigUtil.*
import scala.cli.commands.shared.{
HasLoggingOptions,
ScalaJsOptions,
ScalaNativeOptions,
SharedOptions,
SuppressWarningOptions
}
import scala.cli.commands.tags
import scala.cli.commands.util.ScalacOptionsUtil.*
import scala.cli.config.{ConfigDb, ConfigDbException, Keys}
import scala.concurrent.ExecutionContextExecutorService
import scala.concurrent.duration.*
import scala.util.Properties
import scala.util.control.NonFatal
// format: off
final case class SharedOptions(
@Recurse
suppress: SuppressWarningOptions = SuppressWarningOptions(),
@Recurse
logging: LoggingOptions = LoggingOptions(),
@Recurse
js: ScalaJsOptions = ScalaJsOptions(),
@Recurse
native: ScalaNativeOptions = ScalaNativeOptions(),
@Recurse
compilationServer: SharedCompilationServerOptions = SharedCompilationServerOptions(),
@Recurse
directories: SharedDirectoriesOptions = SharedDirectoriesOptions(),
@Recurse
dependencies: SharedDependencyOptions = SharedDependencyOptions(),
@Recurse
scalac: ScalacOptions = ScalacOptions(),
@Recurse
jvm: SharedJvmOptions = SharedJvmOptions(),
@Recurse
coursier: CoursierOptions = CoursierOptions(),
@Recurse
workspace: SharedWorkspaceOptions = SharedWorkspaceOptions(),
@Recurse
sharedPython: SharedPythonOptions = SharedPythonOptions(),
@Group("Scala")
@HelpMessage(s"Set the Scala version (${Constants.defaultScalaVersion} by default)")
@ValueDescription("version")
@Name("scala")
@Name("S")
@Tag(tags.must)
scalaVersion: Option[String] = None,
@Group("Scala")
@HelpMessage("Set the Scala binary version")
@ValueDescription("version")
@Hidden
@Name("scalaBinary")
@Name("scalaBin")
@Name("B")
@Tag(tags.must)
scalaBinaryVersion: Option[String] = None,
@Recurse
scalacExtra: ScalacExtraOptions = ScalacExtraOptions(),
@Recurse
snippet: SnippetOptions = SnippetOptions(),
@Recurse
markdown: MarkdownOptions = MarkdownOptions(),
@Group("Java")
@HelpMessage("Add extra JARs and compiled classes to the class path")
@ValueDescription("paths")
@Name("jar")
@Name("jars")
@Name("extraJar")
@Name("class")
@Name("extraClass")
@Name("classes")
@Name("extraClasses")
@Name("-classpath")
@Name("-cp")
@Name("classpath")
@Name("classPath")
@Name("extraClassPath")
@Tag(tags.must)
extraJars: List[String] = Nil,
@Group("Java")
@HelpMessage("Add extra JARs in the compilaion class path. Mainly using to run code in managed environments like Spark not to include certain depenencies on runtime ClassPath.")
@ValueDescription("paths")
@Name("compileOnlyJar")
@Name("compileOnlyJars")
@Name("extraCompileOnlyJar")
@Tag(tags.should)
extraCompileOnlyJars: List[String] = Nil,
@Group("Java")
@HelpMessage("Add extra source JARs")
@ValueDescription("paths")
@Name("sourceJar")
@Name("sourceJars")
@Name("extraSourceJar")
@Tag(tags.should)
extraSourceJars: List[String] = Nil,
@Group("Java")
@HelpMessage("Add a resource directory")
@ValueDescription("paths")
@Name("resourceDir")
@Tag(tags.must)
resourceDirs: List[String] = Nil,
@HelpMessage("Specify platform")
@ValueDescription("scala-js|scala-native|jvm")
@Tag(tags.should)
platform: Option[String] = None,
@Group("Scala")
@Tag(tags.implementation)
@Hidden
scalaLibrary: Option[Boolean] = None,
@Group("Scala")
@HelpMessage("Allows to include the Scala compiler artifacts on the classpath.")
@Tag(tags.must)
@Name("withScalaCompiler")
@Name("-with-compiler")
withCompiler: Option[Boolean] = None,
@Group("Java")
@HelpMessage("Do not add dependency to Scala Standard library. This is useful, when Scala CLI works with pure Java projects.")
@Tag(tags.implementation)
@Hidden
java: Option[Boolean] = None,
@HelpMessage("Should include Scala CLI runner on the runtime ClassPath. Runner is added by default for application running on JVM using standard Scala versions. Runner is used to make stack traces more readable in case of application failure.")
@Tag(tags.implementation)
@Hidden
runner: Option[Boolean] = None,
@Hidden
@Tag(tags.should)
@HelpMessage("Generate SemanticDBs")
semanticDb: Option[Boolean] = None,
@Hidden
@Tag(tags.implementation)
@HelpMessage("Add dependency for stubs needed to make $ivy and $dep imports to work.")
addStubs: Option[Boolean] = None,
@Recurse
input: SharedInputOptions = SharedInputOptions(),
@Recurse
helpGroups: HelpGroupOptions = HelpGroupOptions(),
@Hidden
strictBloopJsonCheck: Option[Boolean] = None,
@Name("output-directory")
@Name("d")
@Name("destination")
@Name("compileOutput")
@Name("compileOut")
@HelpMessage("Copy compilation results to output directory using either relative or absolute path")
@ValueDescription("/example/path")
@Tag(tags.must)
compilationOutput: Option[String] = None,
@HelpMessage("Add toolkit to classPath")
@ValueDescription("version|latest")
@Name("toolkit")
withToolkit: Option[String] = None
) extends HasLoggingOptions {
// format: on
def logger: Logger = logging.logger
private def scalaJsOptions(opts: ScalaJsOptions): options.ScalaJsOptions = {
import opts._
options.ScalaJsOptions(
version = jsVersion,
mode = jsMode,
moduleKindStr = jsModuleKind,
checkIr = jsCheckIr,
emitSourceMaps = jsEmitSourceMaps,
sourceMapsDest = jsSourceMapsPath.filter(_.trim.nonEmpty).map(os.Path(_, Os.pwd)),
dom = jsDom,
header = jsHeader,
allowBigIntsForLongs = jsAllowBigIntsForLongs,
avoidClasses = jsAvoidClasses,
avoidLetsAndConsts = jsAvoidLetsAndConsts,
moduleSplitStyleStr = jsModuleSplitStyle,
smallModuleForPackage = jsSmallModuleForPackage,
esVersionStr = jsEsVersion
)
}
private def linkerOptions(opts: ScalaJsOptions): options.scalajs.ScalaJsLinkerOptions = {
import opts._
options.scalajs.ScalaJsLinkerOptions(
linkerPath = jsLinkerPath
.filter(_.trim.nonEmpty)
.map(os.Path(_, Os.pwd)),
scalaJsCliVersion = jsCliVersion.map(_.trim).filter(_.nonEmpty),
javaArgs = jsCliJavaArg,
useJvm = jsCliOnJvm.map {
case false => Left(FetchExternalBinary.platformSuffix())
case true => Right(())
}
)
}
private def scalaNativeOptions(opts: ScalaNativeOptions): options.ScalaNativeOptions = {
import opts._
options.ScalaNativeOptions(
nativeVersion,
nativeMode,
nativeGc,
nativeClang,
nativeClangpp,
nativeLinking,
nativeLinkingDefaults,
nativeCompile,
nativeCompileDefaults
)
}
def buildOptions(
enableJmh: Boolean = false,
jmhVersion: Option[String] = None,
ignoreErrors: Boolean = false
): Either[BuildException, bo.BuildOptions] = either {
val releaseOpt = scalac.scalacOption.getScalacOption("-release")
val targetOpt = scalac.scalacOption.getScalacPrefixOption("-target")
jvm.jvm -> (releaseOpt.toSeq ++ targetOpt) match {
case (Some(j), compilerTargets) if compilerTargets.exists(_ != j) =>
val compilerTargetsString = compilerTargets.distinct.mkString(", ")
logger.error(
s"Warning: different target JVM ($j) and scala compiler target JVM ($compilerTargetsString) were passed."
)
case _ =>
}
val parsedPlatform = platform.map(Platform.normalize).flatMap(Platform.parse)
val platformOpt = value {
(parsedPlatform, js.js, native.native) match {
case (Some(p: Platform.JS.type), _, false) => Right(Some(p))
case (Some(p: Platform.Native.type), false, _) => Right(Some(p))
case (Some(p: Platform.JVM.type), false, false) => Right(Some(p))
case (Some(p), _, _) =>
val jsSeq = if (js.js) Seq(Platform.JS) else Seq.empty
val nativeSeq = if (native.native) Seq(Platform.Native) else Seq.empty
val platformsSeq = Seq(p) ++ jsSeq ++ nativeSeq
Left(new AmbiguousPlatformError(platformsSeq.distinct.map(_.toString)))
case (_, true, true) =>
Left(new AmbiguousPlatformError(Seq(Platform.JS.toString, Platform.Native.toString)))
case (_, true, _) => Right(Some(Platform.JS))
case (_, _, true) => Right(Some(Platform.Native))
case _ => Right(None)
}
}
bo.BuildOptions(
suppressWarningOptions =
bo.SuppressWarningOptions(suppressDirectivesInMultipleFilesWarning),
scalaOptions = bo.ScalaOptions(
scalaVersion = scalaVersion
.map(_.trim)
.filter(_.nonEmpty)
.map(bo.MaybeScalaVersion(_)),
scalaBinaryVersion = scalaBinaryVersion.map(_.trim).filter(_.nonEmpty),
addScalaLibrary = scalaLibrary.orElse(java.map(!_)),
addScalaCompiler = withCompiler,
generateSemanticDbs = semanticDb,
scalacOptions = scalac
.scalacOption
.withScalacExtraOptions(scalacExtra)
.toScalacOptShadowingSeq
.filterNonRedirected
.map(Positioned.commandLine),
compilerPlugins =
SharedOptions.parseDependencies(
dependencies.compilerPlugin.map(Positioned.none),
ignoreErrors
),
platform = platformOpt.map(o => Positioned(List(Position.CommandLine()), o))
),
scriptOptions = bo.ScriptOptions(
codeWrapper = None
),
scalaJsOptions = scalaJsOptions(js),
scalaNativeOptions = scalaNativeOptions(native),
javaOptions = value(scala.cli.commands.util.JvmUtils.javaOptions(jvm)),
jmhOptions = bo.JmhOptions(
addJmhDependencies =
if (enableJmh) jmhVersion.orElse(Some(Constants.jmhVersion))
else None,
runJmh = if (enableJmh) Some(true) else None
),
classPathOptions = bo.ClassPathOptions(
extraClassPath = extraJarsAndClassPath,
extraCompileOnlyJars = extraCompileOnlyClassPath,
extraRepositories = dependencies.repository.map(_.trim).filter(_.nonEmpty),
extraDependencies = ShadowingSeq.from(
SharedOptions.parseDependencies(
dependencies.dependency.map(Positioned.none),
ignoreErrors
) ++ SharedOptions.resolveToolkitDependency(withToolkit)
)
),
internal = bo.InternalOptions(
cache = Some(coursierCache),
localRepository = LocalRepo.localRepo(directories.directories.localRepoDir),
verbosity = Some(logging.verbosity),
strictBloopJsonCheck = strictBloopJsonCheck,
interactive = Some(() => interactive),
addStubsDependencyOpt = addStubs
),
notForBloopOptions = bo.PostBuildOptions(
scalaJsLinkerOptions = linkerOptions(js),
addRunnerDependencyOpt = runner,
python = sharedPython.python,
pythonSetup = sharedPython.pythonSetup,
scalaPyVersion = sharedPython.scalaPyVersion
)
)
}
extension (rawClassPath: List[String]) {
def extractedClassPath: List[os.Path] =
rawClassPath
.flatMap(_.split(File.pathSeparator).toSeq)
.filter(_.nonEmpty)
.distinct
.map(os.Path(_, os.pwd))
.flatMap {
case cp if os.isDir(cp) =>
val jarsInTheDirectory =
os.walk(cp)
.filter(p => os.isFile(p) && p.last.endsWith(".jar"))
List(cp) ++ jarsInTheDirectory // .jar paths have to be passed directly, unlike .class
case cp => List(cp)
}
}
def extraJarsAndClassPath: List[os.Path] =
(extraJars ++ scalac.scalacOption.getScalacOption("-classpath"))
.extractedClassPath
def extraCompileOnlyClassPath: List[os.Path] = extraCompileOnlyJars.extractedClassPath
def globalInteractiveWasSuggested: Either[BuildException, Option[Boolean]] = either {
value(configDb).get(Keys.globalInteractiveWasSuggested) match {
case Right(opt) => opt
case Left(ex) =>
logger.debug(ConfigDbException(ex))
None
}
}
def interactive: Either[BuildException, Interactive] = either {
(
logging.verbosityOptions.interactive,
value(configDb).get(Keys.interactive) match {
case Right(opt) => opt
case Left(ex) =>
logger.debug(ConfigDbException(ex))
None
},
value(globalInteractiveWasSuggested)
) match {
case (Some(true), _, Some(true)) => InteractiveAsk
case (_, Some(true), _) => InteractiveAsk
case (Some(true), _, _) =>
val answers @ List(yesAnswer, _) = List("Yes", "No")
InteractiveAsk.chooseOne(
s"""You have run the current ${ScalaCli.baseRunnerName} command with the --interactive mode turned on.
|Would you like to leave it on permanently?""".stripMargin,
answers
) match {
case Some(answer) if answer == yesAnswer =>
val configDb0 = value(configDb)
value {
configDb0
.set(Keys.interactive, true)
.set(Keys.globalInteractiveWasSuggested, true)
.save(directories.directories.dbPath.toNIO)
.wrapConfigException
}
logger.message(
s"--interactive is now set permanently. All future ${ScalaCli.baseRunnerName} commands will run with the flag set to true."
)
logger.message(
s"If you want to turn this setting off at any point, just run `${ScalaCli.baseRunnerName} config interactive false`."
)
case _ =>
val configDb0 = value(configDb)
value {
configDb0
.set(Keys.globalInteractiveWasSuggested, true)
.save(directories.directories.dbPath.toNIO)
.wrapConfigException
}
logger.message(
s"If you want to turn this setting permanently on at any point, just run `${ScalaCli.baseRunnerName} config interactive true`."
)
}
InteractiveAsk
case _ => InteractiveNop
}
}
def suppressDirectivesInMultipleFilesWarning: Option[Boolean] =
suppress.suppressDirectivesInMultipleFilesWarning.filter(identity).orElse(
configDb.map(_.get(Keys.suppressDirectivesInMultipleFilesWarning))
.map {
case Right(opt) => opt
case Left(ex) =>
logger.debug(ConfigDbException(ex))
None
}
.getOrElse(None)
)
def configDb: Either[BuildException, ConfigDb] =
ConfigDb.open(directories.directories.dbPath.toNIO)
.wrapConfigException
def downloadJvm(jvmId: String, options: bo.BuildOptions): String = {
implicit val ec: ExecutionContextExecutorService = options.finalCache.ec
val javaHomeManager = options.javaHomeManager
.withMessage(s"Downloading JVM $jvmId")
val logger = javaHomeManager.cache
.flatMap(_.archiveCache.cache.loggerOpt)
.getOrElse(_root_.coursier.cache.CacheLogger.nop)
val command = {
val path = logger.use {
try javaHomeManager.get(jvmId).unsafeRun()
catch {
case NonFatal(e) => throw new Exception(e)
}
}
os.Path(path)
}
val ext = if (Properties.isWin) ".exe" else ""
val javaCmd = (command / "bin" / s"java$ext").toString
javaCmd
}
def bloopRifleConfig(): Either[BuildException, BloopRifleConfig] = either {
val options = value(buildOptions(false, None))
lazy val defaultJvmCmd =
downloadJvm(OsLibc.baseDefaultJvm(OsLibc.jvmIndexOs, "17"), options)
val javaCmd = compilationServer.bloopJvm.map(downloadJvm(_, options)).orElse {
for (javaHome <- options.javaHomeLocationOpt()) yield {
val (javaHomeVersion, javaHomeCmd) = OsLibc.javaHomeVersion(javaHome.value)
if (javaHomeVersion >= 17) javaHomeCmd
else defaultJvmCmd
}
}.getOrElse(defaultJvmCmd)
compilationServer.bloopRifleConfig(
logging.logger,
coursierCache,
logging.verbosity,
javaCmd,
directories.directories,
Some(17)
)
}
def compilerMaker(
threads: BuildThreads,
scaladoc: Boolean = false
): Either[BuildException, ScalaCompilerMaker] = either {
if (scaladoc)
SimpleScalaCompilerMaker("java", Nil, scaladoc = true)
else if (compilationServer.server.getOrElse(true))
new BloopCompilerMaker(
value(bloopRifleConfig()),
threads.bloop,
strictBloopJsonCheckOrDefault
)
else
SimpleScalaCompilerMaker("java", Nil)
}
lazy val coursierCache = coursier.coursierCache(logging.logger.coursierLogger(""))
def inputs(
args: Seq[String],
defaultInputs: () => Option[Inputs] = () => Inputs.default()
): Either[BuildException, Inputs] =
SharedOptions.inputs(
args,
defaultInputs,
resourceDirs,
directories.directories,
logger = logger,
coursierCache,
workspace.forcedWorkspaceOpt,
input.defaultForbiddenDirectories,
input.forbid,
scriptSnippetList = allScriptSnippets,
scalaSnippetList = allScalaSnippets,
javaSnippetList = allJavaSnippets,
markdownSnippetList = allMarkdownSnippets,
enableMarkdown = markdown.enableMarkdown,
extraClasspathWasPassed = extraJarsAndClassPath.nonEmpty
)
def allScriptSnippets: List[String] = snippet.scriptSnippet ++ snippet.executeScript
def allScalaSnippets: List[String] = snippet.scalaSnippet ++ snippet.executeScala
def allJavaSnippets: List[String] = snippet.javaSnippet ++ snippet.executeJava
def allMarkdownSnippets: List[String] = snippet.markdownSnippet ++ snippet.executeMarkdown
def validateInputArgs(args: Seq[String]): Seq[Either[String, Seq[Element]]] =
Inputs.validateArgs(
args,
Os.pwd,
SharedOptions.downloadInputs(coursierCache),
SharedOptions.readStdin(logger = logger),
!Properties.isWin,
enableMarkdown = true
)
def strictBloopJsonCheckOrDefault: Boolean =
strictBloopJsonCheck.getOrElse(bo.InternalOptions.defaultStrictBloopJsonCheck)
}
object SharedOptions {
implicit lazy val parser: Parser[SharedOptions] = Parser.derive
implicit lazy val help: Help[SharedOptions] = Help.derive
implicit lazy val jsonCodec: JsonValueCodec[SharedOptions] = JsonCodecMaker.make
private def downloadInputs(cache: FileCache[Task]): String => Either[String, Array[Byte]] = {
url =>
val artifact = Artifact(url).withChanging(true)
cache.fileWithTtl0(artifact)
.left
.map(_.describe)
.map(f => os.read.bytes(os.Path(f, Os.pwd)))
}
/** [[Inputs]] builder, handy when you don't have a [[SharedOptions]] instance at hand */
def inputs(
args: Seq[String],
defaultInputs: () => Option[Inputs],
resourceDirs: Seq[String],
directories: scala.build.Directories,
logger: scala.build.Logger,
cache: FileCache[Task],
forcedWorkspaceOpt: Option[os.Path],
defaultForbiddenDirectories: Boolean,
forbid: List[String],
scriptSnippetList: List[String],
scalaSnippetList: List[String],
javaSnippetList: List[String],
markdownSnippetList: List[String],
enableMarkdown: Boolean = false,
extraClasspathWasPassed: Boolean = false
): Either[BuildException, Inputs] = {
val resourceInputs = resourceDirs
.map(os.Path(_, Os.pwd))
.map { path =>
if (!os.exists(path))
logger.message(s"WARNING: provided resource directory path doesn't exist: $path")
path
}
.map(ResourceDirectory.apply)
val maybeInputs = Inputs(
args,
Os.pwd,
defaultInputs = defaultInputs,
download = downloadInputs(cache),
stdinOpt = readStdin(logger = logger),
scriptSnippetList = scriptSnippetList,
scalaSnippetList = scalaSnippetList,
javaSnippetList = javaSnippetList,
markdownSnippetList = markdownSnippetList,
acceptFds = !Properties.isWin,
forcedWorkspace = forcedWorkspaceOpt,
enableMarkdown = enableMarkdown,
allowRestrictedFeatures = ScalaCli.allowRestrictedFeatures,
extraClasspathWasPassed = extraClasspathWasPassed
)
maybeInputs.map { inputs =>
val forbiddenDirs =
(if (defaultForbiddenDirectories) myDefaultForbiddenDirectories else Nil) ++
forbid.filter(_.trim.nonEmpty).map(os.Path(_, Os.pwd))
inputs
.add(resourceInputs)
.checkAttributes(directories)
.avoid(forbiddenDirs, directories)
}
}
private def readStdin(in: InputStream = System.in, logger: Logger): Option[Array[Byte]] =
if (in == null) {
logger.debug("No stdin available")
None
}
else {
logger.debug("Reading stdin")
val result = in.readAllBytes()
logger.debug(s"Done reading stdin (${result.length} B)")
Some(result)
}
private def myDefaultForbiddenDirectories: Seq[os.Path] =
if (Properties.isWin)
Seq(os.Path("""C:\Windows\System32"""))
else
Nil
def parseDependencies(
deps: List[Positioned[String]],
ignoreErrors: Boolean
): Seq[Positioned[AnyDependency]] =
deps.map(_.map(_.trim)).filter(_.value.nonEmpty)
.flatMap { posDepStr =>
val depStr = posDepStr.value
DependencyParser.parse(depStr) match {
case Left(err) =>
if (ignoreErrors) Nil
else sys.error(s"Error parsing dependency '$depStr': $err")
case Right(dep) => Seq(posDepStr.map(_ => dep))
}
}
private def resolveToolkitDependency(toolkitVersion: Option[String])
: Seq[Positioned[AnyDependency]] =
toolkitVersion.toList.map(Positioned.commandLine).map(Toolkit.resolveDependency)
}