Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 231d6d1

Browse files
committed
Domain generation: Report the number of error that occurred
If error occurred during parsing, they were only logged, not reported in the exit code. Report the number of parsing errors with the program exit code. Signed-off-by: Kevin Rocard <[email protected]>
1 parent 2b7905f commit 231d6d1

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

test/xml-generator/test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@
5858
tofile="-",
5959
lineterm="")
6060
diffs = list(unified)
61-
if not diffs:
62-
sys.exit(0)
63-
else:
61+
if diffs:
6462
for d in diffs:
6563
print(d)
6664
sys.exit(1)
65+
if process.wait() != 1:
66+
print("Error: Expected 1 error, found {}".format(process.returncode))
67+
sys.exit(1)

test/xml-generator/testVector/first.pfw

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ domainGroup: EddGroup
3131
component: /Test/test/block/1
3232
q2.5 = 0
3333
string = some other string
34+
# Should trigger a non fatal error
35+
domain: First

tools/xmlGenerator/domainGenerator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242

4343
def parseArgs():
4444
argparser = argparse.ArgumentParser(description="Parameter-Framework XML \
45-
Settings file generator")
45+
Settings file generator.\n\
46+
Exit with the number of (recoverable or not) error that occured.")
4647
argparser.add_argument('--toplevel-config',
4748
help="Top-level parameter-framework configuration file. Mandatory.",
4849
metavar="TOPLEVEL_CONFIG_FILE",
@@ -183,6 +184,7 @@ def main():
183184
# EDD files (aka ".pfw" files)
184185
#
185186
parsed_edds = parseEdd(args.edd_files, args.verbose)
187+
error_nb = 0
186188

187189
# We need to modify the toplevel configuration file to account for differences
188190
# between development setup and target (installation) setup, in particular, the
@@ -218,7 +220,8 @@ def main():
218220
connector.stdin.close()
219221
connector.wait()
220222
fake_toplevel_config.delete()
223+
return connector.return_code
221224

222225
# If this file is directly executed
223226
if __name__ == "__main__":
224-
main()
227+
exit(main())

tools/xmlGenerator/domainGeneratorConnector.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,21 @@ static const char *usage =
215215
216216
All arguments are mandatory. If no validation is required,
217217
the path to the schemas can be an empty string.
218+
219+
Exit with the number of (recoverable or not error) that occured.
220+
218221
This program is not intended to be used standalone but rather called through
219222
domainGenerator.py)";
220223

224+
/** On linux at least, a program can not exit with a value greater than 255.
225+
* @return min(code, 255);
226+
*/
227+
template <class T>
228+
static inline int normalizeExitCode(T code)
229+
{
230+
return int(std::min<T>(code, std::numeric_limits<uint8_t>::max()));
231+
}
232+
221233
int main(int argc, char *argv[])
222234
{
223235
using std::endl;
@@ -246,8 +258,8 @@ int main(int argc, char *argv[])
246258
// TODO: add a check for conflicting elements
247259
xmlGenerator.exportDomains(std::cout);
248260

249-
return int(std::min<decltype(errorNb)>(errorNb, std::numeric_limits<uint8_t>::max()));
250-
} catch (runtime_error e) {
261+
return normalizeExitCode(errorNb);
262+
} catch (std::exception &e) {
251263
std::cerr << e.what() << std::endl;
252264
return 1;
253265
}

0 commit comments

Comments
 (0)