@@ -12,7 +12,7 @@ import scala.build.compiler.{ScalaCompilerMaker, SimpleScalaCompilerMaker}
12
12
import scala .build .errors .BuildException
13
13
import scala .build .interactive .InteractiveFileOps
14
14
import scala .build .internal .{Constants , Runner }
15
- import scala .build .options .BuildOptions
15
+ import scala .build .options .{ BuildOptions , Scope }
16
16
import scala .cli .CurrentParams
17
17
import scala .cli .commands .publish .ConfigUtil .*
18
18
import scala .cli .commands .shared .{HelpCommandGroup , HelpGroup , SharedOptions }
@@ -52,33 +52,34 @@ object Doc extends ScalaCommand[DocOptions] {
52
52
configDb.get(Keys .actions).getOrElse(None )
53
53
)
54
54
55
- val builds =
56
- Build .build(
57
- inputs,
58
- initialBuildOptions,
59
- compilerMaker,
60
- docCompilerMakerOpt,
61
- logger,
62
- crossBuilds = false ,
63
- buildTests = false ,
64
- partial = None ,
65
- actionableDiagnostics = actionableDiagnostics
66
- )
67
- .orExit(logger)
68
- builds.main match {
69
- case s : Build .Successful =>
55
+ val withTestScope = options.scope.test
56
+ Build .build(
57
+ inputs,
58
+ initialBuildOptions,
59
+ compilerMaker,
60
+ docCompilerMakerOpt,
61
+ logger,
62
+ crossBuilds = false ,
63
+ buildTests = withTestScope ,
64
+ partial = None ,
65
+ actionableDiagnostics = actionableDiagnostics
66
+ )
67
+ .orExit(logger).docBuilds match {
68
+ case b if b.forall(_.success) =>
69
+ val successfulBuilds = b.collect { case s : Build .Successful => s }
70
70
val res0 = doDoc(
71
71
logger,
72
72
options.output.filter(_.nonEmpty),
73
73
options.force,
74
- s,
75
- args.unparsed
74
+ successfulBuilds,
75
+ args.unparsed,
76
+ withTestScope
76
77
)
77
78
res0.orExit(logger)
78
- case _ : Build . Failed =>
79
+ case b if b.exists(bb => ! bb.success && ! bb.cancelled) =>
79
80
System .err.println(" Compilation failed" )
80
81
sys.exit(1 )
81
- case _ : Build . Cancelled =>
82
+ case _ =>
82
83
System .err.println(" Build cancelled" )
83
84
sys.exit(1 )
84
85
}
@@ -88,8 +89,9 @@ object Doc extends ScalaCommand[DocOptions] {
88
89
logger : Logger ,
89
90
outputOpt : Option [String ],
90
91
force : Boolean ,
91
- build : Build .Successful ,
92
- extraArgs : Seq [String ]
92
+ builds : Seq [Build .Successful ],
93
+ extraArgs : Seq [String ],
94
+ withTestScope : Boolean
93
95
): Either [BuildException , Unit ] = either {
94
96
95
97
def defaultName = " scala-doc"
@@ -101,7 +103,7 @@ object Doc extends ScalaCommand[DocOptions] {
101
103
def alreadyExistsCheck (): Either [BuildException , Unit ] = {
102
104
val alreadyExists = ! force && os.exists(destPath)
103
105
if (alreadyExists)
104
- build .options.interactive.map { interactive =>
106
+ builds.head .options.interactive.map { interactive =>
105
107
InteractiveFileOps .erasingPath(interactive, printableDest, destPath) { () =>
106
108
val msg = s " $printableDest already exists "
107
109
System .err.println(s " Error: $msg. Pass -f or --force to force erasing it. " )
@@ -114,10 +116,9 @@ object Doc extends ScalaCommand[DocOptions] {
114
116
115
117
value(alreadyExistsCheck())
116
118
117
- val docJarPath = value(generateScaladocDirPath(Seq (build) , logger, extraArgs))
119
+ val docJarPath = value(generateScaladocDirPath(builds , logger, extraArgs, withTestScope ))
118
120
value(alreadyExistsCheck())
119
- if (force) os.copy.over(docJarPath, destPath)
120
- else os.copy(docJarPath, destPath)
121
+ if force then os.copy.over(docJarPath, destPath) else os.copy(docJarPath, destPath)
121
122
122
123
val printableOutput = CommandUtils .printablePath(destPath)
123
124
@@ -138,12 +139,15 @@ object Doc extends ScalaCommand[DocOptions] {
138
139
def generateScaladocDirPath (
139
140
builds : Seq [Build .Successful ],
140
141
logger : Logger ,
141
- extraArgs : Seq [String ]
142
+ extraArgs : Seq [String ],
143
+ withTestScope : Boolean
142
144
): Either [BuildException , os.Path ] = either {
143
- val docContentDir = builds.head.scalaParams match {
144
- case Some (scalaParams) if scalaParams.scalaVersion.startsWith(" 2." ) =>
145
- builds.head.project.scaladocDir
146
- case Some (scalaParams) =>
145
+ val docContentDir = builds.head.scalaParams
146
+ .map(sp => sp -> sp.scalaVersion.startsWith(" 2." )) match {
147
+ case Some ((_, true )) if withTestScope =>
148
+ builds.find(_.scope == Scope .Test ).getOrElse(builds.head).project.scaladocDir
149
+ case Some ((_, true )) => builds.head.project.scaladocDir
150
+ case Some ((scalaParams, _)) =>
147
151
val res = value {
148
152
Artifacts .fetchAnyDependencies(
149
153
Seq (Positioned .none(dep " org.scala-lang::scaladoc: ${scalaParams.scalaVersion}" )),
0 commit comments