Commits

Anonymous committed 3aa8b3f

Allow Help() to be called multiple times, appending to the text each time. (Chad Austin)

Comments (0)

Files changed (7)

 .B -h 
 argument is given to
 .BR scons .
-.B scons
-will exit after printing out the help text.
+If
+.BR Help
+is called multiple times, the text is appended together in the order
+that
+.BR Help
+is called.
 
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP
 
 RELEASE 0.97 - XXX
 
+  From Chad Austin:
+
+  - Allow Help() to be called multiple times, appending to the help
+    text each call.
+
   From Gary Oberbrunner:
 
   - Add an Environment.Dump() method to print the contents of a

src/engine/SCons/Script/SConscript.py

 
 launch_dir = os.path.abspath(os.curdir)
 
-def do_nothing(text): pass
-HelpFunction = do_nothing
+help_text = None
+
+def HelpFunction(text):
+    global help_text
+    if help_text is None:
+        help_text = text
+    else:
+        help_text = help_text + text
 
 Arguments = {}
 ArgList = []

src/engine/SCons/Script/__init__.py

 repositories = []
 num_jobs = 1 # this is modifed by SConscript.SetJobs()
 
-# Exceptions for this module
-class PrintHelp(Exception):
-    pass
-
 # utility functions
 
 def get_all_children(node): return node.all_children(None)
     global ssoptions
     ssoptions = SConscriptSettableOptions(options)
 
-    if options.help_msg:
-        def raisePrintHelp(text):
-            raise PrintHelp, text
-        SCons.Script.SConscript.HelpFunction = raisePrintHelp
-
     _set_globals(options)
     SCons.Node.implicit_cache = options.implicit_cache
     SCons.Node.implicit_deps_changed = options.implicit_deps_changed
     if not memory_stats is None: memory_stats.append(SCons.Debug.memory())
 
     progress_display("scons: Reading SConscript files ...")
+
+    start_time = time.time()
     try:
-        start_time = time.time()
-        try:
-            for script in scripts:
-                SCons.Script.SConscript._SConscript(fs, script)
-        except SCons.Errors.StopError, e:
-            # We had problems reading an SConscript file, such as it
-            # couldn't be copied in to the BuildDir.  Since we're just
-            # reading SConscript files and haven't started building
-            # things yet, stop regardless of whether they used -i or -k
-            # or anything else, but don't say "Stop." on the message.
-            global exit_status
-            sys.stderr.write("scons: *** %s\n" % e)
-            exit_status = 2
-            sys.exit(exit_status)
-        global sconscript_time
-        sconscript_time = time.time() - start_time
-    except PrintHelp, text:
-        progress_display("scons: done reading SConscript files.")
-        print text
-        print "Use scons -H for help about command-line options."
-        sys.exit(0)
+        for script in scripts:
+            SCons.Script.SConscript._SConscript(fs, script)
+    except SCons.Errors.StopError, e:
+        # We had problems reading an SConscript file, such as it
+        # couldn't be copied in to the BuildDir.  Since we're just
+        # reading SConscript files and haven't started building
+        # things yet, stop regardless of whether they used -i or -k
+        # or anything else, but don't say "Stop." on the message.
+        global exit_status
+        sys.stderr.write("scons: *** %s\n" % e)
+        exit_status = 2
+        sys.exit(exit_status)
+    global sconscript_time
+    sconscript_time = time.time() - start_time
     progress_display("scons: done reading SConscript files.")
 
     # Tell the Node.FS subsystem that we're all done reading the
     fs.chdir(fs.Top)
 
     if options.help_msg:
-        # They specified -h, but there was no Help() inside the
-        # SConscript files.  Give them the options usage.
-        parser.print_help(sys.stdout)
+        if SCons.Script.SConscript.help_text is None:
+            # They specified -h, but there was no Help() inside the
+            # SConscript files.  Give them the options usage.
+            parser.print_help(sys.stdout)
+        else:
+            print SCons.Script.SConscript.help_text
+            print "Use scons -H for help about command-line options."
         sys.exit(0)
 
     # Now that we've read the SConscripts we can set the options
 
 test.run(arguments = '-h', stdout = expect)
 
+test.write('SConstruct', r"""
+Help('\nMulti')
+Help('line\n')
+Help('''\
+help
+text!
+''')
+""")
+
+expect = """\
+scons: Reading SConscript files ...
+scons: done reading SConscript files.
+
+Multiline
+help
+text!
+
+Use scons -H for help about command-line options.
+"""
+
+test.run(arguments = '-h', stdout = expect)
+
 test.pass_test()
 check(['1', '1', cc, string.strip(ccflags + ' -O -g'), 'v', 'v'])
 
 test.run(arguments='-h',
-         stdout = """scons: Reading SConscript files ...
+         stdout = """\
+scons: Reading SConscript files ...
+1
+0
+%s
+%s
+v
+v
 scons: done reading SConscript files.
 Variables settable in custom.py or on the command line:
 
     actual: None
 
 Use scons -H for help about command-line options.
-"""%cc)
+"""%(cc, ccflags and ccflags + ' -O' or '-O', cc))
 
 # Test saving of options and multi loading
 #
 """)
 
 test.run(arguments='-h',
-         stdout = """scons: Reading SConscript files ...
+         stdout = """\
+scons: Reading SConscript files ...
 scons: done reading SConscript files.
 Variables settable in custom.py or on the command line:
 

test/OptionsTypes.py

 
 
 test.run(arguments='-h',
-         stdout = """scons: Reading SConscript files ...
+         stdout = """\
+scons: Reading SConscript files ...
+1
+0
 scons: done reading SConscript files.
 
 warnings: compilation with -Wall and similiar (yes|no)