build: fix ns3 argument splitting on -- separator

This commit is contained in:
Gabriel Ferreira
2022-07-06 16:29:02 -03:00
parent 588a0169d2
commit 9ff4236d5a

32
ns3
View File

@@ -290,10 +290,20 @@ def parse_args(argv):
dest='verbose',
default_value=False)
# Parse known arguments and separate from unknown arguments
args, unknown_args = parser.parse_known_args(argv)
# Try to split -- separated arguments into two lists for ns3 and for the runnable target
try:
args_separator_index = argv.index('--')
ns3_args = argv[:args_separator_index]
runnable_args = argv[args_separator_index + 1:]
except ValueError:
ns3_args = argv
runnable_args = []
if args.run == '':
# Parse known arguments and separate from unknown arguments
args, unknown_args = parser.parse_known_args(ns3_args)
# If run doesn't have a target, print the help message of the run parser
if "run" in args and args.run == '':
parser_run.print_help()
exit(-1)
@@ -342,16 +352,14 @@ def parse_args(argv):
if args.run and args.enable_sudo is None:
args.enable_sudo = True
# Filter arguments before --
setattr(args, "program_args", [])
# Save runnable target arguments
setattr(args, "program_args", runnable_args)
# Emit error in case of unknown arguments
if unknown_args:
try:
args_separator_index = argv.index('--')
args.program_args = argv[args_separator_index + 1:]
except ValueError:
msg = "Unknown options were given: {options}.\n" \
"To see the allowed options add the `--help` option.\n" \
"To forward configuration or runtime options, put them after '--'.\n"
msg = ("Unknown options were given: {options}.\n"
"To see the allowed options add the `--help` option.\n"
"To forward configuration or runtime options, put them after '--'.\n")
if args.run:
msg += "Try: ./ns3 run {target} -- {options}\n"
if args.configure: