stevedlawrence commented on pull request #681:
URL: https://github.com/apache/daffodil/pull/681#issuecomment-972915240
Regarding the version issue, I'm not sure of a way around that, but I'm not
too familar with IDE's. Might be some IDE setting.
I was curious to see if modifying build.sbt to add a new `sbt genExamples`
would be complicated or messy, and I think it actually turned out not too bad:
```scala
import sbt.internal.util.Util
import sbt.io.IO
import scala.sys.process.Process
lazy val genExamples = taskKey[Unit]("Generate runtime2 example files")
lazy val daffodil = project.in(file("."))...
.settings(..., genExamplesSettings)
...
lazy val genExamplesSettings = Seq(
Compile / genExamples := {
val tests = Seq(
"ex_nums.dfdl.xsd" -> "ex_nums",
"nested.dfdl.xsd" -> "NestedUnion",
)
// require that daffodil is staged
(cli / Universal / stage).value
// run "daffodil generate c" for each of the test files and copy the
results
// to the examples directory
val daffodilBinDir = (cli / Universal / stagingDirectory).value / "bin"
val daffodilBinExt = if (Util.isWindows) ".bat" else ""
val daffodilBin = daffodilBinDir / ("daffodil" + daffodilBinExt)
val rootDir = (runtime2 / Test / resourceDirectory).value / "org" /
"apache" / "daffodil" / "runtime2"
val logger = streams.value.log
tests.foreach { test =>
IO.withTemporaryDirectory { tmpDir =>
val res = Process(s"""${daffodilBin} generate c -s ${rootDir /
test._1} ${tmpDir}""").!
if (res != 0) {
logger.error(s"failed to generate example: ${test._1}")
}
val srcDir = tmpDir / "c" / "libruntime"
val tgtDir = rootDir / "examples" / test._2
IO.copyFile(srcDir / "generated_code.c", tgtDir / "generated_code.c")
IO.copyFile(srcDir / "generated_code.h", tgtDir / "generated_code.h")
}
}
},
)
```
It's maybe a bit slower since it requires staging the daffodil CLI, but that
isn't awful. And this doesn't have any version issues since it just executes
the daffodil CLI, which knows its version.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]