Skip to content
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

Scala3doc/community build #10522

Merged
merged 7 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/scala3doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,36 @@ jobs:
echo uplading docs to https://scala3doc.virtuslab.com/$DOC_DEST
az storage container create --name $DOC_DEST --account-name scala3docstorage --public-access container
az storage blob sync -s scala3doc/output -c $DOC_DEST --account-name scala3docstorage

community-docs:
env:
AZURE_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_STORAGE_SAS_TOKEN }}
runs-on: ubuntu-latest
if: "github.event_name == 'pull_request' || contains(github.event.ref, 'scala3doc') || contains(github.event.ref, 'master')"

steps:
- name: Git Checkout
uses: actions/checkout@v2

- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8

- name: Init submodules
run: git submodule update --init --recursive --jobs 7

- name: Generate docs
run: ./project/scripts/sbt "community-build/run doc all docsOutput"

- name: Upload documentation to server
uses: azure/CLI@v1
if: env.AZURE_STORAGE_SAS_TOKEN
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
with:
inlineScript: |
DOC_DEST=pr-${PR_NUMBER:-${GITHUB_REF##*/}}-docs
echo uplading docs to https://scala3doc.virtuslab.com/$DOC_DEST
az storage container create --name $DOC_DEST --account-name scala3docstorage --public-access container
az storage blob sync -s community-build/docsOutput -c $DOC_DEST --account-name scala3docstorage
9 changes: 9 additions & 0 deletions community-build/src/scala/dotty/communitybuild/Fields.scala
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 community-build/src/scala/dotty/communitybuild/FieldsImpl.scala
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)} }
Copy link
Contributor

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?

98 changes: 88 additions & 10 deletions community-build/src/scala/dotty/communitybuild/Main.scala
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)

Loading