Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,14 @@ object Build {
)
)
val testOptions0 = extraTestOptions.orElse(testOptions)
val isScala2 =
value(testOptions0.scalaParams).exists(_.scalaVersion.startsWith("2."))
val finalSources = if doc && isScala2 then
testSources.withExtraSources(mainSources)
else testSources
doBuildScope(
testOptions0,
testSources,
finalSources,
Scope.Test,
actualCompiler = actualCompiler
)
Expand Down
7 changes: 7 additions & 0 deletions modules/build/src/main/scala/scala/build/Sources.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ final case class Sources(
buildOptions: BuildOptions
) {

def withExtraSources(other: Sources): Sources =
copy(
paths = paths ++ other.paths,
inMemory = inMemory ++ other.inMemory,
resourceDirs = resourceDirs ++ other.resourceDirs
)

def withVirtualDir(inputs: Inputs, scope: Scope, options: BuildOptions): Sources = {

val srcRootPath = inputs.generatedSrcRoot(scope)
Expand Down
66 changes: 35 additions & 31 deletions modules/cli/src/main/scala/scala/cli/commands/doc/Doc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.build.compiler.{ScalaCompilerMaker, SimpleScalaCompilerMaker}
import scala.build.errors.BuildException
import scala.build.interactive.InteractiveFileOps
import scala.build.internal.{Constants, Runner}
import scala.build.options.BuildOptions
import scala.build.options.{BuildOptions, Scope}
import scala.cli.CurrentParams
import scala.cli.commands.publish.ConfigUtil.*
import scala.cli.commands.shared.{HelpCommandGroup, HelpGroup, SharedOptions}
Expand Down Expand Up @@ -52,33 +52,34 @@ object Doc extends ScalaCommand[DocOptions] {
configDb.get(Keys.actions).getOrElse(None)
)

val builds =
Build.build(
inputs,
initialBuildOptions,
compilerMaker,
docCompilerMakerOpt,
logger,
crossBuilds = false,
buildTests = false,
partial = None,
actionableDiagnostics = actionableDiagnostics
)
.orExit(logger)
builds.main match {
case s: Build.Successful =>
val withTestScope = options.scope.test
Build.build(
inputs,
initialBuildOptions,
compilerMaker,
docCompilerMakerOpt,
logger,
crossBuilds = false,
buildTests = withTestScope,
partial = None,
actionableDiagnostics = actionableDiagnostics
)
.orExit(logger).docBuilds match {
case b if b.forall(_.success) =>
val successfulBuilds = b.collect { case s: Build.Successful => s }
val res0 = doDoc(
logger,
options.output.filter(_.nonEmpty),
options.force,
s,
args.unparsed
successfulBuilds,
args.unparsed,
withTestScope
)
res0.orExit(logger)
case _: Build.Failed =>
case b if b.exists(bb => !bb.success && !bb.cancelled) =>
System.err.println("Compilation failed")
sys.exit(1)
case _: Build.Cancelled =>
case _ =>
System.err.println("Build cancelled")
sys.exit(1)
}
Expand All @@ -88,8 +89,9 @@ object Doc extends ScalaCommand[DocOptions] {
logger: Logger,
outputOpt: Option[String],
force: Boolean,
build: Build.Successful,
extraArgs: Seq[String]
builds: Seq[Build.Successful],
extraArgs: Seq[String],
withTestScope: Boolean
): Either[BuildException, Unit] = either {

def defaultName = "scala-doc"
Expand All @@ -101,7 +103,7 @@ object Doc extends ScalaCommand[DocOptions] {
def alreadyExistsCheck(): Either[BuildException, Unit] = {
val alreadyExists = !force && os.exists(destPath)
if (alreadyExists)
build.options.interactive.map { interactive =>
builds.head.options.interactive.map { interactive =>
InteractiveFileOps.erasingPath(interactive, printableDest, destPath) { () =>
val msg = s"$printableDest already exists"
System.err.println(s"Error: $msg. Pass -f or --force to force erasing it.")
Expand All @@ -114,10 +116,9 @@ object Doc extends ScalaCommand[DocOptions] {

value(alreadyExistsCheck())

val docJarPath = value(generateScaladocDirPath(Seq(build), logger, extraArgs))
val docJarPath = value(generateScaladocDirPath(builds, logger, extraArgs, withTestScope))
value(alreadyExistsCheck())
if (force) os.copy.over(docJarPath, destPath)
else os.copy(docJarPath, destPath)
if force then os.copy.over(docJarPath, destPath) else os.copy(docJarPath, destPath)

val printableOutput = CommandUtils.printablePath(destPath)

Expand All @@ -138,12 +139,15 @@ object Doc extends ScalaCommand[DocOptions] {
def generateScaladocDirPath(
builds: Seq[Build.Successful],
logger: Logger,
extraArgs: Seq[String]
extraArgs: Seq[String],
withTestScope: Boolean
): Either[BuildException, os.Path] = either {
val docContentDir = builds.head.scalaParams match {
case Some(scalaParams) if scalaParams.scalaVersion.startsWith("2.") =>
builds.head.project.scaladocDir
case Some(scalaParams) =>
val docContentDir = builds.head.scalaParams
.map(sp => sp -> sp.scalaVersion.startsWith("2.")) match {
case Some((_, true)) if withTestScope =>
builds.find(_.scope == Scope.Test).getOrElse(builds.head).project.scaladocDir
case Some((_, true)) => builds.head.project.scaladocDir
case Some((scalaParams, _)) =>
val res = value {
Artifacts.fetchAnyDependencies(
Seq(Positioned.none(dep"org.scala-lang::scaladoc:${scalaParams.scalaVersion}")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import caseapp.*
import caseapp.core.help.Help

import scala.cli.ScalaCli.fullRunnerName
import scala.cli.commands.shared.{HasSharedOptions, HelpGroup, HelpMessages, SharedOptions}
import scala.cli.commands.shared.{
HasSharedOptions,
HelpGroup,
HelpMessages,
ScopeOptions,
SharedOptions
}
import scala.cli.commands.tags

// format: off
Expand All @@ -27,6 +33,8 @@ final case class DocOptions(
@Tag(tags.should)
@ExtraName("defaultScaladocOpts")
defaultScaladocOptions: Option[Boolean] = None,
@Recurse
scope: ScopeOptions = ScopeOptions()
) extends HasSharedOptions
// format: on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
configDb.get(Keys.actions).getOrElse(None)
)

if (options.watch.watchMode) {
val withTestScope = options.scope.test
if options.watch.watchMode then {
var expectedModifyEpochSecondOpt = Option.empty[Long]
val watcher = Build.watch(
inputs,
Expand All @@ -96,7 +97,7 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
docCompilerMakerOpt,
logger,
crossBuilds = cross,
buildTests = options.scope.test,
buildTests = withTestScope,
partial = None,
actionableDiagnostics = actionableDiagnostics,
postAction = () => WatchUtil.printWatchMessage()
Expand All @@ -114,7 +115,8 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
extraArgs = args.unparsed,
expectedModifyEpochSecondOpt = expectedModifyEpochSecondOpt,
allowTerminate = !options.watch.watchMode,
mainClassOptions = options.mainClass
mainClassOptions = options.mainClass,
withTestScope = withTestScope
)
.orReport(logger)
for (valueOpt <- mtimeDestPath)
Expand All @@ -135,7 +137,7 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
docCompilerMakerOpt,
logger,
crossBuilds = cross,
buildTests = options.scope.test,
buildTests = withTestScope,
partial = None,
actionableDiagnostics = actionableDiagnostics
)
Expand All @@ -153,7 +155,8 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
extraArgs = args.unparsed,
expectedModifyEpochSecondOpt = None,
allowTerminate = !options.watch.watchMode,
mainClassOptions = options.mainClass
mainClassOptions = options.mainClass,
withTestScope = withTestScope
)
res0.orExit(logger)
case b if b.exists(bb => !bb.success && !bb.cancelled) =>
Expand Down Expand Up @@ -189,7 +192,8 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
extraArgs: Seq[String],
expectedModifyEpochSecondOpt: Option[Long],
allowTerminate: Boolean,
mainClassOptions: MainClassOptions
mainClassOptions: MainClassOptions,
withTestScope: Boolean
): Either[BuildException, Option[Long]] = either {
if mainClassOptions.mainClassLs.contains(true) then
value {
Expand Down Expand Up @@ -349,7 +353,7 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
else os.write(destPath, content, createFolders = true)
destPath
case PackageType.DocJar =>
val docJarPath = value(docJar(builds, logger, extraArgs))
val docJarPath = value(docJar(builds, logger, extraArgs, withTestScope))
value(alreadyExistsCheck())
if force then os.copy.over(docJarPath, destPath, createFolders = true)
else os.copy(docJarPath, destPath, createFolders = true)
Expand Down Expand Up @@ -547,7 +551,8 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {
def docJar(
builds: Seq[Build.Successful],
logger: Logger,
extraArgs: Seq[String]
extraArgs: Seq[String],
withTestScope: Boolean
): Either[BuildException, os.Path] = either {

val workDir = builds.head.inputs.docJarWorkDir
Expand All @@ -562,7 +567,7 @@ object Package extends ScalaCommand[PackageOptions] with BuildCommandHelpers {

if cacheData.changed then {

val contentDir = value(Doc.generateScaladocDirPath(builds, logger, extraArgs))
val contentDir = value(Doc.generateScaladocDirPath(builds, logger, extraArgs, withTestScope))

var outputStream: OutputStream = null
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,13 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
docBuildOpt match {
case None => None
case Some(docBuild) =>
val docJarPath = value(PackageCmd.docJar(Seq(docBuild), logger, Nil))
val docJar = workingDir / org / s"$moduleName-$ver-javadoc.jar"
val docJarPath = value(PackageCmd.docJar(
builds = Seq(docBuild),
logger = logger,
extraArgs = Nil,
withTestScope = false
))
val docJar = workingDir / org / s"$moduleName-$ver-javadoc.jar"
os.copy.over(docJarPath, docJar, createFolders = true)
Some(docJar)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package scala.build.errors

final class NoDocBuildError extends BuildException(
"Doc build not present. It may have been cancelled."
)
Loading