-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Scala3doc/community build #10522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Scala3doc/community build #10522
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f564342
Allow documenting community build projects
abgruszecki 435f530
Add changes needed to run docs on many project
romanowski 9150f64
community build can run doc on supported tasksFix sources in doc
romanowski db5da88
Improve doc builds in community-build and fix tests
romanowski ad17a28
Run doc on community build over CI
romanowski 5acae67
Fix problems and add logging from doc commands
romanowski 042d58d
Use inline macro to build projectMap
romanowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dotty.communitybuild | ||
|
||
import scala.quoted.Type | ||
|
||
class FieldsDsl[V](v: V): | ||
inline def of[T]: Seq[T] = FieldsImpl.fieldsOfType[V, T](v) | ||
|
||
extension [V](on: V): | ||
def fields = FieldsDsl(on) |
17 changes: 17 additions & 0 deletions
17
community-build/src/scala/dotty/communitybuild/FieldsImpl.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dotty.communitybuild | ||
|
||
import scala.quoted._ | ||
|
||
object FieldsImpl: | ||
inline def fieldsOfType[V, T](inline v: V): Seq[T] = | ||
${ fieldsImpl[V, T]('v) } | ||
|
||
def fieldsImpl[V: Type, T: Type](from: Expr[V])(using Quotes): Expr[Seq[T]] = | ||
import quotes.reflect._ | ||
val retType = TypeTree.of[T].tpe | ||
def isProjectField(s: Symbol) = | ||
s.isValDef && s.tree.asInstanceOf[ValDef].tpt.tpe <:< retType | ||
val projectsTree = Term.of(from) | ||
val symbols = TypeTree.of[V].symbol.members.filter(isProjectField) | ||
val selects = symbols.map(Select(projectsTree, _).asExprOf[T]) | ||
'{ println(${Expr(retType.show)}); ${Varargs(selects)} } | ||
98 changes: 88 additions & 10 deletions
98
community-build/src/scala/dotty/communitybuild/Main.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,91 @@ | ||
package dotty.communitybuild | ||
|
||
object Main { | ||
/** Builds stdlib. | ||
* | ||
* Output is available in build/pack/lib directory in stdlib project. | ||
* | ||
* In the future, we allow building different projects based on arguments, | ||
* but for now stdlib is the only usecase. | ||
*/ | ||
import java.nio.file.Paths | ||
import java.nio.file.Path | ||
import java.nio.file.Files | ||
import scala.sys.process._ | ||
|
||
|
||
object Main: | ||
|
||
private def generateDocs(project: CommunityProject): Seq[Path] = | ||
val name = project.project | ||
try | ||
project.doc() | ||
val pathsOut = s"find community-projects/$name/ -name 'scala3doc.version'".!! | ||
pathsOut.linesIterator.map(Paths.get(_).getParent).toList | ||
catch | ||
case e: Exception => | ||
e.printStackTrace() | ||
Nil | ||
|
||
/** Allows running various commands on community build projects. */ | ||
def main(args: Array[String]): Unit = | ||
projects.stdLib213.publish() | ||
} | ||
args.toList match | ||
case "publish" :: name :: Nil => | ||
case "doc" :: "all" :: destStr :: Nil => | ||
val dest = Paths.get(destStr) | ||
Seq("rm", "-rf", "destStr").! | ||
Files.createDirectory(dest) | ||
val (toRun, ignored) = | ||
allProjects.partition(_.docCommand != null) | ||
|
||
val paths = toRun.map { project => | ||
val name = project.project | ||
val projectDest = dest.resolve(name) | ||
val projectRoot = Paths.get(s"community-projects/$name") | ||
println(s"generating docs for $name into $projectDest") | ||
val generatedDocs = generateDocs(project) | ||
if !Files.exists(projectDest) && generatedDocs.nonEmpty then | ||
Files.createDirectory(projectDest) | ||
|
||
val docsFiles = generatedDocs.map { docsPath => | ||
val destFileName = | ||
docsPath.subpath(2, docsPath.getNameCount).toString.replace('/', '_') | ||
|
||
Seq("cp", "-r", docsPath.toString, projectDest.resolve(destFileName).toString).! | ||
destFileName | ||
} | ||
name -> docsFiles | ||
} | ||
|
||
val (failed, withDocs) = paths.partition{ case (_, paths) => paths.isEmpty } | ||
|
||
val indexFile = withDocs.map { case (name, paths) => | ||
paths.map(p => s"""<a href="$name/$p/index.html">$p</a></br>\n""") | ||
.mkString(s"<h1>$name</h1>","\n", "\n") | ||
}.mkString("<html><body>\n", "\n", "\n</html></body>") | ||
|
||
Files.write(dest.resolve("index.html"), indexFile.getBytes) | ||
|
||
if ignored.nonEmpty then | ||
println(s"Ignored project without doc command: ${ignored.map(_.project)}") | ||
|
||
if failed.nonEmpty then | ||
println(s"Documentation not found for ${failed.map(_._1).mkString(", ")}") | ||
sys.exit(1) | ||
|
||
case "doc" :: names if names.nonEmpty => | ||
val missing = names.filterNot(projectMap.contains) | ||
if missing.nonEmpty then | ||
println(s"Missing projects: ${missing.mkString(", ")}. All projects: ${allProjects.mkString(", ")}") | ||
sys.exit(1) | ||
|
||
val failed = names.filter{ p => | ||
val docsRoots = generateDocs(projectMap(p)) | ||
if docsRoots.nonEmpty then println(s"Docs for $p generated in $docsRoots") | ||
docsRoots.isEmpty | ||
} | ||
if failed.nonEmpty then | ||
println(s"Documentation not found for ${failed.mkString(", ")}") | ||
sys.exit(1) | ||
|
||
case args => | ||
println("USAGE: <COMMAND> <PROJECT NAME>") | ||
println("COMMAND is one of: publish doc") | ||
println("Available projects are:") | ||
allProjects.foreach { k => | ||
println(s"\t$k") | ||
} | ||
sys.exit(1) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Macro looks ok, but the
println
probably shouldn't be here, no?