scons icon indicating copy to clipboard operation
scons copied to clipboard

`scons --help` should still output help if SConstruct is invalid.

Open mkoncek opened this issue 5 years ago • 3 comments

Describe the bug

(@bdbaddog edit:) I'm going to change this to: An invalid SConstruct should still output the --help output. We're not going to change that SCons will process SContruct(s) before outputing --help output. This is part of SCons's long running functionality. SConstructs can add --xyz options so before any command line arguments can be processed it's required to process SConstructs.

From initial issue filing:

Following the "Principle of least astonishment" it would make sense that invoking scons --help does not try to interpret the SConstruct.py file in the current directory and possibly fails to interpret it if it is not currently valid Python code (i. e. interpretation fails). scons --version does not seem to parse Python files.

Required information

  • Link to SCons Users thread discussing your issue. bdbaddog asked me to file the issue in the Discord #scons-help channel
  • Version of SCons v3.1.2
  • Version of Python N/A
  • Which python distribution if applicable (python.org, cygwin, anaconda, macports, brew,etc) N/A
  • How you installed SCons Fedora package
  • What Platform are you on? (Linux/Windows and which version) Fedora 31
  • How to reproduce your issue? Please include a small self contained reproducer. Likely a SConstruct should do for most issues. Create an invalid SConstruct file and invoke scons --help
  • How you invoke scons (The command line you're using "scons --flags some_arguments") scons --help

mkoncek avatar May 05 '20 07:05 mkoncek

Try scons -H, which does not check for options that could have been added by the scripts.

This is unavoidable for scons -h, as it must parse the sconscripts: they could be adding additional options with AddOption and -h (aka --help) promises to display those.

mwichmann avatar May 05 '20 13:05 mwichmann

as @bdbaddog points out, catching errors if in help mode could still allow printing something useful even if the script isn't syntactically correct.

mwichmann avatar May 05 '20 23:05 mwichmann

Okay, so there's special logic that makes --help work if there's no SConstruct, which would normally emit a failure message. Can't really reuse that, because it happens up front, but maybe there's still a way to catch the error from a bad sconscript and be nice if we know help was requested. Is that worth pursuing?

mwichmann avatar May 11 '20 15:05 mwichmann