Fix --postarg and add option --preproc-show-cmdline + unit test

Thanks to @Blues-Today for reporting that --postarg was not working.

This needed a regression test, and the best way to distinguish --prearg from --postarg is to display the full preprocessor command line, therefore a new option was added for that purpose: --preproc-show-cmdline

Fixes #18.
This commit is contained in:
Sei Lisa 2022-06-17 15:09:24 +02:00
parent 8d413f910e
commit 7eaa4cb0ad
3 changed files with 73 additions and 53 deletions

19
main.py
View file

@ -233,6 +233,7 @@ Usage: {progname}
[--precmd=<cmd>] preprocessor command ('cpp' by default)
[--prenodef] no LSL specific defines (__AGENTKEY__ etc.)
[--preshow] show preprocessor output, and stop
[--preproc-show-cmdline] show preprocessor invocation line, and stop
[--avid=<UUID>] * specify UUID of avatar saving the script
[--avname=<name>] * specify name of avatar saving the script
[--assetid=<UUID>] * specify the asset UUID of the script
@ -411,7 +412,7 @@ def main(argv):
'timestamp', 'python-exceptions', 'prettify', 'bom', 'emap',
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
'avid=', 'avname=', 'assetid=', 'shortname=', 'builtins='
'libdata=', 'postarg='))
'libdata=', 'postarg=', 'preproc-show-cmdline'))
except getopt.GetoptError as e:
Usage(argv[0])
werr(u"\nError: %s\n" % str2u(str(e), 'utf8'))
@ -430,6 +431,7 @@ def main(argv):
script_header = ''
script_timestamp = ''
preshow = False
preproc_show_cmdline = False
raise_exception = False
prettify = False
bom = False
@ -505,12 +507,18 @@ def main(argv):
elif opt in ('-P', '--prearg'):
preproc_user_preargs.append(arg)
elif opt in ('-A', '--postarg'):
preproc_user_postargs.append(arg)
elif opt == '--prenodef':
predefines = False
elif opt == '--preshow':
preshow = True
elif opt == '--preproc-show-cmdline':
preproc_show_cmdline = True
elif opt in ('-H', '--header'):
script_header = True
@ -576,6 +584,7 @@ def main(argv):
del args
if not preproc_show_cmdline:
script = ''
if fname == '-':
script = sys.stdin.read()
@ -660,13 +669,15 @@ def main(argv):
preproc_cmdline.append('-D__AGENTNAME__="%s"' % avname)
preproc_cmdline.append('-D__ASSETID__=' + assetid)
preproc_cmdline.append('-D__SHORTFILE__="%s"' % shortname)
preproc_cmdline.append('-D__OPTIMIZER__=LSL PyOptimizer')
preproc_cmdline.append('-D__OPTIMIZER__=LSL-PyOptimizer')
preproc_cmdline.append('-D__OPTIMIZER_VERSION__=' + VERSION)
# Append user arguments at the end to allow them to override defaults
preproc_cmdline += preproc_user_postargs
if preproc != 'none':
if preproc_show_cmdline:
script = ' '.join(preproc_cmdline)
elif preproc != 'none':
# PreparePreproc uses and returns Unicode string encoding.
script = u2b(PreparePreproc(any2u(script, 'utf8')), 'utf8')
# At this point, for the external preprocessor to work we need the
@ -706,7 +717,7 @@ def main(argv):
elif x == 'USE_LAZY_LISTS':
options.add('lazylists')
if not preshow:
if not preshow and not preproc_show_cmdline:
if emap:
options.add('emap')

View file

@ -0,0 +1 @@
cpp --prefix-test-1 --prefix-test-2 -undef -x c -std=c99 -nostdinc -trigraphs -dN -fno-extended-identifiers -Dinteger(...)=((integer)(__VA_ARGS__)) -Dfloat(...)=((float)(__VA_ARGS__)) -Dstring(...)=((string)(__VA_ARGS__)) -Dkey(...)=((key)(__VA_ARGS__)) -Drotation(...)=((rotation)(__VA_ARGS__)) -Dquaternion(...)=((quaternion)(__VA_ARGS__)) -Dvector(...)=((vector)(__VA_ARGS__)) -Dlist(...)=((list)(__VA_ARGS__)) -D__AGENTKEY__="00000000-0000-0000-0000-000000000000" -D__AGENTID__="00000000-0000-0000-0000-000000000000" -D__AGENTIDRAW__=00000000-0000-0000-0000-000000000000 -D__AGENTNAME__="" -D__ASSETID__=00000000-0000-0000-0000-000000000000 -D__SHORTFILE__="" -D__OPTIMIZER__=LSL-PyOptimizer -D__OPTIMIZER_VERSION__=0.3.0beta --suffix-test-1 --suffix-test-2

View file

@ -0,0 +1,8 @@
main.py -y -O clear,processpre \
-p gcpp \
--preproc-show-cmdline \
-P --prefix-test-1 \
-A --suffix-test-1 \
--prearg=--prefix-test-2 \
--postarg=--suffix-test-2 \
-