Пример #1
0
def copy_astylewx_python_files(dist_file):
    """Copy astylewxtest python files to a distribution directory.
       Copied from astylewxtest, not astylewx.
    """
    print("copying file-py")
    pythonfiles = glob.glob(__astylewxtest_dir + "/file-py/*")
    files_copied = 0
    for pythonpath in pythonfiles:
        if not os.path.isfile(pythonpath):
            continue
        sep = pythonpath.rfind(os.sep)
        filename = pythonpath[sep + 1:]
        if (pythonpath.endswith("change_static_wx30.py")
                or pythonpath.endswith("change_static_wx31.py")
                or pythonpath.endswith("libastylewx.py")
                or pythonpath.endswith("to_xxbook.py")
                or pythonpath.endswith("xpm_fix.py")):
            files_copied += 1
            shutil.copy(pythonpath, dist_file)
            print("    " + filename)
    # verify number of files copied (from AStyleWxTest)
    if files_copied != 5:
        libastylewx.system_exit("Error in number of python files copied: " + str(files_copied))
    # verify copy - had a problem with bad filenames
    distfiles = (glob.glob(dist_file + "/*"))
    if len(distfiles) != files_copied:
        libastylewx.system_exit("Error copying python files: " + str(len(distfiles)))
Пример #2
0
def process_wxstc_catalogue_file(wx_path):
    """ Comment out the static build unused lexers in the wxscintilla Catalogue.cxx file.
        This file is in the src/stc/scintilla/src folder, not the build/msw folder.
        A new file named CatalogueStatic.cxx is created with the commented-out lexers.
    """
    updated_file = []           # undated file save area
    lines_changed = 0           # number of lines changed
    catalogue_path = "/src/stc/scintilla/src/Catalogue.cxx"
    print(wx_path)
    file_path = wx_path + catalogue_path
    file_path = file_path.replace('\\', '/')
    if not os.path.isfile(file_path):
        libastylewx.system_exit("No catalogue file to process: " + file_path)
    with open(file_path, mode='r') as file_in:
        for line in file_in:
            #! remove the link lexer statement in CatalogueStatic
            if line.strip().startswith("LINK_LEXER") and "(lmCPP)" not in line:
                line = line.replace("LINK_LEXER", "//LINK_LEXER")
                lines_changed += 1
            updated_file.append(line)

    static_file = catalogue_path
    static_file = static_file.replace("Catalogue", "CatalogueStatic")
    static_path = wx_path + static_file
    # remove an existing static file
    if os.path.isfile(static_path):
        os.remove(static_path)
    # write the static file
    with open(static_path, mode='w') as file_out:
        for line in updated_file:
            file_out.write(line)
    print(lines_changed, "lines in", static_file)
Пример #3
0
def convert_line_ends(dist_dir, to_dos):
    """Convert line ends to dos (CRLF) or linux (LF).
       Needs tofrodos package.
       All files in a directory are converted.
    """
    files = glob.glob(dist_dir + "*.*")
    if os.name == "nt":
        exedir = "C:/Programs/tofrodos/"
        if to_dos:
            call_list = [exedir + "todos"] + files
        else:
            call_list = [exedir + "fromdos"] + files
    else:
        if to_dos:
            call_list = ["todos"] + files
        else:
            call_list = ["fromdos"] + files

    # call the conversion program
    try:
        subprocess.check_call(call_list)
    except subprocess.CalledProcessError as err:
        libastylewx.system_exit("Bad tofro return: " + str(err.returncode))
    except OSError:
        libastylewx.system_exit("Cannot find executable: " + call_list[0])
Пример #4
0
def process_wxstc_vcxproj_file(wx_path):
    """ Change the static unused lexers compile options in the project file.
        This file is in the build/msw folder.
        The static unused lexers are not compiled for the static build.
    """

    catalogue_compile = [
        "    <ClCompile Include=\"..\\..\\src\\stc\\scintilla\\src\\Catalogue.cxx\">",
        "      <ExcludedFromBuild Condition=\"'$(Configuration)'=='Static'\">true</ExcludedFromBuild>",
        "    </ClCompile>",
        "    <ClCompile Include=\"..\\..\\src\\stc\\scintilla\\src\\CatalogueStatic.cxx\">",
        "      <ExcludedFromBuild Condition=\"'$(Configuration)'!='Static'\">true</ExcludedFromBuild>",
        "    </ClCompile>"]
    lexer_exclude = "      <ExcludedFromBuild Condition=\"'$(Configuration)'=='Static'\">true</ExcludedFromBuild>"

    updated_file = []           # undated file save area
    lines_changed = 0           # number of lines changed
    if "vs2010" in wx_path:
        project_path = "/build/msw/wx_vc10_wxscintilla.vcxproj"
    elif "vs2012" in wx_path:
        project_path = "/build/msw/wx_vc11_wxscintilla.vcxproj"
    elif "vs2013" in wx_path or "vs2015" in wx_path or "vs2017" in wx_path:
        project_path = "/build/msw/wx_vc12_wxscintilla.vcxproj"
    else:
        libastylewx.system_exit("Cannot determine Visual Studio Version: " + wx_path)
    orig_path = project_path + ".orig"
    print(wx_path)
    file_path = wx_path + orig_path
    file_path = file_path.replace('\\', '/')
    if not os.path.isfile(file_path):
        shutil.copyfile(wx_path + project_path, file_path)
    # read the .orig file
    with open(file_path, mode='r') as file_in:
        for line in file_in:
            #! check for Catalogue.cxx in wxscintilla
            if "<ClCompile Include=" in line and "Catalogue.cxx" in line:
                for catalogue_new in catalogue_compile:
                    lines_changed += 1
                    updated_file.append(catalogue_new + '\n')
                continue
            #! check for unused static build lexers in wxscintilla
            if "<ClCompile Include=" in line:
                if "\\lexers\\Lex" in line and "\\lexers\\LexCPP" not in line:
                    end = line.find(" />")
                    if end != -1:
                        lines_changed += 1
                        line = line[:end] + ">\n"
                        updated_file.append(line)
                        updated_file.append(lexer_exclude + '\n')
                        line = "    </ClCompile>\n"
            updated_file.append(line)

    # write the new file
    with open(wx_path + project_path, mode='w') as file_out:
        for line in updated_file:
            file_out.write(line)

    print(lines_changed, "lines in", project_path)
    print()
Пример #5
0
def copy_astylewx_image(dist_image):
    """Copy astylewx image directory to a distribution directory.
    """
    print("copying image")
    imagefiles = glob.glob(__astylewx_dir + "/image/*")
    for imagepath in imagefiles:
        shutil.copy(imagepath, dist_image)
    # verify copy - had a problem with bad filenames
    distfiles = (glob.glob(dist_image + "/*.*"))
    if len(distfiles) != len(imagefiles):
        libastylewx.system_exit("Error copying image: " + str(len(distfiles)))
Пример #6
0
def get_image_directory():
    """Get the image directory path for the os environment.
       Extract the directory from path[0]
    """
    imagedir = libastylewx.get_astylewx_directory() + "/image/"
    imagedir = imagedir.replace('\\', '/')
    # verify the path
    if not os.path.isdir(imagedir):
        message = "Cannot find image directory: " + imagedir
        libastylewx.system_exit(message)
    return imagedir
Пример #7
0
def copy_astylewx_dialog(dist_dialog, to_dos=False):
    """Copy astylewx dialog directory to a distribution directory.
    """
    print("copying dialog")
    dialogfiles = glob.glob(__astylewx_dir + "/dialog/*")
    for dialogpath in dialogfiles:
        shutil.copy(dialogpath, dist_dialog)
    convert_line_ends(dist_dialog, to_dos)
    # verify copy - had a problem with bad filenames
    distfiles = (glob.glob(dist_dialog + "/*.*"))
    if len(distfiles) != len(dialogfiles):
        libastylewx.system_exit("Error copying dialog: " + str(len(distfiles)))
Пример #8
0
def extract_astyle_src(dist_src, to_dos=False):
    """Extract astyle src directory to a distribution directory.
    """
    print("extracting src")
    srcfiles = glob.glob(__astyle_dir + "/src/*")
    for srcpath in srcfiles:
        shutil.copy(srcpath, dist_src)
    convert_line_ends(dist_src, to_dos)
    # verify copy - had a problem with bad filenames
    distfiles = (glob.glob(dist_src + "/*.cpp")
                 + glob.glob(dist_src + "/*.h")
                 + glob.glob(dist_src + "/*.rc"))
    if len(distfiles) != len(srcfiles):
        libastylewx.system_exit("Error copying src: " + str(len(distfiles)))
