You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by ji...@apache.org on 2021/12/09 18:34:42 UTC
[daffodil] branch main updated: Rename version header and update C code generator
This is an automated email from the ASF dual-hosted git repository.
jinterrante pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git
The following commit(s) were added to refs/heads/main by this push:
new 08c5a7b Rename version header and update C code generator
08c5a7b is described below
commit 08c5a7ba412ace8c1b5847ed6e12abe85af78ae1
Author: John Interrante <in...@research.ge.com>
AuthorDate: Thu Dec 9 11:16:26 2021 -0500
Rename version header and update C code generator
StringDataInputStreamForUnparse.scala: Restore // $COVERAGE-ON$
because there's a // $COVERAGE-OFF$ preceding it (misc fix too small
for its own JIRA issue).
.clang-format: Move from resources to c so it will be included
alongside Makefile in C code generator's output directory (Makefile
has a "format" goal which needs our .clang-format to do it right).
daffodil_getopt.c: Include renamed version header and add iwyu
comment. Rename daffodil_program_version to match version header's
name.
version.h: Rename to daffodil_version.h (looks better in dired
listing). Also rename include guards and daffodil_program_version to
match version header's name.
CodeGenerator.scala: Change version header's name and reorder lines
better semantically.
CodeGeneratorState.scala: Rename include guards and
daffodil_program_version to match version header's name.
DAFFODIL-2592
---
.../apache/daffodil/io/StringDataInputStreamForUnparse.scala | 2 +-
.../{ => org/apache/daffodil/runtime2/c}/.clang-format | 0
.../org/apache/daffodil/runtime2/c/libcli/daffodil_getopt.c | 10 +++++-----
.../runtime2/c/libcli/{version.h => daffodil_version.h} | 10 +++++-----
.../scala/org/apache/daffodil/runtime2/CodeGenerator.scala | 6 +++---
.../daffodil/runtime2/generators/CodeGeneratorState.scala | 10 +++++-----
6 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/daffodil-io/src/main/scala/org/apache/daffodil/io/StringDataInputStreamForUnparse.scala b/daffodil-io/src/main/scala/org/apache/daffodil/io/StringDataInputStreamForUnparse.scala
index 2a4f1dc..0180d2a 100644
--- a/daffodil-io/src/main/scala/org/apache/daffodil/io/StringDataInputStreamForUnparse.scala
+++ b/daffodil-io/src/main/scala/org/apache/daffodil/io/StringDataInputStreamForUnparse.scala
@@ -66,7 +66,6 @@ final class StringDataInputStreamForUnparse
// $COVERAGE-OFF$ Nothing should be calling these.
private def doNotUse = Assert.usageError("Not to be called on " + Misc.getNameFromClass(this))
-
override def futureData(nBytesRequested: Int): java.nio.ByteBuffer = doNotUse
override def getBinaryDouble(finfo: FormatInfo): Double = doNotUse
override def getBinaryFloat(finfo: FormatInfo): Float = doNotUse
@@ -83,4 +82,5 @@ final class StringDataInputStreamForUnparse
override def hasData: Boolean = doNotUse
override def skip(nBits: Long, finfo: FormatInfo): Boolean = doNotUse
override def resetBitLimit0b(savedBitLimit0b: MaybeULong): Unit = doNotUse
+ // $COVERAGE-ON$
}
diff --git a/daffodil-runtime2/src/main/resources/.clang-format b/daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/.clang-format
similarity index 100%
rename from daffodil-runtime2/src/main/resources/.clang-format
rename to daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/.clang-format
diff --git a/daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/daffodil_getopt.c b/daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/daffodil_getopt.c
index dabb2d6..8605ecc 100644
--- a/daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/daffodil_getopt.c
+++ b/daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/daffodil_getopt.c
@@ -17,10 +17,10 @@
// clang-format off
#include "daffodil_getopt.h"
-#include <string.h> // for strcmp, strrchr
-#include <unistd.h> // for optarg, getopt, optopt, optind
-#include "cli_errors.h" // for CLI_UNEXPECTED_ARGUMENT, CLI_HELP_USAGE, CLI_INVALID_COMMAND, CLI_INVALID_INFOSET, CLI_INVALID_OPTION, CLI_MISSING_COMMAND, CLI_MISSING_VALUE, CLI_PROGRAM_ERROR, CLI_PROGRAM_VERSION
-#include "version.h"
+#include <string.h> // for strcmp, strrchr
+#include <unistd.h> // for optarg, getopt, optopt, optind
+#include "cli_errors.h" // for CLI_UNEXPECTED_ARGUMENT, CLI_HELP_USAGE, CLI_INVALID_COMMAND, CLI_INVALID_INFOSET, CLI_INVALID_OPTION, CLI_MISSING_COMMAND, CLI_MISSING_VALUE, CLI_PROGRAM_ERROR, CLI_PROGRAM_VERSION
+#include "daffodil_version.h" // for daffodil_version
// clang-format on
// Initialize our "daffodil" CLI options
@@ -86,7 +86,7 @@ parse_daffodil_cli(int argc, char *argv[])
break;
case 'V':
error.code = CLI_PROGRAM_VERSION;
- error.arg.s = daffodil_program_version;
+ error.arg.s = daffodil_version;
return &error;
case ':':
error.code = CLI_MISSING_VALUE;
diff --git a/daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/version.h b/daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/daffodil_version.h
similarity index 82%
rename from daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/version.h
rename to daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/daffodil_version.h
index 23a9a88..50659c2 100644
--- a/daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/version.h
+++ b/daffodil-runtime2/src/main/resources/org/apache/daffodil/runtime2/c/libcli/daffodil_version.h
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-#ifndef VERSION_H
-#define VERSION_H
+#ifndef DAFFODIL_VERSION_H
+#define DAFFODIL_VERSION_H
-// This file will be overwritten with the correct program version information
+// This file will be overwritten with the correct Daffodil version information
// when code is generated. This file exists here to support compiling the other
// C files without generated code during Daffodil builds to ensure there are no
// compilation errors in these C files.
-const char *daffodil_program_version = "DAFFODIL_PROGRAM_VERSION";
+const char *daffodil_version = "DAFFODIL VERSION";
-#endif // VERSION_H
+#endif // DAFFODIL_VERSION_H
diff --git a/daffodil-runtime2/src/main/scala/org/apache/daffodil/runtime2/CodeGenerator.scala b/daffodil-runtime2/src/main/scala/org/apache/daffodil/runtime2/CodeGenerator.scala
index 06b15e3..6da98a3 100644
--- a/daffodil-runtime2/src/main/scala/org/apache/daffodil/runtime2/CodeGenerator.scala
+++ b/daffodil-runtime2/src/main/scala/org/apache/daffodil/runtime2/CodeGenerator.scala
@@ -90,17 +90,17 @@ class CodeGenerator(root: Root) extends DFDL.CodeGenerator {
val codeGeneratorState = new CodeGeneratorState()
Runtime2CodeGenerator.generateCode(root.document, codeGeneratorState)
diagnostics = diagnostics ++ root.warnings
+ val versionHeaderText = codeGeneratorState.generateVersionHeader
val codeHeaderText = codeGeneratorState.generateCodeHeader
val codeFileText = codeGeneratorState.generateCodeFile(rootElementName)
- val versionHeaderText = codeGeneratorState.generateVersionHeader
// Write the generated C code into our code subdirectory
+ val generatedVersionHeader = codeDir/"libcli"/"daffodil_version.h"
val generatedCodeHeader = codeDir/"libruntime"/"generated_code.h"
val generatedCodeFile = codeDir/"libruntime"/"generated_code.c"
- val generatedVersionHeader = codeDir/"libcli"/"version.h"
+ os.write.over(generatedVersionHeader, versionHeaderText)
os.write(generatedCodeHeader, codeHeaderText)
os.write(generatedCodeFile, codeFileText)
- os.write.over(generatedVersionHeader, versionHeaderText)
// Return our code directory in case caller wants to call compileCode next
codeDir
diff --git a/daffodil-runtime2/src/main/scala/org/apache/daffodil/runtime2/generators/CodeGeneratorState.scala b/daffodil-runtime2/src/main/scala/org/apache/daffodil/runtime2/generators/CodeGeneratorState.scala
index 1ae4c94..25d5a1e 100644
--- a/daffodil-runtime2/src/main/scala/org/apache/daffodil/runtime2/generators/CodeGeneratorState.scala
+++ b/daffodil-runtime2/src/main/scala/org/apache/daffodil/runtime2/generators/CodeGeneratorState.scala
@@ -609,15 +609,15 @@ class CodeGeneratorState {
}
def generateVersionHeader: String = {
- val program = this.getClass.getPackage.getImplementationTitle
+ val daffodil = this.getClass.getPackage.getImplementationTitle
val version = this.getClass.getPackage.getImplementationVersion
val versionHeader =
- s"""#ifndef VERSION_H
- |#define VERSION_H
+ s"""#ifndef DAFFODIL_VERSION_H
+ |#define DAFFODIL_VERSION_H
|
- |const char *daffodil_program_version = "$program $version";
+ |const char *daffodil_version = "$daffodil $version";
|
- |#endif // VERSION_H
+ |#endif // DAFFODIL_VERSION_H
|""".stripMargin
versionHeader.replace("\r\n", "\n").replace("\n", System.lineSeparator)
}