コード例 #1
0
ファイル: jwack.py プロジェクト: chirayuk/redo
def setup(maxjobs):
    global _fds, _toplevel
    if _fds:
        return  # already set up
    _debug('setup(%d)\n' % maxjobs)
    flags = ' ' + os.getenv('MAKEFLAGS', '') + ' '
    FIND = ' --jobserver-fds='
    ofs = flags.find(FIND)
    if ofs >= 0:
        s = flags[ofs+len(FIND):]
        (arg,junk) = s.split(' ', 1)
        (a,b) = arg.split(',', 1)
        a = atoi(a)
        b = atoi(b)
        if a <= 0 or b <= 0:
            raise ValueError('invalid --jobserver-fds: %r' % arg)
        try:
            fcntl.fcntl(a, fcntl.F_GETFL)
            fcntl.fcntl(b, fcntl.F_GETFL)
        except IOError, e:
            if e.errno == errno.EBADF:
                raise ValueError('broken --jobserver-fds from make; prefix your Makefile rule with a "+"')
            else:
                raise
        _fds = (a,b)
コード例 #2
0
def setup(maxjobs):
    global _fds, _toplevel
    if _fds:
        return  # already set up
    _debug('setup(%d)\n' % maxjobs)
    flags = ' ' + os.getenv('MAKEFLAGS', '') + ' '
    FIND1 = ' --jobserver-auth='  # renamed in GNU make 4.2
    FIND2 = ' --jobserver-fds='   # fallback syntax
    FIND = FIND1
    ofs = flags.find(FIND1)
    if ofs < 0:
      FIND = FIND2
      ofs = flags.find(FIND2)
    if ofs >= 0:
        s = flags[ofs+len(FIND):]
        (arg,junk) = s.split(' ', 1)
        (a,b) = arg.split(',', 1)
        a = atoi(a)
        b = atoi(b)
        if a <= 0 or b <= 0:
            raise ValueError('invalid --jobserver-auth: %r' % arg)
        try:
            fcntl.fcntl(a, fcntl.F_GETFL)
            fcntl.fcntl(b, fcntl.F_GETFL)
        except IOError, e:
            if e.errno == errno.EBADF:
                raise ValueError('broken --jobserver-auth from make; prefix your Makefile rule with a "+"')
            else:
                raise
        _fds = (a,b)
コード例 #3
0
def setup(maxjobs):
    """
    Initialize the jobs state
    """
    global _pipe, _toplevel
    if _pipe:
        return  # Already set up
    _debug('setup(%d)\n' % maxjobs)
    flags = ' ' + os.getenv('MAKEFLAGS', '') + ' '
    FIND = ' --jobserver-fds='
    ofs = flags.find(FIND)
    if ofs >= 0:
        s = flags[ofs + len(FIND):]
        (arg, junk) = s.split(' ', 1)
        (a, b) = arg.split(',', 1)
        a = atoi(a)
        b = atoi(b)
        if a <= 0 or b <= 0:
            raise ValueError('invalid --jobserver-fds: %r' % arg)
        try:
            fcntl.fcntl(a, fcntl.F_GETFL)
            fcntl.fcntl(b, fcntl.F_GETFL)
        except IOError, e:
            if e.errno == errno.EBADF:
                raise ValueError(
                    'broken --jobserver-fds from make; prefix your Makefile rule with a "+"'
                )
            else:
                raise
        _pipe = (a, b)
コード例 #4
0
ファイル: jwack.py プロジェクト: shamer/redo
def setup(maxjobs):
    global _fds, _toplevel
    if _fds:
        return  # already set up
    _debug('setup(%d)\n' % maxjobs)
    flags = ' ' + os.getenv('MAKEFLAGS', '') + ' '
    FIND = ' --jobserver-fds='
    ofs = flags.find(FIND)
    if ofs >= 0:
        s = flags[ofs+len(FIND):]
        (arg,junk) = s.split(' ', 1)
        (a,b) = arg.split(',', 1)
        a = atoi(a)
        b = atoi(b)
        if a <= 0 or b <= 0:
            raise ValueError('invalid --jobserver-fds: %r' % arg)
        try:
            fcntl.fcntl(a, fcntl.F_GETFL)
            fcntl.fcntl(b, fcntl.F_GETFL)
        except IOError as e:
            if e.errno == errno.EBADF:
                raise ValueError('broken --jobserver-fds from make; prefix your Makefile rule with a "+"')
            else:
                raise
        _fds = (a,b)
    if maxjobs and not _fds:
        # need to start a new server
        _toplevel = maxjobs
        _fds = _make_pipe(100)
        _release(maxjobs-1)
        os.putenv('MAKEFLAGS',
                  '%s --jobserver-fds=%d,%d -j' % (os.getenv('MAKEFLAGS'),
                                                    _fds[0], _fds[1]))