Пример #9
0
def copy_build_directories_make(dist_build, build_dir):
    """Copy the build/makefile directories to the distribution directory.
    """
    buildfiles = __astylewx_dir + "/build/"

    makedir = '/' + build_dir + '/'
    dist_astyle_make = dist_build + makedir
    os.mkdir(dist_astyle_make)
    files_copied = 0
    makefiles = glob.glob(buildfiles + makedir + "[Mm]ake*")
    for makefile in makefiles:
        shutil.copy(makefile, dist_astyle_make)
        files_copied += 1
    if files_copied != 1:
        libastylewx.system_exit("Error in number of build files copied: " + str(files_copied))
Пример #10
0
def process_project_files(wx_path):
    """ Process all of the "vcxproj" files in the build/msw path.
    """
    # get the project files
    build_path = wx_path + "/build/msw/"
    if not os.path.exists(build_path):
        libastylewx.system_exit("No path to process: " + build_path)
    file_paths = glob.glob(build_path + "*.vcxproj")

    # process the files
    files_changed = 0               # number of files changed
    for file_path in file_paths:
        updated_file = []           # undated file save area
        lines_changed = 0           # number of lines changed
        is_in_static = False        # is in the Static configuration
        has_static_config = False   # project has a Static configuration
        file_path = file_path.replace('\\', '/')
        if not os.path.exists(file_path):
            libastylewx.system_exit("No file to process: " + file_path)
        # open and process an input file
        with open(file_path, mode='r') as file_in:
            for line in file_in:
                original_line = line
                #! change lines in Static configuration only
                if "ItemDefinitionGroup" in line and "'Static" in line:
                    is_in_static = True
                    has_static_config = True
                if "/ItemDefinitionGroup" in line and is_in_static:
                    is_in_static = False
                if is_in_static:
                    line = change_static_configs(line, file_path)
                if line != original_line:
                    lines_changed += 1
                updated_file.append(line)
        # write the updated output file
        with open(file_path, mode='w') as file_out:
            for line_out in updated_file:
                file_out.write(line_out)
        # print debug data
        unused, project_name = os.path.split(file_path)
        if has_static_config:
            print(lines_changed, "lines in", project_name)
        else:
            print("No Static configuration", project_name)
        if lines_changed > 0:
            files_changed += 1
    print(files_changed, "files in", build_path)
Пример #11
0
def copy_build_directories_cb(dist_build, build_dir):
    """Copy the build/codeblocks directories to the distribution directory.
    """
    buildfiles = __astylewx_dir + "/build/"
    dist_astyle_cb = dist_build + '/' + build_dir + '/'
    os.mkdir(dist_astyle_cb)
    files_copied = 0
    workfiles = glob.glob(buildfiles + build_dir + "/*.workspace")
    for workfile in workfiles:
        shutil.copy(workfile, dist_astyle_cb)
        files_copied += 1
    cbpfiles = glob.glob(buildfiles + build_dir + "/*.cbp")
    for cbpfile in cbpfiles:
        shutil.copy(cbpfile, dist_astyle_cb)
        files_copied += 1
    if files_copied != 6 and files_copied != 7 and files_copied != 10:
        libastylewx.system_exit("Error in number of build files copied: " + str(files_copied))
Пример #12
0
def remove_dist_directories():
    """Remove directories from a previous run.
    """
    dirs = sorted(glob.glob(__base_dir + "/[Dd]ist*/"))
    for directory in dirs:
        if not directory[:-1].lower().endswith("wx"):
            continue
        directory = directory.replace('\\', '/')
        print("remove " + directory)
        # remove the directory - this is a problem with Windows only
        imax = 5
        for i in range(0, imax):
            shutil.rmtree(directory, True)
            if not os.path.isdir(directory):
                break
            if i == imax - 1:
                libastylewx.system_exit("Directory not removed: " + directory)
            time.sleep(2)
Пример #13
0
def extract_astyle_top(dist_top, to_dos=False):
    """Extract astyle top directory to a distribution directory.
    """
    print("extracting top")
    deleted = 0
    docfiles = glob.glob(__astylewx_dir + "/*")
    for filepath in docfiles:
        sep = filepath.rfind(os.sep)
        filename = filepath[sep + 1:]
        if filename == "LICENSE.md":
            shutil.copy(filepath, dist_top)
            print("    " + filename)
        else:
            deleted += 1
    convert_line_ends(dist_top, to_dos)
    # verify copy - had a problem with bad filenames
    distfiles = (glob.glob(dist_top + "/*.md"))
    if len(distfiles) != len(docfiles) - deleted:
        libastylewx.system_exit("Error copying top: " + str(len(distfiles)))
Пример #14
0
def main():
    """ Main processing function.
    """
    if os.name != "nt":
        libastylewx.system_exit("\nThis script is for Windows only!")

    libastylewx.set_text_color("yellow")
    print(libastylewx.get_python_version())

    for wx_path in wx_paths:
        print()
        if not check_static_config(wx_path):
            continue
        process_project_files(wx_path)
        print()
        process_wxstc_vcxproj_file(wx_path)
        print()
        process_wxstc_catalogue_file(wx_path)
        print()
        process_wxsetup_props_file(wx_path)
Пример #15
0
def main():
    """ Main processing function.
    """
    if os.name != "nt":
        libastylewx.system_exit("\nThis script is for Windows only!")

    libastylewx.set_text_color("yellow")
    print(libastylewx.get_python_version())

    for wx_path in wx_paths:
        print()
        if not check_static_config(wx_path):
            continue
        process_project_files(wx_path)
        print()
        process_wxstc_vcxproj_file(wx_path)
        print()
        process_wxstc_catalogue_file(wx_path)
        print()
        process_wxsetup_props_file(wx_path)
Пример #16
0
def main():
    """ Main processing function.
    """
    global __astylewx_file_names
    libastylewx.set_text_color("yellow")
    if not (platform.python_implementation() == "CPython"
            and sys.version_info[0] >= 3):
        libastylewx.system_exit("\nMust use Python version 3 or greater")
    print(get_cppcheck_version(), "\n")
    if len(__astylewx_file_names) == 0:
        __astylewx_file_names = get_astyle_file_names()
    __astylewx_file_names.sort(key=str.lower)
    for file_name in __astylewx_file_names:
        print('Dumping', file_name + '...')
        create_dump_file(file_name)
    for file_name in __astylewx_file_names:
        print()
        dump_file = file_name + '.dump'
        print('Checking', dump_file + '...')
        process_dump_file(dump_file)
    print()
Пример #17
0
def copy_astylewx_doc(dist_doc, to_dos=False):
    """Copy astylewx doc directory to a distribution directory.
    """
    print("copying doc")
    deleted = 0
    docfiles = glob.glob(__astylewx_dir + "/doc/*")
    for filepath in docfiles:
        sep = filepath.rfind(os.sep)
        filename = filepath[sep + 1:]
        if filename in ("index.html", "install.html", "static.html",
                        "styles.css"):
            shutil.copy(filepath, dist_doc)
            print("    " + filename)
        else:
            deleted += 1
    convert_line_ends(dist_doc, to_dos)
    # verify copy - had a problem with bad filenames
    distfiles = (glob.glob(dist_doc + "/*.html") +
                 glob.glob(dist_doc + "/*.css"))
    if len(distfiles) != len(docfiles) - deleted:
        libastylewx.system_exit("Error copying doc: " + str(len(distfiles)))
Пример #18
0
def verify_clang_tidy_version(tidy_exepath):
    """Verify the clang-tidy version number to the expected version.
       A lower version number may result in unexpected warnings.
       The expected version number is global.
       Return the two digit version number.
    """
    # check_output always returns byte code
    try:
        version = subprocess.check_output([tidy_exepath, "-version"])
    except subprocess.CalledProcessError as err:
        libastylewx.system_exit("\nBad clang-tidy return: " + str(err.returncode))
    except OSError:
        libastylewx.system_exit("\nCannot find executable: " + tidy_exepath)

    if platform.python_version_tuple()[0] >= '3':
        version = version.decode()
    version = version[40:43]
    if version < __minimum_version:
        print("\nclang-tidy version ", version,
              "is less than minimum version", __minimum_version, "\n")
    return version
Пример #19
0
def call_7zip(dist_base, compressed_file):
    """Call 7zip to create an archive.
       arg 1- the directory to compress.
       arg 2- name of the compressed file.
    """
    exepath = libastylewx.get_7zip_path()
    compress = [exepath, "a", compressed_file]
    # check file ending to see if it is a tarball
    if compressed_file.endswith((".gz", ".bz2")):
        compress.append("*.tar")
    # stdout file must have full path since 'cwd' is used in call
    filename = libastylewx.get_file_py_directory(True) + "compress.txt"
    outfile = open(filename, 'w')
    try:
        subprocess.check_call(compress, cwd=dist_base, stdout=outfile)
    except subprocess.CalledProcessError as err:
        libastylewx.system_exit("Bad 7zip return: " + str(err.returncode))
    except OSError:
        libastylewx.system_exit("Cannot find executable: " + compress[0])
    outfile.close()
    os.remove(filename)
    print(compressed_file + " created")
