Пример #1
0
def run(fips_dir, proj_dir, target_name, target_cwd):
    if not check_exists(fips_dir):
        log.error("http-server tool not found (npm install http-server -g)")
        return

    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
    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
    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
    else :
        log.error("don't know how to start HTML app on this platform")
Пример #2
0
def serve_webpage(fips_dir, proj_dir) :
    ws_dir = util.get_workspace_dir(fips_dir)
    webpage_dir = '{}/fips-deploy/oryol-webpage'.format(ws_dir)
    p = util.get_host_platform()
    if p == 'osx' :
        try :
            subprocess.call(
                'open http://localhost:8000 ; python {}/mod/httpserver.py'.format(fips_dir),
                cwd = webpage_dir, shell=True)
        except KeyboardInterrupt :
            pass
    elif p == 'win':
        try:
            subprocess.call(
                'cmd /c start http://localhost:8000 && python {}/mod/httpserver.py'.format(fips_dir),
                cwd = webpage_dir, shell=True)
        except KeyboardInterrupt:
            pass
    elif p == 'linux':
        try:
            subprocess.call(
                'xdg-open http://localhost:8000; python {}/mod/httpserver.py'.format(fips_dir),
                cwd = webpage_dir, shell=True)
        except KeyboardInterrupt:
            pass
Пример #3
0
def finish(sdk_dir):
    """finish setting up the emscripten SDK

    FIXME: the used SDK version should be configurable!
    """
    if util.get_host_platform() == 'win':
        # on Windows use a stable SDK version which doesn't require clang to be compiled
        subprocess.call(args=['emsdk.bat', 'update'], cwd=sdk_dir, shell=True)
        subprocess.call(args=['emsdk.bat', 'install',
                              get_sdk_version()],
                        cwd=sdk_dir,
                        shell=True)
        subprocess.call(
            args=['emsdk.bat', 'activate', '--embedded',
                  get_sdk_version()],
            cwd=sdk_dir,
            shell=True)
    else:
        subprocess.call(args=['./emsdk update'], cwd=sdk_dir, shell=True)
        subprocess.call(args=['./emsdk install {}'.format(get_sdk_version())],
                        cwd=sdk_dir,
                        shell=True)
        subprocess.call(
            args=['./emsdk activate --embedded {}'.format(get_sdk_version())],
            cwd=sdk_dir,
            shell=True)
Пример #4
0
def serve_webpage(fips_dir, proj_dir):
    proj_build_dir = util.get_deploy_root_dir(fips_dir, 'sokol-samples')
    webpage_dir = '{}/sokol-webpage'.format(proj_build_dir)
    p = util.get_host_platform()
    if p == 'osx':
        try:
            subprocess.call('http-server -c-1 -g -o'.format(fips_dir),
                            cwd=webpage_dir,
                            shell=True)
        except KeyboardInterrupt:
            pass
    elif p == 'win':
        try:
            subprocess.call('http-server -c-1 -g -o'.format(fips_dir),
                            cwd=webpage_dir,
                            shell=True)
        except KeyboardInterrupt:
            pass
    elif p == 'linux':
        try:
            subprocess.call('http-server -c-1 -g -o'.format(fips_dir),
                            cwd=webpage_dir,
                            shell=True)
        except KeyboardInterrupt:
            pass
Пример #5
0
def get_cc_header_paths():
    '''runs "cc -E -xc++ -v dummy.cc" and extract the header search
    path from stdout, return these as array of strings.
    '''
    if util.get_host_platform() not in ['osx','linux']:
        return []
    
    # write a dummy C source file
    tmp = tempfile.NamedTemporaryFile(delete=False)
    tmp.write(b'int main() {return 0;}')
    tmp.close()

    # run clang in preprocessor mode
    outp = subprocess.check_output(['cc', '-E', '-xc++', '-v', tmp.name], stderr=subprocess.STDOUT).decode("utf-8")

    # delete the temp source file
    os.remove(tmp.name)

    # find the header search paths
    result = []
    capture = False
    for line in outp.splitlines():
        if line == '#include <...> search starts here:':
            # start capturing lines
            capture = True
            continue
        if line == 'End of search list.':
            # finish capturing
            break
        if capture:
            l = line.replace('(framework directory)', '').strip()
            result.append(l)
    return result
