|
1 | 1 | package dotty.communitybuild
|
2 | 2 |
|
3 |
| -object Main { |
4 |
| - /** Builds stdlib. |
5 |
| - * |
6 |
| - * Output is available in build/pack/lib directory in stdlib project. |
7 |
| - * |
8 |
| - * In the future, we allow building different projects based on arguments, |
9 |
| - * but for now stdlib is the only usecase. |
10 |
| - */ |
| 3 | +import java.nio.file.Paths |
| 4 | +import java.nio.file.Path |
| 5 | +import java.nio.file.Files |
| 6 | +import scala.sys.process._ |
| 7 | + |
| 8 | + |
| 9 | +object Main: |
| 10 | + |
| 11 | + private def generateDocs(project: CommunityProject): Seq[Path] = |
| 12 | + val name = project.project |
| 13 | + try |
| 14 | + project.doc() |
| 15 | + val pathsOut = s"find community-projects/$name/ -name 'scala3doc.version'".!! |
| 16 | + pathsOut.linesIterator.map(Paths.get(_).getParent).toList |
| 17 | + catch |
| 18 | + case e: Exception => |
| 19 | + e.printStackTrace() |
| 20 | + Nil |
| 21 | + |
| 22 | + /** Allows running various commands on community build projects. */ |
11 | 23 | def main(args: Array[String]): Unit =
|
12 |
| - projects.stdLib213.publish() |
13 |
| -} |
| 24 | + args.toList match |
| 25 | + case "publish" :: name :: Nil => |
| 26 | + case "doc" :: "all" :: destStr :: Nil => |
| 27 | + val dest = Paths.get(destStr) |
| 28 | + Seq("rm", "-rf", "destStr").! |
| 29 | + Files.createDirectory(dest) |
| 30 | + val (toRun, ignored) = |
| 31 | + allProjects.partition(_.docCommand != null) |
| 32 | + |
| 33 | + val paths = toRun.map { project => |
| 34 | + val name = project.project |
| 35 | + val projectDest = dest.resolve(name) |
| 36 | + val projectRoot = Paths.get(s"community-projects/$name") |
| 37 | + println(s"generating docs for $name into $projectDest") |
| 38 | + val generatedDocs = generateDocs(project) |
| 39 | + if !Files.exists(projectDest) && generatedDocs.nonEmpty then |
| 40 | + Files.createDirectory(projectDest) |
| 41 | + |
| 42 | + val docsFiles = generatedDocs.map { docsPath => |
| 43 | + val destFileName = |
| 44 | + docsPath.subpath(2, docsPath.getNameCount).toString.replace('/', '_') |
| 45 | + |
| 46 | + Seq("cp", "-r", docsPath.toString, projectDest.resolve(destFileName).toString).! |
| 47 | + destFileName |
| 48 | + } |
| 49 | + name -> docsFiles |
| 50 | + } |
| 51 | + |
| 52 | + val (failed, withDocs) = paths.partition{ case (_, paths) => paths.isEmpty } |
| 53 | + |
| 54 | + val indexFile = withDocs.map { case (name, paths) => |
| 55 | + paths.map(p => s"""<a href="$name/$p/index.html">$p</a></br>\n""") |
| 56 | + .mkString(s"<h1>$name</h1>","\n", "\n") |
| 57 | + }.mkString("<html><body>\n", "\n", "\n</html></body>") |
| 58 | + |
| 59 | + Files.write(dest.resolve("index.html"), indexFile.getBytes) |
| 60 | + |
| 61 | + if ignored.nonEmpty then |
| 62 | + println(s"Ignored project without doc command: ${ignored.map(_.project)}") |
| 63 | + |
| 64 | + if failed.nonEmpty then |
| 65 | + println(s"Documentation not found for ${failed.map(_._1).mkString(", ")}") |
| 66 | + sys.exit(1) |
| 67 | + |
| 68 | + case "doc" :: names if names.nonEmpty => |
| 69 | + val missing = names.filterNot(projectMap.contains) |
| 70 | + if missing.nonEmpty then |
| 71 | + println(s"Missing projects: ${missing.mkString(", ")}. All projects: ${allProjects.mkString(", ")}") |
| 72 | + sys.exit(1) |
| 73 | + |
| 74 | + val failed = names.filter{ p => |
| 75 | + val docsRoots = generateDocs(projectMap(p)) |
| 76 | + if docsRoots.nonEmpty then println(s"Docs for $p generated in $docsRoots") |
| 77 | + docsRoots.isEmpty |
| 78 | + } |
| 79 | + if failed.nonEmpty then |
| 80 | + println(s"Documentation not found for ${failed.mkString(", ")}") |
| 81 | + sys.exit(1) |
| 82 | + |
| 83 | + case args => |
| 84 | + println("USAGE: <COMMAND> <PROJECT NAME>") |
| 85 | + println("COMMAND is one of: publish doc") |
| 86 | + println("Available projects are:") |
| 87 | + allProjects.foreach { k => |
| 88 | + println(s"\t$k") |
| 89 | + } |
| 90 | + sys.exit(1) |
| 91 | + |
0 commit comments