Ejemplo n.º 1
0
def get_project_name(prj_path):
    regex = re.compile(r".*\\src\\([\w\.]+).*")
    mo = regex.search(prj_path)
    if mo is not None:
        return mo.group(1)
    else:
        gv.save_debug_info("[## File:%s Line:%d ##] Fail to get project name from project path: %s" % (sys._getframe().f_code.co_filename, sys._getframe().f_lineno, prj_path))
Ejemplo n.º 2
0
def get_source_file_dic(cur_path):
    if os.path.isdir(cur_path):
        for dirs in os.listdir(cur_path):
            filePath = os.path.join(cur_path, dirs)
            if os.path.isdir(filePath):
                get_source_file_dic(filePath)
            else:
                filename = dirs
                if filename.endswith(".cpp") or filename.endswith(".h") or filename.endswith(".hpp"):
                    source_file_dic[filename] = filePath
    else:
        gv.save_debug_info("[## File:%s Line:%d ##] Invalid DIR: %s" % (sys._getframe().f_code.co_filename, sys._getframe().f_lineno, cur_path))
Ejemplo n.º 3
0
def add_marco_in_dictionary(file_path):
    if os.path.isfile(file_path):
        with open(file_path, mode='r', encoding="utf-8") as fr:
            for line in fr:
                if line.find("#define") != -1:
                    regex = re.compile(r"#define\s(\w+)\(.*\).*")
                    mo = regex.search(line)
                    if mo is not None:
                        marco_name = mo.group(1)
                        dic[marco_name] = 1
                    else:
                        gv.save_debug_info("[## File:%s Line:%d ##] addMarcoInDictionary::Pattern not Match! Line: %s" % (sys._getframe().f_code.co_filename, sys._getframe().f_lineno, line))
    else:
        gv.save_debug_info("[## File:%s Line:%d ##] addMarcoInDictionary::File not found" % (sys._getframe().f_code.co_filename, sys._getframe().f_lineno))
def get_projects_from_gmk(gmk_file):
    proj_list = []
    if os.path.isfile(gmk_file):
        with open(gmk_file, mode='r', encoding="utf-8", errors='ignore') as fr:
            for line in fr:
                regex = re.compile(r"(^\w+)\s*:.*")
                mo = regex.search(line)
                if mo is not None:
                    proj = mo.group(1).lower()
                    if proj != "all" and (proj not in proj_list):
                        proj_list.append(mo.group(1))
    else:
        gv.save_debug_info(
            "[## File:%s Line:%d ##] can't find the gmk file: %s!" %
            (sys._getframe().f_code.co_filename, sys._getframe().f_lineno,
             gmk_file))

    return proj_list
def compare_errors(proj_name):
    log_dir = gv.get_compile_log_path()
    dict_file_name = proj_name + ".npy"
    dict_file_name = os.path.join(log_dir, dict_file_name)
    break_loop = False
    build_success = False
    if os.path.isfile(dict_file_name):
        old_source_file_dic = np.load(dict_file_name, allow_pickle=True).item()
        new_source_file_dic, have_errors = get_dictionary_for_error(proj_name)
        if old_source_file_dic == new_source_file_dic:
            gv.save_debug_info(
                "[File:%s Line:%d] No error fixed in last run!" %
                (sys._getframe().f_code.co_filename, sys._getframe().f_lineno))
            break_loop = True
        else:
            if len(new_source_file_dic) == 0:
                break_loop = True
                if not have_errors:
                    build_success = True
                    gv.save_debug_info(
                        "[File:%s Line:%d] There should be no build errors for this project now!"
                        % (sys._getframe().f_code.co_filename,
                           sys._getframe().f_lineno))
                else:
                    gv.save_debug_info(
                        "[File:%s Line:%d] No new errors save into npy file but still have errors in the log!"
                        % (sys._getframe().f_code.co_filename,
                           sys._getframe().f_lineno))
            if os.path.isfile(dict_file_name):
                os.remove(dict_file_name)
                if len(new_source_file_dic) > 0:
                    np.save(dict_file_name, new_source_file_dic)
                    gv.save_debug_info(
                        "[File:%s Line:%d] Some errors fixed in last run and save the new errors into npy file!"
                        % (sys._getframe().f_code.co_filename,
                           sys._getframe().f_lineno))
    else:
        new_source_file_dic, have_errors = get_dictionary_for_error(proj_name)
        if len(new_source_file_dic) > 0:
            np.save(dict_file_name, new_source_file_dic)
            gv.save_debug_info(
                "[File:%s Line:%d] Generate dictionary for log for the first time!"
                %
                (sys._getframe().f_code.co_filename, sys._getframe().f_lineno))
        else:
            break_loop = True
            if not have_errors:
                gv.save_debug_info(
                    "[File:%s Line:%d] No new errors found in the log file!" %
                    (sys._getframe().f_code.co_filename,
                     sys._getframe().f_lineno))
            else:
                gv.save_debug_info(
                    "[File:%s Line:%d] No new errors save into npy file but still have errors in the log!"
                    % (sys._getframe().f_code.co_filename,
                       sys._getframe().f_lineno))

    return break_loop, build_success
