示例#1
0
文件: shell.py 项目: martingkelly/ws
def call_output(cmd, env=None, text=True, override=False):
    '''Calls a given command with the given environment, returning the
    output. Note that we assume the output is UTF-8.'''
    log_cmd(cmd)
    if (not dry_run()) or override:
        out = subprocess.check_output(cmd, env=env)
        if text:
            out = out.decode('utf-8')
        return out
示例#2
0
文件: shell.py 项目: martingkelly/ws
def rmtree(path, fail_ok=False):
    '''Removes the given file or directory, recursively.'''
    log('recursively removing %s' % path)
    if not dry_run():
        try:
            shutil.rmtree(path)
        except FileNotFoundError:
            if not fail_ok:
                raise
示例#3
0
文件: shell.py 项目: martingkelly/ws
def remove(path, fail_ok=False):
    '''Removes the given path.'''
    log('removing %s' % path)
    if not dry_run():
        try:
            os.unlink(path)
        except FileNotFoundError:
            if not fail_ok:
                raise
示例#4
0
def invalidate_checksum(ws, proj):
    '''Invalidates the current project checksum. This can be used to force a
    project to rebuild, for example if one of its dependencies rebuilds.'''
    log('invalidating checksum for %s' % proj)
    if dry_run():
        return

    try:
        remove(get_checksum_file(ws, proj))
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise
示例#5
0
def sync_config(ws):
    '''Writes out the config if and only if it changed since we first read
       it.'''
    if _WS_CONFIG == _ORIG_WS_CONFIG:
        log('ws config did not change, so not updating')
        return
    log('updating config at %s' % ws)

    if dry_run():
        return

    write_config(ws, _WS_CONFIG)
示例#6
0
def calculate_checksum(source_dir):
    '''Calculates and returns the SHA-1 checksum of a given git directory,
    including submodules and dirty files. This function should uniquely
    identify any source code that would impact the build. Note that we ignore
    files that have not been added to git but are in the git directory (files
    on which you have not run "git add". If this is not the case, it is likely
    a bug in the underlying project. Although we could use the find command
    instead of git, it is much slower and takes into account inconsequential
    files, like .cscope or .vim files that don't change the build (and that are
    typically put in .gitignore).

    It is very important that this function is both fast and accurate, as it is
    used to determine when projects need to be rebuilt, and thus gets run
    frequently. If this function gets too slow, working with ws will become
    painful. If this function is not accurate, then ws will have build bugs.'''
    # Collect the SHA-1 of HEAD and the diff of all dirty files.
    #
    # Note that it's very important to use the form "git diff HEAD" rather than
    # "git diff" or "git diff --cached" because "git diff HEAD" collects ALL
    # changes rather than just staged or unstaged changes.
    #
    # Additionally note the use of "submodule foreach --recursive", which will
    # recursively diff all submodules, submodules-inside-submodules, etc. This
    # ensures correctness even if deeply nested submodules change.
    head = call_git(source_dir, ('rev-parse', '--verify', 'HEAD'))
    repo_diff = call_git(source_dir,
                         ('diff',
                          'HEAD',
                          '--diff-algorithm=myers',
                          '--no-renames',
                          '--submodule=short'))
    submodule_diff = call_git(source_dir,
                              ('submodule',
                               'foreach',
                               '--recursive',
                               'git',
                               'diff',
                               'HEAD',
                               '--diff-algorithm=myers',
                               '--no-renames'))

    if dry_run():
        return 'bogus-calculated-checksum'

    # Finally, combine all data into one master hash.
    total = hashlib.sha1()
    total.update(head)
    total.update(repo_diff)
    total.update(submodule_diff)

    return total.hexdigest()
示例#7
0
文件: clean.py 项目: pinklite34/ws
def _force_clean(ws, proj):
    '''Performs a force-clean of a project, removing all files instead of
    politely calling the clean function of the underlying build system.'''
    build_dir = get_build_dir(ws, proj)
    log('removing %s' % build_dir)
    if dry_run():
        return
    try:
        rmtree(build_dir)
    except OSError as e:
        if e.errno == errno.ENOENT:
            log('%s already removed' % build_dir)
        else:
            raise

    config = get_ws_config(ws)
    config['projects'][proj]['taint'] = False
示例#8
0
def get_stored_checksum(ws, proj):
    '''Retrieves the currently stored checksum for a given project, or None if
    there is no checksum (either because the project was cleaned, or because
    we've never built the project before).'''
    if dry_run():
        return 'bogus-stored-checksum'

    checksum_file = get_checksum_file(ws, proj)
    try:
        with open(checksum_file, 'r') as f:
            checksum = f.read().rstrip()
    except IOError:
        return None

    # Note that we don't need to check if the checksum is corrupt. If it is, it
    # will not match the calculated checksum, so we will correctly see a stale
    # checksum.

    return checksum
示例#9
0
文件: shell.py 项目: martingkelly/ws
def call(cmd, **kwargs):
    '''Calls a given command with the given environment, swallowing the
    output.'''
    log_cmd(cmd)
    if not dry_run():
        subprocess.check_call(cmd, **kwargs)
示例#10
0
文件: shell.py 项目: martingkelly/ws
def rename(old, new):
    '''Renames the given path.'''
    log('renaming %s --> %s' % (old, new))
    if not dry_run():
        os.rename(old, new)
示例#11
0
文件: shell.py 项目: martingkelly/ws
def symlink(dest, src):
    '''Makes a symlink from src to dest.'''
    log('making symlink %s --> %s' % (src, dest))
    if not dry_run():
        os.symlink(dest, src)
示例#12
0
文件: shell.py 项目: martingkelly/ws
def mkdir(path):
    '''Makes a directory.'''
    log('making directory %s' % path)
    if not dry_run():
        os.mkdir(path)