Пример #20
0
def verify_clang_tidy_version(tidy_exepath):
    """Verify the clang-tidy version number to the expected version.
       A lower version number may result in unexpected warnings.
       The expected version number is global.
       Return the two digit version number.
    """
    # check_output always returns byte code
    try:
        version = subprocess.check_output([tidy_exepath, "-version"])
    except subprocess.CalledProcessError as err:
        libastylewx.system_exit("\nBad clang-tidy return: " +
                                str(err.returncode))
    except OSError:
        libastylewx.system_exit("\nCannot find executable: " + tidy_exepath)

    if platform.python_version_tuple()[0] >= '3':
        version = version.decode()
    version = version[40:43]
    if version < __minimum_version:
        print("\nclang-tidy version ", version, "is less than minimum version",
              __minimum_version, "\n")
    return version
Пример #21
0
def call_7zip(dist_base, compressed_file):
    """Call 7zip to create an archive.
       arg 1- the directory to compress.
       arg 2- name of the compressed file.
    """
    exepath = libastylewx.get_7zip_path()
    compress = [exepath, "a", compressed_file]
    # check file ending to see if it is a tarball
    if compressed_file.endswith((".gz", ".bz2")):
        compress.append("*.tar")
    # stdout file must have full path since 'cwd' is used in call
    filename = libastylewx.get_file_py_directory(True) + "compress.txt"
    outfile = open(filename, 'w')
    try:
        subprocess.check_call(compress, cwd=dist_base, stdout=outfile)
    except subprocess.CalledProcessError as err:
        libastylewx.system_exit("Bad 7zip return: " + str(err.returncode))
    except OSError:
        libastylewx.system_exit("Cannot find executable: " + compress[0])
    outfile.close()
    os.remove(filename)
    print(compressed_file + " created")
Пример #22
0
def copy_astylewx_doc(dist_doc, to_dos=False):
    """Copy astylewx doc directory to a distribution directory.
    """
    print("copying doc")
    deleted = 0
    docfiles = glob.glob(__astylewx_dir + "/doc/*")
    for filepath in docfiles:
        sep = filepath.rfind(os.sep)
        filename = filepath[sep + 1:]
        if (filename == "index.html"
                or filename == "install.html"
                or filename == "static.html"
                or filename == "styles.css"):
            shutil.copy(filepath, dist_doc)
            print("    " + filename)
        else:
            deleted += 1
    convert_line_ends(dist_doc, to_dos)
    # verify copy - had a problem with bad filenames
    distfiles = (glob.glob(dist_doc + "/*.html")
                 + glob.glob(dist_doc + "/*.css"))
    if len(distfiles) != len(docfiles) - deleted:
        libastylewx.system_exit("Error copying doc: " + str(len(distfiles)))
Пример #23
0
def check_static_config(wx_path):
    """ Check that a "Static" configurartion has been created before update.
        Failure to do this causes bad ".orig" backup files to be saved.
    """
    if "vs2010" in wx_path:
        project_path = "/build/msw/wx_vc10_wxscintilla.vcxproj"
    elif "vs2012" in wx_path:
        project_path = "/build/msw/wx_vc11_wxscintilla.vcxproj"
    elif "vs2013" in wx_path or "vs2015" in wx_path or "vs2017" in wx_path:
        project_path = "/build/msw/wx_vc12_wxscintilla.vcxproj"
    else:
        libastylewx.system_exit("Cannot determine Visual Studio Version: " + wx_path)
    file_path = wx_path + project_path
    file_path = file_path.replace('\\', '/')
    # read the wxscintilla.vcxproj file
    with open(file_path, mode='r') as file_in:
        for line in file_in:
            #! check for Static configuration in wxscintilla
            if "<Configuration>Static</Configuration>" in line:
                return True
    # no static configuration found
    print(wx_path)
    print("No Static configuration to modify!")
    return False
Пример #24
0
def check_static_config(wx_path):
    """ Check that a "Static" configurartion has been created before update.
        Failure to do this causes bad ".orig" backup files to be saved.
    """
    if "vs2010" in wx_path:
        project_path = "/build/msw/wx_vc10_wxscintilla.vcxproj"
    elif "vs2012" in wx_path:
        project_path = "/build/msw/wx_vc11_wxscintilla.vcxproj"
    elif "vs2013" in wx_path or "vs2015" in wx_path:
        project_path = "/build/msw/wx_vc12_wxscintilla.vcxproj"
    else:
        libastylewx.system_exit("Cannot determine Visual Studio Version: " + wx_path)
    file_path = wx_path + project_path
    file_path = file_path.replace('\\', '/')
    # read the wxscintilla.vcxproj file
    with open(file_path, mode='r') as file_in:
        for line in file_in:
            #! check for Static configuration in wxscintilla
            if "<Configuration>Static</Configuration>" in line:
                return True
    # no static configuration found
    print(wx_path)
    print("No Static configuration to modify!")
    return False
Пример #25
0
def extract_astyle_top(dist_top, to_dos=False):
    """Extract astyle top directory to a distribution directory.
    """
    print("extracting top")
    deleted = 0
    docfiles = glob.glob(__astylewx_dir + "/*")
    for filepath in docfiles:
        sep = filepath.rfind(os.sep)
        filename = filepath[sep + 1:]
        if filename == "LICENSE.txt":
            shutil.copy(filepath, dist_top)
            print("    " + filename)
        else:
            deleted += 1
    convert_line_ends(dist_top, to_dos)
    # verify copy - had a problem with bad filenames
    distfiles = (glob.glob(dist_top + "/*.txt"))
    if len(distfiles) != len(docfiles) - deleted:
        libastylewx.system_exit("Error copying top: " + str(len(distfiles)))
    # change file permissions
    for srcfile in distfiles:
        # read/write by the owner and read only by everyone else (-rw-r--r--)
        mode = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
        os.chmod(srcfile, mode)
Пример #26
0
def copy_linux_build_directories(dist_build):
    """Copy the Linux build directories to the distribution directory.
    """
    print("copying build")
    # permissions = read/write by the owner and read only by everyone else
    mode = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)

    # build/clang directory
    print("    clang")
    astylewx_build_clang = __astylewx_dir + "/build/clang/"
    dist_build_clang = dist_build + "/clang/"
    os.makedirs(dist_build_clang)
    files_copied = 0
    for buildfile in ["Makefile", "deps.mak"]:
        files_copied += 1
        make_path_clang = astylewx_build_clang + buildfile
        shutil.copy(make_path_clang, dist_build_clang)
        os.chmod(make_path_clang, mode)
    # verify number of files copied
    if files_copied != 2:
        libastylewx.system_exit("Error in number of clang build files copied: " + str(files_copied))

    # build/gcc directory
    print("    gcc")
    astylewx_build_gcc = __astylewx_dir + "/build/gcc/"
    dist_build_gcc = dist_build + "/gcc/"
    os.makedirs(dist_build_gcc)
    files_copied = 0
    for buildfile in ["Makefile", "deps.mak"]:
        files_copied += 1
        make_path_gcc = astylewx_build_gcc + buildfile
        shutil.copy(make_path_gcc, dist_build_gcc)
        os.chmod(make_path_gcc, mode)
    # verify number of files copied
    if files_copied != 2:
        libastylewx.system_exit("Error in number of gcc build files copied: " + str(files_copied))

    # build/intel directory
    print("    intel")
    astylewx_build_intel = __astylewx_dir + "/build/intel/"
    dist_build_intel = dist_build + "/intel/"
    os.makedirs(dist_build_intel)
    files_copied = 0
    for buildfile in ["Makefile", "deps.mak"]:
        files_copied += 1
        make_path_intel = astylewx_build_intel + buildfile
        shutil.copy(make_path_intel, dist_build_intel)
        os.chmod(make_path_intel, mode)
    # verify number of files copied
    if files_copied != 2:
        libastylewx.system_exit("Error in number of intel build files copied: " + str(files_copied))
