@@ -2,6 +2,7 @@ import java.io.File
22import java .nio .file ._
33
44import Modes ._
5+ import ScaladocGeneration ._
56import com .jsuereth .sbtpgp .PgpKeys
67import sbt .Keys ._
78import sbt ._
@@ -59,6 +60,8 @@ object DottyJSPlugin extends AutoPlugin {
5960}
6061
6162object Build {
63+ import ScaladocConfigs ._
64+
6265 val referenceVersion = " 3.1.2-RC1"
6366
6467 val baseVersion = " 3.1.3-RC1"
@@ -1287,39 +1290,15 @@ object Build {
12871290 libraryDependencies += (" org.scala-js" %%% " scalajs-dom" % " 1.1.0" ).cross(CrossVersion .for3Use2_13)
12881291 )
12891292
1290- def generateDocumentation (targets : Seq [ String ], name : String , outDir : String , ref : String , params : Seq [ String ] = Nil , includeExternalMappings : Boolean = true ) =
1293+ def generateDocumentation (configTask : Def . Initialize [ Task [ GenerationConfig ]] ) =
12911294 Def .taskDyn {
1292- val distLocation = (dist / pack).value
1293- val projectVersion = version.value
1294- IO .createDirectory(file(outDir))
1295- val stdLibVersion = stdlibVersion(NonBootstrapped )
1296- val scalaLib = findArtifactPath(externalCompilerClasspathTask.value, " scala-library" )
1297- val dottyLib = (`scala3-library` / Compile / classDirectory).value
1298- // TODO add versions etc.
1299- def srcManaged (v : String , s : String ) = s " out/bootstrap/stdlib-bootstrapped/scala- $v/src_managed/main/ $s-library-src "
1300- def scalaSrcLink (v : String , s : String ) = s " -source-links: ${s}github://scala/scala/v $v#src/library "
1301- def dottySrcLink (v : String , sourcesPrefix : String = " " , outputPrefix : String = " " ) =
1302- sys.env.get(" GITHUB_SHA" ) match {
1303- case Some (sha) =>
1304- s " -source-links: ${sourcesPrefix}github:// ${sys.env(" GITHUB_REPOSITORY" )}/ $sha$outputPrefix"
1305- case None => s " -source-links: ${sourcesPrefix}github://lampepfl/dotty/ $v$outputPrefix"
1306- }
1307-
1308- val revision = Seq (" -revision" , ref, " -project-version" , projectVersion)
1309- val cmd = Seq (
1310- " -d" ,
1311- outDir,
1312- " -project" ,
1313- name,
1314- scalaSrcLink(stdLibVersion, srcManaged(dottyNonBootstrappedVersion, " scala" ) + " =" ),
1315- dottySrcLink(referenceVersion, srcManaged(dottyNonBootstrappedVersion, " dotty" ) + " =" , " #library/src" ),
1316- dottySrcLink(referenceVersion),
1317- " -Ygenerate-inkuire" ,
1318- ) ++ scalacOptionsDocSettings(includeExternalMappings) ++ revision ++ params ++ targets
1319- import _root_ .scala .sys .process ._
1320- val escapedCmd = cmd.map(arg => if (arg.contains(" " )) s """ " $arg" """ else arg)
1295+ val config = configTask.value
1296+ config.get[OutputDir ].foreach { outDir =>
1297+ IO .createDirectory(file(outDir.value))
1298+ }
1299+ val command = generateCommand(config)
13211300 Def .task {
1322- (Compile / run).toTask(escapedCmd.mkString( " " , " " , " " ) ).value
1301+ (Compile / run).toTask(command ).value
13231302 }
13241303 }
13251304
@@ -1363,66 +1342,40 @@ object Build {
13631342 Test / testcasesSourceRoot := ((`scaladoc-testcases` / baseDirectory).value / " src" ).getAbsolutePath.toString,
13641343 run / baseDirectory := (ThisBuild / baseDirectory).value,
13651344 generateSelfDocumentation := Def .taskDyn {
1366- generateDocumentation(
1367- (Compile / classDirectory).value.getAbsolutePath :: Nil ,
1368- " scaladoc" , " scaladoc/output/self" , VersionUtil .gitHash, Seq (" -usejavacp" )
1369- )
1345+ generateDocumentation(Scaladoc )
13701346 }.value,
1347+
13711348 generateScalaDocumentation := Def .inputTaskDyn {
1372- val extraArgs = spaceDelimited(" [output]" ).parsed
1373- val dest = file(extraArgs.headOption.getOrElse(" scaladoc/output/scala3" )).getAbsoluteFile
1374- val justAPI = extraArgs.drop(1 ).headOption == Some (" --justAPI" )
13751349 val majorVersion = (LocalProject (" scala3-library-bootstrapped" ) / scalaBinaryVersion).value
1376- val dottyJars : Seq [java.io.File ] = Seq (
1377- (`stdlib-bootstrapped`/ Compile / products).value,
1378- (`scala3-interfaces`/ Compile / products).value,
1379- (`tasty-core-bootstrapped`/ Compile / products).value,
1380- ).flatten
1381-
1382- val roots = dottyJars.map(_.getAbsolutePath)
1383-
1384- val managedSources =
1385- (`stdlib-bootstrapped`/ Compile / sourceManaged).value / " scala-library-src"
1386- val projectRoot = (ThisBuild / baseDirectory).value.toPath
1387- val stdLibRoot = projectRoot.relativize(managedSources.toPath.normalize())
1388- val docRootFile = stdLibRoot.resolve(" rootdoc.txt" )
1389-
1390- val dottyManagesSources =
1391- (`stdlib-bootstrapped`/ Compile / sourceManaged).value / " dotty-library-src"
1392-
1393- val dottyLibRoot = projectRoot.relativize(dottyManagesSources.toPath.normalize())
1394-
1395- def generateDocTask =
1396- generateDocumentation(
1397- roots, " Scala 3" , dest.getAbsolutePath, " main" ,
1398- Seq (
1399- " -comment-syntax" , " wiki" ,
1400- s " -source-links:docs=github://lampepfl/dotty/main#docs " ,
1401- " -doc-root-content" , docRootFile.toString,
1402- " -versions-dictionary-url" ,
1403- " https://scala-lang.org/api/versions.json" ,
1404- " -Ydocument-synthetic-types" ,
1405- s " -snippet-compiler: ${dottyLibRoot}/scala/quoted=compile, ${dottyLibRoot}/scala/compiletime=compile "
1406- ) ++ (if (justAPI) Nil else Seq (" -siteroot" , " docs" , " -Yapi-subdirectory" )), includeExternalMappings = false )
1407-
1408- if (dottyJars.isEmpty) Def .task { streams.value.log.error(" Dotty lib wasn't found" ) }
1409- else if (justAPI) generateDocTask
1410- else Def .task{
1411- IO .write(dest / " versions" / " latest-nightly-base" , majorVersion)
1412-
1413- // This file is used by GitHub Pages when the page is available in a custom domain
1414- IO .write(dest / " CNAME" , " dotty.epfl.ch" )
1415- }.dependsOn(generateDocTask)
1350+
1351+ val extraArgs = spaceDelimited(" [<output-dir>] [--justAPI]" ).parsed
1352+ val outputDirOverride = extraArgs.headOption.fold(identity[GenerationConfig ](_))(newDir => {
1353+ config : GenerationConfig => config.add(OutputDir (newDir))
1354+ })
1355+ val justAPIArg : Option [String ] = extraArgs.drop(1 ).find(_ == " --justAPI" )
1356+ val justAPI = justAPIArg.fold(identity[GenerationConfig ](_))(_ => {
1357+ config : GenerationConfig => config.remove[SiteRoot ]
1358+ })
1359+ val overrideFunc = outputDirOverride.andThen(justAPI)
1360+
1361+ val config = Def .task {
1362+ overrideFunc(Scala3 .value)
1363+ }
1364+
1365+ val writeAdditionalFiles = Def .task {
1366+ val dest = file(config.value.get[OutputDir ].get.value)
1367+ if (justAPIArg.isEmpty) {
1368+ IO .write(dest / " versions" / " latest-nightly-base" , majorVersion)
1369+ // This file is used by GitHub Pages when the page is available in a custom domain
1370+ IO .write(dest / " CNAME" , " dotty.epfl.ch" )
1371+ }
1372+ }
1373+
1374+ writeAdditionalFiles.dependsOn(generateDocumentation(config))
14161375 }.evaluated,
14171376
14181377 generateTestcasesDocumentation := Def .taskDyn {
1419- generateDocumentation(
1420- (Test / Build .testcasesOutputDir).value,
1421- " scaladoc testcases" ,
1422- " scaladoc/output/testcases" ,
1423- " main" ,
1424- Seq (" -usejavacp" , " -snippet-compiler:scaladoc-testcases/docs=compile" , " -siteroot" , " scaladoc-testcases/docs" )
1425- )
1378+ generateDocumentation(Testcases )
14261379 }.value,
14271380
14281381 Test / buildInfoKeys := Seq [BuildInfoKey ](
@@ -1803,3 +1756,123 @@ object Build {
18031756 })
18041757 }
18051758}
1759+
1760+ object ScaladocConfigs {
1761+ import Build ._
1762+ private lazy val currentYear : String = java.util.Calendar .getInstance().get(java.util.Calendar .YEAR ).toString
1763+
1764+ def dottyExternalMapping = " .*scala/.*::scaladoc3::https://dotty.epfl.ch/api/"
1765+ def javaExternalMapping = " .*java/.*::javadoc::https://docs.oracle.com/javase/8/docs/api/"
1766+
1767+ lazy val DefaultGenerationConfig = Def .task {
1768+ def distLocation = (dist / pack).value
1769+ def projectVersion = version.value
1770+ def stdLibVersion = stdlibVersion(NonBootstrapped )
1771+ def scalaLib = findArtifactPath(externalCompilerClasspathTask.value, " scala-library" )
1772+ def dottyLib = (`scala3-library` / Compile / classDirectory).value
1773+ def srcManaged (v : String , s : String ) = s " out/bootstrap/stdlib-bootstrapped/scala- $v/src_managed/main/ $s-library-src "
1774+ def scalaSrcLink (v : String , s : String ) = s " ${s}github://scala/scala/v $v#src/library "
1775+ def dottySrcLink (v : String , sourcesPrefix : String = " " , outputPrefix : String = " " ) =
1776+ sys.env.get(" GITHUB_SHA" ) match {
1777+ case Some (sha) =>
1778+ s " ${sourcesPrefix}github:// ${sys.env(" GITHUB_REPOSITORY" )}/ $sha$outputPrefix"
1779+ case None => s " ${sourcesPrefix}github://lampepfl/dotty/ $v$outputPrefix"
1780+ }
1781+
1782+ def defaultSourceLinks : SourceLinks = SourceLinks (
1783+ List (
1784+ scalaSrcLink(stdLibVersion, srcManaged(dottyNonBootstrappedVersion, " scala" ) + " =" ),
1785+ dottySrcLink(referenceVersion, srcManaged(dottyNonBootstrappedVersion, " dotty" ) + " =" , " #library/src" ),
1786+ dottySrcLink(referenceVersion),
1787+ " docs=github://lampepfl/dotty/main#docs"
1788+ )
1789+ )
1790+ def socialLinks = SocialLinks (List (
1791+ " github::https://github.com/lampepfl/dotty" ,
1792+ " discord::https://discord.com/invite/scala" ,
1793+ " twitter::https://twitter.com/scala_lang" ,
1794+ ))
1795+ def projectLogo = ProjectLogo (" docs/_assets/images/logo.svg" )
1796+ def skipByRegex = SkipByRegex (List (" .+\\ .internal($|\\ ..+)" , " .+\\ .impl($|\\ ..+)" ))
1797+ def skipById = SkipById (List (
1798+ " scala.runtime.stdLibPatches" ,
1799+ " scala.runtime.MatchCase"
1800+ ))
1801+ def projectFooter = ProjectFooter (s " Copyright (c) 2002- $currentYear, LAMP/EPFL " )
1802+ def defaultTemplate = DefaultTemplate (" static-site-main" )
1803+ GenerationConfig (
1804+ List (),
1805+ ProjectVersion (projectVersion),
1806+ GenerateInkuire (true ),
1807+ defaultSourceLinks,
1808+ skipByRegex,
1809+ skipById,
1810+ projectLogo,
1811+ socialLinks,
1812+ projectFooter,
1813+ defaultTemplate,
1814+ Author (true ),
1815+ Groups (true )
1816+ )
1817+ }
1818+
1819+ lazy val Scaladoc = Def .task {
1820+ DefaultGenerationConfig .value
1821+ .add(UseJavacp (true ))
1822+ .add(ProjectName (" scaladoc" ))
1823+ .add(OutputDir (" scaladoc/output/self" ))
1824+ .add(Revision (VersionUtil .gitHash))
1825+ .add(ExternalMappings (List (dottyExternalMapping, javaExternalMapping)))
1826+ .withTargets((Compile / classDirectory).value.getAbsolutePath :: Nil )
1827+ }
1828+
1829+ lazy val Testcases = Def .task {
1830+ val tastyRoots = (Test / Build .testcasesOutputDir).value
1831+ DefaultGenerationConfig .value
1832+ .add(UseJavacp (true ))
1833+ .add(OutputDir (" scaladoc/output/testcases" ))
1834+ .add(ProjectName (" scaladoc testcases" ))
1835+ .add(Revision (" main" ))
1836+ .add(SnippetCompiler (List (" scaladoc-testcases/docs=compile" )))
1837+ .add(SiteRoot (" scaladoc-testcases/docs" ))
1838+ .add(ExternalMappings (List (dottyExternalMapping, javaExternalMapping)))
1839+ .withTargets(tastyRoots)
1840+ }
1841+
1842+ lazy val Scala3 = Def .task {
1843+ val dottyJars : Seq [java.io.File ] = Seq (
1844+ (`stdlib-bootstrapped`/ Compile / products).value,
1845+ (`scala3-interfaces`/ Compile / products).value,
1846+ (`tasty-core-bootstrapped`/ Compile / products).value,
1847+ ).flatten
1848+
1849+ val roots = dottyJars.map(_.getAbsolutePath)
1850+
1851+ val managedSources =
1852+ (`stdlib-bootstrapped`/ Compile / sourceManaged).value / " scala-library-src"
1853+ val projectRoot = (ThisBuild / baseDirectory).value.toPath
1854+ val stdLibRoot = projectRoot.relativize(managedSources.toPath.normalize())
1855+ val docRootFile = stdLibRoot.resolve(" rootdoc.txt" )
1856+
1857+ val dottyManagesSources =
1858+ (`stdlib-bootstrapped`/ Compile / sourceManaged).value / " dotty-library-src"
1859+
1860+ val dottyLibRoot = projectRoot.relativize(dottyManagesSources.toPath.normalize())
1861+ DefaultGenerationConfig .value
1862+ .add(ProjectName (" Scala 3" ))
1863+ .add(OutputDir (file(" scaladoc/output/scala3" ).getAbsoluteFile.getAbsolutePath))
1864+ .add(Revision (" main" ))
1865+ .add(ExternalMappings (List (javaExternalMapping)))
1866+ .add(DocRootContent (docRootFile.toString))
1867+ .add(CommentSyntax (" wiki" ))
1868+ .add(VersionsDictionaryUrl (" https://scala-lang.org/api/versions.json" ))
1869+ .add(DocumentSyntheticTypes (true ))
1870+ .add(SnippetCompiler (List (
1871+ s " ${dottyLibRoot}/scala/quoted=compile " ,
1872+ s " ${dottyLibRoot}/scala/compiletime=compile "
1873+ )))
1874+ .add(SiteRoot (" docs" ))
1875+ .add(ApiSubdirectory (true ))
1876+ .withTargets(roots)
1877+ }
1878+ }
0 commit comments