def get_dictionary_for_error(proj_name):
    file_path = gv.get_compile_log_with_path(proj_name)
    dic = {}
    if os.path.isfile(file_path):
        with open(file_path, mode='r', encoding="utf-8") as fr:
            other_error = False
            still_have_errors = False
            for line in fr:
                if line.find(": error :") != -1:
                    #     ..\..\..\libs\cpp\uilib\sadataobjectprovider.cpp(338,37): error :
                    regex = re.compile(r"([\w\.]+)\((\d+),\d+\): error :.*")
                    mo = regex.search(line)
                    if mo is not None:
                        source = mo.group(1)
                        line = mo.group(2)
                        src_line = source, line
                        dic[src_line] = 1
                    else:
                        gv.save_debug_info(
                            "[File:%s Line:%d] pattern not match, new error found!"
                            % (sys._getframe().f_code.co_filename,
                               sys._getframe().f_lineno))
                elif line.find(": fatal error :") != -1 and line.find(
                        "not seen while attempting to use precompiled header"
                ) != -1:
                    #     CL : fatal error : #include of 'stdafx.h' not seen while attempting to use precompiled header
                    source = None
                    line = None
                    src_line = source, line
                    dic[src_line] = 1
                elif line.find(": fatal error :") != -1:
                    #     ..\..\..\libs\cpp\erom_util\lib\memobj.cpp(28,10): fatal error : 'stdafx.h' file not found
                    regex = re.compile(
                        r"([\w\.]+)\((\d+),\d+\): fatal error :.*")
                    mo = regex.search(line)
                    if mo is not None:
                        source = mo.group(1)
                        line = mo.group(2)
                        src_line = source, line
                        dic[src_line] = 1
                    else:
                        gv.save_debug_info(
                            "[File:%s Line:%d] pattern not match, new error found!"
                            % (sys._getframe().f_code.co_filename,
                               sys._getframe().f_lineno))
                        still_have_errors = True
                        other_error = True
                elif line.find("error") != -1 and line.find(
                        "unresolved external symbol") != -1:
                    other_error = True
                    gv.save_debug_info("[File:%s Line:%d] link error found!" %
                                       (sys._getframe().f_code.co_filename,
                                        sys._getframe().f_lineno))
                elif line.find("Error(s)") != -1:
                    #         0 Error(s)
                    regex = re.compile(r"\s*(\d+)\s*Error\(s\).*")
                    mo = regex.search(line)
                    if mo is not None:
                        error_number = int(mo.group(1))
                        if error_number > 0:
                            still_have_errors = True
                # : error LNK
                elif line.find(": error LNK") != -1:
                    gv.save_debug_info("[File:%s Line:%d] link error found!" %
                                       (sys._getframe().f_code.co_filename,
                                        sys._getframe().f_lineno))
                    still_have_errors = True
                    other_error = True

        if len(dic) == 0 and other_error == False:
            gv.save_debug_info(
                "[File:%s Line:%d] No Error found this time. Build succeeded!"
                %
                (sys._getframe().f_code.co_filename, sys._getframe().f_lineno))

        return dic, still_have_errors

    else:
        gv.save_debug_info("[File:%s Line:%d] Log file:%s not found" %
                           (sys._getframe().f_code.co_filename,
                            sys._getframe().f_lineno, file_path))
        gv.my_exit()