Пример #27
0
def run_cppcheck():
    """Run the cppcheck program.
       NOTE: The window stays open only if run from the console.
       --enable=all       Enable all checks
       -f, --force        Force checking if "too many" #ifdefs.
       -h, --help         Print the help information.
       --inconclusive     Error messages for inconclusive analysis.
       -j <jobs>          Start [jobs] threads.
       -q, --quiet        Only print error messages.
       --report-progress  Report progress while checking a file.
       --suppress=<spec>  Suppress a specific warning.
       --suppressions-list=<file> Suppress warnings listed in the file.
       -v, --verbose      More detailed error reports.
       --version          Print the version number.
       --xml              Write results in xml to error stream.
       --xml-version=2    Use new xml format.
    """
    if os.name == "nt":
        exepath = "C:/Program Files/Cppcheck/cppcheck.exe"
        if not os.path.exists(exepath):
            libastylewx.system_exit("Cannot find executable: " + exepath)
    else:
        exepath = "cppcheck"
    verify_cppcheck_version(exepath)
    cppcheck = [exepath]
    # -j<jobs> is threads to use for silmutaneous checking
    # runs faster but messages for the files are mixed
    cppcheck.append("-j2")
    # cppcheck.append("--dump")
    cppcheck.append("--enable=all")
    cppcheck.append("--xml-version=2")
    cppcheck.append("--force")
    cppcheck.append("--inconclusive")
    cppcheck.append("--verbose")
    cppcheck.append("--suppress=functionStatic")
    cppcheck.append("--suppress=noValidConfiguration")
    #~ cppcheck.append("--suppress=purgedConfiguration")
    cppcheck.append("--suppressions-list=" + __suppression_path)
    cppcheck.append(__src_dir)
    # shell=True keeps the console window open, but will not display if run from an editor
    # subprocess.check_output() doesn't work from an editor
    try:
        subprocess.check_call(cppcheck)
    except subprocess.CalledProcessError as err:
        libastylewx.system_exit("Bad cppcheck return: " + str(err.returncode))
    except OSError:
        libastylewx.system_exit("Cannot find executable: " + cppcheck[0])
Пример #28
0
def run_cppcheck():
    """Run the cppcheck program.
       NOTE: The window stays open only if run from the console.
       --enable=all       Enable all checks
       -f, --force        Force checking if "too many" #ifdefs.
       -h, --help         Print the help information.
       --inconclusive     Error messages for inconclusive analysis.
       -j <jobs>          Start [jobs] threads.
       -q, --quiet        Only print error messages.
       --report-progress  Report progress while checking a file.
       --suppress=<spec>  Suppress a specific warning.
       --suppressions-list=<file> Suppress warnings listed in the file.
       -v, --verbose      More detailed error reports.
       --version          Print the version number.
       --xml              Write results in xml to error stream.
       --xml-version=2    Use new xml format.
    """
    if os.name == "nt":
        exepath = "C:/Program Files/Cppcheck/cppcheck.exe"
        if not os.path.exists(exepath):
            libastylewx.system_exit("Cannot find executable: " + exepath)
    else:
        exepath = "cppcheck"
    verify_cppcheck_version(exepath)
    cppcheck = [exepath]
    # -j<jobs> is threads to use for silmutaneous checking
    # runs faster but messages for the files are mixed
    cppcheck.append("-j2")
    # cppcheck.append("--dump")
    cppcheck.append("--enable=all")
    cppcheck.append("--xml-version=2")
    cppcheck.append("--force")
    cppcheck.append("--inconclusive")
    cppcheck.append("--verbose")
    cppcheck.append("--suppress=functionStatic")
    cppcheck.append("--suppress=purgedConfiguration")
    cppcheck.append("--suppressions-list=" + __suppression_path)
    cppcheck.append(__src_dir)
    # shell=True keeps the console window open, but will not display if run from an editor
    # subprocess.check_output() doesn't work from an editor
    try:
        subprocess.check_call(cppcheck)
    except subprocess.CalledProcessError as err:
        libastylewx.system_exit("Bad cppcheck return: " + str(err.returncode))
    except OSError:
        libastylewx.system_exit("Cannot find executable: " + cppcheck[0])
Пример #29
0
def process_project_files(wx_path):
    """ Process all of the "vcxproj" files in the build/msw path.
    """
    # get the project files
    build_path = wx_path + "/build/msw/"
    if not os.path.exists(build_path):
        libastylewx.system_exit("No path to process: " + build_path)
    file_paths = glob.glob(build_path + "*.vcxproj")

    # process the files
    files_changed = 0               # number of files changed
    for file_path in file_paths:
        if not (("vs2010" in wx_path and "_vc10_" in file_path)
                or ("vs2012" in wx_path and "_vc11_" in file_path)
                or ("vs2013" in wx_path and "_vc12_" in file_path)
                or ("vs2015" in wx_path and "_vc12_" in file_path)
                or ("vs2017" in wx_path and "_vc12_" in file_path)):
            continue
        updated_file = []           # undated file save area
        lines_changed = 0           # number of lines changed
        is_in_static = False        # is in the Static configuration
        is_vs2010_x64 = False       # is in a VS 2010 Static configuration for Fix
        has_static_config = False   # project has a Static configuration
        file_path = file_path.replace('\\', '/')
        if not os.path.exists(file_path):
            libastylewx.system_exit("No file to process: " + file_path)
        # open and process an input file
        with open(file_path, mode='r') as file_in:
            for line in file_in:
                original_line = line
                #
                # 3.0.1 FIX FOR BUG IN VS 2010 VCXPROJ FILES
                # Precmpiled header files for ALL x64 configurations are
                # incorrectly output to the Win32 directory.
                # This corrects the problem before continuing.
                # 3.1 USES A .PROPS FILE. DON'T KNOW ABOUT 3.0.2.
                # DO NOT MOVE THIS PROCEDURE FROM HERE.
                if "_vc10_" in file_path:
                    if "ItemDefinitionGroup" in line and "|x64'" in line:
                        is_vs2010_x64 = True
                    if "/ItemDefinitionGroup" in line and is_vs2010_x64:
                        is_vs2010_x64 = False
                    if is_vs2010_x64:
                        if ("<PrecompiledHeaderOutputFile>" in line
                                and "vc_msw" in line):
                            line = line.replace("vc_msw", "vc_x64_msw")
                # END VS 2010 FIX
                #
                # 3.0.1 FIX FOR BUG IN VS 2012-2013 VCXPROJ FILES
                # PDB files for the Release, DLL Release, and Static x64
                # platforms always compile even if no changes were made.
                # This is caused by <DebugInformationFormat> set to "None"
                # and <ProgramDataBaseFileName> having a value.
                # This corrects the problem before continuing.
                # THIS IS FIXED IN 3.1. DON'T KNOW ABOUT 3.0.2
                # DO NOT MOVE THIS PROCEDURE FROM HERE.
                if "_vc11_" in file_path or "_vc12_" in file_path:
                    if "<DebugInformationFormat>" in line and "None" in line:
                        line = line.replace("None", "ProgramDatabase")
                # END VS 2012-2013 FIX
                #
                # change lines in Static configuration only
                if "ItemDefinitionGroup" in line and "'Static" in line:
                    is_in_static = True
                    has_static_config = True
                if "/ItemDefinitionGroup" in line and is_in_static:
                    is_in_static = False
                if is_in_static:
                    line = change_static_configs(line, file_path)
                #
                # TESTS FOR VS 2010 ONLY
                if "_vc10_" in file_path:
                    line = change_vs2010_single_line_data(line)
                # END TESTS FOR VS 2010 ONLY
                #
                if line != original_line:
                    lines_changed += 1
                updated_file.append(line)
        # write the updated output file
        with open(file_path, mode='w') as file_out:
            for line_out in updated_file:
                file_out.write(line_out)
        # print debug data
        unused, project_name = os.path.split(file_path)
        if has_static_config:
            print(lines_changed, "lines in", project_name)
        else:
            print("No Static configuration", project_name)
        if lines_changed > 0:
            files_changed += 1
    print(files_changed, "files in", build_path)
