@@ -138,6 +138,7 @@ object Build {
138
138
logger : Logger ,
139
139
buildClient : BloopBuildClient ,
140
140
compiler : ScalaCompiler ,
141
+ docCompilerOpt : Option [ScalaCompiler ],
141
142
crossBuilds : Boolean ,
142
143
buildTests : Boolean ,
143
144
partial : Option [Boolean ]
@@ -169,9 +170,16 @@ object Build {
169
170
case _ =>
170
171
}
171
172
173
+ final case class NonCrossBuilds (
174
+ main : Build ,
175
+ testOpt : Option [Build ],
176
+ docOpt : Option [Build ],
177
+ testDocOpt : Option [Build ]
178
+ )
179
+
172
180
def doBuild (
173
181
overrideOptions : BuildOptions
174
- ): Either [BuildException , ( Build , Option [ Build ]) ] = either {
182
+ ): Either [BuildException , NonCrossBuilds ] = either {
175
183
176
184
val baseOptions = overrideOptions.orElse(sharedOptions)
177
185
val scopedSources = value(crossSources.scopedSources(baseOptions))
@@ -191,7 +199,8 @@ object Build {
191
199
def doBuildScope (
192
200
options : BuildOptions ,
193
201
sources : Sources ,
194
- scope : Scope
202
+ scope : Scope ,
203
+ actualCompiler : ScalaCompiler = compiler
195
204
): Either [BuildException , Build ] =
196
205
either {
197
206
val sources0 = sources.withVirtualDir(inputs0, scope, options)
@@ -212,7 +221,7 @@ object Build {
212
221
scope,
213
222
logger,
214
223
buildClient,
215
- compiler ,
224
+ actualCompiler ,
216
225
buildTests,
217
226
partial
218
227
)
@@ -221,44 +230,70 @@ object Build {
221
230
}
222
231
223
232
val mainBuild = value(doBuildScope(mainOptions, mainSources, Scope .Main ))
233
+ val mainDocBuildOpt = docCompilerOpt match {
234
+ case None => None
235
+ case Some (docCompiler) =>
236
+ Some (value(doBuildScope(
237
+ mainOptions,
238
+ mainSources,
239
+ Scope .Main ,
240
+ actualCompiler = docCompiler
241
+ )))
242
+ }
224
243
225
- val testBuildOpt =
244
+ def testBuildOpt ( doc : Boolean = false ) = either {
226
245
if (buildTests) {
227
- val testBuild = value {
228
- mainBuild match {
229
- case s : Build .Successful =>
230
- val extraTestOptions = BuildOptions (
231
- classPathOptions = ClassPathOptions (
232
- extraClassPath = Seq (s.output)
233
- )
234
- )
235
- val testOptions0 = extraTestOptions.orElse(testOptions)
236
- doBuildScope(testOptions0, testSources, Scope .Test )
237
- case _ =>
238
- Right (Build .Cancelled (
239
- inputs,
240
- sharedOptions,
241
- Scope .Test ,
242
- " Parent build failed or cancelled"
243
- ))
244
- }
246
+ val actualCompilerOpt =
247
+ if (doc) docCompilerOpt
248
+ else Some (compiler)
249
+ actualCompilerOpt match {
250
+ case None => None
251
+ case Some (actualCompiler) =>
252
+ val testBuild = value {
253
+ mainBuild match {
254
+ case s : Build .Successful =>
255
+ val extraTestOptions = BuildOptions (
256
+ classPathOptions = ClassPathOptions (
257
+ extraClassPath = Seq (s.output)
258
+ )
259
+ )
260
+ val testOptions0 = extraTestOptions.orElse(testOptions)
261
+ doBuildScope(
262
+ testOptions0,
263
+ testSources,
264
+ Scope .Test ,
265
+ actualCompiler = actualCompiler
266
+ )
267
+ case _ =>
268
+ Right (Build .Cancelled (
269
+ inputs,
270
+ sharedOptions,
271
+ Scope .Test ,
272
+ " Parent build failed or cancelled"
273
+ ))
274
+ }
275
+ }
276
+ Some (testBuild)
245
277
}
246
- Some (testBuild)
247
278
}
248
279
else None
280
+ }
249
281
282
+ val testBuildOpt0 = value(testBuildOpt())
250
283
doPostProcess(mainBuild, inputs0, Scope .Main )
251
- for (testBuild <- testBuildOpt )
284
+ for (testBuild <- testBuildOpt0 )
252
285
doPostProcess(testBuild, inputs0, Scope .Test )
253
286
254
- (mainBuild, testBuildOpt)
287
+ val docTestBuildOpt0 = value(testBuildOpt(doc = true ))
288
+
289
+ NonCrossBuilds (mainBuild, testBuildOpt0, mainDocBuildOpt, docTestBuildOpt0)
255
290
}
256
291
257
- def buildScopes (): Either [BuildException , ( Build , Seq [ Build ], Option [ Build ], Seq [ Build ]) ] =
292
+ def buildScopes (): Either [BuildException , Builds ] =
258
293
either {
259
- val (mainBuild, testBuild) = value(doBuild(BuildOptions ()))
294
+ val nonCrossBuilds = value(doBuild(BuildOptions ()))
260
295
261
- val (extraMainBuilds : Seq [ Build ] , extraTestBuilds : Seq [ Build ] ) =
296
+ val (extraMainBuilds, extraTestBuilds, extraDocBuilds, extraDocTestBuilds ) =
262
297
if (crossBuilds) {
263
298
val extraBuilds = value {
264
299
val maybeBuilds = crossOptions.map(doBuild)
@@ -267,21 +302,31 @@ object Build {
267
302
.sequence
268
303
.left.map(CompositeBuildException (_))
269
304
}
270
- (extraBuilds.map(_._1), extraBuilds.flatMap(_._2))
305
+ (
306
+ extraBuilds.map(_.main),
307
+ extraBuilds.flatMap(_.testOpt),
308
+ extraBuilds.flatMap(_.docOpt),
309
+ extraBuilds.flatMap(_.testDocOpt)
310
+ )
271
311
}
272
312
else
273
- (Nil , Nil )
313
+ (Nil , Nil , Nil , Nil )
274
314
275
- (mainBuild, extraMainBuilds, testBuild, extraTestBuilds)
315
+ Builds (
316
+ Seq (nonCrossBuilds.main) ++ nonCrossBuilds.testOpt.toSeq,
317
+ Seq (extraMainBuilds, extraTestBuilds),
318
+ nonCrossBuilds.docOpt.toSeq ++ nonCrossBuilds.testDocOpt.toSeq,
319
+ Seq (extraDocBuilds, extraDocTestBuilds)
320
+ )
276
321
}
277
322
278
- val (mainBuild, extraBuilds, testBuildOpt, extraTestBuilds) = value(buildScopes())
323
+ val builds = value(buildScopes())
279
324
280
- copyResourceToClassesDir(mainBuild )
281
- for (testBuild <- testBuildOpt )
325
+ copyResourceToClassesDir(builds.main )
326
+ for (testBuild <- builds.get( Scope . Test ) )
282
327
copyResourceToClassesDir(testBuild)
283
328
284
- Builds ( Seq (mainBuild) ++ testBuildOpt.toSeq, Seq (extraBuilds, extraTestBuilds))
329
+ builds
285
330
}
286
331
287
332
private def copyResourceToClassesDir (build : Build ) = build match {
@@ -399,6 +444,7 @@ object Build {
399
444
inputs : Inputs ,
400
445
options : BuildOptions ,
401
446
compilerMaker : ScalaCompilerMaker ,
447
+ docCompilerMakerOpt : Option [ScalaCompilerMaker ],
402
448
logger : Logger ,
403
449
crossBuilds : Boolean ,
404
450
buildTests : Boolean ,
@@ -416,16 +462,39 @@ object Build {
416
462
buildClient,
417
463
logger
418
464
) { compiler =>
419
- build(
420
- inputs = inputs,
421
- options = options,
422
- logger = logger,
423
- buildClient = buildClient,
424
- compiler = compiler,
425
- crossBuilds = crossBuilds,
426
- buildTests = buildTests,
427
- partial = partial
428
- )
465
+ docCompilerMakerOpt match {
466
+ case None =>
467
+ build(
468
+ inputs = inputs,
469
+ options = options,
470
+ logger = logger,
471
+ buildClient = buildClient,
472
+ compiler = compiler,
473
+ docCompilerOpt = None ,
474
+ crossBuilds = crossBuilds,
475
+ buildTests = buildTests,
476
+ partial = partial
477
+ )
478
+ case Some (docCompilerMaker) =>
479
+ docCompilerMaker.withCompiler(
480
+ inputs.workspace / Constants .workspaceDirName,
481
+ classesDir0, // ???
482
+ buildClient,
483
+ logger
484
+ ) { docCompiler =>
485
+ build(
486
+ inputs = inputs,
487
+ options = options,
488
+ logger = logger,
489
+ buildClient = buildClient,
490
+ compiler = compiler,
491
+ docCompilerOpt = Some (docCompiler),
492
+ crossBuilds = crossBuilds,
493
+ buildTests = buildTests,
494
+ partial = partial
495
+ )
496
+ }
497
+ }
429
498
}
430
499
}
431
500
@@ -445,6 +514,7 @@ object Build {
445
514
inputs : Inputs ,
446
515
options : BuildOptions ,
447
516
compilerMaker : ScalaCompilerMaker ,
517
+ docCompilerMakerOpt : Option [ScalaCompilerMaker ],
448
518
logger : Logger ,
449
519
crossBuilds : Boolean ,
450
520
buildTests : Boolean ,
@@ -464,6 +534,12 @@ object Build {
464
534
buildClient,
465
535
logger
466
536
)
537
+ val docCompilerOpt = docCompilerMakerOpt.map(_.create(
538
+ inputs.workspace / Constants .workspaceDirName,
539
+ classesDir0,
540
+ buildClient,
541
+ logger
542
+ ))
467
543
468
544
def run () = {
469
545
try {
@@ -473,6 +549,7 @@ object Build {
473
549
logger,
474
550
buildClient,
475
551
compiler,
552
+ docCompilerOpt,
476
553
crossBuilds = crossBuilds,
477
554
buildTests = buildTests,
478
555
partial = partial
@@ -724,7 +801,7 @@ object Build {
724
801
725
802
val projectChanged = compiler.prepareProject(project, logger)
726
803
727
- if (projectChanged && os.isDir(classesDir0)) {
804
+ if (compiler.usesClassDir && projectChanged && os.isDir(classesDir0)) {
728
805
logger.debug(s " Clearing $classesDir0" )
729
806
os.list(classesDir0).foreach { p =>
730
807
logger.debug(s " Removing $p" )
@@ -770,7 +847,7 @@ object Build {
770
847
)
771
848
}
772
849
773
- if (projectChanged && os.isDir(classesDir0)) {
850
+ if (compiler.usesClassDir && projectChanged && os.isDir(classesDir0)) {
774
851
logger.debug(s " Clearing $classesDir0" )
775
852
os.list(classesDir0).foreach { p =>
776
853
logger.debug(s " Removing $p" )
@@ -965,6 +1042,7 @@ object Build {
965
1042
logger,
966
1043
buildClient,
967
1044
compiler,
1045
+ None ,
968
1046
crossBuilds = false ,
969
1047
buildTests = buildTests,
970
1048
partial = None
0 commit comments