コード例 #5
0
ファイル: jwack.py プロジェクト: asokoloski/redo
def _find_fds():
    flags = ' ' + os.getenv('MAKEFLAGS', '') + ' '
    FIND = ' --jobserver-fds='
    ofs = flags.find(FIND)
    if ofs >= 0:
        s = flags[ofs+len(FIND):]
        (arg,junk) = s.split(' ', 1)
        (a,b) = arg.split(',', 1)
        a = atoi(a)
        b = atoi(b)
        if a <= 0 or b <= 0:
            raise ValueError('invalid --jobserver-fds: %r' % arg)
        try:
            fcntl.fcntl(a, fcntl.F_GETFL)
            fcntl.fcntl(b, fcntl.F_GETFL)
        except IOError, e:
            if e.errno == errno.EBADF:
                raise ValueError('broken --jobserver-fds from make; prefix your Makefile rule with a "+"')
            else:
                raise
        return (a,b)
コード例 #6
0
ファイル: jwack.py プロジェクト: asokoloski/redo
def cleanup_on_exec():
    "Close file descriptors"
    fds = _find_fds()
    if fds:
        a, b = fds
        close_on_exec(a, True)
        close_on_exec(b, True)
    for waitfd in os.environ.get('REDO_JWACK', '').split(','):
        waitfd = atoi(waitfd, None)
        if waitfd != None: close_on_exec(waitfd, True)
    del os.environ['REDO_JWACK']
    os.environ['MAKEFLAGS'] = cleanup_makeflags(os.getenv('MAKEFLAGS'))
コード例 #7
0
ファイル: redo.py プロジェクト: reckbo/redo
def read_opts():
    redo_flavour = os.path.splitext(os.path.basename(sys.argv[0]))[0]
    if redo_flavour == "redo-exec":
        return False, 1, redo_flavour, sys.argv[1:]

    o = options.Options(optspec)
    (opt, flags, extra) = o.parse(sys.argv[1:])

    if opt.overwrite:
        os.environ['REDO_OVERWRITE'] = '1'
    if opt.version:
        from version import TAG
        print TAG
        sys.exit(0)
    if opt.debug:
        os.environ['REDO_DEBUG'] = str(opt.debug or 0)
    if opt.verbose:
        os.environ['REDO_VERBOSE'] = '1'
    if opt.xtrace:
        os.environ['REDO_XTRACE'] = '1'
    if opt.keep_going:
        os.environ['REDO_KEEP_GOING'] = '1'
    if opt.shuffle:
        os.environ['REDO_SHUFFLE'] = '1'
    if opt.debug_locks:
        os.environ['REDO_DEBUG_LOCKS'] = '1'
    if opt.debug_pids:
        os.environ['REDO_DEBUG_PIDS'] = '1'
    if opt.old_args:
        os.environ['REDO_OLD_ARGS'] = '1'
    if opt.old_stdout:
        os.environ['REDO_OLD_STDOUT'] = '1'
    if opt.warn_stdout:
        os.environ['REDO_WARN_STDOUT'] = '1'
    if opt.color != None:
        os.environ['REDO_COLOR'] = str(opt.color)
    if opt.log != None:
        os.environ['REDO_LOG'] = str(opt.log)
    if opt.only_log:
        os.environ['REDO_ONLY_LOG'] = '1'
    if opt.main:
        redo_flavour = opt.main

    return True, atoi(opt.jobs or 1), redo_flavour, extra
コード例 #8
0
ファイル: redo.py プロジェクト: tonyg/redo
from logs import warn, err