Пример #30
0
def build_windows_distribution():
    """Copy astylewx files to the windows directory.
    """
    print()
    print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
    print("*        Creating AStyleWx Windows Distribution         *")
    print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
    # the following variables may be modified
    # do NOT use STATIC_XP, there is another script for that
    vsdir = libastylewx.VS_RELEASE
    wxrel = libastylewx.WX_RELEASE
    vscfg = libastylewx.STATIC

    print("Compiling with {0} wxWidgets {1}".format(vsdir, wxrel))
    print("Building AStyleWx release", AS_RELEASE)
    dist_base = get_distribution_folder_windows()
    dist_astylewx = dist_base + "/AStyleWx_{0}_windows".format(
        AS_RELEASE) + "/AStyleWx"
    os.makedirs(dist_astylewx)
    libastylewx.build_astylewx_executable(vscfg)

    # Windows includes an executable in the bin directory
    print("copying exe")
    dist_astylewx_bin = dist_astylewx + "/bin/"
    os.mkdir(dist_astylewx_bin)
    astylewx_build_directory = libastylewx.get_astylewx_build_directory(vscfg)
    # if vscfg == libastylewx.DEBUG:
    #    shutil.copy(astylewx_build_directory + "/debug/AStyleWxd.exe", dist_astylewx_bin)
    # elif vscfg == libastylewx.RELEASE:
    #    shutil.copy(astylewx_build_directory + "/bin/AStyleWx.exe", dist_astylewx_bin)
    # elif vscfg == libastylewx.STATIC:
    #    shutil.copy(astylewx_build_directory + "/binstatic/AStyleWx.exe", dist_astylewx_bin)
    if vscfg == libastylewx.STATIC:
        shutil.copy(astylewx_build_directory + "/binstatic/AStyleWx.exe",
                    dist_astylewx_bin)
    else:
        libastylewx.system_exit("Invalid compile configuration: " + vscfg)

    # top directory
    dist_top = dist_astylewx + "/"
    copy_astylewx_top(dist_top, True)

    # build directory
    dist_build = dist_astylewx + "/build"
    os.mkdir(dist_build)
    copy_windows_build_directories(dist_build)

    # doc directory
    dist_doc = dist_astylewx + "/doc/"
    os.mkdir(dist_doc)
    copy_astylewx_doc(dist_doc, True)

    # dialog directory
    dist_dialog = dist_astylewx + "/dialog/"
    os.mkdir(dist_dialog)
    copy_astylewx_dialog(dist_dialog, True)

    # file-py directory
    dist_python = dist_astylewx + "/file-py/"
    os.mkdir(dist_python)
    copy_astylewx_python_files(dist_python)

    # image directory
    dist_image = dist_astylewx + "/image/"
    os.mkdir(dist_image)
    copy_astylewx_image(dist_image)

    # src directory
    dist_src = dist_astylewx + "/src/"
    os.mkdir(dist_src)
    copy_astylewx_src(dist_src, True)

    # astyle project
    extract_windows_astyle()

    # create zip
    print()
    zipfile = "AStyleWx_{0}_windows.zip".format(AS_RELEASE)
    call_7zip(dist_base, zipfile)
Пример #31
0
def process_wxsetup_props_file(wx_path):
    """ Add the static wxWidgets variables to the wx_setup.props file.
        This file is in the build/msw folder.
    """

    suffix_additions = [
        "",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static' and '$(CharacterSet)'=='Unicode'\">",
        "    <wxSuffix>us</wxSuffix>", "  </PropertyGroup>",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static' and '$(CharacterSet)'!='Unicode'\">",
        "    <wxSuffix>s</wxSuffix>", "  </PropertyGroup>",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static'\">",
        "    <wxCfg>s</wxCfg>", "  </PropertyGroup>", ""
    ]

    directory_additions = [
        "",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static'\">",
        "    <wxOutDir>..\\..\\lib\\$(wxCompilerPrefix)$(wxArchSuffix)_lib$(wxCfg)\\</wxOutDir>",
        "  </PropertyGroup>",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static'\">",
        "    <wxIntRootDir>$(wxCompilerPrefix)$(wxArchSuffix)_$(wxToolkitPrefix)$(wxSuffix)\\</wxIntRootDir>",
        "  </PropertyGroup>", ""
    ]

    updated_file = []  # undated file save area
    wxsuffix_stmts = 0  # number of <wxSuffix> statements
    wxintrootdir_stmts = 0  # number of <wxIntRootDir> statements
    lines_changed = 0  # number of lines changed
    # determine the file name
    if "vs2010" in wx_path:  # vs2010 does NOT have a setup.props
        return
    elif "vs2012" in wx_path:
        project_path = "/build/msw/wx_vc11_wx_setup.props"
    elif "vs2013" in wx_path or "vs2015" in wx_path:
        project_path = "/build/msw/wx_vc12_wx_setup.props"
    else:
        libastylewx.system_exit("Cannot determine Visual Studio Version: " +
                                wx_path)
    orig_path = project_path + ".orig"
    print(wx_path)
    file_path = wx_path + orig_path
    file_path = file_path.replace('\\', '/')
    if not os.path.isfile(file_path):
        shutil.copyfile(wx_path + project_path, file_path)
    # read the .orig file
    with open(file_path, mode='r') as file_in:
        for line in file_in:
            #! check for end of <wxSuffix> statements
            if "<wxSuffix>" in line:
                wxsuffix_stmts += 1
            if "</PropertyGroup>" in line and wxsuffix_stmts == 4:
                wxsuffix_stmts = 9  # don't do it again
                updated_file.append(line)
                for setup_new in suffix_additions:
                    lines_changed += 1
                    updated_file.append(setup_new + '\n')
                continue
            #! check for end of <wxIntRootDir> statements
            if "<wxIntRootDir>" in line:
                wxintrootdir_stmts += 1
            if "</PropertyGroup>" in line and wxintrootdir_stmts == 4:
                wxintrootdir_stmts = 9  # don't do it again
                updated_file.append(line)
                for setup_new in directory_additions:
                    lines_changed += 1
                    updated_file.append(setup_new + '\n')
                continue

            updated_file.append(line)

    # write the new file
    with open(wx_path + project_path, mode='w') as file_out:
        for line in updated_file:
            file_out.write(line)

    print(lines_changed, "lines in", project_path)
    print()
Пример #32
0
def process_wxstc_vcxproj_file(wx_path):
    """ Change the static unused lexers compile options in the project file.
        This file is in the build/msw folder.
        The static unused lexers are not compiled for the static build.
    """

    catalogue_compile = [
        "    <ClCompile Include=\"..\\..\\src\\stc\\scintilla\\src\\Catalogue.cxx\">",
        "      <ExcludedFromBuild Condition=\"'$(Configuration)'=='Static'\">true</ExcludedFromBuild>",
        "    </ClCompile>",
        "    <ClCompile Include=\"..\\..\\src\\stc\\scintilla\\src\\CatalogueStatic.cxx\">",
        "      <ExcludedFromBuild Condition=\"'$(Configuration)'!='Static'\">true</ExcludedFromBuild>",
        "    </ClCompile>"
    ]
    lexer_exclude = "      <ExcludedFromBuild Condition=\"'$(Configuration)'=='Static'\">true</ExcludedFromBuild>"

    updated_file = []  # undated file save area
    lines_changed = 0  # number of lines changed
    if "vs2010" in wx_path:
        project_path = "/build/msw/wx_vc10_wxscintilla.vcxproj"
    elif "vs2012" in wx_path:
        project_path = "/build/msw/wx_vc11_wxscintilla.vcxproj"
    elif "vs2013" in wx_path or "vs2015" in wx_path:
        project_path = "/build/msw/wx_vc12_wxscintilla.vcxproj"
    else:
        libastylewx.system_exit("Cannot determine Visual Studio Version: " +
                                wx_path)
    orig_path = project_path + ".orig"
    print(wx_path)
    file_path = wx_path + orig_path
    file_path = file_path.replace('\\', '/')
    if not os.path.isfile(file_path):
        shutil.copyfile(wx_path + project_path, file_path)
    # read the .orig file
    with open(file_path, mode='r') as file_in:
        for line in file_in:
            #! check for Catalogue.cxx in wxscintilla
            if "<ClCompile Include=" in line and "Catalogue.cxx" in line:
                for catalogue_new in catalogue_compile:
                    lines_changed += 1
                    updated_file.append(catalogue_new + '\n')
                continue
            #! check for unused static build lexers in wxscintilla
            if "<ClCompile Include=" in line:
                if "\\lexers\\Lex" in line and not "\\lexers\\LexCPP" in line:
                    end = line.find(" />")
                    if end != -1:
                        lines_changed += 1
                        line = line[:end] + ">\n"
                        updated_file.append(line)
                        updated_file.append(lexer_exclude + '\n')
                        line = "    </ClCompile>\n"
            updated_file.append(line)

    # write the new file
    with open(wx_path + project_path, mode='w') as file_out:
        for line in updated_file:
            file_out.write(line)

    print(lines_changed, "lines in", project_path)
    print()
