Commits

Tom Tanner  committed f4b736e

Added option for readonly cache, allowed multiple --debug options,
made some improvements in error handling

  • Participants
  • Parent commits 904ed58

Comments (0)

Files changed (3)

File src/engine/SCons/CacheDir.py

 cache_debug = False
 cache_force = False
 cache_show = False
+cache_readonly = False
 
 def CacheRetrieveFunc(target, source, env):
     t = target[0]
 CacheRetrieveSilent = SCons.Action.Action(CacheRetrieveFunc, None)
 
 def CachePushFunc(target, source, env):
+    if cache_readonly: return
+
     t = target[0]
     if t.nocache:
         return
     def is_enabled(self):
         return (cache_enabled and not self.path is None)
 
+    def is_readonly(self):
+        return cache_readonly
+
     def cachepath(self, node):
         """
         """
         return False
 
     def push(self, node):
-        if not self.is_enabled():
+        if self.is_readonly() or not self.is_enabled():
             return
         return CachePush(node, [], node.get_build_env())
 

File src/engine/SCons/Script/Main.py

             SCons.Taskmaster.OutOfDateTask.fail_stop(self)
             exit_status = status
             this_build_status = status
-            
+
     def executed(self):
         t = self.targets[0]
         if self.top and not t.has_builder() and not t.side_effect:
             except ValueError:
                 t, e = exc_info
                 tb = None
-                
+
         # Deprecated string exceptions will have their string stored
         # in the first entry of the tuple.
         if e is None:
         errfmt = "scons: *** [%s] %s\n"
         sys.stderr.write(errfmt % (nodename, buildError))
 