Пример #6
0
def get_vs_header_paths(fips_dir, proj_dir, cfg):
    '''hacky way to find the header search path in the latest installed
    Windows 10 Kit and Visual Studio instance
    '''
    if util.get_host_platform() != 'win':
        return []

    # Windows system headers are in 2 locations, first find the latest Windows Kit
    result = []
    kits = glob.glob('C:/Program Files (x86)/Windows Kits/10/Include/*/')
    if kits:
        latest = max(kits).replace('\\','/')
        subdirs = glob.glob(latest + '/*/')
        for d in subdirs:
            result.append(d.replace('\\','/'))

    # next get the used active Visual Studio instance from the cmake cache
    proj_name = util.get_project_name_from_dir(proj_dir)
    build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
    outp = subprocess.check_output(['cmake', '-LA', '.'], cwd=build_dir).decode("utf-8")
    for line in outp.splitlines():
        if line.startswith('CMAKE_LINKER:FILEPATH='):
            bin_index = line.find('/bin/')
            if bin_index > 0:
                result.append(line[22:bin_index+1]+'include')
    return result
Пример #7
0
def serve_webpage(fips_dir, proj_dir):
    ws_dir = util.get_workspace_dir(fips_dir)
    webpage_dir = '{}/fips-deploy/{}'.format(ws_dir, WebpageDeployDir)
    p = util.get_host_platform()
    if p == 'osx':
        try:
            subprocess.call('http-server -c-1 -g -o'.format(fips_dir),
                            cwd=webpage_dir,
                            shell=True)
        except KeyboardInterrupt:
            pass
    elif p == 'win':
        try:
            subprocess.call('http-server -c-1 -g -o'.format(fips_dir),
                            cwd=webpage_dir,
                            shell=True)
        except KeyboardInterrupt:
            pass
    elif p == 'linux':
        try:
            subprocess.call('http-server -c-1 -g -o'.format(fips_dir),
                            cwd=webpage_dir,
                            shell=True)
        except KeyboardInterrupt:
            pass
Пример #8
0
def get_cc_header_paths():
    '''runs "cc -E -xc++ -v dummy.cc" and extract the header search
    path from stdout, return these as array of strings.
    '''
    if util.get_host_platform() not in ['osx', 'linux']:
        return []

    # write a dummy C source file
    tmp = tempfile.NamedTemporaryFile(delete=False)
    tmp.write(b'int main() {return 0;}')
    tmp.close()

    # run clang in preprocessor mode
    outp = subprocess.check_output(['cc', '-E', '-xc++', '-v', tmp.name],
                                   stderr=subprocess.STDOUT).decode("utf-8")

    # delete the temp source file
    os.remove(tmp.name)

    # find the header search paths
    result = []
    capture = False
    for line in outp.splitlines():
        if line == '#include <...> search starts here:':
            # start capturing lines
            capture = True
            continue
        if line == 'End of search list.':
            # finish capturing
            break
        if capture:
            l = line.replace('(framework directory)', '').strip()
            result.append(l)
    return result
Пример #9
0
def get_vs_header_paths(fips_dir, proj_dir, cfg):
    '''hacky way to find the header search path in the latest installed
    Windows 10 Kit and Visual Studio instance
    '''
    if util.get_host_platform() != 'win':
        return []

    # Windows system headers are in 2 locations, first find the latest Windows Kit
    result = []
    kits = glob.glob('C:/Program Files (x86)/Windows Kits/10/Include/*/')
    if kits:
        latest = max(kits).replace('\\', '/')
        subdirs = glob.glob(latest + '/*/')
        for d in subdirs:
            result.append(d.replace('\\', '/'))

    # next get the used active Visual Studio instance from the cmake cache
    proj_name = util.get_project_name_from_dir(proj_dir)
    build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
    outp = subprocess.check_output(['cmake', '-LA', '.'],
                                   cwd=build_dir).decode("utf-8")
    for line in outp.splitlines():
        if line.startswith('CMAKE_LINKER:FILEPATH='):
            bin_index = line.find('/bin/')
            if bin_index > 0:
                result.append(line[22:bin_index + 1] + 'include')
    return result