Пример #33
0
def process_project_files(wx_path):
    """ Process all of the "vcxproj" files in the build/msw path.
    """
    # get the project files
    build_path = wx_path + "/build/msw/"
    if not os.path.exists(build_path):
        libastylewx.system_exit("No path to process: " + build_path)
    file_paths = glob.glob(build_path + "*.vcxproj")

    # process the files
    files_changed = 0  # number of files changed
    for file_path in file_paths:
        if not (("vs2010" in wx_path and "_vc10_" in file_path) or
                ("vs2012" in wx_path and "_vc11_" in file_path) or
                ("vs2013" in wx_path and "_vc12_" in file_path) or
                ("vs2015" in wx_path and "_vc12_" in file_path)):
            continue
        updated_file = []  # undated file save area
        lines_changed = 0  # number of lines changed
        is_in_static = False  # is in the Static configuration
        is_vs2010_x64 = False  # is in a VS 2010 Static configuration for Fix
        has_static_config = False  # project has a Static configuration
        file_path = file_path.replace('\\', '/')
        if not os.path.exists(file_path):
            libastylewx.system_exit("No file to process: " + file_path)
        # open and process an input file
        with open(file_path, mode='r') as file_in:
            for line in file_in:
                original_line = line
                #
                # 3.0.1 FIX FOR BUG IN VS 2010 VCXPROJ FILES
                # Precmpiled header files for ALL x64 configurations are
                # incorrectly output to the Win32 directory.
                # This corrects the problem before continuing.
                # 3.1 USES A .PROPS FILE. DON'T KNOW ABOUT 3.0.2.
                # DO NOT MOVE THIS PROCEDURE FROM HERE.
                if "_vc10_" in file_path:
                    if "ItemDefinitionGroup" in line and "|x64'" in line:
                        is_vs2010_x64 = True
                    if "/ItemDefinitionGroup" in line and is_vs2010_x64:
                        is_vs2010_x64 = False
                    if is_vs2010_x64:
                        if ("<PrecompiledHeaderOutputFile>" in line
                                and "vc_msw" in line):
                            line = line.replace("vc_msw", "vc_x64_msw")
                # END VS 2010 FIX
                #
                # 3.0.1 FIX FOR BUG IN VS 2012-2013 VCXPROJ FILES
                # PDB files for the Release, DLL Release, and Static x64
                # platforms always compile even if no changes were made.
                # This is caused by <DebugInformationFormat> set to "None"
                # and <ProgramDataBaseFileName> having a value.
                # This corrects the problem before continuing.
                # THIS IS FIXED IN 3.1. DON'T KNOW ABOUT 3.0.2
                # DO NOT MOVE THIS PROCEDURE FROM HERE.
                if "_vc11_" in file_path or "_vc12_" in file_path:
                    if "<DebugInformationFormat>" in line and "None" in line:
                        line = line.replace("None", "ProgramDatabase")
                # END VS 2012-2013 FIX
                #
                # change lines in Static configuration only
                if "ItemDefinitionGroup" in line and "'Static" in line:
                    is_in_static = True
                    has_static_config = True
                if "/ItemDefinitionGroup" in line and is_in_static:
                    is_in_static = False
                if is_in_static:
                    line = change_static_configs(line, file_path)
                #
                # TESTS FOR VS 2010 ONLY
                if "_vc10_" in file_path:
                    line = change_vs2010_single_line_data(line)
                # END TESTS FOR VS 2010 ONLY
                #
                if line != original_line:
                    lines_changed += 1
                updated_file.append(line)
        # write the updated output file
        with open(file_path, mode='w') as file_out:
            for line_out in updated_file:
                file_out.write(line_out)
        # print debug data
        unused, project_name = os.path.split(file_path)
        if has_static_config:
            print(lines_changed, "lines in", project_name)
        else:
            print("No Static configuration", project_name)
        if lines_changed > 0:
            files_changed += 1
    print(files_changed, "files in", build_path)
