stevedlawrence edited a comment 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
   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",
       )
   
       val rootDir = (runtime2 / Test / resourceDirectory).value / "org" / 
"apache" / "daffodil" / "runtime2"
       val cp = (cli / Runtime / dependencyClasspath).value
       val stream = streams.value
       val mainClass = "org.apache.daffodil.Main"
       val forkOpts = ForkOptions()
                      .withBootJars(cp.files.toVector)
       tests.foreach { test =>
         IO.withTemporaryDirectory { tmpDir =>
           val args = Seq(mainClass, "generate", "c", "-s", (rootDir / 
test._1).toString, tmpDir.toString)
           val ret = Fork.java(forkOpts, args)
           if (ret != 0) {
             stream.log.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")
         }
       }
     },
   )
   ```
   
   This depends on the Daffodil jars being built, and then fors java with the 
correct arguments to the run the CLI C generator to generate code to a temp 
directory and copy the generated files to the example directory.


-- 
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]


Reply via email to