Пример #10
0
def run(proj_dir):
    host = util.get_host_platform()
    if host == 'linux':
        try:
            if find_executable("clion.sh") is not None:
                subprocess.Popen('clion.sh {}'.format(proj_dir),
                                 cwd=proj_dir,
                                 shell=True)
            else:
                subprocess.Popen('clion {}'.format(proj_dir),
                                 cwd=proj_dir,
                                 shell=True)
        except OSError:
            log.error("Failed to run JetBrains CLion as 'clion' or 'clion.sh'")
    elif host == 'osx':
        try:
            subprocess.Popen(
                'open /Applications/CLion.app --args {}'.format(proj_dir),
                cwd=proj_dir,
                shell=True)
        except OSError:
            log.error(
                "Failed to run JetBrains CLion as '/Applications/CLion.app'")
    else:
        log.error("Not supported on this platform")
Пример #11
0
def serve_webpage(fips_dir, proj_dir) :
    ws_dir = util.get_workspace_dir(fips_dir)
    webpage_dir = '{}/fips-deploy/sokol-webpage'.format(ws_dir)
    p = util.get_host_platform()
    if p == 'osx' :
        try :
            subprocess.call(
                'open http://localhost:8000 ; python {}/mod/httpserver.py'.format(fips_dir),
                cwd = webpage_dir, shell=True)
        except KeyboardInterrupt :
            pass
    elif p == 'win':
        try:
            subprocess.call(
                'cmd /c start http://localhost:8000 && python {}/mod/httpserver.py'.format(fips_dir),
                cwd = webpage_dir, shell=True)
        except KeyboardInterrupt:
            pass
    elif p == 'linux':
        try:
            subprocess.call(
                'xdg-open http://localhost:8000; python {}/mod/httpserver.py'.format(fips_dir),
                cwd = webpage_dir, shell=True)
        except KeyboardInterrupt:
            pass
Пример #12
0
def serve_webpage(fips_dir, proj_dir):
    proj_build_dir = util.get_deploy_root_dir(fips_dir, 'chips-test')
    webpage_dir = '{}/chips-webpage'.format(proj_build_dir)
    p = util.get_host_platform()
    if p == 'osx':
        try:
            subprocess.call(
                'open http://localhost:8000 ; python {}/mod/httpserver.py'.
                format(fips_dir),
                cwd=webpage_dir,
                shell=True)
        except KeyboardInterrupt:
            pass
    elif p == 'win':
        try:
            subprocess.call(
                'cmd /c start http://localhost:8000 && python {}/mod/httpserver.py'
                .format(fips_dir),
                cwd=webpage_dir,
                shell=True)
        except KeyboardInterrupt:
            pass
    elif p == 'linux':
        try:
            subprocess.call(
                'xdg-open http://localhost:8000; python {}/mod/httpserver.py'.
                format(fips_dir),
                cwd=webpage_dir,
                shell=True)
        except KeyboardInterrupt:
            pass
Пример #13
0
def update_android_sdk(fips_dir, proj_dir) :
    # FIXME: hardcoded version numbers should be configurable
    if util.get_host_platform() == 'win' :
        cmd = '{}/tools/android.bat update sdk -f -u --all --filter tools,platform-tools,build-tools-19.1.0,android-19'.format(get_androidsdk_dir(fips_dir))
    else :
        cmd = 'sh {}/tools/android update sdk -f -u --all --filter tools,platform-tools,build-tools-19.1.0,android-19'.format(get_androidsdk_dir(fips_dir))
    print cmd
    subprocess.call(cmd, cwd=fips_dir, shell=True)
Пример #14
0
def uncompress(fips_dir, path) :
    # the python zip module doesn't preserve the executable flags, so just
    # call unzip on Linux and OSX
    if util.get_host_platform() in ['osx', 'linux']:
        subprocess.call('unzip {}'.format(path), cwd=get_sdk_dir(fips_dir), shell=True)
    else:
        with zipfile.ZipFile(path, 'r') as archive:
            archive.extractall(get_sdk_dir(fips_dir))
