-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add schema validation code to C generator #1098
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,32 +59,53 @@ Compile source code: | |
|
||
sbt compile | ||
|
||
### Tests | ||
### Test | ||
|
||
Run unit tests: | ||
Check all unit tests pass: | ||
|
||
sbt test | ||
|
||
Run slower integration tests: | ||
Check all integration tests pass: | ||
|
||
sbt daffodil-test-integration/test | ||
|
||
### Command Line Interface | ||
### Format | ||
|
||
Build the command line interface (Linux and Windows shell scripts in | ||
`daffodil-cli/target/universal/stage/bin/`; see the [Command Line | ||
Interface] documentation for details on their usage): | ||
Check format of source and sbt files: | ||
|
||
sbt scalafmtCheckAll scalafmtSbtCheck | ||
|
||
Reformat source and sbt files if necessary: | ||
|
||
sbt scalafmtAll scalafmtSbt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth adding commands for what you use to format h C code? Maybe for a future PR, it might be worth adding an sbt task that executes those commands with the right options (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we can write a sbt task which runs clang-format on the C files and errors if it finds and reports any diffs. However, some people may get an error running the task (especially if the task's purpose is to run all the language formatters from a single command) since clang-format is not commonly installed on many (most?) machines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. As long as the error is something useful that should be fine. I recommend doing it later though, doesn't have to be part of this PR. |
||
|
||
### Build | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we need another build section for building and locally publishing the jars? Anyone developing something integrating Daffodil may want that. Maybe something like this?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'll document the publish commands too and explain Ivy is also used by sbt to build schema-only projects. |
||
|
||
Build the Daffodil command line interface (Linux and Windows shell | ||
scripts in `daffodil-cli/target/universal/stage/bin/`; see the | ||
[Command Line Interface] documentation for details on their usage): | ||
|
||
sbt daffodil-cli/stage | ||
|
||
### License Check | ||
Publish the Daffodil jars to a Maven repository (for Java projects) or | ||
Ivy repository (for Scala or schema projects). | ||
|
||
Maven (for Java or mvn): | ||
|
||
sbt publishM2 | ||
|
||
Ivy (for Scala or sbt): | ||
|
||
sbt publishLocal | ||
|
||
### Check Licenses | ||
|
||
Run [Apache RAT] (license audit report in `target/rat.txt` and error | ||
if any unapproved licenses are found): | ||
|
||
sbt ratCheck | ||
|
||
### Test Coverage Report | ||
### Check Coverage | ||
|
||
Run [sbt-scoverage] (report in `target/scala-ver/scoverage-report/`): | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
// auto-maintained by iwyu | ||
// clang-format off | ||
#include "daffodil_getopt.h" | ||
#include <string.h> // for strcmp, strrchr | ||
|
@@ -29,23 +30,15 @@ struct daffodil_cli daffodil_cli = { | |
DAFFODIL_MISSING_COMMAND, // default subcommand | ||
}; | ||
|
||
// Initialize our "daffodil parse" CLI options | ||
// Initialize our "daffodil parse/unparse" CLI options | ||
|
||
struct daffodil_parse_cli daffodil_parse = { | ||
struct daffodil_pu_cli daffodil_pu = { | ||
"xml", // default infoset type | ||
"-", // default infile | ||
"-", // default outfile | ||
false, // default validate | ||
}; | ||
|
||
// Initialize our "daffodil unparse" CLI options | ||
|
||
struct daffodil_unparse_cli daffodil_unparse = { | ||
"xml", // default infoset type | ||
"-", // default infile | ||
"-", // default outfile | ||
}; | ||
|
||
// Parse our command line interface. Note there is NO portable way to | ||
// parse "daffodil [options] command [more options] arguments" with | ||
// getopt. We will have to put all options before all arguments, | ||
|
@@ -63,7 +56,7 @@ parse_daffodil_cli(int argc, char *argv[]) | |
|
||
// We expect callers to put all non-option arguments at the end | ||
int opt = 0; | ||
while ((opt = getopt(argc, argv, ":hI:o:V:v")) != -1) | ||
while ((opt = getopt(argc, argv, ":hI:o:r:s:V:v")) != -1) | ||
{ | ||
switch (opt) | ||
{ | ||
|
@@ -78,17 +71,21 @@ parse_daffodil_cli(int argc, char *argv[]) | |
error.arg.s = optarg; | ||
return &error; | ||
} | ||
daffodil_parse.infoset_converter = optarg; | ||
daffodil_unparse.infoset_converter = optarg; | ||
daffodil_pu.infoset_converter = optarg; | ||
break; | ||
case 'o': | ||
daffodil_parse.outfile = optarg; | ||
daffodil_unparse.outfile = optarg; | ||
daffodil_pu.outfile = optarg; | ||
break; | ||
case 'r': | ||
// Ignore "-r root" option/optarg | ||
break; | ||
case 's': | ||
// Ignore "-s schema" option/optarg | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand this, why of options to just ignore them? Seems that could be very confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A workflow I sometimes use with code generators, DFDL schemas, and TDML tests is to run I thought I could hide this behavior from users (the usage message doesn't mention the -r and -s options) while making life easier for developers and testers who know about this hidden behavior for greater compatibility between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, makes sense. As long as the optinos aren't in the usage I think it's fine. But it would be worth adding that reasoning as a comment. |
||
case 'V': | ||
if (strcmp("limited", optarg) == 0 || strcmp("on", optarg) == 0) | ||
{ | ||
daffodil_parse.validate = true; | ||
daffodil_pu.validate = true; | ||
} | ||
else if (strcmp("off", optarg) != 0) | ||
{ | ||
|
@@ -122,25 +119,14 @@ parse_daffodil_cli(int argc, char *argv[]) | |
{ | ||
const char *arg = argv[i]; | ||
|
||
if (DAFFODIL_PARSE == daffodil_cli.subcommand) | ||
{ | ||
if (strcmp("-", daffodil_parse.infile) == 0) | ||
{ | ||
daffodil_parse.infile = arg; | ||
} | ||
else | ||
{ | ||
error.code = CLI_UNEXPECTED_ARGUMENT; | ||
error.arg.s = arg; | ||
return &error; | ||
} | ||
} | ||
else if (DAFFODIL_UNPARSE == daffodil_cli.subcommand) | ||
if (DAFFODIL_MISSING_COMMAND != daffodil_cli.subcommand) | ||
{ | ||
if (strcmp("-", daffodil_unparse.infile) == 0) | ||
// Set infile only once | ||
if (strcmp("-", daffodil_pu.infile) == 0) | ||
{ | ||
daffodil_unparse.infile = arg; | ||
daffodil_pu.infile = arg; | ||
} | ||
// Error if infile is followed by another arg | ||
else | ||
{ | ||
error.code = CLI_UNEXPECTED_ARGUMENT; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#ifndef DAFFODIL_GETOPT_H | ||
#define DAFFODIL_GETOPT_H | ||
|
||
// auto-maintained by iwyu | ||
// clang-format off | ||
#include <stdbool.h> // for bool | ||
#include "errors.h" // for Error | ||
|
@@ -35,24 +36,15 @@ extern struct daffodil_cli | |
} subcommand; | ||
} daffodil_cli; | ||
|
||
// Declare our "daffodil parse" CLI options | ||
// Declare our "daffodil parse/unparse" CLI options | ||
|
||
extern struct daffodil_parse_cli | ||
extern struct daffodil_pu_cli | ||
{ | ||
const char *infoset_converter; | ||
const char *infile; | ||
const char *outfile; | ||
bool validate; | ||
} daffodil_parse; | ||
|
||
// Declare our "daffodil unparse" CLI options | ||
|
||
extern struct daffodil_unparse_cli | ||
{ | ||
const char *infoset_converter; | ||
const char *infile; | ||
const char *outfile; | ||
} daffodil_unparse; | ||
bool validate; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this change 👍 . I've never been a huge fan of aligning variable names in C. |
||
} daffodil_pu; | ||
|
||
// Parse our command line interface | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: why give people the choice?
We don't have to provide this flexibility unless we or users depend on it for some reason.
This works, so "it aint broke" so no need to change anything. I just wanted to comment that we don't really have to provide options like this unless they're really really required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're talking about the paragraph
If you want to use clang instead of gcc, ...
, I originally added that paragraph because you told me you didn't want to require GNU-licensed tools to develop or use any part of Daffodil. I even made sure that the GitHub Action workflow (main.yml) would set these environment variables to build Daffodil with clang and lvvm-ar instead of gcc and ar. I can reword the paragraph to say you can set these environment variables to use clang and llvm-ar instead of gcc and ar if you have a policy forbidding GNU-licensed tools.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, gcc is GPLv3 which is category X, so I had concerns about implying it was required. I did find this open Jira LEGAL issue that discusses this:
https://issues.apache.org/jira/browse/LEGAL-390?jql=project+%3D+LEGAL+AND+text+%7E+%22gcc%22+ORDER+BY+updated+DESC%2C+priority+DESC
Sounds like the resolution it's it's fine to use. I'd suggest we still do mention clang support so that people can use it if they want and don't have to figure it all out. But maybe that's an addendum or something, and everything else implies the use of gcc if the goal is to simplify this?