def make_compiler_component(driver): """ Given the name of a compiler driver, generate a string describing the compiler suite and version. Returns ``"unknown-compiler"`` if the compiler cannot be identified. """ from hpx.process import process windows = 0 try: from sys import getwindowsversion # on windows, running cl.exe with no args returns what we want windows = 1 proc = process("%s" % driver) except ImportError as err: # on POSIX, assume GNU-style long options proc = process("%s --version" % driver) proc.wait() raw = proc.read() if (windows): compiler = compile(r'Version ([0-9.]+)').match(raw) if (compiler): compiler = compiler.expand(r'msvc-\2') if compile(r'^[a-z0-9\-.]+$').match(compiler): return compiler else: return "msvc" # handle GNU GCC and Intel compiler = compile( r'^(icc|icpc|gcc|g[+][+])[^ ]* [(][^)]+[)] ([0-9.]+)').match(raw) if (compiler): unescaped = compiler.expand(r'\1-\2') compiler = compile(r'[+]').sub("x", unescaped) if compile(r'^[a-z0-9\-.]+$').match(compiler): return compiler else: unescaped = compile(r'^(icc|icpc|gcc|g[+][+])').match(raw).expand( r'\1') return compile(r'[+]').sub("x", unescaped) # handle Clang compiler = compile(r'(clang) version ([0-9.]+)').match(raw) if (compiler): compiler = compiler.expand(r'\1-\2') if compile(r'^[a-z0-9\-.]+$').match(compiler): return compiler else: return compile(r'^(clang)').match(raw).expand(r'\1') return "unknown-compiler"
def make_compiler_component(driver): """ Given the name of a compiler driver, generate a string describing the compiler suite and version. Returns ``"unknown-compiler"`` if the compiler cannot be identified. """ from hpx.process import process windows = 0 try: from sys import getwindowsversion # on windows, running cl.exe with no args returns what we want windows = 1 proc = process("%s" % driver) except ImportError as err: # on POSIX, assume GNU-style long options proc = process("%s --version" % driver) proc.wait() raw = proc.read() if (windows): compiler = compile(r'Version ([0-9.]+)').match(raw) if (compiler): compiler = compiler.expand(r'msvc-\2') if compile(r'^[a-z0-9\-.]+$').match(compiler): return compiler else: return "msvc" # handle GNU GCC and Intel compiler = compile(r'^(icc|icpc|gcc|g[+][+])[^ ]* [(][^)]+[)] ([0-9.]+)').match(raw) if (compiler): unescaped = compiler.expand(r'\1-\2') compiler = compile(r'[+]').sub("x", unescaped) if compile(r'^[a-z0-9\-.]+$').match(compiler): return compiler else: unescaped = compile(r'^(icc|icpc|gcc|g[+][+])').match(raw).expand(r'\1') return compile(r'[+]').sub("x", unescaped) # handle Clang compiler = compile(r'(clang) version ([0-9.]+)').match(raw) if (compiler): compiler = compiler.expand(r'\1-\2') if compile(r'^[a-z0-9\-.]+$').match(compiler): return compiler else: return compile(r'^(clang)').match(raw).expand(r'\1') return "unknown-compiler"
def make_compiler_component(driver): """ Given the name of a compiler driver, generate a string describing the compiler suite and version. Returns ``"unknown-compiler"`` if the compiler cannot be identified. """ from hpx.process import process windows = 0 try: from sys import getwindowsversion # on windows, running cl.exe with no args returns what we want windows = 1 proc = process("%s" % driver) except ImportError, err: # on POSIX, assume GNU-style long options proc = process("%s --version" % driver)
def run(cmd, timeout=3600): proc = process(cmd) (timed_out, returncode) = proc.wait(timeout) output = '' while True: s = proc.read() if s: output += s else: break return (timed_out, returncode, output)
def run(cmd, outfl = None, timeout = 360): start = datetime.now() proc = process(cmd) (timed_out, returncode) = proc.wait(timeout) now = datetime.now() while outfl: s = proc.read() if s: writeres(s, outfl) else: break if timed_out: writeres('Command timed out.\n', outfl) return (returncode, now - start)
def run(cmd, outfl=None, timeout=360): start = datetime.now() proc = process(cmd) (timed_out, returncode) = proc.wait(timeout) now = datetime.now() while outfl: s = proc.read() if s: writeres(s, outfl) else: break if timed_out: writeres('Command timed out.\n', outfl) return (returncode, now - start)
def revision(wc_path=None): """ Return the SVN revision of the given path, or None if the given path is not a working copy. If path is None, the current working directory is queried. Throws IOError if the path doesn't exist. """ from hpx.process import process from os.path import realpath, exists if wc_path == None: from os import getcwd wc_path = getcwd() wc_path = realpath(wc_path) if not exists(wc_path): from os import strerror from errno import errorcode, ENOENT raise IOError(ENOENT, strerror(ENOENT), wc_path) windows = 0 proc = None try: from sys import getwindowsversion # On Windows, we might have to fall back to subwcrev.exe (from TortoiseSVN). windows = 1 try: proc = process( "svnversion %s" % wc_path.replace('\\', '/')) except WindowsError, err: # We couldn't find svnversion, fallback to subwcrev.exe from tempfile import NamedTemporaryFile from os import unlink from os.path import normpath # Create two temporary files for use with subwcrev.exe input = NamedTemporaryFile(delete=False) output = NamedTemporaryFile(delete=False) input.write("$WCREV$$WCMODS?M:$\n") input.close() output.close() proc = process( "subwcrev.exe %s %s %s" % ( wc_path.replace('\\', '/') , input.name.replace('\\', '/') , output.name.replace('\\', '/'))) proc.wait() results = open(output.name.replace('\\', '/')) raw = results.read().rstrip() results.close() # Clean up the temporary files unlink(input.name.replace('\\', '/')) unlink(output.name.replace('\\', '/')) if 0 == len(raw): return None else: return raw except ImportError, err: # On POSIX, svnversion should always be available if SVN is installed. proc = process("svnversion %s" % wc_path)