def test_display(self): old_stdout = sys.stdout sys.stdout = OutBuffer() display("line1") display.set_mode(0) display("line2") display.set_mode(1) display("line3") display("line4\n", append_newline=0) display.set_mode(0) display("dont print1") display("dont print2\n", append_newline=0) display.set_mode(1) assert sys.stdout.buffer == "line1\nline3\nline4\n" sys.stdout = old_stdout
def _main(): targets = [] # Enable deprecated warnings by default. SCons.Warnings._warningOut = _scons_internal_warning SCons.Warnings.enableWarningClass(SCons.Warnings.DeprecatedWarning) SCons.Warnings.enableWarningClass(SCons.Warnings.CorruptSConsignWarning) all_args = sys.argv[1:] try: all_args = string.split(os.environ['SCONSFLAGS']) + all_args except KeyError: # it's OK if there's no SCONSFLAGS pass parser = OptParser() global options, ssoptions options, args = parser.parse_args(all_args) 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 SCons.Node.implicit_deps_unchanged = options.implicit_deps_unchanged if options.warn: _setup_warn(options.warn) if options.noexec: SCons.Action.execute_actions = None CleanTask.execute = CleanTask.show if options.no_progress or options.silent: display.set_mode(0) if options.silent: SCons.Action.print_actions = None if options.cache_disable: def disable(self): pass SCons.Node.FS.default_fs.CacheDir = disable if options.cache_force: SCons.Node.FS.default_fs.cache_force = 1 if options.cache_show: SCons.Node.FS.default_fs.cache_show = 1 if options.directory: cdir = _create_path(options.directory) try: os.chdir(cdir) except: sys.stderr.write("Could not change directory to %s\n" % cdir) xmit_args = [] for a in args: if '=' in a: xmit_args.append(a) else: targets.append(a) SCons.Script.SConscript._scons_add_args(xmit_args) target_top = None if options.climb_up: target_top = '.' # directory to prepend to targets script_dir = os.getcwd() # location of script while script_dir and not _SConstruct_exists(script_dir): script_dir, last_part = os.path.split(script_dir) if last_part: target_top = os.path.join(last_part, target_top) else: script_dir = '' if script_dir: display("scons: Entering directory `%s'" % script_dir) os.chdir(script_dir) else: raise SCons.Errors.UserError, "No SConstruct file found." SCons.Node.FS.default_fs.set_toplevel_dir(os.getcwd()) # Now that the top-level directory has been set, # we can initialize the default Environment. SCons.Defaults._default_env = SCons.Environment.Environment() scripts = [] if options.file: scripts.extend(options.file) if not scripts: sfile = _SConstruct_exists() if sfile: scripts.append(sfile) if options.help_msg: if not scripts: # There's no SConstruct, but they specified -h. # Give them the options usage now, before we fail # trying to read a non-existent SConstruct file. parser.print_help() sys.exit(0) SCons.Script.SConscript.print_help = 1 if not scripts: raise SCons.Errors.UserError, "No SConstruct file found." if scripts[0] == "-": d = SCons.Node.FS.default_fs.getcwd() else: d = SCons.Node.FS.default_fs.File(scripts[0]).dir SCons.Node.FS.default_fs.set_SConstruct_dir(d) class Unbuffered: def __init__(self, file): self.file = file def write(self, arg): self.file.write(arg) self.file.flush() def __getattr__(self, attr): return getattr(self.file, attr) sys.stdout = Unbuffered(sys.stdout) if options.include_dir: sys.path = options.include_dir + sys.path global repositories for rep in repositories: SCons.Node.FS.default_fs.Repository(rep) display("scons: Reading SConscript files ...") try: start_time = time.time() try: for script in scripts: SCons.Script.SConscript.SConscript(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