Пример #15
0
def check_config_valid(fips_dir, cfg, print_errors=False) :
    """check if provided config is valid, and print errors if not

    :param cfg:     a loaded config object
    :returns:       (True, [ errors ]) tuple with result and error messages
    """
    errors = []
    valid = True

    # check whether all required fields are present
    # (NOTE: name and folder should always be present since they are appended
    # during loading)
    required_fields = ['name', 'folder', 'platform', 'generator', 'build_tool', 'build_type']
    for field in required_fields :
        if field not in cfg :
            errors.append("missing field '{}' in '{}'".format(field, cfg['path']))
            valid = False
    
    # check if the platform string is valid
    if not valid_platform(cfg['platform']) :
        errors.append("invalid platform name '{}' in '{}'".format(cfg['platform'], cfg['path']))
        valid = False

    # check if the platform can be built on current host platform
    if cfg['platform'] not in target_platforms[util.get_host_platform()] :
        errors.append("'{}' is not a valid target platform for host '{}'".format(cfg['platform'], util.get_host_platform()))
        valid = False

    # check if the target platform SDK is installed
    if not check_sdk(fips_dir, cfg['platform']) :
        errors.append("platform sdk for '{}' not installed (see './fips help setup')".format(cfg['platform']))
        valid = False

    # check if the generator name is valid
    if not valid_generator(cfg['generator']) :
        errors.append("invalid generator name '{}' in '{}'".format(cfg['generator'], cfg['path']))
        valid = False

    # check if build tool is valid
    if not valid_build_tool(cfg['build_tool']) :
        errors.append("invalid build_tool name '{}' in '{}'".format(cfg['build_tool'], cfg['path']))
        valid = False

    # check if the build tool can be found
    if not check_build_tool(fips_dir, cfg['build_tool']) :
        errors.append("build tool '{}' not found".format(cfg['build_tool']))
        valid = False

    # check if build type is valid (Debug, Release, Profiling)
    if not valid_build_type(cfg['build_type']) :
        errors.append("invalid build_type '{}' in '{}'".format(cfg['build_type'], cfg['path']))
        valid = False

    if print_errors :
        for error in errors :
            log.error(error, False)

    return (valid, errors)
Пример #16
0
def remove_old_sdks(fips_dir):
    # this checks for any "old" SDKs and removes them
    old_sdk_path = get_sdkroot_dir(fips_dir) + '/' + util.get_host_platform()
    if os.path.isdir(old_sdk_path):
        if util.confirm(log.RED + "Delete obsolete emscripten SDK in '{}'?".format(old_sdk_path) + log.DEF):
            log.info("Deleting '{}'...".format(old_sdk_path))
            shutil.rmtree(old_sdk_path, onerror=remove_readonly)
        else:
            log.info("'No' selected, nothing deleted")
Пример #17
0
def view(fips_dir, proj_dir):
    proj_name = util.get_project_name_from_dir(proj_dir)
    out_dir = util.get_workspace_dir(fips_dir)+'/fips-deploy/'+proj_name+'-markdeep'
    if os.path.isfile(out_dir+'/index.html'):
        p = util.get_host_platform()
        if p == 'osx':
            subprocess.call('open index.html', cwd=out_dir, shell=True)
        elif p == 'win':
            subprocess.call('start index.html', cwd=out_dir, shell=True)
        elif p == 'linux':
            subprocess.call('xdg-open index.html', cwd=out_dir, shell=True)
    else:
        log.error('no generated index.html found: {}'.format(out_dir+'/index.html'))
Пример #18
0
def view(fips_dir, proj_dir):
    proj_name = util.get_project_name_from_dir(proj_dir)
    out_dir = util.get_workspace_dir(fips_dir)+'/fips-deploy/'+proj_name+'-markdeep'
    if os.path.isfile(out_dir+'/index.html'):
        p = util.get_host_platform()
        if p == 'osx':
            subprocess.call('open index.html', cwd=out_dir, shell=True)
        elif p == 'win':
            subprocess.call('start index.html', cwd=out_dir, shell=True)
        elif p == 'linux':
            subprocess.call('xdg-open index.html', cwd=out_dir, shell=True)
    else:
        log.error('no generated index.html found: {}'.format(out_dir+'/index.html'))
