8000 Add server less mode (enable with --server=false) by alexarchambault · Pull Request #771 · VirtusLab/scala-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add server less mode (enable with --server=false) #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension
8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 34 additions & 76 deletions modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.concurrent.{ScheduledExecutorService, ScheduledFuture}

import scala.build.EitherCps.{either, value}
import scala.build.Ops._
import scala.build.blooprifle.BloopRifleConfig
import scala.build.compiler.{ScalaCompiler, ScalaCompilerMaker}
import scala.build.errors._
import scala.build.internal.{Constants, CustomCodeWrapper, MainClass, Util}
import scala.build.options.validation.ValidationException
Expand Down Expand Up @@ -112,8 +112,6 @@ object Build {
def diagnostics: None.type = None
}

def defaultStrictBloopJsonCheck = true

def updateInputs(
inputs: Inputs,
options: BuildOptions,
Expand All @@ -139,7 +137,7 @@ object Build {
options: BuildOptions,
logger: Logger,
buildClient: BloopBuildClient,
bloopServer: bloop.BloopServer,
compiler: ScalaCompiler,
crossBuilds: Boolean,
buildTests: Boolean,
partial: Option[Boolean]
Expand Down Expand Up @@ -214,7 +212,7 @@ object Build {
scope,
logger,
buildClient,
bloopServer,
compiler,
buildTests,
partial
)
Expand Down Expand Up @@ -314,7 +312,7 @@ object Build {
scope: Scope,
logger: Logger,
buildClient: BloopBuildClient,
bloopServer: bloop.BloopServer,
compiler: ScalaCompiler,
buildTests: Boolean,
partial: Option[Boolean]
): Either[BuildException, Build] = either {
Expand All @@ -328,7 +326,7 @@ object Build {
scope,
logger,
buildClient,
bloopServer,
compiler,
partial
)
}
Expand All @@ -343,7 +341,7 @@ object Build {
logger,
successful.options.javaHome().value.javaCommand,
buildClient,
bloopServer,
compiler,
buildTests
)
res.flatMap {
Expand Down Expand Up @@ -400,8 +398,7 @@ object Build {
def build(
inputs: Inputs,
options: BuildOptions,
threads: BuildThreads,
bloopConfig: BloopRifleConfig,
compilerMaker: ScalaCompilerMaker,
logger: Logger,
crossBuilds: Boolean,
buildTests: Boolean,
Expand All @@ -413,48 +410,25 @@ object Build {
)
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)

bloop.BloopServer.withBuildServer(
bloopConfig,
"scala-cli",
Constants.version,
(inputs.workspace / Constants.workspaceDirName).toNIO,
classesDir0.toNIO,
compilerMaker.withCompiler(
inputs.workspace / Constants.workspaceDirName,
classesDir0,
buildClient,
threads.bloop,
logger.bloopRifleLogger
) { bloopServer =>
logger
) { compiler =>
build(
inputs = inputs,
options = options,
logger = logger,
buildClient = buildClient,
bloopServer = bloopServer,
compiler = compiler,
crossBuilds = crossBuilds,
buildTests = buildTests,
partial = partial
)
}
}

def build(
inputs: Inputs,
options: BuildOptions,
bloopConfig: BloopRifleConfig,
logger: Logger,
crossBuilds: Boolean,
buildTests: Boolean,
partial: Option[Boolean]
): Either[BuildException, Builds] =
build(
inputs,
options, /*scope,*/ BuildThreads.create(),
bloopConfig,
logger,
crossBuilds = crossBuilds,
buildTests = buildTests,
partial = partial
)

def validate(
logger: Logger,
options: BuildOptions
Expand All @@ -470,7 +444,7 @@ object Build {
def watch(
inputs: Inputs,
options: BuildOptions,
bloopConfig: BloopRifleConfig,
compilerMaker: ScalaCompilerMaker,
logger: Logger,
crossBuilds: Boolean,
buildTests: Boolean,
Expand All @@ -484,15 +458,11 @@ object Build {
)
val threads = BuildThreads.create()
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)
val bloopServer = bloop.BloopServer.buildServer(
bloopConfig,
"scala-cli",
Constants.version,
(inputs.workspace / Constants.workspaceDirName).toNIO,
classesDir0.toNIO,
val compiler = compilerMaker.create(
inputs.workspace / Constants.workspaceDirName,
classesDir0,
buildClient,
threads.bloop,
logger.bloopRifleLogger
logger
)

def run() = {
Expand All @@ -502,7 +472,7 @@ object Build {
options,
logger,
buildClient,
bloopServer,
compiler,
crossBuilds = crossBuilds,
buildTests = buildTests,
partial = partial
Expand All @@ -518,7 +488,7 @@ object Build {

run()

val watcher = new Watcher(ListBuffer(), threads.fileWatcher, run(), bloopServer.shutdown())
val watcher = new Watcher(ListBuffer(), threads.fileWatcher, run(), compiler.shutdown())

def doWatch(): Unit =
for (elem <- inputs.elements) {
Expand Down Expand Up @@ -673,7 +643,7 @@ object Build {
scalaJsScalacOptions ++
scalacReleaseV

val scalaCompiler = ScalaCompiler(
val scalaCompilerParams = ScalaCompilerParams(
scalaVersion = params.scalaVersion,
scalaBinaryVersion = params.scalaBinaryVersion,
scalacOptions = scalacOptions,
Expand All @@ -699,7 +669,7 @@ object Build {
directory = inputs.workspace / Constants.workspaceDirName,
workspace = inputs.workspace,
classesDir = classesDir0,
scalaCompiler = scalaCompiler,
scalaCompiler = scalaCompilerParams,
scalaJsOptions =
if (options.platform.value == Platform.JS) Some(options.scalaJsOptions.config(logger))
else None,
Expand All @@ -726,6 +696,7 @@ object Build {
options: BuildOptions,
compilerJvmVersionOpt: Option[Positioned[Int]],
scope: Scope,
compiler: ScalaCompiler,
logger: Logger
): Either[BuildException, (os.Path, ScalaParameters, Artifacts, Project, Boolean)] = either {

Expand All @@ -749,12 +720,9 @@ object Build {
)
}

val updatedBloopConfig = project.writeBloopFile(
options.internal.strictBloopJsonCheck.getOrElse(defaultStrictBloopJsonCheck),
logger
)
val projectChanged = compiler.prepareProject(project, logger)

if (updatedBloopConfig && os.isDir(classesDir0)) {
if (projectChanged && os.isDir(classesDir0)) {
logger.debug(s"Clearing $classesDir0")
os.list(classesDir0).foreach { p =>
logger.debug(s"Removing $p")
Expand All @@ -766,7 +734,7 @@ object Build {
}
}

(classesDir0, params, artifacts, project, updatedBloopConfig)
(classesDir0, params, artifacts, project, projectChanged)
}

def buildOnce(
Expand All @@ -777,7 +745,7 @@ object Build {
scope: Scope,
logger: Logger,
buildClient: BloopBuildClient,
bloopServer: bloop.BloopServer,
compiler: ScalaCompiler,
partialOpt: Option[Boolean]
): Either[BuildException, Build] = either {

Expand All @@ -787,23 +755,20 @@ object Build {
case Some(error) => value(Left(error))
}

val (classesDir0, scalaParams, artifacts, project, updatedBloopConfig) = value {
val bloopJvmVersion = Positioned(
List(Position.Bloop(bloopServer.bloopInfo.javaHome)),
bloopServer.bloopInfo.jvmVersion
)
val (classesDir0, scalaParams, artifacts, project, projectChanged) = value {
prepareBuild(
inputs,
sources,
generatedSources,
options,
Some(bloopJvmVersion),
compiler.jvmVersion,
scope,
compiler,
logger
)
}

if (updatedBloopConfig && os.isDir(classesDir0)) {
if (projectChanged && os.isDir(classesDir0)) {
logger.debug(s"Clearing $classesDir0")
os.list(classesDir0).foreach { p =>
logger.debug(s"Removing $p")
Expand All @@ -822,14 +787,7 @@ object Build {
options.notForBloopOptions.packageOptions.packageTypeOpt.exists(_.sourceBased)
}

val success =
partial ||
Bloop.compile(
inputs.scopeProjectName(scope),
bloopServer,
logger,
buildTargetsTimeout = 20.seconds
)
val success = partial || compiler.compile(project, logger)

if (success)
Successful(
Expand Down Expand Up @@ -958,7 +916,7 @@ object Build {
logger: Logger,
javaCommand: String,
buildClient: BloopBuildClient,
bloopServer: bloop.BloopServer,
compiler: ScalaCompiler,
buildTests: Boolean
): Either[BuildException, Option[Build]] = either {
val jmhProjectName = inputs.projectName + "_jmh"
Expand Down Expand Up @@ -1004,7 +962,7 @@ object Build {
updatedOptions,
logger,
buildClient,
bloopServer,
compiler,
crossBuilds = false,
buildTests = buildTests,
partial = None
Expand Down
2 changes: 1 addition & 1 deletion modules/build/src/main/scala/scala/build/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final case class Project(
workspace: os.Path,
directory: os.Path,
classesDir: os.Path,
scalaCompiler: ScalaCompiler,
scalaCompiler: ScalaCompilerParams,
scalaJsOptions: Option[BloopConfig.JsConfig],
scalaNativeOptions: Option[BloopConfig.NativeConfig],
projectName: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scala.build

final case class ScalaCompiler(
final case class ScalaCompilerParams(
scalaVersion: String,
scalaBinaryVersion: String,
scalacOptions: Seq[String],
Expand Down
Loading
0