Skip to content

Commit 2fda4ab

Browse files
committed
Do not require to define --generator in C++ build script
The generator can be defined either by the --generator cli flag of build.py or through the optionally included config file (--include argument). However, until now, it was mandatory to define the generator with --generator even if it was also defined (or redefined) by the include file as well. Now, it's optional which approach is used.
1 parent 3c5b5ac commit 2fda4ab

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

grammarinator-cxx/dev/build.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright (c) 2025 Renata Hodovan, Akos Kiss.
3+
# Copyright (c) 2025-2026 Renata Hodovan, Akos Kiss.
44
#
55
# Licensed under the BSD 3-Clause License
66
# <LICENSE.rst or https://opensource.org/licenses/BSD-3-Clause>.
@@ -123,7 +123,7 @@ def main():
123123
help='format of the saved trees (choices: %(choices)s; default: flatbuffers)')
124124
sgrp.add_argument('--include', metavar='FILE',
125125
help='file to include when compiling the specialized artefacts (default: derived from the generator class name by appending .hpp)')
126-
sgrp.add_argument('--includedir', metavar='DIR', action='append',
126+
sgrp.add_argument('--includedir', metavar='DIR', action='append', default=[],
127127
help='directory to append to the include path, usually which contains the file produced by grammarinator-process (may be specified multiple times)')
128128
sgrp.add_argument('--suffix', metavar='NAME',
129129
help='suffix of the specialized artefacts, possibly referring to the input format (default: derived from the generator class name by removing Generator and lowercasing)')
@@ -134,8 +134,11 @@ def main():
134134
'json': 'JsonTreeCodec'
135135
}[args.tree_format] if args.tree_format else None
136136

137-
if (args.generate or args.grlf) and (not args.includedir or not args.generator):
138-
parser.error('To build specialized artefacts, the `--generator` and `--includedir` arguments must be defined.')
137+
if args.generate or args.fuzznull or args.grlf:
138+
if not args.includedir or (not args.generator and not args.include):
139+
parser.error('To build specialized artefacts, either the `--generator` or the `--include`, and the `--includedir` arguments must be defined.')
140+
if not args.generator and not args.suffix:
141+
sys.stderr.write(f'{parser.prog}: Neither `--generator` nor `--suffix` is defined; the created binary will get a default name.\n')
139142

140143
try:
141144
configure_cmake(args)

0 commit comments

Comments
 (0)