Пример #19
0
def finish(sdk_dir) :
    """finish setting up the emscripten SDK

    FIXME: the used SDK version should be configurable!
    """
    if util.get_host_platform() == 'win' :
        # on Windows use a stable SDK version which doesn't require clang to be compiled
        subprocess.call(args='emsdk.bat update', cwd=sdk_dir, shell=True)
        subprocess.call(args='emsdk.bat install {}'.format(get_sdk_version()), cwd=sdk_dir, shell=True)
        subprocess.call(args='emsdk.bat activate --embedded {}'.format(get_sdk_version()), cwd=sdk_dir, shell=True)
    else :
        subprocess.call(args='./emsdk update', cwd=sdk_dir, shell=True)
        subprocess.call(args='./emsdk install {}'.format(get_sdk_version()), cwd=sdk_dir, shell=True)
        subprocess.call(args='./emsdk activate --embedded {}'.format(get_sdk_version()), cwd=sdk_dir, shell=True)
Пример #20
0
def check_tools(fips_dir) :
    """check whether required command line tools can be found"""
    log.colored(log.YELLOW, '=== tools:')
    tools = [ git, cmake, ccmake, cmake_gui, make, ninja, xcodebuild, java, ant, node, python2, ccache ]
    platform = util.get_host_platform()
    for tool in tools:
        if platform in tool.platforms :
            if tool.check_exists(fips_dir) :
                log.ok(tool.name, 'found')
            else :
                if tool.optional :
                    log.optional(tool.name, 'OPTIONAL, NOT FOUND ({})'.format(tool.not_found))
                else :
                    log.failed(tool.name, 'NOT FOUND ({})'.format(tool.not_found))
Пример #21
0
def update_android_sdk(fips_dir, proj_dir):
    # FIXME: hardcoded version numbers should be configurable
    if util.get_host_platform() == 'win':
        cmd = [
            '{}/tools/android.bat'.format(get_androidsdk_dir(fips_dir)),
            'update', 'sdk', '-f', '-u', '--all', '--filter',
            'tools,platform-tools,build-tools-19.1.0,android-19'
        ]
    else:
        cmd = [
            'sh', '{}/tools/android'.format(get_androidsdk_dir(fips_dir)),
            'update', 'sdk', '-f', '-u', '--all', '--filter',
            'tools,platform-tools,build-tools-19.1.0,android-19'
        ]
    print cmd
    subprocess.call(args=cmd, cwd=fips_dir)
Пример #22
0
def run(proj_dir):
    host = util.get_host_platform()
    if host == 'linux':
        try:
            if find_executable("clion.sh") is not None:
                subprocess.Popen('clion.sh {}'.format(proj_dir), cwd=proj_dir, shell=True)
            else:
                subprocess.Popen('clion {}'.format(proj_dir), cwd=proj_dir, shell=True)
        except OSError:
            log.error("Failed to run JetBrains CLion as 'clion' or 'clion.sh'")
    elif host == 'osx':
        try:
            subprocess.Popen('open /Applications/CLion.app --args {}'.format(proj_dir), cwd=proj_dir, shell=True)
        except OSError:
            log.error("Failed to run JetBrains CLion as '/Applications/CLion.app'")
    else:
        log.error("Not supported on this platform")
Пример #23
0
def problem_matcher():
    # FIXME: an actual compiler identification would be better here!
    if util.get_host_platform() == 'win':
        # assume that Windows is always the Visual Studio compiler
        return "$msCompile"
    else:
        return {
            'owner': 'cpp',
            'fileLocation': 'absolute',
            'pattern': {
                'regexp': '^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$',
                'file': 1,
                'line': 2,
                'column': 3,
                'severity': 4,
                'message': 5
            }
        }
Пример #24
0
def problem_matcher():
    # FIXME: an actual compiler identification would be better here!
    if util.get_host_platform() == 'win':
        # assume that Windows is always the Visual Studio compiler
        return "$msCompile"
    else:
        return {
            'owner': 'cpp',
            'fileLocation': 'absolute',
            'pattern': {
                'regexp': '^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$',
                'file': 1,
                'line': 2,
                'column': 3,
                'severity': 4,
                'message': 5
            }
        }
Пример #25
0
def check_exists(fips_dir):
    """test if 'clion' is in the path
    :returns:   True if clion is in the path
    """
    host = util.get_host_platform()
    if host == 'linux':
        try:
            subprocess.check_output("snap list | grep 'clion'", shell=True)
            return True
        except (OSError, subprocess.CalledProcessError):
            return False
    elif host == 'osx':
        try:
            subprocess.check_output("mdfind -name CLion.app | grep 'CLion'",
                                    shell=True)
            return True
        except (OSError, subprocess.CalledProcessError):
            return False
    else:
        return False
