def show(self): if (self.targets[0].has_builder() or self.targets[0].side_effect) \ and not os.path.isdir(str(self.targets[0])): display("Removed " + str(self.targets[0])) if SCons.Script.SConscript.clean_targets.has_key(self.targets[0]): files = SCons.Script.SConscript.clean_targets[self.targets[0]] for f in files: SCons.Util.fs_delete(str(f), 0)
def remove(self): if self.targets[0].has_builder() or self.targets[0].side_effect: for t in self.targets: try: removed = t.remove() except OSError, e: print "scons: Could not remove '%s':" % str(t), e.strerror else: if removed: display("Removed " + str(t))
def execute(self): target = self.targets[0] if target.get_state() == SCons.Node.up_to_date: if self.top and target.has_builder(): display('scons: "%s" is up to date.' % str(target)) elif target.has_builder() and not hasattr(target.builder, 'status'): if print_time: start_time = time.time() SCons.Taskmaster.Task.execute(self) if print_time: finish_time = time.time() global command_time command_time = command_time + finish_time - start_time print "Command execution time: %f seconds" % (finish_time - start_time)
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
def display(self, message): display('scons: ' + message)
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 except PrintHelp, text: display("scons: done reading SConscript files.") print text print "Use scons -H for help about command-line options." sys.exit(0) display("scons: done reading SConscript files.") SCons.Node.FS.default_fs.chdir(SCons.Node.FS.default_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) sys.exit(0) # Now that we've read the SConscripts we can set the options # that are SConscript settable:
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