Skip to content

Commit 57d6335

Browse files
authored
Merge pull request #3075 from Gedochao/maintenance/more-env-vars
Add more env vars & generate reference docs for them
2 parents 5fe92a7 + 79672e7 commit 57d6335

File tree

4 files changed

+192
-5
lines changed

4 files changed

+192
-5
lines changed

modules/core/src/main/scala/scala/build/internals/EnvVar.scala

+62-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object EnvVar {
5757
}""".stripMargin
5858
}
5959
}
60-
def allGroups: Seq[EnvVarGroup] = Seq(ScalaCli, Java, Coursier, Spark, Misc, Internal)
60+
def allGroups: Seq[EnvVarGroup] = Seq(ScalaCli, Java, Bloop, Coursier, Spark, Misc, Internal)
6161
def all: Seq[EnvVar] = allGroups.flatMap(_.all)
6262
def allBsp: Seq[EnvVar] = all.filter(_.passToIde)
6363
object Java extends EnvVarGroup {
@@ -83,16 +83,44 @@ object EnvVar {
8383
val dyldLibraryPath = EnvVar("DYLD_LIBRARY_PATH", "Runtime library paths on Mac OS X")
8484
val ldLibraryPath = EnvVar("LD_LIBRARY_PATH", "Runtime library paths on Linux")
8585
val pathExt = EnvVar("PATHEXT", "Executable file extensions on Windows")
86+
val pwd = EnvVar("PWD", "Current working directory", passToIde = false)
8687
val shell = EnvVar("SHELL", "The currently used shell")
8788
val vcVarsAll = EnvVar("VCVARSALL", "Visual C++ Redistributable Runtimes")
8889
val zDotDir = EnvVar("ZDOTDIR", "Zsh configuration directory")
90+
val mavenHome = EnvVar("MAVEN_HOME", "Maven home directory")
8991
}
9092

9193
object Coursier extends EnvVarGroup {
9294
override def groupName: String = "Coursier"
93-
override def all = Seq(coursierCache, coursierMode)
94-
val coursierCache = EnvVar("COURSIER_CACHE", "Coursier cache location")
95-
val coursierMode = EnvVar("COURSIER_MODE", "Coursier mode (can be set to 'offline')")
95+
override def all = Seq(
96+
coursierBinDir,
97+
coursierCache,
98+
coursierConfigDir,
99+
coursierCredentials,
100+
insideEmacs,
101+
coursierExperimental,
102+
coursierJni,
103+
coursierMode,
104+
coursierNoTerm,
105+
coursierProgress,
106+
coursierRepositories,
107+
coursierVendoredZis,
108+
csMavenHome
109+
)
110+
val coursierBinDir = EnvVar("COURSIER_BIN_DIR", "Coursier app binaries directory")
111+
val coursierCache = EnvVar("COURSIER_CACHE", "Coursier cache location")
112+
val coursierConfigDir = EnvVar("COURSIER_CONFIG_DIR", "Coursier configuration directory")
113+
val coursierCredentials = EnvVar("COURSIER_CREDENTIALS", "Coursier credentials")
114+
val coursierExperimental = EnvVar("COURSIER_EXPERIMENTAL", "Experimental mode toggle")
115+
val coursierJni = EnvVar("COURSIER_JNI", "Coursier JNI toggle")
116+
val coursierMode = EnvVar("COURSIER_MODE", "Coursier mode (can be set to 'offline')")
117+
val coursierNoTerm = EnvVar("COURSIER_NO_TERM", "Terminal toggle")
118+
val coursierProgress = EnvVar("COURSIER_PROGRESS", "Progress bar toggle")
119+
val coursierRepositories = EnvVar("COURSIER_REPOSITORIES", "Coursier repositories")
120+
val coursierVendoredZis =
121+
EnvVar("COURSIER_VENDORED_ZIS", "Toggle io.github.scala_cli.zip.ZipInputStream")
122+
val csMavenHome = EnvVar("CS_MAVEN_HOME", "Coursier Maven home directory")
123+
val insideEmacs = EnvVar("INSIDE_EMACS", "Emacs toggle")
96124
}
97125

98126
object ScalaCli extends EnvVarGroup {
@@ -108,6 +136,7 @@ object EnvVar {
108136
vendoredZipInputStream
109137
)
110138
val config = EnvVar("SCALA_CLI_CONFIG", "Scala CLI configuration file path")
139+
val extraTimeout = Bloop.bloopExtraTimeout.copy(requiresPower = false)
111140
val home = EnvVar("SCALA_CLI_HOME", "Scala CLI home directory")
112141
val interactive = EnvVar("SCALA_CLI_INTERACTIVE", "Interactive mode toggle")
113142
val interactiveInputs = EnvVar("SCALA_CLI_INTERACTIVE_INPUTS", "Interactive mode inputs")
@@ -124,6 +153,35 @@ object EnvVar {
124153
val sparkHome = EnvVar("SPARK_HOME", "Spark installation directory", requiresPower = true)
125154
}
126155

156+
object Bloop extends EnvVarGroup {
157+
override def groupName: String = "Bloop"
158+
override def all = Seq(
159+
bloopComputationCores,
160+
bloopDaemonDir,
161+
bloopJavaOpts,
162+
bloopModule,
163+
bloopPort,
164+
bloopScalaVersion,
165+
bloopVersion,
166+
bloopServer,
167+
bloopExtraTimeout
168+
)
169+
val bloopComputationCores = EnvVar(
170+
"BLOOP_COMPUTATION_CORES",
171+
"Number of computation cores to be used",
172+
requiresPower = true
173+
)
174+
val bloopDaemonDir = EnvVar("BLOOP_DAEMON_DIR", "Bloop daemon directory", requiresPower = true)
175+
val bloopJavaOpts = EnvVar("BLOOP_JAVA_OPTS", "Bloop Java options", requiresPower = true)
176+
val bloopModule = EnvVar("BLOOP_MODULE", "Bloop default module", requiresPower = true)
177+
val bloopPort = EnvVar("BLOOP_PORT", "Bloop default port", requiresPower = true)
178+
val bloopScalaVersion =
179+
EnvVar("BLOOP_SCALA_VERSION", "Bloop default Scala version", requiresPower = true)
180+
val bloopVersion = EnvVar("BLOOP_VERSION", "Bloop default version", requiresPower = true)
181+
val bloopServer = EnvVar("BLOOP_SERVER", "Bloop default host", requiresPower = true)
182+
val bloopExtraTimeout = EnvVar("SCALA_CLI_EXTRA_TIMEOUT", "Extra timeout", requiresPower = true)
183+
}
184+
127185
object Internal extends EnvVarGroup {
128186
override def groupName: String = "Internal"
129187
def all = Seq(ci)

modules/generate-reference-doc/src/main/scala/scala/cli/doc/GenerateReferenceDoc.scala

+40-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.util
1313

1414
import scala.build.info.{ArtifactId, BuildInfo, ExportDependencyFormat, ScopedBuildInfo}
1515
import scala.build.internal.Constants
16+
import scala.build.internals.EnvVar
1617
import scala.build.options.{BuildOptions, BuildRequirements, WithBuildRequirements}
1718
import scala.build.preprocessing.directives.DirectiveHandler
1819
import scala.build.preprocessing.directives.DirectivesPreprocessingUtils.*
@@ -606,6 +607,34 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
606607
b.mkString
607608
}
608609

610+
private def envVarContent(groups: Seq[EnvVar.EnvVarGroup], onlyRestricted: Boolean): String = {
611+
val b = new StringBuilder
612+
b.section(
613+
"""---
614+
|title: Environment variables
615+
|sidebar_position: 7
616+
|---""".stripMargin
617+
)
618+
b.section(
619+
"""Scala CLI uses environment variables to configure its behavior.
620+
|Below you can find a list of environment variables used and recognized by Scala CLI.
621+
|
622+
|However, it should by no means be treated as an exhaustive list.
623+
|Some tools and libraries Scala CLI integrates with may have their own, which may or may not be listed here.
624+
|""".stripMargin
625+
)
626+
groups.foreach { group =>
627+
b.section(
628+
s"## ${group.groupName}",
629+
group.all
630+
.filter(ev => !ev.requiresPower || !onlyRestricted)
631+
.map(ev => s" - `${ev.name}`: ${if ev.requiresPower then "" else ""}${ev.description}")
632+
.mkString("\n")
633+
)
634+
}
635+
b.mkString
636+
}
637+
609638
def run(options: InternalDocOptions, args: RemainingArgs): Unit = {
610639

611640
val scalaCli = new ScalaCliCommands(
@@ -644,16 +673,21 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
644673
)
645674
val restrictedDocsDir = os.rel / "scala-command"
646675

676+
val allEnvVarsContent = envVarContent(EnvVar.allGroups, onlyRestricted = false)
677+
val restrictedEnvVarsContent = envVarContent(Seq(EnvVar.ScalaCli), onlyRestricted = true)
678+
647679
if (options.check) {
648680
val content = Seq(
649681
(os.rel / "cli-options.md") -> allCliOptionsContent,
650682
(os.rel / "commands.md") -> allCommandsContent,
651683
(os.rel / "directives.md") -> allDirectivesContent,
652684
(os.rel / "build-info.md") -> buildInfoContent,
685+
(os.rel / "env-vars.md") -> allEnvVarsContent,
653686
(os.rel / restrictedDocsDir / "cli-options.md") -> restrictedCliOptionsContent,
654687
(os.rel / restrictedDocsDir / "commands.md") -> restrictedCommandsContent,
655688
(os.rel / restrictedDocsDir / "directives.md") -> restrictedDirectivesContent,
656-
(os.rel / restrictedDocsDir / "runner-specification") -> scalaOptionsReference
689+
(os.rel / restrictedDocsDir / "runner-specification") -> scalaOptionsReference,
690+
(os.rel / restrictedDocsDir / "env-vars.md") -> restrictedEnvVarsContent
657691
)
658692
var anyDiff = false
659693
for ((dest, content0) <- content) {
@@ -678,6 +712,7 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
678712
maybeWrite(options.outputPath / "commands.md", allCommandsContent)
679713
maybeWrite(options.outputPath / "directives.md", allDirectivesContent)
680714
maybeWrite(options.outputPath / "build-info.md", buildInfoContent)
715+
maybeWrite(options.outputPath / "env-vars.md", allEnvVarsContent)
681716

682717
maybeWrite(
683718
options.outputPath / restrictedDocsDir / "cli-options.md",
@@ -692,6 +727,10 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
692727
options.outputPath / restrictedDocsDir / "runner-specification.md",
693728
scalaOptionsReference
694729
)
730+
maybeWrite(
731+
options.outputPath / restrictedDocsDir / "env-vars.md",
732+
restrictedEnvVarsContent
733+
)
695734
}
696735
}
697736
}

website/docs/reference/env-vars.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Environment variables
3+
sidebar_position: 7
4+
---
5+
6+
Scala CLI uses environment variables to configure its behavior.
7+
Below you can find a list of environment variables used and recognized by Scala CLI.
8+
9+
However, it should by no means be treated as an exhaustive list.
10+
Some tools and libraries Scala CLI integrates with may have their own, which may or may not be listed here.
11+
12+
13+
## Scala CLI
14+
- `SCALA_CLI_CONFIG`: Scala CLI configuration file path
15+
- `SCALA_CLI_HOME`: Scala CLI home directory
16+
- `SCALA_CLI_INTERACTIVE`: Interactive mode toggle
17+
- `SCALA_CLI_INTERACTIVE_INPUTS`: Interactive mode inputs
18+
- `SCALA_CLI_POWER`: Power mode toggle
19+
- `SCALA_CLI_PRINT_STACK_TRACES`: Print stack traces toggle
20+
- `SCALA_CLI_SODIUM_JNI_ALLOW`: Allow to load libsodiumjni
21+
- `SCALA_CLI_VENDORED_ZIS`: Toggle io.github.scala_cli.zip.ZipInputStream
22+
23+
## Java
24+
- `JAVA_HOME`: Java installation directory
25+
- `JAVA_OPTS`: Java options
26+
- `JDK_JAVA_OPTIONS`: JDK Java options
27+
28+
## Bloop
29+
- `BLOOP_COMPUTATION_CORES`: ⚡ Number of computation cores to be used
30+
- `BLOOP_DAEMON_DIR`: ⚡ Bloop daemon directory
31+
- `BLOOP_JAVA_OPTS`: ⚡ Bloop Java options
32+
- `BLOOP_MODULE`: ⚡ Bloop default module
33+
- `BLOOP_PORT`: ⚡ Bloop default port
34+
- `BLOOP_SCALA_VERSION`: ⚡ Bloop default Scala version
35+
- `BLOOP_VERSION`: ⚡ Bloop default version
36+
- `BLOOP_SERVER`: ⚡ Bloop default host
37+
- `SCALA_CLI_EXTRA_TIMEOUT`: ⚡ Extra timeout
38+
39+
## Coursier
40+
- `COURSIER_BIN_DIR`: Coursier app binaries directory
41+
- `COURSIER_CACHE`: Coursier cache location
42+
- `COURSIER_CONFIG_DIR`: Coursier configuration directory
43+
- `COURSIER_CREDENTIALS`: Coursier credentials
44+
- `INSIDE_EMACS`: Emacs toggle
45+
- `COURSIER_EXPERIMENTAL`: Experimental mode toggle
46+
- `COURSIER_JNI`: Coursier JNI toggle
47+
- `COURSIER_MODE`: Coursier mode (can be set to 'offline')
48+
- `COURSIER_NO_TERM`: Terminal toggle
49+
- `COURSIER_PROGRESS`: Progress bar toggle
50+
- `COURSIER_REPOSITORIES`: Coursier repositories
51+
- `COURSIER_VENDORED_ZIS`: Toggle io.github.scala_cli.zip.ZipInputStream
52+
- `CS_MAVEN_HOME`: Coursier Maven home directory
53+
54+
## Spark
55+
- `SPARK_HOME`: ⚡ Spark installation directory
56+
57+
## Miscellaneous
58+
- `PATH`: The app path variable
59+
- `DYLD_LIBRARY_PATH`: Runtime library paths on Mac OS X
60+
- `LD_LIBRARY_PATH`: Runtime library paths on Linux
61+
- `PATHEXT`: Executable file extensions on Windows
62+
- `SHELL`: The currently used shell
63+
- `VCVARSALL`: Visual C++ Redistributable Runtimes
64+
- `ZDOTDIR`: Zsh configuration directory
65+
66+
## Internal
67+
- `CI`: ⚡ Marker for running on the CI
68+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Environment variables
3+
sidebar_position: 7
4+
---
5+
6+
Scala CLI uses environment variables to configure its behavior.
7+
Below you can find a list of environment variables used and recognized by Scala CLI.
8+
9+
However, it should by no means be treated as an exhaustive list.
10+
Some tools and libraries Scala CLI integrates with may have their own, which may or may not be listed here.
11+
12+
13+
## Scala CLI
14+
- `SCALA_CLI_CONFIG`: Scala CLI configuration file path
15+
- `SCALA_CLI_HOME`: Scala CLI home directory
16+
- `SCALA_CLI_INTERACTIVE`: Interactive mode toggle
17+
- `SCALA_CLI_INTERACTIVE_INPUTS`: Interactive mode inputs
18+
- `SCALA_CLI_POWER`: Power mode toggle
19+
- `SCALA_CLI_PRINT_STACK_TRACES`: Print stack traces toggle
20+
- `SCALA_CLI_SODIUM_JNI_ALLOW`: Allow to load libsodiumjni
21+
- `SCALA_CLI_VENDORED_ZIS`: Toggle io.github.scala_cli.zip.ZipInputStream
22+

0 commit comments

Comments
 (0)