Пример #26
0
def check_tools(fips_dir):
    """check whether required command line tools can be found"""
    log.colored(log.YELLOW, '=== tools:')
    tools = [
        git, cmake, ccmake, cmake_gui, make, ninja, xcrun, javac, java, node,
        ccache, vscode, clion, httpserver, wasmtime
    ]
    platform = util.get_host_platform()
    for tool in tools:
        if platform in tool.platforms:
            if tool.check_exists(fips_dir):
                log.ok(tool.name, 'found')
            else:
                if tool.optional:
                    log.optional(
                        tool.name,
                        'OPTIONAL, NOT FOUND ({})'.format(tool.not_found))
                else:
                    log.failed(tool.name,
                               'NOT FOUND ({})'.format(tool.not_found))
Пример #27
0
def check_exists(fips_dir) :
    """test if 'clion' is in the path
    :returns:   True if clion is in the path
    """
    host = util.get_host_platform()
    if host == 'linux':
        # See if CLion was installed from a tar.gz and manually added to the path ("clion.sh"),
        # or added to the path using the "create launcher" command in CLion, which would by default
        # create a symlink from clion.sh to /usr/local/bin/clion.
        # This will also pick up CLion if it was installed using snap.
        if find_executable("clion.sh") is not None or find_executable("clion") is not None:
            return True
        else:
            return False
    elif host == 'osx':
        try:
            subprocess.check_output("mdfind -name CLion.app | grep 'CLion'", shell=True)
            return True
        except (OSError, subprocess.CalledProcessError):
            return False
    else:
        return False
Пример #28
0
def get_sdk_dir(fips_dir) :
    """return the platform-specific SDK dir"""
    return util.get_workspace_dir(fips_dir) + '/fips-sdks/' + util.get_host_platform()
Пример #29
0
def write_launch_json(fips_dir, proj_dir, vscode_dir, cfg):
    '''write the .vscode/launch.json file'''
    proj_name = util.get_project_name_from_dir(proj_dir)
    exe_targets = read_cmake_targets(fips_dir, proj_dir, cfg, ['app'])
    deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
    build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])

    pre_launch_build_options = [('', True), (' [Skip Build]', False)]
    stop_at_entry_options = [('', False), (' [Stop At Entry]', True)]

    launch = {'version': '0.2.0', 'configurations': []}
    for tgt in exe_targets:
        for pre_launch_build in pre_launch_build_options:
            for stop_at_entry in stop_at_entry_options:
                path = deploy_dir + '/' + tgt
                if util.get_host_platform() == 'win':
                    path += '.exe'
                cwd = os.path.dirname(path)
                osx_path = path + '.app/Contents/MacOS/' + tgt
                osx_cwd = os.path.dirname(osx_path)
                if os.path.isdir(osx_cwd):
                    path = osx_path
                    cwd = osx_cwd
                if util.get_host_platform() == 'win':
                    c = {
                        'name': tgt + pre_launch_build[0] + stop_at_entry[0],
                        'type': 'cppvsdbg',
                        'request': 'launch',
                        'program': path,
                        'args': [],
                        'stopAtEntry': stop_at_entry[1],
                        'cwd': cwd,
                        'environment': [],
                        'externalConsole': False,
                        'preLaunchTask': tgt if pre_launch_build[1] else ''
                    }
                elif util.get_host_platform() == 'linux':
                    c = {
                        'name': tgt + pre_launch_build[0] + stop_at_entry[0],
                        'type': 'cppdbg',
                        'request': 'launch',
                        'program': path,
                        'args': [],
                        'stopAtEntry': stop_at_entry[1],
                        'cwd': cwd,
                        'externalConsole': False,
                        'MIMode': 'gdb',
                        'preLaunchTask': tgt if pre_launch_build[1] else ''
                    }
                else:
                    c = {
                        'name': tgt + pre_launch_build[0] + stop_at_entry[0],
                        'type': 'cppdbg',
                        'request': 'launch',
                        'program': path,
                        'args': [],
                        'stopAtEntry': stop_at_entry[1],
                        'cwd': cwd,
                        'externalConsole': False,
                        'MIMode': 'lldb',
                        'preLaunchTask': tgt if pre_launch_build[1] else ''
                    }
                launch['configurations'].append(c)

    # add a python code-generator debug config
    c = {
        'name':
        'fips codegen',
        'type':
        'python',
        'request':
        'launch',
        'stopOnEntry':
        True,
        'pythonPath':
        '${config:python.pythonPath}',
        'program':
        build_dir + '/fips-gen.py',
        'args': [build_dir + '/fips_codegen.yml'],
        "cwd":
        proj_dir,
        "debugOptions":
        ["WaitOnAbnormalExit", "WaitOnNormalExit", "RedirectOutput"]
    }
    launch['configurations'].append(c)

    # add a python debug config for each fips verb
    for verb_name, verb_mod in verb.verbs.items():
        # ignore standard verbs
        if fips_dir not in inspect.getfile(verb_mod):
            c = {
                'name':
                'fips {}'.format(verb_name),
                'type':
                'python',
                'request':
                'launch',
                'stopOnEntry':
                True,
                'pythonPath':
                '${config:python.pythonPath}',
                'program':
                proj_dir + '/fips',
                'args': [verb_name],
                'cwd':
                proj_dir,
                "debugOptions":
                ["WaitOnAbnormalExit", "WaitOnNormalExit", "RedirectOutput"]
            }
            launch['configurations'].append(c)
    launch_path = vscode_dir + '/launch.json'
    log.info('  writing {}'.format(launch_path))
    with open(launch_path, 'w') as f:
        json.dump(launch, f, indent=1, separators=(',', ':'))
