Skip to content

Commit f6b7bd0

Browse files
committed
Create new bloop project for js and native platform
1 parent e294fc9 commit f6b7bd0

File tree

8 files changed

+63
-38
lines changed

8 files changed

+63
-38
lines changed

modules/build/src/main/scala/scala/build/Build.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ object Build {
166166

167167
val scopedSources = value(crossSources0.scopedSources(baseOptions))
168168
val sources = scopedSources.sources(scope, baseOptions)
169+
val buildOptions = sources.buildOptions
169170

170-
val generatedSources = sources.generateSources(inputs.generatedSrcRoot(scope))
171-
val buildOptions = sources.buildOptions
171+
val generatedSources =
172+
sources.generateSources(inputs.generatedSrcRoot(scope, buildOptions.platform.value))
172173

173174
val scopeParams =
174175
if (scope == Scope.Main) Nil
@@ -178,8 +179,8 @@ object Build {
178179
val res = build(
179180
inputs0,
180181
sources,
181-
inputs.projectName,
182-
inputs.generatedSrcRoot(scope),
182+
inputs.projectName(buildOptions.platform.value),
183+
inputs.generatedSrcRoot(scope, buildOptions.platform.value),
183184
generatedSources,
184185
buildOptions,
185186
scope,
@@ -262,7 +263,7 @@ object Build {
262263
}.map { build =>
263264
postProcess(
264265
build.generatedSources,
265-
inputs.generatedSrcRoot(Scope.Main),
266+
inputs.generatedSrcRoot(Scope.Main, build.options.platform.value),
266267
build.output,
267268
logger,
268269
inputs.workspace,
@@ -394,7 +395,7 @@ object Build {
394395
logger,
395396
keepDiagnostics = options.internal.keepDiagnostics
396397
)
397-
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)
398+
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName(options.platform.value))
398399

399400
bloop.BloopServer.withBuildServer(
400401
bloopConfig,
@@ -458,7 +459,7 @@ object Build {
458459
keepDiagnostics = options.internal.keepDiagnostics
459460
)
460461
val threads = BuildThreads.create()
461-
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)
462+
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName(options.platform.value))
462463
val bloopServer = bloop.BloopServer.buildServer(
463464
bloopConfig,
464465
"scala-cli",
@@ -881,7 +882,7 @@ object Build {
881882
buildClient: BloopBuildClient,
882883
bloopServer: bloop.BloopServer
883884
): Either[BuildException, Option[Build]] = either {
884-
val jmhProjectName = inputs.projectName + "_jmh"
885+
val jmhProjectName = inputs.projectName(build.options.platform.value) + "_jmh"
885886
val jmhOutputDir = inputs.workspace / ".scala" / jmhProjectName
886887
os.remove.all(jmhOutputDir)
887888
val jmhSourceDir = jmhOutputDir / "sources"

modules/build/src/main/scala/scala/build/CrossSources.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final case class CrossSources(
1616

1717
def withVirtualDir(inputs: Inputs, scope: Scope, options: BuildOptions): CrossSources = {
1818

19-
val srcRootPath = inputs.generatedSrcRoot(scope)
19+
val srcRootPath = inputs.generatedSrcRoot(scope, options.platform.value)
2020
val resourceDirs0 = options.classPathOptions.resourcesVirtualDir.map { path =>
2121
HasBuildRequirements(BuildRequirements(), srcRootPath / path)
2222
}

modules/build/src/main/scala/scala/build/Inputs.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.security.MessageDigest
77
import java.util.zip.{ZipEntry, ZipInputStream}
88

99
import scala.annotation.tailrec
10-
import scala.build.options.Scope
10+
import scala.build.options.{Platform, Scope}
1111
import scala.build.preprocessing.ScopePath
1212
import scala.util.matching.Regex
1313

@@ -85,25 +85,26 @@ final case class Inputs(
8585

8686
lazy val inputsHash: String =
8787
Inputs.inputsHash(elements)
88-
lazy val projectName = {
88+
def projectName(platform: Platform) = {
8989
val needsSuffix = mayAppendHash && (elements match {
9090
case Seq(d: Inputs.Directory) => d.path != workspace
9191
case _ => true
9292
})
93-
if (needsSuffix) baseProjectName + "-" + inputsHash
94-
else baseProjectName
93+
val pSuffix = platform match {
94+
case Platform.JS => "-js"
95+
case Platform.Native => "-native"
96+
case Platform.JVM => ""
97+
}
98+
if (needsSuffix) baseProjectName + "-" + inputsHash + pSuffix
99+
else baseProjectName + pSuffix
95100
}
96101

97-
def scopeProjectName(scope: Scope): String =
98-
if (scope == Scope.Main) projectName
99-
else projectName + "-" + scope.name
100-
101102
def add(extraElements: Seq[Inputs.Element]): Inputs =
102103
if (elements.isEmpty) this
103104
else copy(elements = elements ++ extraElements)
104105

105-
def generatedSrcRoot(scope: Scope): os.Path =
106-
workspace / ".scala" / projectName / "src_generated" / scope.name
106+
def generatedSrcRoot(scope: Scope, platform: Platform): os.Path =
107+
workspace / ".scala" / projectName(platform) / "src_generated" / scope.name
107108

108109
private def inHomeDir(directories: Directories): Inputs =
109110
copy(

modules/build/src/main/scala/scala/build/bsp/BspImpl.scala

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ final class BspImpl(
7777
val options0Main = sourcesMain.buildOptions
7878
val options0Test = sourcesTest.buildOptions.orElse(options0Main)
7979

80-
val generatedSourcesMain = sourcesMain.generateSources(inputs.generatedSrcRoot(Scope.Main))
81-
val generatedSourcesTest = sourcesTest.generateSources(inputs.generatedSrcRoot(Scope.Test))
80+
val generatedSourcesMain =
81+
sourcesMain.generateSources(inputs.generatedSrcRoot(Scope.Main, options0Main.platform.value))
82+
val generatedSourcesTest =
83+
sourcesTest.generateSources(inputs.generatedSrcRoot(Scope.Test, options0Test.platform.value))
8284

8385
actualLocalServer.setExtraDependencySources(buildOptions.classPathOptions.extraSourceJars)
8486
actualLocalServer.setGeneratedSources(generatedSourcesMain ++ generatedSourcesTest)
@@ -87,7 +89,7 @@ final class BspImpl(
8789
Build.prepareBuild(
8890
inputs,
8991
sourcesMain,
90-
inputs.projectName,
92+
inputs.projectName(options0Main.platform.value),
9193
generatedSourcesMain,
9294
options0Main,
9395
Scope.Main,
@@ -103,7 +105,7 @@ final class BspImpl(
103105
Build.prepareBuild(
104106
inputs,
105107
sourcesTest,
106-
inputs.projectName,
108+
inputs.projectName(options0Test.platform.value),
107109
generatedSourcesTest,
108110
options0Test,
109111
Scope.Test,
@@ -152,8 +154,8 @@ final class BspImpl(
152154
Build.buildOnce(
153155
inputs,
154156
preBuildDataMain.sources,
155-
inputs.projectName,
156-
inputs.generatedSrcRoot(Scope.Main),
157+
inputs.projectName(preBuildDataMain.buildOptions.platform.value),
158+
inputs.generatedSrcRoot(Scope.Main, preBuildDataMain.buildOptions.platform.value),
157159
preBuildDataMain.generatedSources,
158160
preBuildDataMain.buildOptions,
159161
Scope.Main,
@@ -164,8 +166,8 @@ final class BspImpl(
164166
Build.buildOnce(
165167
inputs,
166168
preBuildDataTest.sources,
167-
inputs.projectName,
168-
inputs.generatedSrcRoot(Scope.Test),
169+
inputs.projectName(preBuildDataTest.buildOptions.platform.value),
170+
inputs.generatedSrcRoot(Scope.Test, preBuildDataTest.buildOptions.platform.value),
169171
preBuildDataTest.generatedSources,
170172
preBuildDataTest.buildOptions,
171173
Scope.Test,
@@ -252,7 +254,7 @@ final class BspImpl(
252254
() => {
253255
Build.postProcess(
254256
generatedSources,
255-
inputs.generatedSrcRoot(Scope.Main),
257+
inputs.generatedSrcRoot(Scope.Main, buildOptions.platform.value),
256258
classesDir0,
257259
logger,
258260
inputs.workspace,
@@ -261,7 +263,7 @@ final class BspImpl(
261263
).left.foreach(_.foreach(showGlobalWarningOnce))
262264
Build.postProcess(
263265
generatedSourcesTest,
264-
inputs.generatedSrcRoot(Scope.Test),
266+
inputs.generatedSrcRoot(Scope.Test, buildOptions.platform.value),
265267
classesDir0Test,
266268
logger,
267269
inputs.workspace,
@@ -308,7 +310,10 @@ final class BspImpl(
308310
threads.buildThreads.bloop.jsonrpc, // meh
309311
logger
310312
)
311-
actualLocalClient.setProjectName(inputs.workspace, inputs.projectName)
313+
actualLocalClient.setProjectName(
314+
inputs.workspace,
315+
inputs.projectName(buildOptions.platform.value)
316+
)
312317
val localClient: b.BuildClient with BloopBuildClient =
313318
if (verbosity >= 3)
314319
new BspImpl.LoggingBspClient(actualLocalClient)
@@ -327,7 +332,8 @@ final class BspImpl(
327332

328333
def run(): Future[Unit] = {
329334

330-
val classesDir = Build.classesRootDir(inputs.workspace, inputs.projectName)
335+
val classesDir =
336+
Build.classesRootDir(inputs.workspace, inputs.projectName(buildOptions.platform.value))
331337

332338
remoteServer = BloopServer.buildServer(
333339
bloopRifleConfig,
@@ -348,8 +354,14 @@ final class BspImpl(
348354
compile(actualLocalServer, threads.prepareBuildExecutor, doCompile),
349355
logger = logger
350356
)
351-
actualLocalServer.setProjectName(inputs.workspace, inputs.projectName)
352-
actualLocalServer.setProjectTestName(inputs.workspace, inputs.projectName)
357+
actualLocalServer.setProjectName(
358+
inputs.workspace,
359+
inputs.projectName(buildOptions.platform.value)
360+
)
361+
actualLocalServer.setProjectTestName(
362+
inputs.workspace,
363+
inputs.projectName(buildOptions.platform.value)
364+
)
353365

354366
val localServer: b.BuildServer with b.ScalaBuildServer with b.JavaBuildServer =
355367
if (verbosity >= 3)

modules/build/src/test/scala/scala/build/tests/BuildProjectTests.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ class BuildProjectTests extends munit.FunSuite {
7373
val sources = Sources(Nil, Nil, None, Nil, options)
7474
val logger = new LoggerMock()
7575
val res =
76-
Build.buildProject(inputs, sources, inputs.projectName, Nil, options, Scope.Test, logger)
76+
Build.buildProject(
77+
inputs,
78+
sources,
79+
inputs.projectName(options.platform.value),
80+
Nil,
81+
options,
82+
Scope.Test,
83+
logger
84+
)
7785

7886
val scalaCompilerOptions = res.fold(throw _, identity).scalaCompiler.scalacOptions
7987
(scalaCompilerOptions, res.fold(throw _, identity).javacOptions, logger.diagnostics)
@@ -151,7 +159,7 @@ class BuildProjectTests extends munit.FunSuite {
151159
val project = Build.buildProject(
152160
inputs,
153161
sources,
154-
inputs.projectName,
162+
inputs.projectName(options.platform.value),
155163
Nil,
156164
options,
157165
Scope.Main,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ object Package extends ScalaCommand[PackageOptions] {
405405
logger: Logger
406406
): Unit = {
407407
val workDir =
408-
build.options.scalaNativeOptions.nativeWorkDir(inputs.workspace, inputs.projectName)
408+
build.options.scalaNativeOptions.nativeWorkDir(
409+
inputs.workspace,
410+
inputs.projectName(build.options.platform.value)
411+
)
409412

410413
buildNative(build, mainClass, destPath, workDir, logger)
411414
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object Run extends ScalaCommand[RunOptions] {
4343
def maybeRun(build: Build.Successful, allowTerminate: Boolean): Either[BuildException, Unit] =
4444
maybeRunOnce(
4545
inputs.workspace,
46-
inputs.projectName,
46+
inputs.projectName(options.buildOptions.platform.value),
4747
build,
4848
programArgs,
4949
logger,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object Test extends ScalaCommand[TestOptions] {
5959
}
6060
val retCodeOrError = testOnce(
6161
inputs.workspace,
62-
inputs.projectName,
62+
inputs.projectName(s.options.platform.value),
6363
s,
6464
options.requireTests,
6565
args.unparsed,

0 commit comments

Comments
 (0)