try:
    if vars_init.is_toplevel:
        builder.start_stdin_log_reader(status=opt.status, details=opt.details,
            pretty=opt.pretty, color=opt.color,
            debug_locks=opt.debug_locks, debug_pids=opt.debug_pids)
    for t in targets:
        if os.path.exists(t):
            f = state.File(name=t)
            if not f.is_generated:
                warn('%s: exists and not marked as generated; not redoing.\n'
                     % f.nicename())
    state.rollback()
    
    j = atoi(opt.jobs or 1)
    if j < 1 or j > 1000:
        err('invalid --jobs value: %r\n' % opt.jobs)
    jwack.setup(j)
    try:
        assert(state.is_flushed())
        retcode = builder.main(targets, lambda t: (True, True))
        assert(state.is_flushed())
    finally:
        try:
            state.rollback()
        finally:
            try:
                jwack.force_return_tokens()
            except Exception, e:
                traceback.print_exc(100, sys.stderr)
コード例 #9
0
# ----------------------------------------------------------------------

if not os.environ.get('REDO'):
    import sys
    sys.stderr.write('%s: error: must be run from inside a .do\n' %
                     sys.argv[0])
    sys.exit(100)

# ----------------------------------------------------------------------
# Public variables
# ----------------------------------------------------------------------

PWD = os.environ.get('REDO_PWD', '')
TARGET = os.environ.get('REDO_TARGET', '')
DEPTH = os.environ.get('REDO_DEPTH', '')
DEBUG = atoi(os.environ.get('REDO_DEBUG', ''))
DEBUG_LOCKS = os.environ.get('REDO_DEBUG_LOCKS', '') and 1 or 0
DEBUG_PIDS = os.environ.get('REDO_DEBUG_PIDS', '') and 1 or 0
VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0
XTRACE = os.environ.get('REDO_XTRACE', '') and 1 or 0
KEEP_GOING = os.environ.get('REDO_KEEP_GOING', '') and 1 or 0
SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0
STARTDIR = os.environ.get('REDO_STARTDIR', '')
RUNID = atoi(os.environ.get('REDO_RUNID')) or None
BASE = os.environ['REDO_BASE']
while BASE and BASE.endswith('/'):
    BASE = BASE[:-1]

UNLOCKED = os.environ.get('REDO_UNLOCKED', '') and 1 or 0
os.environ['REDO_UNLOCKED'] = ''  # not inheritable by subprocesses
コード例 #10
0
ファイル: redo.py プロジェクト: cidermole/redo
if opt.old_args:
    os.environ['REDO_OLD_ARGS'] = '1'
if opt.target_only:
    os.environ['REDO_TARGET_ONLY'] = '1'

import vars_init
vars_init.init(targets)

import vars, state, builder, jwack
from log import warn, err

try:
    for t in targets:
        if os.path.exists(t):
            f = state.File(name=t)
            if not f.is_generated:
                warn('%s: exists and not marked as generated; not redoing.\n'
                     % f.nicename())
    
    j = atoi(opt.jobs or 1)
    if j < 1 or j > 1000:
        err('invalid --jobs value: %r\n' % opt.jobs)
    jwack.setup(j)
    try:
        retcode = builder.main(targets, lambda t: True)
    finally:
        jwack.force_return_tokens()
    sys.exit(retcode)
except KeyboardInterrupt:
    sys.exit(200)
コード例 #11
0
        try:
            fcntl.fcntl(a, fcntl.F_GETFL)
            fcntl.fcntl(b, fcntl.F_GETFL)
        except IOError, e:
            if e.errno == errno.EBADF:
                raise ValueError(
                    'broken --jobserver-auth from make; prefix your Makefile rule with a "+"'
                )
            else:
                raise
        _tokenfds = (a, b)

    cheats = os.getenv('REDO_CHEATFDS', '')
    if cheats:
        (a, b) = cheats.split(',', 1)
        a = atoi(a)
        b = atoi(b)
        if a <= 0 or b <= 0:
            raise ValueError('invalid REDO_CHEATFDS: %r' % cheats)
        _cheatfds = (a, b)

    if not _tokenfds:
        # need to start a new server
        _toplevel = maxjobs
        _tokenfds = _make_pipe(100)
        _create_tokens(maxjobs - 1)
        _release_except_mine()
        os.putenv(
            'MAKEFLAGS', '%s -j --jobserver-auth=%d,%d --jobserver-fds=%d,%d' %
            (os.getenv('MAKEFLAGS', ''), _tokenfds[0], _tokenfds[1],
             _tokenfds[0], _tokenfds[1]))