Пример #30
0
def get_sdk_dir(fips_dir) :
    """return the platform-specific SDK dir"""
    return util.get_workspace_dir(fips_dir) + '/fips-sdks/' + util.get_host_platform()
Пример #31
0
def get_sdk_version() :
    return sdk_version[util.get_host_platform()]
Пример #32
0
def get_archive_name() :
    """return name of sdk archive"""
    return archives[util.get_host_platform()]
Пример #33
0
def get_archive_name() :
    """return name of sdk archive"""
    return archives[util.get_host_platform()]
Пример #34
0
def get_androidndk_archive_path(fips_dir) :
    return get_sdk_dir(fips_dir) + '/' + ndk_archives[util.get_host_platform()]
Пример #35
0
def get_default_config() :
    """get the default config name for this platform

    :returns:   default config name for this host platform
    """
    return default_config[util.get_host_platform()]
Пример #36
0
def get_sdk_url() :
    """lookup SDK url for this host platform"""
    return urls[util.get_host_platform()]
Пример #37
0
def get_sdk_url() :
    """lookup SDK url for this host platform"""
    return urls[util.get_host_platform()]
Пример #38
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 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))
Пример #39
0
def get_ndk_url() :
    return ndk_urls[util.get_host_platform()]
Пример #40
0
def run(fips_dir, proj_dir, cfg_name, target_name, target_args):
    """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
    """

    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)

            cmd_line = []
            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=deploy_dir,
                                        shell=True)
                    except KeyboardInterrupt:
                        pass
                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=deploy_dir, shell=True)
                    except KeyboardInterrupt:
                        pass
                elif util.get_host_platform() == 'linux':
                    try:
                        subprocess.call([
                            'xdg-open http://localhost:8000/{}; python {}/mod/httpserver.py'
                            .format(html_name, fips_dir)
                        ],
                                        cwd=deploy_dir,
                                        shell=True)
                    except KeyboardInterrupt:
                        pass
                else:
                    log.error(
                        "don't know how to start HTML app on this platform")
            elif os.path.isdir('{}/{}.app'.format(deploy_dir, target_name)):
                # special case: Mac app
                cmd_line = [
                    'open', '{}/{}.app'.format(deploy_dir, target_name)
                ]
                if target_args:
                    cmd_line.append('--args')
            else:
                cmd_line = ['{}/{}'.format(deploy_dir, target_name)]
            if cmd_line:
                if target_args:
                    cmd_line.extend(target_args)
                try:
                    subprocess.call(args=cmd_line, cwd=deploy_dir)
                except OSError, e:
                    log.error("Failed to execute '{}' with '{}'".format(
                        target_name, e.strerror))
