@@ -835,6 +835,13 @@ object Defaults extends BuildCommon {
835
835
}) :+ compileAnalysisFile.value.toPath
836
836
},
837
837
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,
838
845
clean := (compileOutputs / clean).value,
839
846
earlyOutputPing := Def .promise[Boolean ],
840
847
compileProgress := {
@@ -1027,9 +1034,9 @@ object Defaults extends BuildCommon {
1027
1034
val cache = state.value.extendedClassLoaderCache
1028
1035
mkScalaInstance(
1029
1036
version,
1030
- allJars,
1031
1037
libraryJars,
1032
- compilerJar,
1038
+ allJars,
1039
+ Seq .empty,
1033
1040
cache,
1034
1041
scalaInstanceTopLoader.value
1035
1042
)
@@ -1059,31 +1066,43 @@ object Defaults extends BuildCommon {
1059
1066
1060
1067
def scalaInstanceFromUpdate : Initialize [Task [ScalaInstance ]] = Def .task {
1061
1068
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 {
1066
1077
m <- toolReport.modules if m.module.name.startsWith(id)
1067
1078
(art, file) <- m.artifacts if art.`type` == Artifact .DefaultType
1068
1079
} 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))
1071
1090
val libraryJars = ScalaArtifacts .libraryIds(sv).map(file)
1072
- val compilerJar = file( ScalaArtifacts .compilerId(sv))
1091
+
1073
1092
mkScalaInstance(
1074
1093
sv,
1075
- allJars,
1076
1094
libraryJars,
1077
- compilerJar,
1095
+ allCompilerJars,
1096
+ allDocJars,
1078
1097
state.value.extendedClassLoaderCache,
1079
1098
scalaInstanceTopLoader.value,
1080
1099
)
1081
1100
}
1082
1101
private [this ] def mkScalaInstance (
1083
1102
version : String ,
1084
- allJars : Seq [File ],
1085
1103
libraryJars : Array [File ],
1086
- compilerJar : File ,
1104
+ allCompilerJars : Seq [File ],
1105
+ allDocJars : Seq [File ],
1087
1106
classLoaderCache : ClassLoaderCache ,
1088
1107
topLoader : ClassLoader ,
1089
1108
): ScalaInstance = {
@@ -1096,17 +1115,33 @@ object Defaults extends BuildCommon {
1096
1115
}
1097
1116
}
1098
1117
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
+
1100
1126
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)
1102
1136
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)
1110
1145
)
1111
1146
}
1112
1147
def scalaInstanceFromHome (dir : File ): Initialize [Task [ScalaInstance ]] = Def .task {
@@ -1117,9 +1152,9 @@ object Defaults extends BuildCommon {
1117
1152
}
1118
1153
mkScalaInstance(
1119
1154
dummy.version,
1120
- dummy.allJars,
1121
1155
dummy.libraryJars,
1122
- dummy.compilerJar,
1156
+ dummy.compilerJars,
1157
+ dummy.allJars,
1123
1158
state.value.extendedClassLoaderCache,
1124
1159
scalaInstanceTopLoader.value,
1125
1160
)
@@ -1991,6 +2026,16 @@ object Defaults extends BuildCommon {
1991
2026
else Map .empty[File , URL ]
1992
2027
},
1993
2028
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
+ },
1994
2039
key in TaskZero := {
1995
2040
val s = streams.value
1996
2041
val cs : Compilers = compilers.value
@@ -2005,21 +2050,24 @@ object Defaults extends BuildCommon {
2005
2050
val fiOpts = fileInputOptions.value
2006
2051
val reporter = (compile / bspReporter).value
2007
2052
val converter = fileConverter.value
2053
+ val tFiles = tastyFiles.value
2054
+ val sv = scalaVersion.value
2008
2055
(hasScala, hasJava) match {
2009
2056
case (true , _) =>
2010
2057
val options = sOpts ++ Opts .doc.externalAPI(xapis)
2011
2058
val runDoc = Doc .scaladoc(label, s.cacheStoreFactory sub " scala" , cs.scalac match {
2012
2059
case ac : AnalyzingCompiler => ac.onArgs(exported(s, " scaladoc" ))
2013
2060
}, 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)
2015
2063
case (_, true ) =>
2016
2064
val javadoc =
2017
2065
sbt.inc.Doc .cachedJavadoc(label, s.cacheStoreFactory sub " java" , cs.javaTools)
2018
2066
javadoc.run(
2019
2067
srcs.toList map { x =>
2020
2068
converter.toVirtualFile(x.toPath)
2021
2069
},
2022
- cp.toList map { x =>
2070
+ cp map { x =>
2023
2071
converter.toVirtualFile(x.toPath)
2024
2072
},
2025
2073
converter,
@@ -2913,7 +2961,8 @@ object Classpaths {
2913
2961
},
2914
2962
ivyConfigurations ++= Configurations .auxiliary,
2915
2963
ivyConfigurations ++= {
2916
- if (managedScalaInstance.value && scalaHome.value.isEmpty) Configurations .ScalaTool :: Nil
2964
+ if (managedScalaInstance.value && scalaHome.value.isEmpty)
2965
+ Configurations .ScalaTool :: Configurations .ScalaDocTool :: Nil
2917
2966
else Nil
2918
2967
},
2919
2968
// Coursier needs these
@@ -3103,10 +3152,15 @@ object Classpaths {
3103
3152
else base
3104
3153
val sbtOrg = scalaOrganization.value
3105
3154
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
3110
3164
},
3111
3165
// in case of meta build, exclude all sbt modules from the dependency graph, so we can use the sbt resolved by the launcher
3112
3166
allExcludeDependencies := {
0 commit comments