diff --git a/build.sbt b/build.sbt index a711217bfa..58ac01f026 100644 --- a/build.sbt +++ b/build.sbt @@ -24,6 +24,7 @@ lazy val genProps = taskKey[Seq[File]]("Generate properties scala source") lazy val genSchemas = taskKey[Seq[File]]("Generate DFDL schemas") lazy val genCExamples = taskKey[Seq[File]]("Generate C example files") lazy val genVersion = taskKey[Seq[File]]("Generate VERSION file") +lazy val genTunablesDoc = taskKey[Unit]("Generate tunables docs from dafext.xsd file") lazy val daffodil = project .in(file(".")) @@ -52,7 +53,14 @@ lazy val daffodil = project tutorials, udf ) - .settings(commonSettings, nopublish, ratSettings, unidocSettings, genCExamplesSettings) + .settings( + commonSettings, + nopublish, + ratSettings, + unidocSettings, + genTunablesDocSettings, + genCExamplesSettings + ) lazy val macroLib = Project("daffodil-macro-lib", file("daffodil-macro-lib")) .settings(commonSettings, nopublish) @@ -481,6 +489,99 @@ lazy val unidocSettings = (JavaUnidoc / unidoc / unidocAllSources).value.map(apiDocSourceFilter) ) +lazy val genTunablesDocSettings = Seq( + Compile / genTunablesDoc := { + val dafExtFile = + (propgen / Compile / resources).value.filter(_.getName == "dafext.xsd").head + val outputDocFile = (Compile / target).value / "tunables.md" + // parse xsd file + val dafExtXml = scala.xml.XML.loadFile(dafExtFile) + // extract information + val tunablesSeq = (dafExtXml \ "element" \\ "element") + // build documentation + val sectionsSeq = tunablesSeq.flatMap { ele => + val subtitle = ele \@ "name" + val documentation = (ele \ "annotation" \ "documentation").text + val sections = + if (documentation.nonEmpty && !documentation.trim.startsWith("Deprecated")) { + val s = + s""" + |#### $subtitle + |$documentation + |""".stripMargin + Some(s) + } else { + None + } + sections + } + val documentationPage = + s"""|--- + |layout: page + |title: DFDL Tunables + |group: nav-right + |--- + | + | + | + |Daffodil provides tunables as a way to change its behavior. + |Tunables are set by way of the ``tunables`` element in [config files](/configuration) + |or from the [cli](/cli) via the ``-T`` option. + | + |#### Config Example + | ``` xml + | + | + | + | encodingErrorPolicyError + | + | + | + | ``` + | + | The config file can then be passed into daffodil subcommands via the ``-c|--config`` options. + | + |#### CLI Example + | ``` bash + | daffodil parse -s schema.xsd -TsuppressSchemaDefinitionWarnings="encodingErrorPolicyError" data.bin + | ``` + | + | + |### Definitions + |${sectionsSeq.mkString("\n")} + |""".stripMargin + IO.write(outputDocFile, s"$documentationPage") + println(s"Generated tunables documentation at: $outputDocFile") + }, + Compile / compile := { + val res = (Compile / compile).value + (Compile / genTunablesDoc).value + res + } +) + lazy val genCExamplesSettings = Seq( Compile / genCExamples := { val cp = (codeGenC / Test / dependencyClasspath).value