From: <no...@fe...> - 2010-10-07 05:26:06
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "An advanced programming language". The branch, master has been updated via 49bd05cf9e9ffe8d0b41451d93bc045465cc8e2d (commit) from 8b7a4f79a2af14c2a4e0a27f157889416bc6e779 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 49bd05cf9e9ffe8d0b41451d93bc045465cc8e2d Author: John Skaller <sk...@us...> Date: Thu Oct 7 16:25:22 2010 +1100 Get rid of the old fbuild.. not maintained anymore so useless. diff --git a/fbuild_old/bin/fbuild b/fbuild_old/bin/fbuild deleted file mode 100755 index 57676ab..0000000 --- a/fbuild_old/bin/fbuild +++ /dev/null @@ -1,489 +0,0 @@ -#!/usr/bin/env python -############################################################### -# FELIX MAKE SCRIPT -############################################################### -import os -import sys -import glob -import shutil -import imp - -# forward import of set -try: - set -except NameError: - from sets import Set as set - -sys.path.append( - os.path.join(os.path.dirname(sys.argv[0]), '..', 'lib') -) - -os.environ['PYTHONPATH'] = os.pathsep.join([ - os.path.join(os.path.dirname(sys.argv[0]), '..', 'lib'), - os.environ.get('PYTHONPATH', ''), -]) - -if '' not in sys.path: sys.path.insert(0, '') - -import fbuild.flxbuild.flxutil -import fbuild.flxbuild.package -import fbuild.flxbuild.process - -# ------------------------------------------------ -# Load the initial config -# ------------------------------------------------ - -try: - import config -except Exception: - import traceback - xt,xv,tb = sys.exc_info() - print "ERROR IN config/__init__.py" - traceback.print_exception(xt,xv,tb) - print "You must either" - print "(a) edit config/__init__.py and fix the error, or," - print "(b) i) delete it, and," - print " ii) run 'python script/make_config.py'" - print " again to reset it:" - print " this is done automatically by 'make boot'" - sys.exit(1) - -# ------------------------------------------------ -# PROCESS COMMAND LINE OPTIONS -# ------------------------------------------------ - -import fbuildroot_old as fbuildroot - -def load_options(): - from optparse import OptionParser, make_option - - parser = OptionParser() - parser.add_options([ - make_option('-v', '--verbose', - action='count', - default=1, - help='print out extra debugging info'), - make_option('-q', '--quiet', - action='count', - default=0, - help='do not print out extra debugging info'), - make_option('--force', - action='store_true', - default=False, - help='force running a process'), - make_option('--phase', dest='selected_phases', metavar='PHASE', - action='append', - default=[], - help='run only this phase of the build'), - make_option('--pkg', dest='selected_packages', metavar='PKG', - action='append', - default=[], - help='build only these packages'), - make_option('--model', dest='selected_models', metavar='MODEL', - action='append', - default=[], - help='build only the phases which can run on this platform'), - make_option('--lparchive', - metavar='PATH', - help='use an alternative lpsrc directory'), - ]) - - try: - extra_options = fbuildroot.options - except AttributeError: - pass - else: - option_group = parser.add_option_group('project options') - option_group.add_options(extra_options) - - options, args = parser.parse_args() - - #### - - # temporary hack to set up the shell - config.HOST_OCAML.verbose = options.verbose - config.HOST_CC.verbose = options.verbose - config.HOST_CXX.verbose = options.verbose - config.TARGET_CC.verbose = options.verbose - config.TARGET_CXX.verbose = options.verbose - - config.HOST_OCAML.quiet = options.quiet - config.HOST_CC.quiet = options.quiet - config.HOST_CXX.quiet = options.quiet - config.TARGET_CC.quiet = options.quiet - config.TARGET_CXX.quiet = options.quiet - - #### - - #### - - # if the user didn't say which phases to run - # then run all the phases that use the host model - # On building on Linux for MinGW, the build model - # is linux, and the host model is mingw, the target - # is win32. We'd be running all MinGW phases. - # note a phase is named for the targetted product - # NOT the machine that generates it. Thus host - # phase mingw means 'compile on Linux for MingW' - - if not options.selected_phases and not options.selected_models: - options.selected_models = [config.host_model] - - for model in options.selected_models: - if model == config.build_model and 'build' not in options.selected_phases: - options.selected_phases.append('build') - - if model == config.host_model and 'host' not in options.selected_phases: - options.selected_phases.append('host') - - if model == config.target_model and 'target' not in options.selected_phases: - options.selected_phases.append('target') - - if model == config.run_model and 'run' not in options.selected_phases: - options.selected_phases.append('run') - - #### - - if options.lparchive: - config.FLX_LPARCHIVE = options.lparchive - - return options, args - - -def initial_extraction(options, args): - if "extract" not in args and "force_extract" not in args: - return - - paks = glob.glob(os.path.join(config.FLX_LPARCHIVE, "lpsrc", "*.pak")) - - for p in paks: - print "EXTRACTING", p, "from", config.FLX_LPARCHIVE - if "force_extract" in args: - cmd = (config.ISCR, '--force', '--break-on-error', p) - else: - cmd = (config.ISCR, '--break-on-error', p) - - fbuild.flxbuild.flxutil.execute(cmd, - verbose=options.verbose, - quiet=options.quiet, - ) - - # this is a hack - fbuild.flxbuild.flxutil.mkdirs('speed') - shutil.copy(os.path.join('misc', 'interscript.css'), 'speed') - - print "EXTRACTION COMPLETE" - sys.exit(0) - -# ---------------------------------------------------------------------------- - -def load_packages(): - pkgs = [] - unsorted_pkgs = [] - - for i in glob.glob(os.path.join(config.src_dir, "cpkgs", "target", "*.py")): - shutil.copy(i, os.path.join('cpkgs', 'target')) - - for i in \ - glob.glob(os.path.join("spkgs", "*.py")) + \ - glob.glob(os.path.join(config.src_dir, "spkgs", "*.py")): - pkg = os.path.basename(os.path.splitext(i)[0]) - if pkg == '__init__': - continue - - f, filename, description = imp.find_module(pkg, [os.path.dirname(i)]) - try: - module = imp.load_module(pkg, f, filename, description) - finally: - if f: - f.close() - - unsorted_pkgs.append(pkg) - d = {} - for k, v in module.__dict__.iteritems(): - if k[0] != '_': - d[k] = v - fbuild.flxbuild.package.pkgd[pkg] = d - - def addpkg_r(pkg): - if pkg not in pkgs: - if pkg not in fbuild.flxbuild.package.pkgd.keys(): - print "Unknown package", pkg - print "Please extract!" - sys.exit(1) - else: - reqs = fbuild.flxbuild.package.pkgd[pkg].get('pkg_requires',[]) - fbuild.flxbuild.package.pkgreqs[pkg]=reqs - for i in reqs: - addpkg_r(i) - pkgs.append(pkg) - - for pkg in unsorted_pkgs: - addpkg_r(pkg) - - # invert the requirements in order to determine the dependencies - fbuild.flxbuild.package.pkgdeps.update( - fbuild.flxbuild.flxutil.invert(fbuild.flxbuild.package.pkgreqs)) - - return pkgs - -# ------------------------------------------------- -# LOAD PROCESSES - - -def load_process(process_path, options, args): - p = process_path.split('.') - module, name = '.'.join(p[:-1]), p[-1] - process = getattr(__import__(module, {}, {}, ['']), name) - - if not callable(process): - raise ImportError - - if type(process) is type: - process = process( - verbose=options.verbose, - quiet=options.quiet, - optimise=options.optimise, - debug=options.debug, - force=options.force or 'force' in args, - options=args, - ) - - return process - - -def load_processes(options, args): - for phase, processes in fbuildroot.fbuild_processes.iteritems(): - for process_path in processes: - process = load_process(process_path, options, args) - fbuild.flxbuild.process.processes[process_path] = process - -# ----------------------------------------------------------------------------- - -def calculate_packages(options, phase, packages): - if options.selected_packages: - selected_pkgs = options.selected_packages - else: - selected_pkgs = [] - max_len = max([len(s) for s in fbuild.flxbuild.package.pkgd]) - - for pkg, pkgdict in fbuild.flxbuild.package.pkgd.iteritems(): - latest_src_time = fbuild.flxbuild.process.get_latest_src_time(pkgdict) - - stamp = os.path.join('pkg-stamps', '%s.%s' % (pkg, phase)) - latest_build_time = fbuild.flxbuild.flxutil.filetime(stamp) - - if latest_build_time == 0: - print "Pak %s (virtual)" % pkg.ljust(max_len), 'UNBUILT' - selected_pkgs.append(pkg) - elif latest_build_time < latest_src_time: - print "Pak %s changed: %s" % ( - pkg.ljust(max_len), - fbuild.flxbuild.flxutil.fmtime(latest_src_time), - ) - selected_pkgs.append(pkg) - - return [pkg for pkg in packages if pkg in selected_pkgs] - -#### - -def run_phase(options, phase, packages): - print '-' * 78 - print '***** MAKING PHASE', phase - pkgsummary = {} - for pkg in calculate_packages(options, phase, packages): - pkgdict = fbuild.flxbuild.package.pkgd[pkg] - print "*****", phase, "MAKING PACKAGE", pkg, "************" - stamp = os.path.join("pkg-stamps", "%s.%s" % (pkg, phase)) - if os.path.exists(stamp): - os.remove(stamp) - - for process in fbuildroot.fbuild_processes.get(phase, []): - #print "*****", phase, "RUNNING PROCESS", process, "************" - result = fbuild.flxbuild.process.processes[process](pkg, pkgdict, pkgsummary) - if not result and result is not None: - break - else: - fbuild.flxbuild.process.enstamp(stamp, options.quiet) - - if pkgsummary: - pkgsummary = pkgsummary.items() - pkgsummary.sort() - print phase, "PHASE SUMMARY" - for (package, process), summary in pkgsummary: - if summary != "no tests": - print ' ', process.ljust(25), ':', package.ljust(20), ':', summary - -# ----------------------------------------------------------------------------- - -def print_failures(): - # print out all the failed processes - failure_log = fbuild.flxbuild.flxutil.Tee() - - failure_log.write("----- PROCESS STATUS -----\n") - failed = 0 - fatal = 0 - for name, process in fbuild.flxbuild.process.processes.iteritems(): - try: - failures = process.failures - successes = process.successes - dummy = process.dummy - used = process.used - except AttributeError: - continue - - nfail = len(failures) - npass = len(successes) - failed = failed or nfail > 0 - fatal = fatal or (nfail > 0 and not dummy) - - if nfail: - print >> failure_log, 'PROCESS **FAILED**:', name, nfail, '/', npass + nfail, 'failures' - if dummy: - print >> failure_log, " [Expected failure, doesn't break build]" - else: - if used: - print >> failure_log, 'PROCESS PASSED :', name, npass, 'passed' - else: - pass - #print >> failure_log, 'PROCESS UNUSED :', name - - if not failed: - return False - - print '^^^^^^^^^^ FAILURES by group ^^^^^^^^^^^^^' - - kats = {} - for name, process in fbuild.flxbuild.process.processes.iteritems(): - try: - failures = process.failures - except AttributeError: - continue - - if not failures: - continue - - print '- %s: %s' % (len(failures), name) - - lookup = {} - - for pkg, file, failure in failures: - files = lookup.get(pkg, []) - files.append(file) - lookup[pkg] = files - - lookup = lookup.items() - lookup.sort() - - for pkg, files in lookup: - files.sort() - - print ' - %s: %s' % (len(files), pkg) - lastfile = "" - for file in files: - if file == lastfile: continue - lastfile = file - # grab the first line of the file to see if it - # has a #line number to print out as well, so we can - # localize the error to the interscript file location - - emitted = 0 - f = open(file) - eat = 1 - while eat == 1: - try: - line = f.readline() - except: - eat = 0 - if emitted == 0: fstring = file - else: fstring = "" - if emitted == 0 and line[0:5] == '#line': - comment = line - elif line [0:8] == "//Check ": - kat = line[8:].strip() - l = kats.get(kat,[]) - l.append(file) - kats[kat]=l - comment = kat - else: - if emitted == 0: - comment = line - else: - comment = "" - eat = 0 - if line != "": - print ' %-35s %s' % (fstring, comment.strip()) - emitted = 1 - if emitted == 0: - print ' %s' % file - f.close() - - print '^^^^^^^^^^ FAILURES by category ^^^^^^^^^^' - keys = kats.keys() - keys.sort() - for kat in keys: - print kat+":" - files = kats[kat] - for file in files: - print " ",file - - f = open('errors.log', 'w') - try: - f.write(failure_log.getvalue()) - finally: - f.close() - - return fatal - -# ----------------------------------------------------------------------------- - -def main(): - # add the felix directory to the search paths - sys.path.append(config.src_dir) - os.environ['PYTHONPATH'] = \ - config.src_dir + os.pathsep + os.environ.get('PYTHONPATH', '') - - options, args = load_options() - initial_extraction(options, args) - packages = load_packages() - load_processes(options, args) - - #### - - # run all the pre-processes - for process in fbuildroot.fbuild_preprocesses: - load_process(process, options, args).preprocess() - - # execute user selected processes in command line order - for arg in args: - # check in the build system stock process set - # these are run independently of the selected phase - if arg in fbuild.flxbuild.process.processes: - fbuild.flxbuild.process.processes[arg].runme() - else: - # try seeing if it's a process - try: - process = load_process(arg, options, args) - except ImportError: - pass - else: - process.runme() - - else: - # otherwise run all the processes specified by the application - # for the selected phases, in the application specified phase order - for phase in options.selected_phases: - run_phase(options, phase, packages) - - #### - - if print_failures(): - print "********* BUILD FAILED ********************" - return 1 - else: - print "*********** RUN COMPLETE: NO UNEXPECTED FAILURES DETECTED *******" - - return 0 - -if __name__ == '__main__': - sys.exit(main()) diff --git a/fbuild_old/bin/make_config.py b/fbuild_old/bin/make_config.py deleted file mode 100755 index 67e3bb7..0000000 --- a/fbuild_old/bin/make_config.py +++ /dev/null @@ -1,600 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -import time -import glob -from optparse import OptionParser, make_option -import shutil - -sys.path.append( - os.path.join(os.path.dirname(sys.argv[0]), '..', 'lib') -) - -os.environ['PYTHONPATH'] = os.pathsep.join([ - os.path.join(os.path.dirname(sys.argv[0]), '..', 'lib'), - os.environ.get('PYTHONPATH', ''), -]) - -from fbuild.flxbuild.flxutil import xqt, ExecutionError -from fbuild.flxbuild.config_support import pr, pa - -import version - -# ----------------------------------------------------------------------------- - -# supported platforms - -platforms = [ - "posix", - "cygwin", - "nocygwin", - "mingw", - "win32", - "win64", - "osx", - "detect" - "solaris", - "bsd", - "linux" - ] - -# map other names for them, obtained from -# various place like os.platform, os.system("mname -u"), etc - -archmap = { - "irix":"posix", - "irix64":"posix", - "unix":"posix", - "posix":"posix", - "linux":"linux", - "gnu/linux":"linux", - "solaris":"solaris", - "sunos":"solaris", - "cygwin":"cygwin", - "nocygwin":"nocygwin", - "mingw":"mingw", - "windows":"win32", - "nt":"win32", - "win32":"win32", - "win64":"win64", - "darwin":"osx", - "freebsd":"bsd", - "netbsd":"bsd", - "openbsd":"bsd", - "osx":"osx", - "detect":"detect" - } - -ALL_PHASES = ["build", "host", "target", "run"] - -# ----------------------------------------------------------------------------- - -def check_model(m): - try: - m = archmap[m] - except KeyError: - print "Unknown model '"+m+"' please choose one of:" - for m in platforms: print " * " + m - sys.exit(1) - return m - -def load_options(): - parser = OptionParser() - parser.add_options([ - make_option('-v', '--verbose', - action='count', - default=0, - help='print out extra debugging info'), - make_option('-q', '--quiet', - dest='verbose', - action='store_const', - const=0, - help='do not print out extra debugging info'), - make_option('--prefix', - help='install into this prefixed directory', - default=os.environ.get('PREFIX', '/usr/local')), - make_option('-I', '--include-path', - metavar='INCLUDE_PATH', - dest='include_paths', - action='append', - help='additionally search these paths for headers'), - make_option('-L', '--lib-path', - metavar='LIB_PATH', - dest='lib_paths', - action='append', - help='additionally search these paths for libraries'), - make_option('--build', - dest='build_model', - help='specify the build model'), - make_option('--host', - dest='host_model', - help='specify the host model'), - make_option('--target', - dest='target_model', - help='specify the target model'), - make_option('--run', - dest='run_model', - help='specify the run model'), - make_option('--buildcc', - metavar='CC', - help='specify the build c compiler'), - make_option('--hostcc', - metavar='CC', - help='specify the host c compiler'), - make_option('--targetcc', - metavar='CC', - help='specify the target c compiler'), - make_option('--buildcxx', - metavar='CXX', - help='specify the build c++ compiler'), - make_option('--hostcxx', - metavar='CXX', - help='specify the host c++ compiler'), - make_option('--targetcxx', - metavar='CXX', - help='specify the target c++ compiler'), - make_option('--boot', - dest='bootfile', - help='add a config bootfile for additional config modification'), - make_option('--src-dir', - metavar='PATH', - default=os.environ.get("SRC_DIR", os.curdir), - help='specify the source directory'), - make_option('--lparchive', - metavar='PATH', - default=os.environ.get("FLX_LPARCHIVE", os.curdir), - help='specify the location of the interscript files'), - make_option('--phase', - dest='phases', - action='append', - default=[], - help='specify which phases to configure'), - ]) - - options, args = parser.parse_args() - - if not options.verbose: - options.quiet = 2 - else: - options.quiet = 0 - - if options.build_model: - print "Specified build model", options.build_model - options.build_model = check_model(options.build_model) - else: - # attempt to find the Felix name for the build OS - # using uname -s, or, if that fails, Python os.name - # if the final result isn't a name we recognize - # set the build_model to 'detect' to indicate C level - # testing is to be used. Note that these C tests are - # done anyhow, and may verify, refine, or otherwise - # munge this result .. however we need some initial - # indication HOW to perform these tests. - - try: - output = xqt('uname', '-s') - except ExecutionError: - try: - options.build_model = archmap[os.name] - except KeyError: - print "uname -s and Python returns unknown OS type, assuming 'detect'" - options.build_model = "detect" - else: - output = output[0].strip().lower() - options.build_model = archmap[output] - - # attempt to find the Felix name for the build OS - # using uname -s, or, if that fails, Python os.name - # if the final result isn't a name we recognize - # set the build_model to 'detect' to indicate C level - # testing is to be used. Note that these C tests are - # done anyhow, and may verify, refine, or otherwise - # munge this result .. however we need some initial - # indication HOW to perform these tests. - - try: - output = xqt('uname', '-s') - except ExecutionError: - try: - options.build_model = archmap[os.name] - except KeyError: - print "uname -s and Python returns unknown OS type, assuming 'detect'" - options.build_model = "detect" - else: - output = output[0].strip().lower() - options.build_model = archmap[output] - - print "Build platform: " + options.build_model - - if options.host_model: - print "Specified host model", options.host_model - options.host_model = check_model(options.host_model) - - if options.target_model: - print "Specified target model", options.target_model - options.target_model = check_model(options.target_model) - - if options.run_model: - print "Specified run model", options.run_model - options.run_model = check_model(options.run_model) - - for phase in options.phases: - if phase not in ALL_PHASES: - print "UNKNOWN PHASE", phase,"not in", ALL_PHASES - sys.exit(1) - - if not options.phases: - options.phases = ALL_PHASES - - if options.bootfile: - try: - execfile(options.bootfile) - print "Loaded", options.bootfile - except: - print "Cannot execute specified bootstrap file: ", options.bootfile - sys.exit(1) - - return options, args - -#--------------------------------------------------- -# Discover C/C++ compilers, linker, and other 'binutils' - -import fbuild.flxbuild.ocaml_class -import fbuild.flxbuild.gcc_class -import fbuild.flxbuild.gxx_class -import fbuild.flxbuild.msvcc_class -import fbuild.flxbuild.msvcxx_class - -# -# Detect the native build model -# -# This model has two uses: first, to build any build time -# tools needed to assist in generating the sources -# and second, to aid in selecting the options to cross-compile -# for the chosen host and target -# - -def load_compiler(options, compiler, cc, input_cc, phase, model, suffix): - CC = compiler(verbose=options.verbose, quiet=options.quiet) - - CC.set_options( - COM=cc, - include_paths=options.include_paths, - lib_paths=options.lib_paths, - use=phase, - model=model, - build=options.build_model, - ) - - if input_cc and ( - input_cc.options.COM == CC.options.COM and - input_cc.options.model == CC.options.model and - input_cc.options.build == CC.options.build): - print 'using the', input_cc.options.use, 'CC options for the', phase, 'CC' - CC.load_options(os.path.join('config', input_cc.options.use + suffix)) - CC.options.use = phase - else: - CC.check_options() - CC.report_config() - CC.save_options(os.path.join('config', phase + suffix)) - - return CC - - - -def load_compilers(options, phase, model, cc, cxx, - input_cc=None, - input_cxx=None): - print - print "++++++++++++++++++++++++++++++++++++++++++++++++++++++++" - print "Checking", phase, "MODEL", model - print "++++++++++++++++++++++++++++++++++++++++++++++++++++++++" - print - - if model in ["win32","win64"]: - CC = fbuild.flxbuild.msvcc_class.msvcc - CXX = fbuild.flxbuild.msvcxx_class.msvcxx - else: - CC = fbuild.flxbuild.gcc_class.gcc - CXX = fbuild.flxbuild.gxx_class.gxx - - CC = load_compiler(options, CC, cc, input_cc, phase, model, '_cc.py') - CXX = load_compiler(options, CXX, cxx, input_cxx, phase, model, '_cxx.py') - - return CC, CXX - -# ----------------------------------------------------------------------------- - -def configure_build(options): - BUILD_CC, BUILD_CXX = load_compilers(options, - phase='build', - model=options.build_model, - cc=options.buildcc, - cxx=options.buildcxx, - ) - - BUILD_CC.check_options() - BUILD_CC.report_config() - BUILD_CC.save_options("config/build_cc.py") - options.build_model = BUILD_CC.options.model - - BUILD_CXX.check_options() - BUILD_CXX.report_config() - BUILD_CXX.save_options("config/build_cxx.py") - options.build_model = BUILD_CXX.options.model - - cpkgs = glob.glob("cpkgs"+os.sep+"build"+os.sep+"*.py") - for cpkgf in cpkgs: - cpkg = os.path.splitext(os.path.basename(cpkgf))[0] - print "build CONFIGURING", cpkg - __import__('cpkgs.build.' + cpkg) - - return BUILD_CC, BUILD_CXX - - -def configure_host(options, BUILD_CC, BUILD_CXX): - # - # Now create the host model: the compiler has to run - # on the build machine, but can cross compile for - # the host (if so, we can build but not test Felix) - # - # Cross compilation of the host tools may prevent any - # testing of the tools - # - - if not options.host_model: - options.host_model = options.build_model - print "Defaulting host model to build model:", options.host_model - - HOST_CC, HOST_CXX = load_compilers(options, - phase='host', - model=options.host_model, - cc=options.hostcc, - cxx=options.hostcxx, - input_cc=BUILD_CC, - input_cxx=BUILD_CXX, - ) - - HOST_OCAML = fbuild.flxbuild.ocaml_class.ocaml(verbose=options.verbose, quiet=options.quiet) - - camllinkopts = "" - if HOST_CXX.options.CYGWIN: - camllinkopts = '-ccopt "-Wl,--stack -Wl,10485760" ' - - HOST_OCAML.autodetect(camllinkopts) - HOST_OCAML.report_config() - HOST_OCAML.save_options("config/ocaml_config.py") - - options.host_model = HOST_CXX.options.model - - cpkgs = glob.glob("cpkgs"+os.sep+"host"+os.sep+"*.py") - for cpkgf in cpkgs: - cpkg = os.path.splitext(os.path.basename(cpkgf))[0] - print "host CONFIGURING", cpkg - __import__('cpkgs.host.' + cpkg) - - return HOST_CC, HOST_CXX, HOST_OCAML - - -def configure_target(options, HOST_CC, HOST_CXX): - # - # Now create the target model: the compiler has to run - # on the build machine, but can cross compile for - # the target - # - # cross compilation of C++ generated by Felix allows us to - # check the generated code compiles, but not that it runs - # [but the output is largely portable so we can still try] - # - - if not options.target_model: - options.target_model = options.host_model - print "Defaulting target model to host model:", options.target_model - - TARGET_CC, TARGET_CXX = load_compilers(options, - phase='target', - model=options.target_model, - cc=options.targetcc, - cxx=options.targetcxx, - input_cc=HOST_CC, - input_cxx=HOST_CXX, - ) - - options.target_model = TARGET_CXX.options.model - - return TARGET_CC, TARGET_CXX - - -def configure_run(options): - if not options.run_model: - options.run_model = options.target_model - print "Defaulting run model to target model:", options.run_model - -# ----------------------------------------------------------------------------- - -def write_config(options, CONFIG_TIME, - BUILD_CC, BUILD_CXX, - HOST_CC, HOST_CXX, HOST_OCAML, - TARGET_CC, TARGET_CXX): - try: - print "Writing main config file" - f = open("config"+os.sep+"__init__.py","w") - pr(f,'import sys') - pr(f,"if '' not in sys.path: sys.path = [''] + sys.path") - pr(f,'#'+CONFIG_TIME) - pr(f,"CONFIG_TIME = " + repr(CONFIG_TIME)) - pr(f,"flx_version = " + repr(version.flx_version)) - pr(f,"flx_version_major = " + repr(version.flx_version_major)) - pr(f,"godi_revision = " + repr(version.godi_revision)) - pr(f,"debian_revision = " + repr(version.debian_revision)) - if options.bootfile: - pr(f,"try:") - pr(f," execfile('config/config_bootstrap.py')") - pr(f,"except: pass") - pr(f,"import fbuild.flxbuild.gcc_class") - pr(f,"import fbuild.flxbuild.msvcc_class") - pr(f,"import fbuild.flxbuild.gxx_class") - pr(f,"import fbuild.flxbuild.msvcxx_class") - pr(f,"import fbuild.flxbuild.ocaml_class") - pr(f,"from fbuild.flxbuild.config_support import *") - - pr(f,"") - pr(f,"#User configurable section") - pr(f,"SUPPORT_DYNAMIC_LOADING = " + repr(TARGET_CXX.options.SUPPORT_DYNAMIC_LOADING)) - pr(f,"SUPPORT_STATIC_LINKAGE = 1") - if TARGET_CXX.options.SUPPORT_DYNAMIC_LOADING: - pr(f,"DEFAULT_LINK_MODEL = 'dynamic'") - else: - pr(f,"DEFAULT_LINK_MODEL = 'static'") - pr(f,"build_model = " + repr(options.build_model)) - pr(f,"host_model = " + repr(options.host_model)) - pr(f,"target_model = " + repr(options.target_model)) - pr(f,"run_model = " + repr(options.run_model)) - - # target model switches - pr(f,"CYGWIN = " + repr(TARGET_CXX.options.CYGWIN)) - pr(f,"MACOSX = " + repr(TARGET_CXX.options.MACOSX)) - pr(f,"WIN32 = " + repr(TARGET_CXX.options.WIN32)) - pr(f,"WIN64 = " + repr(TARGET_CXX.options.WIN64)) - pr(f,"POSIX = " + repr(TARGET_CXX.options.POSIX)) - pr(f,"SOLARIS = " + repr(TARGET_CXX.options.SOLARIS)) - pr(f,"BSD = " + repr(TARGET_CXX.options.BSD)) - pr(f,"LINUX = " + repr(TARGET_CXX.options.LINUX)) - pr(f,"PREFIX = " + repr(options.prefix)) - pr(f,"src_dir = " + repr(options.src_dir)) - pr(f,"FLX_LPARCHIVE = " + repr(options.lparchive)) - pr(f,"FLX_RTL_DIR = " + repr(os.path.join('lib', 'rtl'))) - pr(f,"FLX_HOST_CONFIG_DIR = " + repr(os.path.join('config', 'host'))) - pr(f,"FLX_TARGET_CONFIG_DIR = " + repr(os.path.join('config', 'target'))) - pr(f,"") - - pr(f,"HOST_OCAML = fbuild.flxbuild.ocaml_class.ocaml()") - pr(f,"HOST_OCAML.load_options("+repr('config'+os.sep+'ocaml_config.py')+")") - - cc = HOST_CC.__class__.__name__ - pr(f,"HOST_CC = fbuild.flxbuild."+cc+"_class."+cc+"()") - pr(f,"HOST_CC.load_options("+repr('config'+os.sep+'host_cc.py')+")") - cc = TARGET_CC.__class__.__name__ - pr(f,"TARGET_CC = fbuild.flxbuild."+cc+"_class."+cc+"()") - pr(f,"TARGET_CC.load_options("+repr('config'+os.sep+'target_cc.py')+")") - - cxx = HOST_CXX.__class__.__name__ - pr(f,"HOST_CXX = fbuild.flxbuild."+cxx+"_class."+cxx+"()") - pr(f,"HOST_CXX.load_options("+repr('config'+os.sep+'host_cxx.py')+")") - cxx = TARGET_CXX.__class__.__name__ - pr(f,"TARGET_CXX = fbuild.flxbuild."+cxx+"_class."+cxx+"()") - pr(f,"TARGET_CXX.load_options("+repr('config'+os.sep+'target_cxx.py')+")") - pr(f,"") - - if options.target_model in ["win32","win64"]: - HAVE_MSVC = 1 - HAVE_GNU = 0 - DIFF = 'FC /L /W' - else: - HAVE_MSVC = 0 - HAVE_GNU = 1 - - #DIFF = "diff -a -b " # build system is Unix Python - # RF - trying out args that work on solaris (-a = not cool) - # could use that sys type stuff here? - DIFF = 'diff -b' - - pr(f,"HAVE_GNU = " + repr(HAVE_GNU)) - pr(f,"FLXCC_CPP='cpp '") - pr(f,"HAVE_MSVC = " + repr(HAVE_MSVC)) - pr(f,"DIFF = " + repr(DIFF)) - - ISCR = sys.executable + ' ' + \ - os.path.join(options.src_dir, 'interscript', 'bin', 'iscr.py') + \ - ' --cache-prefix=lpsrc-cache' - pr(f,"ISCR = " + repr(ISCR)) - - # --------------------------------------------------- - - # RF: noone seems to be using the results of this - # JS: Not yet: policy is to test it out anyhow, in case needed - # - # uname -s: kernel name "linux" on linux - # uname -n: network node name "rosella" on JS box - # uname -r: kernel-release "2.6.12-10-amd64-k8" on JS box - # uname -v: kernel-version " #1 Thu Dec 22 11:12:06 UTC 2005" on JS box - # uname -m: machine hardware name: "x86_64" on JS box - # uname -o: operating system: "GNU/Linux" on JS box - # uname -p: OSX only? on osx reports broad cpu type (e.g. powerpc) - # not sure what it reports on intel macs. - # machine command reports very specific cpu type, e.g. ppc7450, ppc7400 - - try: - output = xqt('uname', '-m') - except ExecutionError: - ARCH = "unknown" - else: - ARCH = output[0].strip().lower() - pr(f,"ARCH = " + repr(ARCH)) - - try: - if options.build_model == 'osx': - output = xqt('uname -p') - else: - output = xqt('uname -o') - except ExecutionError: - OS = 'unknown' - else: - OS = output[0].strip().lower() - - pr(f,"OS = " + repr(OS)) - - pr(f,"") - pr(f,"# HACK to get all the target variables into global namespace") - f.close() - if options.bootfile: - print "Copying bootfile :", options.bootfile - shutil.copy(options.bootfile, os.path.join('config', 'config_bootstrap.py')) - except EnvironmentError: - print "Unable to create config"+os.sep+"__init__.py" - sys.exit(1) - - print "Created config"+os.sep+"__init__.py" - print "Edit this file to set your preferences" - print "This file will not be clobbered by the Felix build process" - - cpkgs = glob.glob("cpkgs"+os.sep+"target"+os.sep+"*.py") - for cpkgf in cpkgs: - cpkg = os.path.splitext(os.path.basename(cpkgf))[0] - print "target CONFIGURING", cpkg - __import__('cpkgs.target.' + cpkg) - -# ----------------------------------------------------------------------------- - -def main(): - time_stamp_format = "%Y/%m/%d %H:%M:%S UTC" - config_time = time.gmtime(time.time()) - CONFIG_TIME = time.strftime(time_stamp_format, config_time) - - options, args = load_options() - - if args: - print 'Unknown configure args:', args - return 1 - - if not os.path.exists('config'): - os.path.mkdir('config') - - BUILD_CC, BUILD_CXX = configure_build(options) - HOST_CC, HOST_CXX, HOST_OCAML = configure_host(options, BUILD_CC, BUILD_CXX) - TARGET_CC, TARGET_CXX = configure_target(options, HOST_CC, HOST_CXX) - configure_run(options) - - write_config(options, CONFIG_TIME, - BUILD_CC, BUILD_CXX, - HOST_CC, HOST_CXX, HOST_OCAML, - TARGET_CC, TARGET_CXX, - ) - - return 0 - -# ----------------------------------------------------------------------------- - -if __name__ == '__main__': - sys.exit(main()) diff --git a/fbuild_old/lib/fbuild/__init__.py b/fbuild_old/lib/fbuild/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/fbuild_old/lib/fbuild/compat/_Queue.py b/fbuild_old/lib/fbuild/compat/_Queue.py deleted file mode 100644 index e4b9d3a..0000000 --- a/fbuild_old/lib/fbuild/compat/_Queue.py +++ /dev/null @@ -1,221 +0,0 @@ -"""A multi-producer, multi-consumer queue.""" - -from time import time as _time - -try: - from collections import deque -except ImportError: - class deque(list): - def popleft(self): - return self.pop(0) - -__all__ = ['Empty', 'Full', 'Queue'] - -class Empty(Exception): - "Exception raised by Queue.get(block=0)/get_nowait()." - pass - -class Full(Exception): - "Exception raised by Queue.put(block=0)/put_nowait()." - pass - -class Queue: - """Create a queue object with a given maximum size. - - If maxsize is <= 0, the queue size is infinite. - """ - def __init__(self, maxsize=0): - try: - import threading - except ImportError: - import dummy_threading as threading - self._init(maxsize) - # mutex must be held whenever the queue is mutating. All methods - # that acquire mutex must release it before returning. mutex - # is shared between the three conditions, so acquiring and - # releasing the conditions also acquires and releases mutex. - self.mutex = threading.Lock() - # Notify not_empty whenever an item is added to the queue; a - # thread waiting to get is notified then. - self.not_empty = threading.Condition(self.mutex) - # Notify not_full whenever an item is removed from the queue; - # a thread waiting to put is notified then. - self.not_full = threading.Condition(self.mutex) - # Notify all_tasks_done whenever the number of unfinished tasks - # drops to zero; thread waiting to join() is notified to resume - self.all_tasks_done = threading.Condition(self.mutex) - self.unfinished_tasks = 0 - - def task_done(self): - """Indicate that a formerly enqueued task is complete. - - Used by Queue consumer threads. For each get() used to fetch a task, - a subsequent call to task_done() tells the queue that the processing - on the task is complete. - - If a join() is currently blocking, it will resume when all items - have been processed (meaning that a task_done() call was received - for every item that had been put() into the queue). - - Raises a ValueError if called more times than there were items - placed in the queue. - """ - self.all_tasks_done.acquire() - try: - unfinished = self.unfinished_tasks - 1 - if unfinished <= 0: - if unfinished < 0: - raise ValueError('task_done() called too many times') - self.all_tasks_done.notifyAll() - self.unfinished_tasks = unfinished - finally: - self.all_tasks_done.release() - - def join(self): - """Blocks until all items in the Queue have been gotten and processed. - - The count of unfinished tasks goes up whenever an item is added to the - queue. The count goes down whenever a consumer thread calls task_done() - to indicate the item was retrieved and all work on it is complete. - - When the count of unfinished tasks drops to zero, join() unblocks. - """ - self.all_tasks_done.acquire() - try: - while self.unfinished_tasks: - self.all_tasks_done.wait() - finally: - self.all_tasks_done.release() - - def qsize(self): - """Return the approximate size of the queue (not reliable!).""" - self.mutex.acquire() - n = self._qsize() - self.mutex.release() - return n - - def empty(self): - """Return True if the queue is empty, False otherwise (not reliable!).""" - self.mutex.acquire() - n = self._empty() - self.mutex.release() - return n - - def full(self): - """Return True if the queue is full, False otherwise (not reliable!).""" - self.mutex.acquire() - n = self._full() - self.mutex.release() - return n - - def put(self, item, block=True, timeout=None): - """Put an item into the queue. - - If optional args 'block' is true and 'timeout' is None (the default), - block if necessary until a free slot is available. If 'timeout' is - a positive number, it blocks at most 'timeout' seconds and raises - the Full exception if no free slot was available within that time. - Otherwise ('block' is false), put an item on the queue if a free slot - is immediately available, else raise the Full exception ('timeout' - is ignored in that case). - """ - self.not_full.acquire() - try: - if not block: - if self._full(): - raise Full - elif timeout is None: - while self._full(): - self.not_full.wait() - else: - if timeout < 0: - raise ValueError("'timeout' must be a positive number") - endtime = _time() + timeout - while self._full(): - remaining = endtime - _time() - if remaining <= 0.0: - raise Full - self.not_full.wait(remaining) - self._put(item) - self.unfinished_tasks += 1 - self.not_empty.notify() - finally: - self.not_full.release() - - def put_nowait(self, item): - """Put an item into the queue without blocking. - - Only enqueue the item if a free slot is immediately available. - Otherwise raise the Full exception. - """ - return self.put(item, False) - - def get(self, block=True, timeout=None): - """Remove and return an item from the queue. - - If optional args 'block' is true and 'timeout' is None (the default), - block if necessary until an item is available. If 'timeout' is - a positive number, it blocks at most 'timeout' seconds and raises - the Empty exception if no item was available within that time. - Otherwise ('block' is false), return an item if one is immediately - available, else raise the Empty exception ('timeout' is ignored - in that case). - """ - self.not_empty.acquire() - try: - if not block: - if self._empty(): - raise Empty - elif timeout is None: - while self._empty(): - self.not_empty.wait() - else: - if timeout < 0: - raise ValueError("'timeout' must be a positive number") - endtime = _time() + timeout - while self._empty(): - remaining = endtime - _time() - if remaining <= 0.0: - raise Empty - self.not_empty.wait(remaining) - item = self._get() - self.not_full.notify() - return item - finally: - self.not_empty.release() - - def get_nowait(self): - """Remove and return an item from the queue without blocking. - - Only get an item if one is immediately available. Otherwise - raise the Empty exception. - """ - return self.get(False) - - # Override these methods to implement other queue organizations - # (e.g. stack or priority queue). - # These will only be called with appropriate locks held - - # Initialize the queue representation - def _init(self, maxsize): - self.maxsize = maxsize - self.queue = deque() - - def _qsize(self): - return len(self.queue) - - # Check whether the queue is empty - def _empty(self): - return not self.queue - - # Check whether the queue is full - def _full(self): - return self.maxsize > 0 and len(self.queue) == self.maxsize - - # Put a new item in the queue - def _put(self, item): - self.queue.append(item) - - # Get an item from the queue - def _get(self): - return self.queue.popleft() diff --git a/fbuild_old/lib/fbuild/compat/__init__.py b/fbuild_old/lib/fbuild/compat/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/fbuild_old/lib/fbuild/compat/_subprocess.py b/fbuild_old/lib/fbuild/compat/_subprocess.py deleted file mode 100644 index fa3d683..0000000 --- a/fbuild_old/lib/fbuild/compat/_subprocess.py +++ /dev/null @@ -1,1246 +0,0 @@ -# subprocess - Subprocesses with accessible I/O streams -# -# For more information about this module, see PEP 324. -# -# This module should remain compatible with Python 2.2, see PEP 291. -# -# Copyright (c) 2003-2005 by Peter Astrand <as...@ly...> -# -# Licensed to PSF under a Contributor Agreement. -# See http://www.python.org/2.4/license for licensing details. - -r"""subprocess - Subprocesses with accessible I/O streams - -This module allows you to spawn processes, connect to their -input/output/error pipes, and obtain their return codes. This module -intends to replace several other, older modules and functions, like: - -os.system -os.spawn* -os.popen* -popen2.* -commands.* - -Information about how the subprocess module can be used to replace these -modules and functions can be found below. - - - -Using the subprocess module -=========================== -This module defines one class called Popen: - -class Popen(args, bufsize=0, executable=None, - stdin=None, stdout=None, stderr=None, - preexec_fn=None, close_fds=False, shell=False, - cwd=None, env=None, universal_newlines=False, - startupinfo=None, creationflags=0): - - -Arguments are: - -args should be a string, or a sequence of program arguments. The -program to execute is normally the first item in the args sequence or -string, but can be explicitly set by using the executable argument. - -On UNIX, with shell=False (default): In this case, the Popen class -uses os.execvp() to execute the child program. args should normally -be a sequence. A string will be treated as a sequence with the string -as the only item (the program to execute). - -On UNIX, with shell=True: If args is a string, it specifies the -command string to execute through the shell. If args is a sequence, -the first item specifies the command string, and any additional items -will be treated as additional shell arguments. - -On Windows: the Popen class uses CreateProcess() to execute the child -program, which operates on strings. If args is a sequence, it will be -converted to a string using the list2cmdline method. Please note that -not all MS Windows applications interpret the command line the same -way: The list2cmdline is designed for applications using the same -rules as the MS C runtime. - -bufsize, if given, has the same meaning as the corresponding argument -to the built-in open() function: 0 means unbuffered, 1 means line -buffered, any other positive value means use a buffer of -(approximately) that size. A negative bufsize means to use the system -default, which usually means fully buffered. The default value for -bufsize is 0 (unbuffered). - -stdin, stdout and stderr specify the executed programs' standard -input, standard output and standard error file handles, respectively. -Valid values are PIPE, an existing file descriptor (a positive -integer), an existing file object, and None. PIPE indicates that a -new pipe to the child should be created. With None, no redirection -will occur; the child's file handles will be inherited from the -parent. Additionally, stderr can be STDOUT, which indicates that the -stderr data from the applications should be captured into the same -file handle as for stdout. - -If preexec_fn is set to a callable object, this object will be called -in the child process just before the child is executed. - -If close_fds is true, all file descriptors except 0, 1 and 2 will be -closed before the child process is executed. - -if shell is true, the specified command will be executed through the -shell. - -If cwd is not None, the current directory will be changed to cwd -before the child is executed. - -If env is not None, it defines the environment variables for the new -process. - -If universal_newlines is true, the file objects stdout and stderr are -opened as a text files, but lines may be terminated by any of '\n', -the Unix end-of-line convention, '\r', the Macintosh convention or -'\r\n', the Windows convention. All of these external representations -are seen as '\n' by the Python program. Note: This feature is only -available if Python is built with universal newline support (the -default). Also, the newlines attribute of the file objects stdout, -stdin and stderr are not updated by the communicate() method. - -The startupinfo and creationflags, if given, will be passed to the -underlying CreateProcess() function. They can specify things such as -appearance of the main window and priority for the new process. -(Windows only) - - -This module also defines two shortcut functions: - -call(*popenargs, **kwargs): - Run command with arguments. Wait for command to complete, then - return the returncode attribute. - - The arguments are the same as for the Popen constructor. Example: - - retcode = call(["ls", "-l"]) - -check_call(*popenargs, **kwargs): - Run command with arguments. Wait for command to complete. If the - exit code was zero then return, otherwise raise - CalledProcessError. The CalledProcessError object will have the - return code in the returncode attribute. - - The arguments are the same as for the Popen constructor. Example: - - check_call(["ls", "-l"]) - -Exceptions ----------- -Exceptions raised in the child process, before the new program has -started to execute, will be re-raised in the parent. Additionally, -the exception object will have one extra attribute called -'child_traceback', which is a string containing traceback information -from the childs point of view. - -The most common exception raised is OSError. This occurs, for -example, when trying to execute a non-existent file. Applications -should prepare for OSErrors. - -A ValueError will be raised if Popen is called with invalid arguments. - -check_call() will raise CalledProcessError, if the called process -returns a non-zero return code. - - -Security --------- -Unlike some other popen functions, this implementation will never call -/bin/sh implicitly. This means that all characters, including shell -metacharacters, can safely be passed to child processes. - - -Popen objects -============= -Instances of the Popen class have the following methods: - -poll() - Check if child process has terminated. Returns returncode - attribute. - -wait() - Wait for child process to terminate. Returns returncode attribute. - -communicate(input=None) - Interact with process: Send data to stdin. Read data from stdout - and stderr, until end-of-file is reached. Wait for process to - terminate. The optional input argument should be a string to be - sent to the child process, or None, if no data should be sent to - the child. - - communicate() returns a tuple (stdout, stderr). - - Note: The data read is buffered in memory, so do not use this - method if the data size is large or unlimited. - -The following attributes are also available: - -stdin - If the stdin argument is PIPE, this attribute is a file object - that provides input to the child process. Otherwise, it is None. - -stdout - If the stdout argument is PIPE, this attribute is a file object - that provides output from the child process. Otherwise, it is - None. - -stderr - If the stderr argument is PIPE, this attribute is file object that - provides error output from the child process. Otherwise, it is - None. - -pid - The process ID of the child process. - -returncode - The child return code. A None value indicates that the process - hasn't terminated yet. A negative value -N indicates that the - child was terminated by signal N (UNIX only). - - -Replacing older functions with the subprocess module -==================================================== -In this section, "a ==> b" means that b can be used as a replacement -for a. - -Note: All functions in this section fail (more or less) silently if -the executed program cannot be found; this module raises an OSError -exception. - -In the following examples, we assume that the subprocess module is -imported with "from subprocess import *". - - -Replacing /bin/sh shell backquote ---------------------------------- -output=`mycmd myarg` -==> -output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0] - - -Replacing shell pipe line -------------------------- -output=`dmesg | grep hda` -==> -p1 = Popen(["dmesg"], stdout=PIPE) -p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) -output = p2.communicate()[0] - - -Replacing os.system() ---------------------- -sts = os.system("mycmd" + " myarg") -==> -p = Popen("mycmd" + " myarg", shell=True) -pid, sts = os.waitpid(p.pid, 0) - -Note: - -* Calling the program through the shell is usually not required. - -* It's easier to look at the returncode attribute than the - exitstatus. - -A more real-world example would look like this: - -try: - retcode = call("mycmd" + " myarg", shell=True) - if retcode < 0: - print >>sys.stderr, "Child was terminated by signal", -retcode - else: - print >>sys.stderr, "Child returned", retcode -except OSError, e: - print >>sys.stderr, "Execution failed:", e - - -Replacing os.spawn* -------------------- -P_NOWAIT example: - -pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg") -==> -pid = Popen(["/bin/mycmd", "myarg"]).pid - - -P_WAIT example: - -retcode = os.spawnlp(os.P_WAIT, "/bin/mycmd", "mycmd", "myarg") -==> -retcode = call(["/bin/mycmd", "myarg"]) - - -Vector example: - -os.spawnvp(os.P_NOWAIT, path, args) -==> -Popen([path] + args[1:]) - - -Environment example: - -os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env) -==> -Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"}) - - -Replacing os.popen* -------------------- -pipe = os.popen(cmd, mode='r', bufsize) -==> -pipe = Popen(cmd, shell=True, bufsize=bufsize, stdout=PIPE).stdout - -pipe = os.popen(cmd, mode='w', bufsize) -==> -pipe = Popen(cmd, shell=True, bufsize=bufsize, stdin=PIPE).stdin - - -(child_stdin, child_stdout) = os.popen2(cmd, mode, bufsize) -==> -p = Popen(cmd, shell=True, bufsize=bufsize, - stdin=PIPE, stdout=PIPE, close_fds=True) -(child_stdin, child_stdout) = (p.stdin, p.stdout) - - -(child_stdin, - child_stdout, - child_stderr) = os.popen3(cmd, mode, bufsize) -==> -p = Popen(cmd, shell=True, bufsize=bufsize, - stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) -(child_stdin, - child_stdout, - child_stderr) = (p.stdin, p.stdout, p.stderr) - - -(child_stdin, child_stdout_and_stderr) = os.popen4(cmd, mode, bufsize) -==> -p = Popen(cmd, shell=True, bufsize=bufsize, - stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) -(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout) - - -Replacing popen2.* ------------------- -Note: If the cmd argument to popen2 functions is a string, the command -is executed through /bin/sh. If it is a list, the command is directly -executed. - -(child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode) -==> -p = Popen(["somestring"], shell=True, bufsize=bufsize - stdin=PIPE, stdout=PIPE, close_fds=True) -(child_stdout, child_stdin) = (p.stdout, p.stdin) - - -(child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize, mode) -==> -p = Popen(["mycmd", "myarg"], bufsize=bufsize, - stdin=PIPE, stdout=PIPE, close_fds=True) -(child_stdout, child_stdin) = (p.stdout, p.stdin) - -The popen2.Popen3 and popen3.Popen4 basically works as subprocess.Popen, -except that: - -* subprocess.Popen raises an exception if the execution fails -* the capturestderr argument is replaced with the stderr argument. -* stdin=PIPE and stdout=PIPE must be specified. -* popen2 closes all filedescriptors by default, but you have to specify - close_fds=True with subprocess.Popen. - - -""" - -import sys -mswindows = (sys.platform == "win32") - -import os -import types -import traceback - -# Exception classes used by this module. -class CalledProcessError(Exception): - """This exception is raised when a process run by check_call() returns - a non-zero exit status. The exit status will be stored in the - returncode attribute.""" - def __init__(self, returncode, cmd): - self.returncode = returncode - self.cmd = cmd - def __str__(self): - return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode) - - -if mswindows: - import threading - import msvcrt - if 0: # <-- change this to use pywin32 instead of the _subprocess driver - import pywintypes - from win32api import GetStdHandle, STD_INPUT_HANDLE, \ - STD_OUTPUT_HANDLE, STD_ERROR_HANDLE - from win32api import GetCurrentProcess, DuplicateHandle, \ - GetModuleFileName, GetVersion - from win32con import DUPLICATE_SAME_ACCESS, SW_HIDE - from win32pipe import CreatePipe - from win32process import CreateProcess, STARTUPINFO, \ - GetExitCodeProcess, STARTF_USESTDHANDLES, \ - STARTF_USESHOWWINDOW, CREATE_NEW_CONSOLE - from win32event import WaitForSingleObject, INFINITE, WAIT_OBJECT_0 - else: - from _subprocess import * - class STARTUPINFO: - dwFlags = 0 - hStdInput = None - hStdOutput = None - hStdError = None - wShowWindow = 0 - class pywintypes: - error = IOError -else: - import select - import errno - import fcntl - import pickle - -__all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call", "CalledProcessError"] - -try: - MAXFD = os.sysconf("SC_OPEN_MAX") -except: - MAXFD = 256 - -# True/False does not exist on 2.2.0 -try: - False -except NameError: - False = 0 - True = 1 - -_active = [] - -def _cleanup(): - for inst in _active[:]: - if inst.poll(_deadstate=sys.maxint) >= 0: - try: - _active.remove(inst) - except ValueError: - # This can happen if two threads create a new Popen instance. - # It's harmless that it was already removed, so ignore. - pass - -PIPE = -1 -STDOUT = -2 - - -def call(*popenargs, **kwargs): - """Run command with arguments. Wait for command to complete, then - return the returncode attribute. - - The arguments are the same as for the Popen constructor. Example: - - retcode = call(["ls", "-l"]) - """ - return Popen(*popenargs, **kwargs).wait() - - -def check_call(*popenargs, **kwargs): - """Run command with arguments. Wait for command to complete. If - the exit code was zero then return, otherwise raise - CalledProcessError. The CalledProcessError object will have the - return code in the returncode attribute. - - The arguments are the same as for the Popen constructor. Example: - - check_call(["ls", "-l"]) - """ - retcode = call(*popenargs, **kwargs) - cmd = kwargs.get("args") - if cmd is None: - cmd = popenargs[0] - if retcode: - raise CalledProcessError(retcode, cmd) - return retcode - - -def list2cmdline(seq): - """ - Translate a sequence of arguments into a command line - string, using the same rules as the MS C runtime: - - 1) Arguments are delimited by white space, which is either a - space or a tab. - - 2) A string surrounded by double quotation marks is - interpreted as a single argument, regard... [truncated message content] |