-        if (buildError.exc_info[2] and buildError.exc_info[1] and 
+        if (buildError.exc_info[2] and buildError.exc_info[1] and
            not isinstance(
-               buildError.exc_info[1], 
+               buildError.exc_info[1],
                (EnvironmentError, SCons.Errors.StopError,
                             SCons.Errors.UserError))):
             type, value, trace = buildError.exc_info
+            if tb: traceback.print_tb(tb, file=sys.stderr) #added by TT
             traceback.print_exception(type, value, trace)
         elif tb and print_stacktrace:
             sys.stderr.write("scons: internal stack trace:\n")
     """Handle syntax errors. Print out a message and show where the error
     occurred.
     """
+    sys.stderr = sys.__stderr__
+    sys.stdout = sys.__stdout__
     etype, value, tb = sys.exc_info()
     lines = traceback.format_exception_only(etype, value)
     for line in lines:
     Input is a "pre-processed" stack trace in the form
     returned by traceback.extract_tb() or traceback.extract_stack()
     """
-    
+
     tb.reverse()
 
     # find the deepest traceback frame that is not part
 
 def _scons_user_error(e):
     """Handle user errors. Print out a message and a description of the
-    error, along with the line number and routine where it occured. 
+    error, along with the line number and routine where it occured.
     The file and line number will be the deepest stack frame that is
     not part of SCons itself.
     """
+    sys.stderr = sys.__stderr__
+    sys.stdout = sys.__stdout__
     global print_stacktrace
     etype, value, tb = sys.exc_info()
     if print_stacktrace:
     """Handle all errors but user errors. Print out a message telling
     the user what to do in this case and print a normal trace.
     """
+    sys.stderr = sys.__stderr__
+    sys.stdout = sys.__stdout__
     print 'internal error'
     traceback.print_exc()
     sys.exit(2)
     else:
         site_dir_name = "site_scons"
         err_if_not_found = False
-        
+
     site_dir = os.path.join(topdir, site_dir_name)
     if not os.path.exists(site_dir):
         if err_if_not_found:
         _load_site_scons_dir(d.path, options.site_dir)
     elif not options.no_site_dir:
         _load_all_site_scons_dirs(d.path)
-        
+
     if options.include_dir:
         sys.path = options.include_dir + sys.path
 
         # reading SConscript files and haven't started building
         # things yet, stop regardless of whether they used -i or -k
         # or anything else.
+        sys.stderr = sys.__stderr__
         sys.stderr.write("scons: *** %s  Stop.\n" % e)
-        exit_status = 2
-        sys.exit(exit_status)
+        sys.exit(2)
     global sconscript_time
     sconscript_time = time.time() - start_time
 
         # Build the targets
         nodes = _build_targets(fs, options, targets, target_top)
         if not nodes:
+            sys.stderr = sys.__stderr__
+            sys.stdout = sys.__stdout__
+            print 'Found no nodes to build?'
             exit_status = 2
 
 def _build_targets(fs, options, targets, target_top):
         SCons.Node.FS.set_diskcheck(options.diskcheck)
 
     SCons.CacheDir.cache_enabled = not options.cache_disable
+    SCons.CacheDir.cache_readonly = options.cache_readonly
     SCons.CacheDir.cache_debug = options.cache_debug
     SCons.CacheDir.cache_force = options.cache_force
     SCons.CacheDir.cache_show = options.cache_show
                         # x doesn't have a cwd, so it's either not a target,
                         # or not a file, so go ahead and keep it as a default
                         # target and let the engine sort it out:
-                        return 1                
+                        return 1
                 d = list(filter(check_dir, SCons.Script.DEFAULT_TARGETS))
                 SCons.Script.DEFAULT_TARGETS[:] = d
                 target_top = None
         prof = Profile()
         try:
             prof.runcall(_main, parser)
-        except SConsPrintHelpException, e:
+        finally:
             prof.dump_stats(options.profile_file)
-            raise e
-        except SystemExit:
-            pass
-        prof.dump_stats(options.profile_file)
     else:
         _main(parser)
 
     except (ImportError, AttributeError):
         # On Windows there is no scons.py, so there is no
         # __main__.__version__, hence there is no script version.
-        pass 
+        pass
     parts.append(version_string("engine", SCons))
     parts.append(path_string("engine", SCons))
     parts.append("__COPYRIGHT__")
     values = SConsOptions.SConsValues(parser.get_default_values())
 
     OptionsParser = parser
-    
+
     try:
         _exec_main(parser, values)
     except SystemExit, s:
+        sys.stderr = sys.__stderr__
+        sys.stdout = sys.__stdout__
         if s:
             exit_status = s
     except KeyboardInterrupt:
         parser.print_help()
         exit_status = 0
     except SCons.Errors.BuildError, e:
+        sys.stderr = sys.__stderr__
+        sys.stdout = sys.__stdout__
+        print e
         exit_status = e.exitstatus
     except:
         # An exception here is likely a builtin Python exception Python
         # code in an SConscript file.  Show them precisely what the
         # problem was and where it happened.
+        sys.stderr = sys.__stderr__
+        sys.stdout = sys.__stdout__
         SCons.Script._SConscript.SConscript_exception()
         sys.exit(2)
 
+    sys.stderr = sys.__stderr__
+    sys.stdout = sys.__stdout__
+
     memory_stats.print_stats()
     count_stats.print_stats()
 

File src/engine/SCons/Script/SConsOptions.py

                   action="store_true",
                   help="Do not retrieve built targets from CacheDir.")
 
+    op.add_option('--cache-readonly',
+                  dest='cache_readonly', default=False,
+                  action="store_true",
+                  help="Do not update CacheDir with built targets.")
+
     op.add_option('--cache-force', '--cache-populate',
                   dest='cache_force', default=False,
                   action="store_true",
     def opt_debug(option, opt, value, parser,
                   debug_options=debug_options,
                   deprecated_debug_options=deprecated_debug_options):
-        if value in debug_options:
-            parser.values.debug.append(value)
-            if value in deprecated_debug_options.keys():
-                try:
-                    parser.values.delayed_warnings
-                except AttributeError:
-                    parser.values.delayed_warnings = []
-                msg = deprecated_debug_options[value]
-                w = "The --debug=%s option is deprecated%s." % (value, msg)
-                t = (SCons.Warnings.DeprecatedDebugOptionsWarning, w)
-                parser.values.delayed_warnings.append(t)
-        else:
-            raise OptionValueError("Warning:  %s is not a valid debug type" % value)
+        for o in value.split(','):
+            if o in debug_options:
+                parser.values.debug.append(o)
+                if value in deprecated_debug_options.keys():
+                    try:
+                        parser.values.delayed_warnings
+                    except AttributeError:
+                        parser.values.delayed_warnings = []
+                    msg = deprecated_debug_options[value]
+                    w = "The --debug=%s option is deprecated%s." % (o, msg)
+                    t = (SCons.Warnings.DeprecatedDebugOptionsWarning, w)
+                    parser.values.delayed_warnings.append(t)
+            else:
+                raise OptionValueError("Warning:  %s is not a valid debug type" % o)
     opt_debug_help = "Print various types of debugging information: %s." \
                      % ", ".join(debug_options)
     op.add_option('--debug',