def handle_proj(proj_name=None):
    make_for_this_gmk = False
    if proj_name is None:
        make_for_this_gmk = True
        proj_name = gv.get_gmk_file_name()
    log_dir = gv.get_compile_log_path()
    log_name = proj_name + '.cmplog'
    npy_name = proj_name + '.npy'
    proj_log_file_path = os.path.join(log_dir, log_name)
    proj_npy_file_path = os.path.join(log_dir, npy_name)
    if os.path.isfile(proj_log_file_path):
        os.remove(proj_log_file_path)
    if os.path.isfile(proj_npy_file_path):
        os.remove(proj_npy_file_path)

    error_npy_file_path = os.path.join(log_dir, gv.collect_npy_file_name)
    err_proj_dic = {}
    error_npy_file_path_exists = False
    if os.path.isfile(error_npy_file_path):
        err_proj_dic = np.load(error_npy_file_path, allow_pickle=True).item()
        error_npy_file_path_exists = True
    else:
        gv.save_debug_info(
            "[File:%s Line:%d] can't find the npy file which save the project with errors!"
            % (sys._getframe().f_code.co_filename, sys._getframe().f_lineno))
        gv.my_exit()

    while 1:
        cpp_file_path = gv.get_cpp_path()
        rce.load_source_file_dic(cpp_file_path)
        dic = rce.parse_logfile(proj_log_file_path)
        if len(dic) > 0:
            rce.fixErrorByParsingLog(dic)
        if os.path.isfile(proj_log_file_path):
            os.remove(proj_log_file_path)
        if error_npy_file_path_exists:
            if len(err_proj_dic) > 0 and err_proj_dic.__contains__(proj_name):
                if make_for_this_gmk:
                    gmk_name = gv.get_gmk_file_name_with_suffix()
                    cmp_cmd = "cd %s && make -f %s >> %s" % (
                        gv.get_gmk_file_path(), gmk_name, proj_log_file_path)
                    os.system(cmp_cmd)
                else:
                    cmp_cmd = "make -f %s %s >> %s" % (gv.gmk_file, proj_name,
                                                       proj_log_file_path)
                    os.system(cmp_cmd)
            else:
                gv.save_debug_info(
                    "[File:%s Line:%d] No need to recompile for project: %s is not in the error dictionary when collect the error log!"
                    % (sys._getframe().f_code.co_filename,
                       sys._getframe().f_lineno, proj_name))
                break
        else:
            if make_for_this_gmk:
                gmk_name = gv.get_gmk_file_name_with_suffix()
                cmp_cmd = "cd %s && make -f %s >> %s" % (
                    gv.get_gmk_file_path(), gmk_name, proj_log_file_path)
                os.system(cmp_cmd)
            else:
                cmp_cmd = "make -f %s %s >> %s" % (gv.gmk_file, proj_name,
                                                   proj_log_file_path)
                os.system(cmp_cmd)
        need_break, success = compare_errors(proj_name)

        if success:
            if os.path.isfile(proj_log_file_path):
                os.remove(proj_log_file_path)
            if os.path.isfile(proj_npy_file_path):
                os.remove(proj_npy_file_path)

        if need_break or gv.break_once:
            break
                regex = re.compile(r"(^\w+)\s*:.*")
                mo = regex.search(line)
                if mo is not None:
                    proj = mo.group(1).lower()
                    if proj != "all" and (proj not in proj_list):
                        proj_list.append(mo.group(1))
    else:
        gv.save_debug_info(
            "[## File:%s Line:%d ##] can't find the gmk file: %s!" %
            (sys._getframe().f_code.co_filename, sys._getframe().f_lineno,
             gmk_file))

    return proj_list


if __name__ == '__main__':
    prj_list = get_projects_from_gmk(gv.gmk_file)
    if len(prj_list) != 0:
        for proj in prj_list:
            if proj.find("clean") != -1:
                continue
            gv.save_debug_info("[## File:%s Line:%d ##] handle %s now!" %
                               (sys._getframe().f_code.co_filename,
                                sys._getframe().f_lineno, proj))
            feacl.handle_proj(proj)
        cl.collect_log()
    else:
        gv.save_debug_info(
            "[## File:%s Line:%d ##] project list is empty!" %
            (sys._getframe().f_code.co_filename, sys._getframe().f_lineno))
