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

Expose Sphinx option to treat warnings as errors #154

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions src/main/scala/com/typesafe/sbt/site/sphinx/SphinxHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.typesafe.sbt.site.Compat.{Process, _}
/**
* Combined inputs for Sphinx runner.
*/
case class SphinxInputs(src: File, include: FileFilter, exclude: FileFilter, incremental: Boolean, tags: Seq[String], properties: Map[String, String], env: Map[String, String])
case class SphinxInputs(src: File, include: FileFilter, exclude: FileFilter, incremental: Boolean, warningIsError: Boolean, tags: Seq[String], properties: Map[String, String], env: Map[String, String])

object SphinxRunner {
/**
Expand Down Expand Up @@ -55,16 +55,16 @@ private[sphinx] class CommandLineSphinxRunner extends SphinxRunner {
}

def generateHtml(inputs: SphinxInputs, target: File, cacheDir: File, log: Logger): File = {
sphinxBuild("html", inputs.src, inputs.include, inputs.exclude, target, cacheDir, inputs.incremental, inputs.tags, inputs.properties, inputs.env, log)
sphinxBuild("html", inputs.src, inputs.include, inputs.exclude, target, cacheDir, inputs.incremental, inputs.warningIsError, inputs.tags, inputs.properties, inputs.env, log)
}

def generatePdf(inputs: SphinxInputs, target: File, cacheDir: File, log: Logger): Seq[File] = {
val latexOutput = sphinxBuild("latex", inputs.src, inputs.include, inputs.exclude, target, cacheDir, inputs.incremental, inputs.tags, inputs.properties, inputs.env, log)
val latexOutput = sphinxBuild("latex", inputs.src, inputs.include, inputs.exclude, target, cacheDir, inputs.incremental, inputs.warningIsError, inputs.tags, inputs.properties, inputs.env, log)
makePdf(latexOutput, log)
}

def generateEpub(inputs: SphinxInputs, target: File, cacheDir: File, log: Logger): File = {
sphinxBuild("epub", inputs.src, inputs.include, inputs.exclude, target, cacheDir, inputs.incremental, inputs.tags, inputs.properties, inputs.env, log)
sphinxBuild("epub", inputs.src, inputs.include, inputs.exclude, target, cacheDir, inputs.incremental, inputs.warningIsError, inputs.tags, inputs.properties, inputs.env, log)
}

/**
Expand Down Expand Up @@ -97,7 +97,7 @@ private[sphinx] class CommandLineSphinxRunner extends SphinxRunner {
* Run sphinx-build with a given builder (html or latex).
* @return output directory
*/
private def sphinxBuild(builder: String, src: File, include: FileFilter, exclude: FileFilter, baseTarget: File, cacheDir: File, incremental: Boolean, tags: Seq[String], properties: Map[String, String], env: Map[String,String], log: Logger): File = {
private def sphinxBuild(builder: String, src: File, include: FileFilter, exclude: FileFilter, baseTarget: File, cacheDir: File, incremental: Boolean, warningIsError: Boolean, tags: Seq[String], properties: Map[String, String], env: Map[String,String], log: Logger): File = {
val target = baseTarget / builder
val doctrees = baseTarget / "doctrees" / builder
val cache = cacheDir / "sphinx" / builder
Expand All @@ -110,10 +110,11 @@ private[sphinx] class CommandLineSphinxRunner extends SphinxRunner {
if (!incremental) IO.delete(target)
val logger = sphinxLogger(log)
val buildOptions = if (!incremental) Seq("-a", "-E") else Seq.empty[String]
val warningOptions = if (warningIsError) Seq("-W") else Seq.empty[String]
val colourOptions = Seq("-N")
val tagOptions = tags flatMap (Seq("-t", _))
val propertyOptions = (properties map { case (k, v) => "-D%s=%s" format (k, v) }).toSeq
val command = Seq("sphinx-build") ++ buildOptions ++ colourOptions ++ Seq("-b", builder, "-d", doctrees.absolutePath) ++ tagOptions ++ propertyOptions ++ Seq(src.absolutePath, target.absolutePath)
val command = Seq("sphinx-build") ++ buildOptions ++ warningOptions ++ colourOptions ++ Seq("-b", builder, "-d", doctrees.absolutePath) ++ tagOptions ++ propertyOptions ++ Seq(src.absolutePath, target.absolutePath)
log.debug("Command: " + command.mkString(" "))
log.debug("Environment: " + env)
val exitCode = Process(command, src, env.toSeq : _*) ! logger
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/typesafe/sbt/site/sphinx/SphinxKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ trait SphinxKeys {
"sphinx-properties", "-D options that should be passed when running Sphinx.")
val sphinxIncremental = SettingKey[Boolean](
"sphinx-incremental", "Use incremental Sphinx building. Off by default.")
val sphinxWarningIsError = SettingKey[Boolean](
"sphinx-warningiserror", "Treat warnings as errors. Off by default.")
val sphinxInputs = TaskKey[SphinxInputs](
"sphinx-inputs", "Combined inputs for the Sphinx runner.")
val sphinxRunner = TaskKey[SphinxRunner](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object SphinxPlugin extends AutoPlugin {
sphinxProperties := Map.empty,
sphinxEnv := Map.empty,
sphinxIncremental := false,
sphinxWarningIsError := false,
includeFilter in generate := AllPassFilter,
excludeFilter in generate := HiddenFileFilter,
sphinxInputs := combineSphinxInputs.value,
Expand Down Expand Up @@ -78,6 +79,7 @@ object SphinxPlugin extends AutoPlugin {
(includeFilter in generate).value,
(excludeFilter in generate).value,
sphinxIncremental.value,
sphinxWarningIsError.value,
sphinxTags.value,
sphinxProperties.value,
sphinxEnv.value
Expand Down