Exemplo n.º 1
0
Arquivo: gdb.py Projeto: floooh/fips
def gdb(fips_dir, proj_dir, cfg_name, target=None, target_args=None) :
    """debug a single target with gdb"""

    # prepare
    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 :
            # check if config is valid
            config_valid, _ = config.check_config_valid(fips_dir, proj_dir, cfg, print_errors = True)
            if config_valid :
                deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
                log.colored(log.YELLOW, "=== gdb: {}".format(cfg['name']))
                cmdLine = ['gdb', "-ex", "run", "--args", target]
                if target_args :
                    cmdLine.extend(target_args)
                try:
                    subprocess.call(args = cmdLine, cwd = deploy_dir)
                except OSError :
                    log.error("Failed to execute gdb (not installed?)")
            else :
                log.error("Config '{}' not valid in this environment".format(cfg['name']))
    else :
        log.error("No valid configs found for '{}'".format(cfg_name))

    return True
Exemplo n.º 2
0
def valgrind(fips_dir, proj_dir, cfg_name, target, target_args) :
    """debug a single target with valgrind"""

    # prepare
    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 :
            # check if config is valid
            config_valid, _ = config.check_config_valid(fips_dir, proj_dir, cfg, print_errors = True)
            if config_valid :
                deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
                valgrind_bin = settings.get(proj_dir, 'valgrind')
                if not valgrind_bin :
                    valgrind_bin = 'valgrind'
                log.colored(log.YELLOW, "=== valgrind: {} ({})".format(cfg['name'], valgrind_bin))
                cmd_line = valgrind_bin
                if target_args :
                    cmd_line += ' ' + ' '.join(target_args)
                else :
                    cmd_line += ' ' + '--leak-check=no'
                    cmd_line += ' ' + '--show-reachable=yes'
                    cmd_line += ' ' + '--track-fds=yes'
                    cmd_line += ' ' + '--run-libc-freeres=no'
                    cmd_line += ' ' + "--log-file={}/valgrind-{}.log".format(proj_dir, target)
                cmd_line += ' ' + "./{}".format(target)
                #log.colored(log.GREEN, "cmdline: {}".format(cmd_line))
                subprocess.call(args = cmd_line, cwd = deploy_dir, shell = True)
            else :
                log.error("Config '{}' not valid in this environment".format(cfg['name']))
    else :
        log.error("No valid configs found for '{}'".format(cfg_name))

    return True
Exemplo n.º 3
0
def clean(fips_dir, proj_dir, cfg_name) :
    """clean build files

    :param fips_dir:    absolute path of fips
    :param proj_dir:    absolute project path
    :param cfg_name:    config name (or pattern)
    """
    proj_name = util.get_project_name_from_dir(proj_dir)
    configs = config.load(fips_dir, proj_dir, cfg_name)
    if configs :
        for cfg in configs :
            log.colored(log.YELLOW, "=== clean: {}".format(cfg['name']))

            build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
            if os.path.isdir(build_dir) :
                shutil.rmtree(build_dir)
                log.info("  deleted '{}'".format(build_dir))

            deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg)
            if os.path.isdir(deploy_dir) :
                shutil.rmtree(deploy_dir)
                log.info("  deleted '{}'".format(deploy_dir))
    else :
        log.error("No valid configs found for '{}'".format(cfg_name))
Exemplo n.º 4
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))
Exemplo n.º 5
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=(',',':'))
Exemplo n.º 6
0
#-------------------------------------------------------------------------------
# HACK: Find fips-deploy dir the hard way
# TODO: Fips need pass to generators the fips-deploy dir ready to be used
os_name = platform.system().lower()
extension = ""
proj_path = os.path.normpath('{}/..'.format(os.path.dirname(os.path.abspath(__file__))))
items = settings.load(proj_path)
if not items:
    items = {'config': settings.get_default('config')}

# HACK: even setting PROJECT in fips_setup does not work here without a way to get the
# fips-deploy path, so we force to search in Project for windows as it is the default
if os_name == "windows":
    extension = ".exe"

deploy_path = util.get_deploy_dir("../fips", "fips-tests", {'name': items['config']})

#-------------------------------------------------------------------------------
def get_generator_path() :
    """find util_generate_requires exectuable, fail if not exists"""

    bin_path = os.path.abspath('{}/util_generate_requires{}'.format(deploy_path, extension))
    print "TRY: " + bin_path
    if not os.path.isfile(bin_path) :
        os_name = platform.system().lower()
        bin_path = '{}/util_generate_requires{}'.format(proj_path, extension)
        bin_path = os.path.normpath(bin_path)
        print "TRY: " + bin_path
        
        if not os.path.isfile(bin_path) :
            log.error("util_generate_requires executable not found")
Exemplo n.º 7
0
# HACK: Find fips-deploy dir the hard way
# TODO: Fips need pass to generators the fips-deploy dir ready to be used
os_name = platform.system().lower()
extension = ""
proj_path = os.path.normpath('{}/..'.format(os.path.dirname(os.path.abspath(__file__))))
items = settings.load(proj_path)
if not items:
    items = {'config': settings.get_default('config')}

# HACK: even setting PROJECT in fips_setup does not work here without a way to get the
# fips-deploy path, so we force to search in Project for windows as it is the default
if os_name == "windows":
    extension = ".exe"

deploy_path = util.get_deploy_dir(proj_path + "/Third/fips", "Src", {'name': items['config']})

#-------------------------------------------------------------------------------
def get_shaderc_path() :
    """find shaderc compiler, fail if not exists"""

    shaderc_path = os.path.abspath('{}/shaderc{}'.format(deploy_path, extension))
    print "####shaderC path: %s" % (shaderc_path)
    # if not os.path.isfile(shaderc_path) :
        # os_name = platform.system().lower()
        # shaderc_path = '{}/bgfx/tools/bin/{}/shaderc{}'.format(proj_path, os_name, extension)
        # shaderc_path = os.path.normpath(shaderc_path)
        
        # if not os.path.isfile(shaderc_path) :
            # log.error("bgfx shaderc executable not found, please run 'make tools' in bgfx directory: ", shaderc_path)