Ejemplo n.º 9
0
def add_addr_for_function(file_path):
    if os.path.isfile(file_path):
        file_changed = False
        tmpfile = file_path + '.temp'
        with open(file_path, mode='r', encoding="utf-8", errors='ignore') as fr, open(tmpfile, mode='w',
                                                                                      encoding="utf-8") as fw:
            file_changed = False
            map_start = False
            this_class = "default"
            new_code_block = ""
            old_code_block = ""
            code_block_changed = False
            clang_begin = False
            clang_found = False
            undefined_clang_begin = False
            undefined_clang_found = False
            for line in fr:
                if line.find("__clang__") != -1 and map_start:
                    if line.find("!defined") != -1:
                        undefined_clang_begin = True
                        undefined_clang_found = True
                    else:
                        clang_begin = True
                        clang_found = True
                if line.find("#else") != -1 and clang_found == True and map_start == True:
                    clang_begin = False
                if line.find("#else") != -1 and undefined_clang_found == True and map_start == True:
                    undefined_clang_begin = False
                if line.find(beginMap) != -1:
                    map_start = True
                    regex = re.compile(r"\s*BEGIN_MESSAGE_MAP\s*\(\s*[\w_:]+\s*,\s*([\w_:]+)\s*\)")
                    mo = regex.search(line)
                    if mo is not None:
                        this_class = mo.group(1)
                    else:
                        gv.save_debug_info("[File:%s Line:%d] Can't find thisCalss in file: %s!" % (
                            sys._getframe().f_code.co_filename, sys._getframe().f_lineno, file_path))
                        exit(0)
                    fw.write(line)
                    continue
                if line.find(endMap) != -1:
                    map_start = False
                    this_class = "default"
                    if not clang_found and not undefined_clang_found :
                        new_code_block = "#if defined (__clang__)\n" + new_code_block + "#else\n" + old_code_block + "#endif\n"
                    if code_block_changed:
                        fw.write(new_code_block)
                    else:
                        fw.write(old_code_block)
                    new_code_block = ""
                    old_code_block = ""
                    fw.write(line)
                    code_block_changed = False
                    clang_begin = False
                    clang_found = False
                    undefined_clang_begin = False
                    undefined_clang_found = False
                    continue

                if map_start:
                    old_code_block = old_code_block + line
                    if line.find("//") == -1:
                        # ON_EVENT(DSCDMapControl, IDC_MAP, 4 /* RequestData */, OnRequestDataMap, VTS_BSTR VTS_I4 VTS_I2 VTS_PVARIANT VTS_PBOOL)
                        new_line = line
                        should_bread = False
                        while not should_bread:
                            scope_issue = True
                            regex = re.compile(r"(\s*ON_UPDATE_COMMAND_UI\s*\(.*,\s*)(\w+::\w+\s*\))")
                            mo = regex.search(new_line)
                            if mo is None:
                                regex = re.compile(r"(\s*ON_UPDATE_COMMAND_UI\s*\(.*,\s*)(\w+\s*\))")
                                mo = regex.search(new_line)
                                scope_issue = False
                            if mo is not None:
                                prefix = mo.group(1)
                                suffix = mo.group(2)
                                if (clang_begin == True and clang_found == True) or (
                                        undefined_clang_begin == False and undefined_clang_found == True):
                                    if scope_issue:
                                        new_line = prefix + '&' + suffix + "\n"
                                    else:
                                        new_line = prefix + '&' + this_class + "::" + suffix + "\n"
                                    file_changed = True
                                    code_block_changed = True
                                else:
                                    should_bread = True
                                # gv.save_debug_info("[File:%s Line:%d] regex match, modify this line!" %(sys._getframe().f_code.co_filename,sys._getframe().f_lineno))
                            else:
                                should_bread = True
                                # gv.save_debug_info("[File:%s Line:%d] regex not match!" %(sys._getframe().f_code.co_filename,sys._getframe().f_lineno))

                        new_code_block = new_code_block + new_line
                    # if(line.find("\\") == -1)
                    else:
                        new_code_block = new_code_block + line
                # if(mapStart == True):
                else:
                    fw.write(line)

        if file_changed:
            checkout_cmd = "p4 -p perforceserver1.pgdev.sap.corp:1971 -u i325629 -p 2wsx#EDC -c aurora_feat_clang64_chris edit %s" % (
                file_path)
            os.system(checkout_cmd)
            os.remove(file_path)
            os.rename(tmpfile, file_path)
            gv.save_debug_info("[## File:%s Line:%d ##] File: %s updated" % (sys._getframe().f_code.co_filename, sys._getframe().f_lineno, file_path))
        else:
            if os.path.isfile(tmpfile):
                os.remove(tmpfile)

    else:
        gv.save_debug_info("[## File:%s Line:%d ##] addAddrForFunction::File not found" % (sys._getframe().f_code.co_filename, sys._getframe().f_lineno))