Beispiel #1
0
def run(fips_dir, proj_dir, cfg_name, target_name, target_args, target_cwd):
    """run a build target executable

    :param fips_dir:    absolute path of fips
    :param proj_dir:    absolute path of project dir
    :param cfg_name:    config name or pattern
    :param target_name: the target name
    :param target_args: command line arguments for build target
    :param target_cwd:  working directory or None
    """

    retcode = 10
    proj_name = util.get_project_name_from_dir(proj_dir)
    util.ensure_valid_project_dir(proj_dir)

    # load the config(s)
    configs = config.load(fips_dir, proj_dir, cfg_name)
    if configs:
        for cfg in configs:
            log.colored(
                log.YELLOW, "=== run '{}' (config: {}, project: {}):".format(
                    target_name, cfg['name'], proj_name))

            # find deploy dir where executables live
            deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
            if not target_cwd:
                target_cwd = deploy_dir

            if cfg['platform'] == 'emscripten':
                # special case: emscripten app
                html_name = target_name + '.html'
                if util.get_host_platform() == 'osx':
                    try:
                        subprocess.call(
                            'open http://localhost:8080/{} ; http-server -c-1 -g'
                            .format(html_name),
                            cwd=target_cwd,
                            shell=True)
                    except KeyboardInterrupt:
                        return 0
                elif util.get_host_platform() == 'win':
                    try:
                        cmd = 'cmd /c start http://localhost:8080/{} && http-server -c-1 -g'.format(
                            html_name)
                        subprocess.call(cmd, cwd=target_cwd, shell=True)
                    except KeyboardInterrupt:
                        return 0
                elif util.get_host_platform() == 'linux':
                    try:
                        subprocess.call(
                            'xdg-open http://localhost:8080/{}; http-server -c-1 -g'
                            .format(html_name),
                            cwd=target_cwd,
                            shell=True)
                    except KeyboardInterrupt:
                        return 0
                else:
                    log.error(
                        "don't know how to start HTML app on this platform")
            elif cfg['platform'] == 'android':
                try:
                    adb_path = android.get_adb_path(fips_dir)
                    pkg_name = android.target_to_package_name(target_name)
                    # Android: first re-install the apk...
                    cmd = '{} install -r {}.apk'.format(adb_path, target_name)
                    subprocess.call(cmd, shell=True, cwd=deploy_dir)
                    # ...then start the apk
                    cmd = '{} shell am start -n {}/android.app.NativeActivity'.format(
                        adb_path, pkg_name)
                    subprocess.call(cmd, shell=True)
                    # ...then run adb logcat
                    cmd = '{} logcat'.format(adb_path)
                    subprocess.call(cmd, shell=True)
                    return 0
                except KeyboardInterrupt:
                    return 0

            elif os.path.isdir('{}/{}.app'.format(deploy_dir, target_name)):
                # special case: Mac app
                cmd_line = '{}/{}.app/Contents/MacOS/{}'.format(
                    deploy_dir, target_name, target_name)
            else:
                cmd_line = '{}/{}'.format(deploy_dir, target_name)
            if cmd_line:
                if target_args:
                    cmd_line += ' ' + ' '.join(target_args)
                try:
                    retcode = subprocess.call(args=cmd_line,
                                              cwd=target_cwd,
                                              shell=True)
                except OSError as e:
                    log.error("Failed to execute '{}' with '{}'".format(
                        target_name, e.strerror))
    else:
        log.error("No valid configs found for '{}'".format(cfg_name))

    return retcode
Beispiel #2
0
def run(fips_dir, proj_dir, cfg_name, target_name, target_args, target_cwd) :
    """run a build target executable

    :param fips_dir:    absolute path of fips
    :param proj_dir:    absolute path of project dir
    :param cfg_name:    config name or pattern
    :param target_name: the target name
    :param target_args: command line arguments for build target
    :param target_cwd:  working directory or None
    """

    retcode = 10
    proj_name = util.get_project_name_from_dir(proj_dir)
    util.ensure_valid_project_dir(proj_dir)
    
    # load the config(s)
    configs = config.load(fips_dir, proj_dir, cfg_name)
    if configs :
        for cfg in configs :
            log.colored(log.YELLOW, "=== run '{}' (config: {}, project: {}):".format(target_name, cfg['name'], proj_name))

            # find deploy dir where executables live
            deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg)
            if not target_cwd :
                target_cwd = deploy_dir

            if cfg['platform'] in ['emscripten', 'pnacl'] : 
                # special case: emscripten app
                if cfg['platform'] == 'emscripten' :
                    html_name = target_name + '.html'
                else :
                    html_name = target_name + '_pnacl.html'
                if util.get_host_platform() == 'osx' :
                    try :
                        subprocess.call(
                            'open http://localhost:8000/{} ; python {}/mod/httpserver.py'.format(html_name, fips_dir),
                            cwd = target_cwd, shell=True)
                    except KeyboardInterrupt :
                        return 0
                elif util.get_host_platform() == 'win' :
                    try :
                        cmd = 'cmd /c start http://localhost:8000/{} && python {}/mod/httpserver.py'.format(html_name, fips_dir)
                        subprocess.call(cmd, cwd = target_cwd, shell=True)
                    except KeyboardInterrupt :
                        return 0
                elif util.get_host_platform() == 'linux' :
                    try :
                        subprocess.call(
                            'xdg-open http://localhost:8000/{}; python {}/mod/httpserver.py'.format(html_name, fips_dir),
                            cwd = target_cwd, shell=True)
                    except KeyboardInterrupt :
                        return 0
                else :
                    log.error("don't know how to start HTML app on this platform")
            elif cfg['platform'] == 'android' :
                try :
                    adb_path = android.get_adb_path(fips_dir)
                    # Android: first install the apk...
                    cmd = '{} install -r {}/{}-debug.apk'.format(adb_path, deploy_dir, target_name)
                    subprocess.call(cmd, shell=True)
                    # ...then start the apk
                    cmd = '{} shell am start -n com.fips.{}/android.app.NativeActivity'.format(adb_path, target_name)
                    subprocess.call(cmd, shell=True)
                    # ...then run adb logcat
                    cmd = '{} logcat'.format(adb_path)
                    subprocess.call(cmd, shell=True)
                    return 0
                except KeyboardInterrupt :
                    return 0

            elif os.path.isdir('{}/{}.app'.format(deploy_dir, target_name)) :
                # special case: Mac app
                cmd_line = '{}/{}.app/Contents/MacOS/{}'.format(deploy_dir, target_name, target_name)
            else :
                cmd_line = '{}/{}'.format(deploy_dir, target_name) 
            if cmd_line :
                if target_args :
                    cmd_line += ' ' + ' '.join(target_args)
                try:
                    retcode = subprocess.call(args=cmd_line, cwd=target_cwd, shell=True)
                except OSError, e:
                    log.error("Failed to execute '{}' with '{}'".format(target_name, e.strerror))