Skip to content

Commit 03607b2

Browse files
committed
[nomerge] Build man pages and scala-dist.jar from sbt
- ManMaker is compiled in a new subproject “manual”. A simple command line runner complements the ant task so that it can be run from sbt. - Another new subproject “scala-dist” is responsible for building the scala-dist.jar artifact.
1 parent 7a75c0f commit 03607b2

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

build.sbt

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ lazy val library = configureAsSubproject(project)
185185
includeFilter in unmanagedResources in Compile := "*.tmpl" | "*.xml" | "*.js" | "*.css" | "rootdoc.txt",
186186
// Include forkjoin classes in scala-library.jar
187187
mappings in Compile in packageBin ++=
188-
(mappings in Compile in packageBin in LocalProject("forkjoin")).value
188+
(mappings in Compile in packageBin in forkjoin).value
189189
)
190190
.settings(filterDocSources("*.scala" -- (regexFileFilter(".*/runtime/.*\\$\\.scala") ||
191191
regexFileFilter(".*/runtime/ScalaRunTime\\.scala") ||
@@ -395,6 +395,52 @@ lazy val test = project.
395395
)
396396
)
397397

398+
lazy val manual = configureAsSubproject(project)
399+
.settings(
400+
libraryDependencies ++= Seq(scalaXmlDep, antDep),
401+
classDirectory in Compile := (target in Compile).value / "classes"
402+
)
403+
.settings(disableDocsAndPublishingTasks: _*)
404+
.dependsOn(library)
405+
406+
lazy val scalaDist = Project("scala-dist", file(".") / "target" / "scala-dist-dist-src-dummy")
407+
.settings(commonSettings: _*)
408+
.settings(
409+
doc := file("!!! NO DOCS !!!"),
410+
mappings in Compile in packageBin ++= {
411+
val binBaseDir = buildDirectory.value / "pack"
412+
val binMappings = (mkBin in dist).value.pair(relativeTo(binBaseDir), errorIfNone = false)
413+
// With the way the resource files are spread out over the project sources we can't just add
414+
// an unmanagedResourceDirectory, so we generate the mappings manually:
415+
val docBaseDir = (baseDirectory in ThisBuild).value
416+
val docMappings = (docBaseDir / "doc").*** pair relativeTo(docBaseDir)
417+
val resBaseDir = (baseDirectory in ThisBuild).value / "src/manual/scala/tools/docutil/resources"
418+
val resMappings = resBaseDir ** ("*.html" | "*.css" | "*.gif" | "*.png") pair (p => relativeTo(resBaseDir)(p).map("doc/tools/" + _))
419+
docMappings ++ resMappings ++ binMappings
420+
},
421+
resourceGenerators in Compile += Def.task {
422+
val command = "fsc, scala, scalac, scaladoc, scalap"
423+
val htmlOut = (resourceManaged in Compile).value / "doc/tools"
424+
val manOut = (resourceManaged in Compile).value / "genman"
425+
val fixedManOut = (resourceManaged in Compile).value / "man"
426+
IO.createDirectory(htmlOut)
427+
IO.createDirectory(manOut / "man1")
428+
toError(runner.value.run("scala.tools.docutil.ManMaker",
429+
(fullClasspath in Compile in manual).value.files,
430+
Seq(command, htmlOut.getAbsolutePath, manOut.getAbsolutePath),
431+
streams.value.log))
432+
(manOut ** "*.1" pair rebase(manOut, fixedManOut)).foreach { case (in, out) =>
433+
// Generated manpages should always use LF only. There doesn't seem to be a good reason
434+
// for generating them with the platform EOL first and then converting them but that's
435+
// what the ant build does.
436+
IO.write(out, IO.readBytes(in).filterNot(_ == '\r'))
437+
}
438+
(htmlOut ** "*.html").get ++ (fixedManOut ** "*.1").get
439+
}.taskValue,
440+
managedResourceDirectories in Compile := Seq((resourceManaged in Compile).value),
441+
packageOptions in Compile in packageBin := Seq.empty
442+
)
443+
398444
lazy val root = (project in file(".")).
399445
aggregate(library, forkjoin, reflect, compiler, interactive, repl, replJline, replJlineEmbedded,
400446
scaladoc, scalap, actors, partestExtras, junit).settings(

src/manual/scala/tools/docutil/ManMaker.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,13 @@ class ManMaker extends Task {
5757
})
5858
}
5959
}
60+
61+
/** Command line runner for ManMaker which is called from the sbt build. */
62+
object ManMaker extends App {
63+
val Array(commands, htmlout, manout) = args
64+
val mm = new ManMaker
65+
mm.setCommand(commands)
66+
mm.setHtmlout(new File(htmlout))
67+
mm.setManout(new File(manout))
68+
mm.execute()
69+
}

0 commit comments

Comments
 (0)