예제 #1
0
def run_new_command(blade_path, command, options, targets):
    blade_root = util.find_file_bottom_up('BLADE_ROOT', from_dir=util.get_cwd())
    if blade_root:
        console.output("The sub dir is a blade project.")
        return -1
    NewProject.check_project_name(options.project_name)
    NewProject.check_email(options.email)
    NewProject.new_project(blade_path=blade_path, command=command, options=options, targets=targets)
    return 0
예제 #2
0
def run_subcommand_profile(command, options, targets, blade_path, build_dir):
    pstats_file = os.path.join(build_dir, 'blade.pstats')
    # NOTE: can't use an plain int variable to receive exit_code
    # because in python int is an immutable object, assign to it in the runctx
    # wll not modify the local exit_code.
    # so we use a mutable object list to obtain the return value of run_subcommand
    exit_code = [-1]
    cProfile.runctx("exit_code[0] = run_subcommand(command, options, targets, blade_path, build_dir)",
                    globals(), locals(), pstats_file)
    p = pstats.Stats(pstats_file)
    p.sort_stats('cumulative').print_stats(20)
    p.sort_stats('time').print_stats(20)
    console.output('Binary profile file `%s` is also generated, '
                   'you can use `gprof2dot` or `vprof` to convert it to graph, eg:' % pstats_file)
    console.output('  gprof2dot.py -f pstats --color-nodes-by-selftime %s'
                   ' | dot -T pdf -o blade.pdf' % pstats_file)
    return exit_code[0]
예제 #3
0
def run_subcommand_profile(command, options, targets, blade_path, build_dir):
    pstats_file = os.path.join(build_dir, 'blade.pstats')
    # NOTE: can't use an plain int variable to receive exit_code
    # because in python int is an immutable object, assign to it in the runctx
    # wll not modify the local exit_code.
    # so we use a mutable object list to obtain the return value of run_subcommand
    exit_code = [-1]
    cProfile.runctx("exit_code[0] = run_subcommand(command, options, targets, blade_path, build_dir)",
                    globals(), locals(), pstats_file)
    p = pstats.Stats(pstats_file)
    p.sort_stats('cumulative').print_stats(20)
    p.sort_stats('time').print_stats(20)
    console.output('Binary profile file `%s` is also generated, '
                   'you can use `gprof2dot` or `vprof` to convert it to graph, eg:' % pstats_file)
    console.output('  gprof2dot.py -f pstats --color-nodes-by-selftime %s'
                 ' | dot -T pdf -o blade.pdf' % pstats_file)
    return exit_code[0]
예제 #4
0
def _show_progress(p, rf):
    # Convert description message such as '[1/123] CC xxx.cc' into progress bar
    progress_re = re.compile(r'^\[(\d+)/(\d+)\]\s+')
    try:
        while True:
            p.poll()
            line = rf.readline().strip()
            if line:
                m = progress_re.match(line)
                if m:
                    console.show_progress_bar(int(m.group(1)), int(m.group(2)))
                else:
                    console.clear_progress_bar()
                    console.output(line)
            elif p.returncode is not None:
                break
            else:
                # Avoid cost too much cpu
                time.sleep(0.1)
    finally:
        console.clear_progress_bar()
예제 #5
0
def _show_progress(p, rf):
    # Convert description message such as '[1/123] CC xxx.cc' into progress bar
    progress_re = re.compile(r'^\[(\d+)/(\d+)\]\s+')
    try:
        while True:
            p.poll()
            line = rf.readline().strip()
            if line:
                m = progress_re.match(line)
                if m:
                    console.show_progress_bar(int(m.group(1)), int(m.group(2)))
                else:
                    console.clear_progress_bar()
                    console.output(line)
            elif p.returncode is not None:
                break
            else:
                # Avoid cost too much cpu
                time.sleep(0.1)
    finally:
        console.clear_progress_bar()
예제 #6
0
    def create_project_fie(name):
        with open(os.path.join(name, "BLADE_ROOT"), 'w', encoding='utf-8') as f:
            f.write(new_template._BLADE_ROOT_)
        with open(os.path.join(name, "ChangeLog"), 'w', encoding='utf-8') as f:
            pass
        if NewProject.project_cfg_json_template['project info']['project type'] == 'lib':
            with open(os.path.join(name, "src/BUILD"), 'w', encoding='utf-8') as f:
                f.write(new_template._CC_LIB_CONFIG_.substitute(name=NewProject.project_cfg_json_template["project info"]['name']))
            with open(os.path.join(name, "unittest/BUILD"), 'w', encoding='utf-8') as f:
                f.write(new_template._CC_TEST_CONFIG_.substitute(name=NewProject.project_cfg_json_template["project info"]['name']))
        elif NewProject.project_cfg_json_template['project info']['project type'] == 'exec':
            with open(os.path.join(name, "src/BUILD"), 'w', encoding='utf-8') as f:
                f.write(new_template._CC_BIN_CONFIG_.substitute(name=NewProject.project_cfg_json_template["project info"]['name']))
        else:
            with open(os.path.join(name, "src/BUILD"), 'w', encoding='utf-8') as f:
                f.write(new_template._CC_LIB_CONFIG_.substitute(name=NewProject.project_cfg_json_template["project info"]['name']))
                f.write('\n')
                f.write(new_template._CC_BIN_CONFIG_.substitute(name=NewProject.project_cfg_json_template["project info"]['name']))
            with open(os.path.join(name, "unittest/BUILD"), 'w', encoding='utf-8') as f:
                f.write(new_template._CC_TEST_CONFIG_.substitute(name=NewProject.project_cfg_json_template["project info"]['name']))

        with open(os.path.join(name, "README.md") , 'w', encoding='utf-8') as f:
            f.write(new_template._README_.substitute(author=NewProject.project_cfg_json_template["project info"]['author'],
            email=NewProject.project_cfg_json_template["project info"]['email'],
            date=NewProject.project_cfg_json_template["project info"]['create date']))
        with open(os.path.join(name, "LICENSE.md"), 'w', encoding='utf-8') as f:
            pass
        with open(os.path.join(name, "AUTHORS"), 'w', encoding='utf-8') as f:
            f.writelines([NewProject.project_cfg_json_template['project info']['author']])
        with open(os.path.join(name, ".blade/config.json"), 'w', encoding='utf-8') as f:
            json.dump(NewProject.project_cfg_json_template, f, indent=4)
        with open(os.path.join(name, ".clang-format"), 'w', encoding='utf-8') as f:
            f.write(new_template._CLANG_FORMAT_)

        console.output('[info]: ----------Project (%s) create success----------' % NewProject.project_cfg_json_template['project info']['name'])
        console.output('[project name    ]:   %s' % name)
        console.output('[project language]:   %s' % NewProject.project_cfg_json_template['project info']['project language'])
        console.output('[project type    ]:   %s' % NewProject.project_cfg_json_template['project info']['project type'])
        console.output('[author          ]:   %s' % NewProject.project_cfg_json_template['project info']['author'])
        console.output('[email           ]:   %s' % NewProject.project_cfg_json_template['project info']['email'])
        console.output('[create date     ]:   %s' % NewProject.project_cfg_json_template["project info"]["create date"])