Пример #41
0
def write_launch_json(fips_dir, proj_dir, vscode_dir, cfg):
    '''write the .vscode/launch.json file'''
    proj_name = util.get_project_name_from_dir(proj_dir)
    exe_targets = read_cmake_targets(fips_dir, proj_dir, cfg, ['app'])
    deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
    build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])

    pre_launch_build_options = [('', True), (' [Skip Build]', False)]
    stop_at_entry_options = [('', False), (' [Stop At Entry]', True)]

    launch = {
        'version': '0.2.0',
        'configurations': []
    }
    for tgt in exe_targets:
        for pre_launch_build in pre_launch_build_options:
            for stop_at_entry in stop_at_entry_options:
                path = deploy_dir + '/' + tgt
                if util.get_host_platform() == 'win':
                    path += '.exe'
                cwd = os.path.dirname(path)
                osx_path = path + '.app/Contents/MacOS/' + tgt
                osx_cwd = os.path.dirname(osx_path)
                if os.path.isdir(osx_cwd):
                    path = osx_path
                    cwd = osx_cwd
                if util.get_host_platform() == 'win':
                    c = {
                        'name': tgt + pre_launch_build[0] + stop_at_entry[0],
                        'type': 'cppvsdbg',
                        'request': 'launch',
                        'program': path,
                        'args': [],
                        'stopAtEntry': stop_at_entry[1],
                        'cwd': cwd,
                        'environment': [],
                        'externalConsole': False,
                        'preLaunchTask': tgt if pre_launch_build[1] else ''
                    }
                elif util.get_host_platform() == 'linux':
                    c = {
                        'name': tgt + pre_launch_build[0] + stop_at_entry[0],
                        'type': 'cppdbg',
                        'request': 'launch',
                        'program': path,
                        'args': [],
                        'stopAtEntry': stop_at_entry[1],
                        'cwd': cwd,
                        'externalConsole': False,
                        'MIMode': 'gdb',
                        'preLaunchTask': tgt if pre_launch_build[1] else ''
                    }
                else:
                    c = {
                        'name': tgt + pre_launch_build[0] + stop_at_entry[0],
                        'type': 'cppdbg',
                        'request': 'launch',
                        'program': path,
                        'args': [],
                        'stopAtEntry': stop_at_entry[1],
                        'cwd': cwd,
                        'externalConsole': False,
                        'MIMode': 'lldb',
                        'preLaunchTask': tgt if pre_launch_build[1] else ''
                    }
                launch['configurations'].append(c)

    # add a python code-generator debug config
    c = {
        'name': 'fips codegen',
        'type': 'python',
        'request': 'launch',
        'stopOnEntry': True,
        'pythonPath': '${config:python.pythonPath}',
        'program': build_dir + '/fips-gen.py',
        'args': [ build_dir + '/fips_codegen.yml' ],
        "cwd": proj_dir,
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    }
    launch['configurations'].append(c)

    # add a python debug config for each fips verb
    for verb_name, verb_mod in verb.verbs.items() :
        # ignore standard verbs
        if fips_dir not in inspect.getfile(verb_mod):
            c = {
                'name': 'fips {}'.format(verb_name),
                'type': 'python',
                'request': 'launch',
                'stopOnEntry': True,
                'pythonPath': '${config:python.pythonPath}',
                'program': proj_dir + '/fips',
                'args': [ verb_name ],
                'cwd': proj_dir,
                "debugOptions": [
                    "WaitOnAbnormalExit",
                    "WaitOnNormalExit",
                    "RedirectOutput"
                ]
            }
            launch['configurations'].append(c)
    launch_path = vscode_dir + '/launch.json'
    log.info('  writing {}'.format(launch_path))
    with open(launch_path, 'w') as f:
        json.dump(launch, f, indent=1, separators=(',',':'))
Пример #42
0
def get_sdk_version() :
    return sdk_version[util.get_host_platform()]
Пример #43
0
def get_sdk_dir(fips_dir) :
    return util.get_workspace_dir(fips_dir) + '/fips-sdks/' + util.get_host_platform()
Пример #44
0
def get_default_config():
    """get the default config name for this platform

    :returns:   default config name for this host platform
    """
    return default_config[util.get_host_platform()]
Пример #45
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
Пример #46
0
def get_androidsdk_dir(fips_dir) :
    return get_sdk_dir(fips_dir) + '/' + sdk_paths[util.get_host_platform()]