예제 #1
0
    def do(cls, ws, args):
        '''Executes the rename command.'''
        if args.old_ws == 'default':
            raise WSError('cannot rename the default workspace; please use ws '
                          'default if you want to change it')

        old_ws_dir = get_ws_dir(args.root, args.old_ws)
        if not os.path.exists(old_ws_dir):
            raise WSError('workspace %s does not exist' % args.old_ws)

        d = parse_manifest(args.root)
        for proj in d:
            build_dir = get_build_dir(old_ws_dir, proj)
            if os.path.exists(build_dir):
                raise WSError('cannot rename a workspace that contains build '
                              'artifacts, as some builds contain absolute '
                              'paths and are thus not relocatable. Please '
                              'force-clean this workspace first and then '
                              'rename it.')

        new_ws_dir = get_ws_dir(args.root, args.new_ws)
        if os.path.exists(new_ws_dir):
            raise WSError('workspace %s already exists; please delete it '
                          'first if you want to do this rename' % args.new_ws)

        rename(old_ws_dir, new_ws_dir)
        default_link = get_default_ws_link(args.root)
        if os.readlink(default_link) == args.old_ws:
            remove(default_link)
            symlink(args.new_ws, default_link)
예제 #2
0
파일: test.py 프로젝트: martingkelly/ws
    def do(cls, ws, args):
        '''Executes the test subcmd.'''
        d = parse_manifest(args.root)

        # Validate.
        for project in args.projects:
            if project not in d:
                raise WSError('unknown project %s' % project)

        if len(args.projects) == 0:
            projects = d.keys()
        else:
            projects = args.projects

        for proj in projects:
            build_dir = get_build_dir(ws, proj)
            if not os.path.isdir(build_dir):
                raise WSError('build directory for %s doesn\'t exist; have '
                              'you built it yet?' % proj)

            if 'tests' not in d[proj]:
                raise WSError('no test configured for %s' % proj)

        for proj in projects:
            log('testing %s' % proj)
            build_env = get_build_env(ws, d, proj)
            cmds = d[proj]['tests']
            _test(args.root, ws, proj, cmds, build_env)
예제 #3
0
파일: clean.py 프로젝트: pinklite34/ws
def _polite_clean(root, ws, proj, d):
    '''Performs a polite-clean of a project, calling the underlying build
    system of a project and asking it to clean itself.'''
    builder = get_builder(d, proj)
    build_dir = get_build_dir(ws, proj)
    if not os.path.exists(build_dir):
        return

    build_env = get_build_env(ws, d, proj)
    prefix = get_install_dir(ws, proj)
    source_dir = get_source_dir(root, d, proj)
    builder.clean(proj, prefix, source_dir, build_dir, build_env)
예제 #4
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
예제 #5
0
파일: env.py 프로젝트: pinklite34/ws
    def do(cls, ws, args):
        '''Executes the env command.'''
        build_dir = get_build_dir(ws, args.project)
        if not os.path.isdir(build_dir):
            raise WSError('build directory for %s doesn\'t exist; have you '
                          'built it yet?' % args.project)

        d = parse_manifest(args.root)
        build_env = get_build_env(ws, d, args.project, True)

        # Add the build directory to the path for convenience of running
        # non-installed binaries, such as unit tests.
        merge_var(build_env, 'PATH', [build_dir])

        if len(args.command) > 0:
            cmd = args.command
        else:
            cmd = [get_shell()]

        exe = os.path.basename(cmd[0])
        if exe == 'bash':
            # Tweak the prompt to make it obvious we're in a special env.
            prompt = (
                '\\[\033[1;32m\\][ws:%s env]\\[\033[m\\] \\u@\\h:\\w\\$ '  # noqa: E501
                % args.project)
            build_env['PS1'] = prompt
            cmd.insert(1, '--norc')

        # Set an env var so the user can easily cd $WSBUILD and run tests or
        # similar inside the build directory.
        build_env['WSBUILD'] = build_dir

        log('execing with %s build environment: %s' % (args.project, cmd))

        if args.build_dir:
            args.current_dir = build_dir

        if args.current_dir is not None:
            os.chdir(args.current_dir)

        os.execvpe(cmd[0], cmd, build_env)
예제 #6
0
파일: build.py 프로젝트: martingkelly/ws
def _build(root, ws, proj, d, current, ws_config, force):
    '''Builds a given project.'''
    if not ws_config['projects'][proj]['enable']:
        log('not building manually disabled project %s' % proj,
            logging.WARNING)
        return True

    if ws_config['projects'][proj]['taint']:
        log('force-cleaning tainted project %s' % proj, logging.WARNING)
        clean(root, ws, proj, d, True)

    source_dir = get_source_dir(root, d, proj)
    if not force:
        stored = get_stored_checksum(ws, proj)
        if current == stored:
            log('checksum for %s is current; skipping' % proj)
            return True
    else:
        log('forcing a build of %s' % proj)

    # Make the project directory if needed.
    proj_dir = get_proj_dir(ws, proj)
    try:
        mkdir(proj_dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise

    # Make the build directory if needed.
    build_dir = get_build_dir(ws, proj)
    try:
        mkdir(build_dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise
        needs_configure = False
    else:
        needs_configure = True

    # Populate the convenience source link.
    source_link = get_source_link(ws, proj)
    if not os.path.exists(source_link):
        source_dir = get_source_dir(root, d, proj)
        symlink(source_dir, source_link)

    # Invalidate the checksums for any downstream projects.
    for downstream_dep in d[proj]['downstream']:
        invalidate_checksum(ws, downstream_dep)

    # Add envs to find all projects on which this project is dependent.
    build_env = get_build_env(ws, d, proj)

    # Configure.
    builder = get_builder(d, proj)
    prefix = get_install_dir(ws, proj)
    extra_args = d[proj]['args'] + ws_config['projects'][proj]['args']
    if needs_configure:
        try:
            success = builder.conf(proj, prefix, source_dir, build_dir,
                                   build_env, ws_config['type'],
                                   d[proj]['builder-args'], extra_args)
        except Exception as _e:
            success = False
            e = _e
        else:
            e = None
        if not success:
            # Remove the build directory if we failed so that we are forced to
            # re-run configure next time.
            rmtree(build_dir)
            if e is not None:
                raise e
            else:
                return False

    # Build.
    success = builder.build(proj, prefix, source_dir, build_dir, build_env,
                            d[proj]['targets'], d[proj]['builder-args'],
                            d[proj]['args'])
    if success:
        set_stored_checksum(ws, proj, current)

    return success