Skip to content

Commit d687cf1

Browse files
authored
Merge pull request sbt#6234 from adpi2/scala3doc
Add support for Scala3doc
2 parents cd794ee + 8f5c222 commit d687cf1

File tree

7 files changed

+111
-35
lines changed

7 files changed

+111
-35
lines changed

main/src/main/scala/sbt/Defaults.scala

Lines changed: 85 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,13 @@ object Defaults extends BuildCommon {
835835
}) :+ compileAnalysisFile.value.toPath
836836
},
837837
compileOutputs := compileOutputs.triggeredBy(compile).value,
838+
tastyFiles := Def.taskIf {
839+
if (ScalaArtifacts.isScala3(scalaVersion.value)) {
840+
val _ = compile.value
841+
val tastyFiles = classDirectory.value.**("*.tasty").get
842+
tastyFiles.map(_.getAbsoluteFile)
843+
} else Nil
844+
}.value,
838845
clean := (compileOutputs / clean).value,
839846
earlyOutputPing := Def.promise[Boolean],
840847
compileProgress := {
@@ -1027,9 +1034,9 @@ object Defaults extends BuildCommon {
10271034
val cache = state.value.extendedClassLoaderCache
10281035
mkScalaInstance(
10291036
version,
1030-
allJars,
10311037
libraryJars,
1032-
compilerJar,
1038+
allJars,
1039+
Seq.empty,
10331040
cache,
10341041
scalaInstanceTopLoader.value
10351042
)
@@ -1059,31 +1066,43 @@ object Defaults extends BuildCommon {
10591066

10601067
def scalaInstanceFromUpdate: Initialize[Task[ScalaInstance]] = Def.task {
10611068
val sv = scalaVersion.value
1062-
val toolReport = update.value.configuration(Configurations.ScalaTool) getOrElse
1063-
sys.error(noToolConfiguration(managedScalaInstance.value))
1064-
def files(id: String) =
1065-
for {
1069+
val fullReport = update.value
1070+
1071+
val toolReport = fullReport
1072+
.configuration(Configurations.ScalaTool)
1073+
.getOrElse(sys.error(noToolConfiguration(managedScalaInstance.value)))
1074+
1075+
def file(id: String): File = {
1076+
val files = for {
10661077
m <- toolReport.modules if m.module.name.startsWith(id)
10671078
(art, file) <- m.artifacts if art.`type` == Artifact.DefaultType
10681079
} yield file
1069-
def file(id: String) = files(id).headOption getOrElse sys.error(s"Missing $id jar file")
1070-
val allJars = toolReport.modules.flatMap(_.artifacts.map(_._2))
1080+
files.headOption getOrElse sys.error(s"Missing $id jar file")
1081+
}
1082+
1083+
val allCompilerJars = toolReport.modules.flatMap(_.artifacts.map(_._2))
1084+
val allDocJars =
1085+
fullReport
1086+
.configuration(Configurations.ScalaDocTool)
1087+
.toSeq
1088+
.flatMap(_.modules)
1089+
.flatMap(_.artifacts.map(_._2))
10711090
val libraryJars = ScalaArtifacts.libraryIds(sv).map(file)
1072-
val compilerJar = file(ScalaArtifacts.compilerId(sv))
1091+
10731092
mkScalaInstance(
10741093
sv,
1075-
allJars,
10761094
libraryJars,
1077-
compilerJar,
1095+
allCompilerJars,
1096+
allDocJars,
10781097
state.value.extendedClassLoaderCache,
10791098
scalaInstanceTopLoader.value,
10801099
)
10811100
}
10821101
private[this] def mkScalaInstance(
10831102
version: String,
1084-
allJars: Seq[File],
10851103
libraryJars: Array[File],
1086-
compilerJar: File,
1104+
allCompilerJars: Seq[File],
1105+
allDocJars: Seq[File],
10871106
classLoaderCache: ClassLoaderCache,
10881107
topLoader: ClassLoader,
10891108
): ScalaInstance = {
@@ -1096,17 +1115,33 @@ object Defaults extends BuildCommon {
10961115
}
10971116
}
10981117
else topLoader
1099-
val allJarsDistinct = allJars.distinct
1118+
1119+
val compilerJars = allCompilerJars.filterNot(libraryJars.contains).distinct.toArray
1120+
val docJars = allDocJars
1121+
.filterNot(jar => libraryJars.contains(jar) || compilerJars.contains(jar))
1122+
.distinct
1123+
.toArray
1124+
val allJars = libraryJars ++ compilerJars ++ docJars
1125+
11001126
val libraryLoader = classLoaderCache(libraryJars.toList, jansiExclusionLoader)
1101-
val fullLoader = classLoaderCache(allJarsDistinct.toList, libraryLoader)
1127+
val compilerLoader = classLoaderCache(
1128+
// It should be `compilerJars` but it would break on `3.0.0-M2` because of
1129+
// https://github.com/lampepfl/dotty/blob/d932af954ef187d7bdb87500d49ed0ff530bd1e7/sbt-bridge/src/xsbt/CompilerClassLoader.java#L108-L117
1130+
allCompilerJars.toList,
1131+
libraryLoader
1132+
)
1133+
val fullLoader =
1134+
if (docJars.isEmpty) compilerLoader
1135+
else classLoaderCache(docJars.distinct.toList, compilerLoader)
11021136
new ScalaInstance(
1103-
version,
1104-
fullLoader,
1105-
libraryLoader,
1106-
libraryJars,
1107-
compilerJar,
1108-
allJarsDistinct.toArray,
1109-
Some(version)
1137+
version = version,
1138+
loader = fullLoader,
1139+
loaderCompilerOnly = compilerLoader,
1140+
loaderLibraryOnly = libraryLoader,
1141+
libraryJars = libraryJars,
1142+
compilerJars = compilerJars,
1143+
allJars = allJars,
1144+
explicitActual = Some(version)
11101145
)
11111146
}
11121147
def scalaInstanceFromHome(dir: File): Initialize[Task[ScalaInstance]] = Def.task {
@@ -1117,9 +1152,9 @@ object Defaults extends BuildCommon {
11171152
}
11181153
mkScalaInstance(
11191154
dummy.version,
1120-
dummy.allJars,
11211155
dummy.libraryJars,
1122-
dummy.compilerJar,
1156+
dummy.compilerJars,
1157+
dummy.allJars,
11231158
state.value.extendedClassLoaderCache,
11241159
scalaInstanceTopLoader.value,
11251160
)
@@ -1991,6 +2026,16 @@ object Defaults extends BuildCommon {
19912026
else Map.empty[File, URL]
19922027
},
19932028
fileInputOptions := Seq("-doc-root-content", "-diagrams-dot-path"),
2029+
scalacOptions := {
2030+
val compileOptions = scalacOptions.value
2031+
val sv = scalaVersion.value
2032+
val config = configuration.value
2033+
val projectName = name.value
2034+
if (ScalaArtifacts.isScala3(sv)) {
2035+
val project = if (config == Compile) projectName else s"$projectName-$config"
2036+
Seq("-project", project)
2037+
} else compileOptions
2038+
},
19942039
key in TaskZero := {
19952040
val s = streams.value
19962041
val cs: Compilers = compilers.value
@@ -2005,21 +2050,24 @@ object Defaults extends BuildCommon {
20052050
val fiOpts = fileInputOptions.value
20062051
val reporter = (compile / bspReporter).value
20072052
val converter = fileConverter.value
2053+
val tFiles = tastyFiles.value
2054+
val sv = scalaVersion.value
20082055
(hasScala, hasJava) match {
20092056
case (true, _) =>
20102057
val options = sOpts ++ Opts.doc.externalAPI(xapis)
20112058
val runDoc = Doc.scaladoc(label, s.cacheStoreFactory sub "scala", cs.scalac match {
20122059
case ac: AnalyzingCompiler => ac.onArgs(exported(s, "scaladoc"))
20132060
}, fiOpts)
2014-
runDoc(srcs, cp, out, options, maxErrors.value, s.log)
2061+
val docSrcs = if (ScalaArtifacts.isScala3(sv)) tFiles else srcs
2062+
runDoc(docSrcs, cp, out, options, maxErrors.value, s.log)
20152063
case (_, true) =>
20162064
val javadoc =
20172065
sbt.inc.Doc.cachedJavadoc(label, s.cacheStoreFactory sub "java", cs.javaTools)
20182066
javadoc.run(
20192067
srcs.toList map { x =>
20202068
converter.toVirtualFile(x.toPath)
20212069
},
2022-
cp.toList map { x =>
2070+
cp map { x =>
20232071
converter.toVirtualFile(x.toPath)
20242072
},
20252073
converter,
@@ -2913,7 +2961,8 @@ object Classpaths {
29132961
},
29142962
ivyConfigurations ++= Configurations.auxiliary,
29152963
ivyConfigurations ++= {
2916-
if (managedScalaInstance.value && scalaHome.value.isEmpty) Configurations.ScalaTool :: Nil
2964+
if (managedScalaInstance.value && scalaHome.value.isEmpty)
2965+
Configurations.ScalaTool :: Configurations.ScalaDocTool :: Nil
29172966
else Nil
29182967
},
29192968
// Coursier needs these
@@ -3103,10 +3152,15 @@ object Classpaths {
31033152
else base
31043153
val sbtOrg = scalaOrganization.value
31053154
val version = scalaVersion.value
3106-
if (scalaHome.value.isDefined || scalaModuleInfo.value.isEmpty || !managedScalaInstance.value)
3107-
pluginAdjust
3108-
else
3109-
ScalaArtifacts.toolDependencies(sbtOrg, version) ++ pluginAdjust
3155+
val extResolvers = externalResolvers.value
3156+
val allToolDeps =
3157+
if (scalaHome.value.isDefined || scalaModuleInfo.value.isEmpty || !managedScalaInstance.value)
3158+
Nil
3159+
else if (extResolvers.contains(Resolver.JCenterRepository)) {
3160+
ScalaArtifacts.toolDependencies(sbtOrg, version) ++
3161+
ScalaArtifacts.docToolDependencies(sbtOrg, version)
3162+
} else ScalaArtifacts.toolDependencies(sbtOrg, version)
3163+
allToolDeps ++ pluginAdjust
31103164
},
31113165
// in case of meta build, exclude all sbt modules from the dependency graph, so we can use the sbt resolved by the launcher
31123166
allExcludeDependencies := {

main/src/main/scala/sbt/Keys.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ object Keys {
223223
val manipulateBytecode = taskKey[CompileResult]("Manipulates generated bytecode").withRank(BTask)
224224
val compileIncremental = taskKey[CompileResult]("Actually runs the incremental compilation").withRank(DTask)
225225
val previousCompile = taskKey[PreviousResult]("Read the incremental compiler analysis from disk").withRank(DTask)
226+
val tastyFiles = taskKey[Seq[File]]("Returns the TASTy files produced by compilation").withRank(DTask)
226227
private[sbt] val compileScalaBackend = taskKey[CompileResult]("Compiles only Scala sources if pipelining is enabled. Compiles both Scala and Java sources otherwise").withRank(Invisible)
227228
private[sbt] val compileEarly = taskKey[CompileAnalysis]("Compiles only Scala sources if pipelining is enabled, and produce an early output (pickle JAR)").withRank(Invisible)
228229
private[sbt] val earlyOutputPing = taskKey[PromiseWrap[Boolean]]("When pipelining is enabled, this returns true when early output (pickle JAR) is created; false otherwise").withRank(Invisible)

project/Dependencies.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ object Dependencies {
1414
// sbt modules
1515
private val ioVersion = nightlyVersion.getOrElse("1.4.0")
1616
private val lmVersion =
17-
sys.props.get("sbt.build.lm.version").orElse(nightlyVersion).getOrElse("1.5.0-M2")
18-
val zincVersion = nightlyVersion.getOrElse("1.5.0-M1")
17+
sys.props.get("sbt.build.lm.version").orElse(nightlyVersion).getOrElse("1.5.0-M3")
18+
val zincVersion = nightlyVersion.getOrElse("1.5.0-M2")
1919

2020
private val sbtIO = "org.scala-sbt" %% "io" % ioVersion
2121

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lazy val root = (project in file("."))
2+
.settings(
3+
scalaVersion := "3.0.0-M3",
4+
resolvers += Resolver.JCenterRepository
5+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package foo
2+
3+
final val foo="Foo"
4+
5+
object A:
6+
/**
7+
* @param i An argument
8+
*/
9+
def x(i:Int)=3
10+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
> doc
2+
$ exists target/scala-3.0.0-M3/api/index.html
3+
$ exists target/scala-3.0.0-M3/api/api/foo/A$.html
4+
$ exists target/scala-3.0.0-M3/api/api/foo.html

zinc-lm-integration/src/main/scala/sbt/internal/inc/ZincComponentCompiler.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ private[sbt] object ZincComponentCompiler {
128128
val properties = ResourceLoader.getSafePropertiesFor("compiler.properties", loader)
129129
val loaderVersion = Option(properties.getProperty("version.number"))
130130
val scalaV = loaderVersion.getOrElse("unknown")
131+
val allJars = jarsToLoad.map(_.toFile).toArray
131132
new ScalaInstance(
132133
scalaV,
133134
loader,
135+
loader,
134136
loaderLibraryOnly,
135137
scalaLibraryJars.map(_.toFile).toArray,
136-
scalaCompilerJar.toFile,
137-
jarsToLoad.map(_.toFile).toArray,
138+
allJars,
139+
allJars,
138140
loaderVersion,
139141
)
140142
}

0 commit comments

Comments
 (0)