Пример #34
0
def build_windows_distribution():
    """Copy astylewx files to the windows directory.
    """
    print()
    print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
    print("*        Creating AStyleWx Windows Distribution         *")
    print("* * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
    # the following variables may be modified
    # do NOT use STATIC_XP, there is another script for that
    vsdir = libastylewx.VS_RELEASE
    wxrel = libastylewx.WX_RELEASE
    vscfg = libastylewx.STATIC

    print("Compiling with ({0}) wxWidgets {1}".format(vsdir, wxrel))
    print("Building AStyleWx release", AS_RELEASE)
    dist_base = get_distribution_folder_windows()
    dist_astylewx = dist_base + "/AStyleWx_{0}_windows".format(AS_RELEASE) + "/AStyleWx"
    os.makedirs(dist_astylewx)
    libastylewx.build_astylewx_executable(vscfg)

    # Windows includes an executable in the bin directory
    print("copying exe")
    dist_astylewx_bin = dist_astylewx + "/bin/"
    os.mkdir(dist_astylewx_bin)
    astylewx_build_directory = libastylewx.get_astylewx_build_directory(vscfg)
    # if vscfg == libastylewx.DEBUG:
    #    shutil.copy(astylewx_build_directory + "/debug/AStyleWxd.exe", dist_astylewx_bin)
    # elif vscfg == libastylewx.RELEASE:
    #    shutil.copy(astylewx_build_directory + "/bin/AStyleWx.exe", dist_astylewx_bin)
    # elif vscfg == libastylewx.STATIC:
    #    shutil.copy(astylewx_build_directory + "/binstatic/AStyleWx.exe", dist_astylewx_bin)
    if vscfg == libastylewx.STATIC:
        shutil.copy(astylewx_build_directory + "/binstatic/AStyleWx.exe", dist_astylewx_bin)
    else:
        libastylewx.system_exit("Invalid compile configuration: " + vscfg)

    # top directory
    dist_top = dist_astylewx + "/"
    copy_astylewx_top(dist_top, True)

    # build directory
    dist_build = dist_astylewx + "/build"
    os.mkdir(dist_build)
    copy_windows_build_directories(dist_build)

    # doc directory
    dist_doc = dist_astylewx + "/doc/"
    os.mkdir(dist_doc)
    copy_astylewx_doc(dist_doc, True)

    # dialog directory
    dist_dialog = dist_astylewx + "/dialog/"
    os.mkdir(dist_dialog)
    copy_astylewx_dialog(dist_dialog, True)

    # file-py directory
    dist_python = dist_astylewx + "/file-py/"
    os.mkdir(dist_python)
    copy_astylewx_python_files(dist_python)

    # image directory
    dist_image = dist_astylewx + "/image/"
    os.mkdir(dist_image)
    copy_astylewx_image(dist_image)

    # src directory
    dist_src = dist_astylewx + "/src/"
    os.mkdir(dist_src)
    copy_astylewx_src(dist_src, True)

    # astyle project
    extract_windows_astyle()

    # create zip
    print()
    zipfile = "AStyleWx_{0}_windows.zip".format(AS_RELEASE)
    call_7zip(dist_base, zipfile)
Пример #35
0
def run_clang_tidy(tidy_exepath, tidy_version, file_name):
    """Run the clang-tidy program for the specified file.
       NOTE: The window stays open only if run from the console.
    """
    # cppcoreguidelines-owning-memory
    # cppcoreguidelines-pro-type-member-init gives constructor does not initialize warning
    # cppcoreguidelines-pro-type-vararg don't use printf in astyle_main
    # google-global-names-in-headers, don't like the restriction (std::vector)
    # google-build-using-namespace gives warning for "using namespace"
    # google-readability-braces-around-statements
    # google-readability-casting replaces c-style casts with c++ casts
    # google-readability-todo adds username to todo comments
    # google-runtime-int values are determined by wxWidgets
    # google-runtime-references 'const' is determined by wxWidgets, cannot fix
    # hicpp-braces-around-statements redirects to readability-braces-around-statements
    # hicpp-member-init adds braces to member variables for initialization
    # hicpp-use-auto redirects to modernize-use-auto
    # hicpp-use-noexcept redirects to modernize-use-noexcept
    # llvm-header-guard adds the filepath to the header guard name
    # misc-misplaced-widening-cast is casting size_t to int instead of int to size_t
    # misc-unused-parameters caused several false positives, is checked by compiler
    # readability-braces-around-statements expects braces around single statements
    # readability-implicit-bool-cast use 'if (x=0)' instead of 'if (!x)'
    # readability-implicit-bool-conversion replaces above ...bool-cast in version6
    # readability-simplify-boolean-expr returns a conditional statement
    #
    # modernize-use-auto recommends using auto for variable types
    #
    # to fix one option: (disable checks, add the option, include -fix)
    # clangtidy.append("-checks=-*,readability-implicit-bool-cast")
    # clangtidy.append("-fix")
    #
    # version 5 checks
    tidy_checks = ("-checks=*,"
                   "-cppcoreguidelines-pro-type-member-init,"
                   "-google-global-names-in-headers,"
                   "-google-readability-braces-around-statements,"
                   "-google-readability-todo,"
                   "-google-runtime-int,"
                   "-google-runtime-references,"
                   "-hicpp-member-init,"
                   "-llvm-header-guard,"
                   "-misc-unused-parameters,"
                   "-readability-braces-around-statements,"
                   "-readability-implicit-bool-cast,"
                   "-readability-simplify-boolean-expr,"
                   "-modernize-use-auto")
    # version 6 checks
    if tidy_version[:1] > "5":
        tidy_checks += (","
                        "-cppcoreguidelines-owning-memory,"
                        "-fuchsia-default-arguments,"
                        "-hicpp-braces-around-statements,"
                        "-hicpp-use-auto,"
                        "-hicpp-use-noexcept,"
                        "-readability-implicit-bool-conversion")
    clangtidy = [tidy_exepath]
    clangtidy.append(tidy_checks)
    clangtidy.append("-header-filter=-^wx,$Base.h") # exclude wx and dialog headers
    clangtidy.append(__src_dir + file_name)
    clangtidy.append("--")                  # compiler options follow
    clangtidy.append("-std=c++14")          # c++14 minimum is required for clang
    clangtidy.append("-fno-rtti")
    clangtidy.append("-fno-exceptions")
    clangtidy.append("-I" + libastylewx.get_astylewx_directory() + "/dialog")
    if os.name == "nt":
        clangtidy.append("-I" + __wxw + "/include")
        clangtidy.append("-I" + __wxw + "/lib/vc_lib/mswud")
    else:
        clangtidy.append("-I" + __wxw + "/include/wx-3.0")
        # too many errors with setup.h
        #clangtidy.append("-I" + __wxw + "/lib/x86_64-linux-gnu/wx/include/gtk2-unicode-3.0")
    # stdout file must have full path
    filename = __src_dir + "xclang-" + file_name + ".txt"
    outfile = open(filename, 'w')
    print()
    print(file_name)
    # shell=True keeps the console window open, but will not display if run from an editor
    # subprocess.check_call() doesn't work from an editor
    try:
        subprocess.check_call(clangtidy, stdout=outfile)
    except subprocess.CalledProcessError as err:
        libastylewx.system_exit("Bad clang-tidy return: " + str(err.returncode))
    except OSError:
        libastylewx.system_exit("Cannot find executable: " + clangtidy[0])
Пример #36
0
def process_wxsetup_props_file(wx_path):
    """ Add the static wxWidgets variables to the wx_setup.props file.
        This file is in the build/msw folder.
    """

    suffix_additions = [
        "",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static' and '$(CharacterSet)'=='Unicode'\">",
        "    <wxSuffix>us</wxSuffix>",
        "  </PropertyGroup>",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static' and '$(CharacterSet)'!='Unicode'\">",
        "    <wxSuffix>s</wxSuffix>",
        "  </PropertyGroup>",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static'\">",
        "    <wxCfg>s</wxCfg>",
        "  </PropertyGroup>",
        ""]

    directory_additions = [
        "",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static'\">",
        "    <wxOutDir>..\\..\\lib\\$(wxCompilerPrefix)$(wxArchSuffix)_lib$(wxCfg)\\</wxOutDir>",
        "  </PropertyGroup>",
        "  <PropertyGroup Label=\"UserMacros\" Condition=\"'$(Configuration)'=='Static'\">",
        "    <wxIntRootDir>$(wxCompilerPrefix)$(wxArchSuffix)_$(wxToolkitPrefix)$(wxSuffix)\\</wxIntRootDir>",
        "  </PropertyGroup>",
        ""]

    updated_file = []           # undated file save area
    wxsuffix_stmts = 0          # number of <wxSuffix> statements
    wxintrootdir_stmts = 0      # number of <wxIntRootDir> statements
    lines_changed = 0           # number of lines changed
    # determine the file name
    if "vs2010" in wx_path:		# vs2010 does NOT have a setup.props
        return
    elif "vs2012" in wx_path:
        project_path = "/build/msw/wx_vc11_wx_setup.props"
    elif "vs2013" in wx_path or "vs2015" in wx_path or "vs2017" in wx_path:
        project_path = "/build/msw/wx_vc12_wx_setup.props"
    else:
        libastylewx.system_exit("Cannot determine Visual Studio Version: " + wx_path)
    orig_path = project_path + ".orig"
    print(wx_path)
    file_path = wx_path + orig_path
    file_path = file_path.replace('\\', '/')
    if not os.path.isfile(file_path):
        shutil.copyfile(wx_path + project_path, file_path)
    # read the .orig file
    with open(file_path, mode='r') as file_in:
        for line in file_in:
            #! check for end of <wxSuffix> statements
            if "<wxSuffix>" in line:
                wxsuffix_stmts += 1
            if "</PropertyGroup>" in line and wxsuffix_stmts == 4:
                wxsuffix_stmts = 9			# don't do it again
                updated_file.append(line)
                for setup_new in suffix_additions:
                    lines_changed += 1
                    updated_file.append(setup_new + '\n')
                continue
            #! check for end of <wxIntRootDir> statements
            if "<wxIntRootDir>" in line:
                wxintrootdir_stmts += 1
            if "</PropertyGroup>" in line and wxintrootdir_stmts == 4:
                wxintrootdir_stmts = 9		# don't do it again
                updated_file.append(line)
                for setup_new in directory_additions:
                    lines_changed += 1
                    updated_file.append(setup_new + '\n')
                continue

            updated_file.append(line)

    # write the new file
    with open(wx_path + project_path, mode='w') as file_out:
        for line in updated_file:
            file_out.write(line)

    print(lines_changed, "lines in", project_path)
    print()
Пример #37
0
def change_variables(file_path):
    """Process a file.
    """
    global __num_cb, __num_lb, __num_nb, __num_tb

    if not os.path.exists(file_path):
        libastylewx.system_exit("No file to process: " + file_path)
    # extra lines for wxTreebook
    tba = '\tm_notebook->AddPage( NULL, wxT("Artistic Style Options"), false );\n'
    tbe = '\tm_notebook->AddPage( NULL, wxT("Editor Options"), false );\n'

    # get variables
    new_header = get_new_header()
    new_macro = get_new_macro()
    file_in = open(file_path, 'r')
    updated_lines = []

    for line in file_in:
        if len(line) == 0 or line.startswith("//"):
            updated_lines.append(line)
            continue
        # replace objects (wxNotebook) and events (wxNotebookEvent)
        if "wxChoicebook" in line and __new_book != "wxChoicebook":
            line = line.replace("wxChoicebook", __new_book)
            __num_cb += 1
        elif "wxListbook" in line and __new_book != "wxListbook":
            line = line.replace("wxListbook", __new_book)
            __num_lb += 1
        elif "wxNotebook" in line and __new_book != "wxNotebook":
            line = line.replace("wxNotebook", __new_book)
            __num_nb += 1
        elif "wxTreebook" in line and __new_book != "wxTreebook":
            line = line.replace("wxTreebook", __new_book)
            __num_tb += 1

        # replace include
        if "choicebk.h" in line and __new_book != "wxChoicebook":
            line = line.replace("choicebk.h", new_header)
            __num_cb += 1
        elif "listbook.h" in line and __new_book != "wxListbook":
            line = line.replace("listbook.h", new_header)
            __num_lb += 1
        elif "notebook.h" in line and __new_book != "wxNotebook":
            line = line.replace("notebook.h", new_header)
            __num_nb += 1
        elif "treebook.h" in line and __new_book != "wxTreebook":
            line = line.replace("treebook.h", new_header)
            __num_tb += 1

        # replace page change event (EVT_NOTEBOOK_PAGE_CHANGED)
        if "_CHOICEBOOK_" in line and __new_book != "wxChoicebook":
            line = line.replace("_CHOICEBOOK_", new_macro)
            __num_cb += 1
        elif "_LISTBOOK_" in line and __new_book != "wxListbook":
            line = line.replace("_LISTBOOK_", new_macro)
            __num_lb += 1
        elif "_NOTEBOOK_" in line and __new_book != "wxNotebook":
            line = line.replace("_NOTEBOOK_", new_macro)
            __num_nb += 1
        elif "_TREEBOOK_" in line and __new_book != "wxTreebook":
            line = line.replace("_TREEBOOK_", new_macro)
            __num_tb += 1

        # replace AddPage strings
        # remove tba and tbe from all files
        # tba and tbe will be restated to wxTreebook
        if "AddPage" in line or "AddSubPage" in line:
            if "AddPage" in line and "NULL" in line:
                continue
            if __new_book == "wxChoicebook":
                line = process_choicebook_pages(line)
            elif __new_book == "wxListbook":
                line = process_listbook_pages(line)
            elif __new_book == "wxNotebook":
                line = process_notebook_pages(line)
            elif __new_book == "wxTreebook":
                if "m_stylePage" in line:
                    updated_lines.append(tba)
                if "m_optionsPage" in line:
                    updated_lines.append(tbe)
                line = process_treebook_pages(line)

        updated_lines.append(line)

    file_in.close()

    if __num_cb or __num_lb or __num_nb or __num_tb:
        write_output_file(updated_lines, file_path)
Пример #38
0
def run_clang_tidy(tidy_exepath, tidy_version, file_name):
    """Run the clang-tidy program for the specified file.
       NOTE: The window stays open only if run from the console.
    """
    # cppcoreguidelines-owning-memory
    # cppcoreguidelines-pro-type-member-init gives constructor does not initialize warning
    # cppcoreguidelines-pro-type-vararg don't use printf in astyle_main
    # google-global-names-in-headers, don't like the restriction (std::vector)
    # google-build-using-namespace gives warning for "using namespace"
    # google-readability-braces-around-statements
    # google-readability-casting replaces c-style casts with c++ casts
    # google-readability-todo adds username to todo comments
    # google-runtime-int values are determined by wxWidgets
    # google-runtime-references 'const' is determined by wxWidgets, cannot fix
    # hicpp-braces-around-statements redirects to readability-braces-around-statements
    # hicpp-member-init adds braces to member variables for initialization
    # hicpp-use-auto redirects to modernize-use-auto
    # hicpp-use-noexcept redirects to modernize-use-noexcept
    # llvm-header-guard adds the filepath to the header guard name
    # misc-misplaced-widening-cast is casting size_t to int instead of int to size_t
    # misc-unused-parameters caused several false positives, is checked by compiler
    # readability-braces-around-statements expects braces around single statements
    # readability-implicit-bool-cast use 'if (x=0)' instead of 'if (!x)'
    # readability-implicit-bool-conversion replaces above ...bool-cast in version6
    # readability-simplify-boolean-expr returns a conditional statement
    #
    # modernize-use-auto recommends using auto for variable types
    #
    # to fix one option: (disable checks, add the option, include -fix)
    # clangtidy.append("-checks=-*,readability-implicit-bool-cast")
    # clangtidy.append("-fix")
    #
    # version 5 checks
    tidy_checks = ("-checks=*,"
                   "-cppcoreguidelines-pro-type-member-init,"
                   "-google-global-names-in-headers,"
                   "-google-readability-braces-around-statements,"
                   "-google-readability-todo,"
                   "-google-runtime-int,"
                   "-google-runtime-references,"
                   "-hicpp-member-init,"
                   "-llvm-header-guard,"
                   "-misc-unused-parameters,"
                   "-readability-braces-around-statements,"
                   "-readability-implicit-bool-cast,"
                   "-readability-simplify-boolean-expr,"
                   "-modernize-use-auto")
    # version 6 checks
    if tidy_version[:1] > "5":
        tidy_checks += (","
                        "-cppcoreguidelines-owning-memory,"
                        "-fuchsia-default-arguments,"
                        "-hicpp-braces-around-statements,"
                        "-hicpp-use-auto,"
                        "-hicpp-use-noexcept,"
                        "-readability-implicit-bool-conversion")
    clangtidy = [tidy_exepath]
    clangtidy.append(tidy_checks)
    clangtidy.append(
        "-header-filter=-^wx,$Base.h")  # exclude wx and dialog headers
    clangtidy.append(__src_dir + file_name)
    clangtidy.append("--")  # compiler options follow
    clangtidy.append("-std=c++14")  # c++14 minimum is required for clang
    clangtidy.append("-fno-rtti")
    clangtidy.append("-fno-exceptions")
    clangtidy.append("-I" + libastylewx.get_astylewx_directory() + "/dialog")
    if os.name == "nt":
        clangtidy.append("-I" + __wxw + "/include")
        clangtidy.append("-I" + __wxw + "/lib/vc_lib/mswud")
    else:
        clangtidy.append("-I" + __wxw + "/include/wx-3.0")
        # too many errors with setup.h
        #clangtidy.append("-I" + __wxw + "/lib/x86_64-linux-gnu/wx/include/gtk2-unicode-3.0")
    # stdout file must have full path
    filename = __src_dir + "xclang-" + file_name + ".txt"
    outfile = open(filename, 'w')
    print()
    print(file_name)
    # shell=True keeps the console window open, but will not display if run from an editor
    # subprocess.check_call() doesn't work from an editor
    try:
        subprocess.check_call(clangtidy, stdout=outfile)
    except subprocess.CalledProcessError as err:
        libastylewx.system_exit("Bad clang-tidy return: " +
                                str(err.returncode))
    except OSError:
        libastylewx.system_exit("Cannot find executable: " + clangtidy[0])
Пример #39
0

# -----------------------------------------------------------------------------


def write_output_file(updated_lines, file_path):
    """Rename the current file by appending a ".orig" extension.
       Write a new file to replace the .orig file.
    """
    orig_file = file_path + ".orig"
    # remove an existion .orig file
    if os.path.isfile(orig_file):
        os.remove(orig_file)
    # rename the current file
    os.rename(file_path, orig_file)
    # write the new file
    file_out = open(file_path, "w")
    for line in updated_lines:
        file_out.write(line)
    file_out.close()


# -----------------------------------------------------------------------------

# make the module executable
if __name__ == "__main__":
    main()
    libastylewx.system_exit()

# -----------------------------------------------------------------------------
Пример #40
0
def change_variables(file_path):
    """Process a file.
    """
    global __num_cb, __num_lb, __num_nb, __num_tb

    if not os.path.exists(file_path):
        libastylewx.system_exit("No file to process: " + file_path)
    # extra lines for wxTreebook
    tba = '\tm_notebook->AddPage( NULL, wxT("Artistic Style Options"), false );\n'
    tbe = '\tm_notebook->AddPage( NULL, wxT("Editor Options"), false );\n'

    # get variables
    new_header = get_new_header()
    new_macro = get_new_macro()
    file_in = open(file_path, 'r')
    updated_lines = []

    for line in file_in:
        if len(line) == 0 or line.startswith("//"):
            updated_lines.append(line)
            continue
        # replace objects (wxNotebook) and events (wxNotebookEvent)
        if "wxChoicebook" in line and __new_book != "wxChoicebook":
            line = line.replace("wxChoicebook", __new_book)
            __num_cb += 1
        elif "wxListbook" in line and __new_book != "wxListbook":
            line = line.replace("wxListbook", __new_book)
            __num_lb += 1
        elif "wxNotebook" in line and __new_book != "wxNotebook":
            line = line.replace("wxNotebook", __new_book)
            __num_nb += 1
        elif "wxTreebook" in line and __new_book != "wxTreebook":
            line = line.replace("wxTreebook", __new_book)
            __num_tb += 1

        # replace include
        if "choicebk.h" in line and __new_book != "wxChoicebook":
            line = line.replace("choicebk.h", new_header)
            __num_cb += 1
        elif "listbook.h" in line and __new_book != "wxListbook":
            line = line.replace("listbook.h", new_header)
            __num_lb += 1
        elif "notebook.h" in line and __new_book != "wxNotebook":
            line = line.replace("notebook.h", new_header)
            __num_nb += 1
        elif "treebook.h" in line and __new_book != "wxTreebook":
            line = line.replace("treebook.h", new_header)
            __num_tb += 1

        # replace page change event (EVT_NOTEBOOK_PAGE_CHANGED)
        if "_CHOICEBOOK_" in line and __new_book != "wxChoicebook":
            line = line.replace("_CHOICEBOOK_", new_macro)
            __num_cb += 1
        elif "_LISTBOOK_" in line and __new_book != "wxListbook":
            line = line.replace("_LISTBOOK_", new_macro)
            __num_lb += 1
        elif "_NOTEBOOK_" in line and __new_book != "wxNotebook":
            line = line.replace("_NOTEBOOK_", new_macro)
            __num_nb += 1
        elif "_TREEBOOK_" in line and __new_book != "wxTreebook":
            line = line.replace("_TREEBOOK_", new_macro)
            __num_tb += 1

        # replace AddPage strings
        # remove tba and tbe from all files
        # tba and tbe will be restated to wxTreebook
        if "AddPage" in line or "AddSubPage" in line:
            if "AddPage" in line and "NULL" in line:
                continue
            if __new_book == "wxChoicebook":
                line = process_choicebook_pages(line)
            elif __new_book == "wxListbook":
                line = process_listbook_pages(line)
            elif __new_book == "wxNotebook":
                line = process_notebook_pages(line)
            elif __new_book == "wxTreebook":
                if "m_stylePage" in line:
                    updated_lines.append(tba)
                if "m_optionsPage" in line:
                    updated_lines.append(tbe)
                line = process_treebook_pages(line)

        updated_lines.append(line)

    file_in.close()

    if __num_cb or __num_lb or __num_nb or __num_tb:
        write_output_file(updated_lines, file_path)
        print(tabs_text.format(__tabs - __tab_total))
        errors = True
    if __indents != __indent_total:
        indents_text = "There are {0} indent diffs."
        print(indents_text .format(__indents - __indent_total))
        errors = True
    if __pads != __pad_total:
        pads_text = "There are {0} pad diffs."
        print(pads_text.format(__pads - __pad_total))
        errors = True
    if __formats != __format_total:
        formats_text = "There are {0} format diffs."
        print(formats_text.format(__formats - __format_total))
        errors = True
    if __others != __other_total:
        others_text = "There are {0} other diffs."
        print(others_text.format(__others - __other_total))
        errors = True
    if not errors:
        print("There are NO diffs in the number of lines to be changed!!!")


# -----------------------------------------------------------------------------

# make the module executable
if __name__ == "__main__":
    main()
    libastylewx.system_exit()

# -----------------------------------------------------------------------------