Esempio n. 1
0
def prepare_binary():
    env = common.prepare_env()

    # make dir to put the binary in
    if not os.path.isdir(os.path.join("..", "artifact")):
        os.mkdir(os.path.join("..", "artifact"))

    BUILD_FILENAME = ""

    # list executables
    BUILD_FILENAME = common.find_binary('.')
    if BUILD_FILENAME == "":
        BUILD_FILENAME = common.find_binary(os.path.join("..", "artifact"))

    if isinstance(BUILD_FILENAME, str):
        BUILD_FILENAME = list(BUILD_FILENAME)

    BUILD_FILENAMES = BUILD_FILENAME

    for BUILD_FILENAME in BUILD_FILENAMES:
        DEST_FILENAME = common.prepare_filename(BUILD_FILENAME)

        print(f"OS Name:        {env['OS_NAME']}")
        print(f"OS Version:     {env['OS_VERSION']}")
        print(f"Build Filename: {BUILD_FILENAME}")
        print(f"Dest Filename:  {DEST_FILENAME}")
        if not BUILD_FILENAME == "":
            print("Build Filesize: " + common.file_size(BUILD_FILENAME))
        else:
            exit(1)

        if not BUILD_FILENAME == "":
            move(os.path.join(".", BUILD_FILENAME),
                 os.path.join("..", "artifact", BUILD_FILENAME))
def main() -> bool:
    args = parse_arguments()

    # Set up some logging
    level = logging.INFO if not args.verbose else logging.DEBUG
    logging.basicConfig(
        stream=sys.stdout,
        level=level,
        format='%(asctime)s %(name)s %(levelname)s %(message)s',
        datefmt='%m-%d %H:%M',
    )

    # Find clang-format, validate version
    path_to_cf = common.find_binary(program_name, args.path)
    cf = ClangFormatter(path_to_cf)
    if cf.version < common.MIN_VERSION_REQUIRED:
        logging.error(
            f'''Incorrect version of {program_name}: got {cf.version} but at \
                least {common.MIN_VERSION_REQUIRED} is required''')
        sys.exit(1)

    # Find changed source files.
    source_files = re.compile(r'\.(h|hpp|c|cpp)$')
    if args.all_files:
        files = common.all_files()
    else:
        files = common.changed_files(compare_to='origin/develop')
    changes = [f for f in files if re.search(source_files, f)]

    # Validate each with clang-format
    lint_clean = []
    for change in changes:
        lint_clean.append(cf.lint(change, print_output=args.print_output))
    return all(lint_clean)
Esempio n. 3
0
def main() -> bool:
    args = parse_arguments()

    # Set up some logging
    level = logging.INFO if not args.verbose else logging.DEBUG
    logging.basicConfig(
        stream=sys.stdout,
        level=level,
        format='%(asctime)s %(name)s %(levelname)s %(message)s',
        datefmt='%m-%d %H:%M',
    )

    # Find clang-tidy, validate version
    path_to_ct = common.find_binary(program_name, args.path)
    ct = ClangTidier(path_to_ct, args.build_dir)
    if ct.version < common.MIN_VERSION_REQUIRED:
        logging.error(
            f'''Incorrect version of {program_name}: got {ct.version} but at \
                least {common.MIN_VERSION_REQUIRED} is required''')
        sys.exit(1)

    # clang-tidy operates only on c/cpp files (h/hpp files are linted
    # transitively). Only check c/cpp files.
    cpp_files = re.compile(r'\.(c|cpp|cc|cxx)$')
    if args.all_files:
        files = common.all_files()
    else:
        files = common.changed_files(compare_to='origin/develop')
    changes = [f for f in files if re.search(cpp_files, f)]

    # Validate each with clang-tidy in parallel
    with mp.Pool(nprocs) as pool:
        tasks = [
            pool.apply_async(
                ct.lint,
                args=(f, ),
                kwds=dict(print_output=args.print_output, fix=args.fix),
            ) for f in changes
        ]

        # Execute subtasks
        result = all([task.get() for task in tasks])

        # Print any output if requested
        while args.print_output and not output_queue.empty():
            print(output_queue.get())

        return result
for travis in [
        os.path.join(".", ".travis.yml"),
        os.path.join(".", ".travis.off")
]:
    if os.path.isfile(travis):
        os.remove(travis)

# nuke test suite if it exists
if os.path.isdir(os.path.join(".", "tests")):
    distutils.dir_util.remove_tree(os.path.join(".", "tests"))

BUILD_FILENAME = ""
ZIP_FILENAME = ""

# list executables
BUILD_FILENAME = common.find_binary(os.path.join("."))
if BUILD_FILENAME == "":
    BUILD_FILENAME = common.find_binary(os.path.join("..", "artifact"))

if isinstance(BUILD_FILENAME, str):
    BUILD_FILENAME = list(BUILD_FILENAME)

BUILD_FILENAMES = BUILD_FILENAME

print(BUILD_FILENAMES)

if len(BUILD_FILENAMES) > 0:
    for BUILD_FILENAME in BUILD_FILENAMES:
        if not BUILD_FILENAME == "":
            if "artifact" not in BUILD_FILENAME:
                # move the binary to temp folder
Esempio n. 5
0
def prepare_release():
    env = common.prepare_env()  # get env vars

    dirs = [
        os.path.join("..", "artifact"),  # temp dir for binary
        os.path.join("..", "build"),  # temp dir for other stuff
        os.path.join("..", "deploy")  # dir for archive
    ]
    for dirname in dirs:
        if not os.path.isdir(dirname):
            os.makedirs(dirname)

    # make dirs for each os
    for dirname in ["linux", "macos", "windows"]:
        if not os.path.isdir(os.path.join("..", "deploy", dirname)):
            os.mkdir(os.path.join("..", "deploy", dirname))

    # sanity check permissions for working_dirs.json
    dirpath = "."
    for dirname in ["resources", "user", "meta", "manifests"]:
        dirpath += os.path.join(dirpath, dirname)
        if os.path.isdir(dirpath):
            os.chmod(dirpath, 0o755)

    # nuke git files
    for git in [
            os.path.join(".", ".gitattrubutes"),
            os.path.join(".", ".gitignore")
    ]:
        if os.path.isfile(git):
            os.remove(git)

    # nuke travis file if it exists
    for travis in [
            os.path.join(".", ".travis.yml"),
            os.path.join(".", ".travis.off")
    ]:
        if os.path.isfile(travis):
            os.remove(travis)

    # nuke test suite if it exists
    if os.path.isdir(os.path.join(".", "tests")):
        distutils.dir_util.remove_tree(os.path.join(".", "tests"))

    BUILD_FILENAME = ""
    ZIP_FILENAME = ""

    # list executables
    BUILD_FILENAME = common.find_binary(os.path.join("."))
    if BUILD_FILENAME == "":
        BUILD_FILENAME = common.find_binary(os.path.join("..", "artifact"))

    if isinstance(BUILD_FILENAME, str):
        BUILD_FILENAME = list(BUILD_FILENAME)

    BUILD_FILENAMES = BUILD_FILENAME

    print(BUILD_FILENAMES)

    if len(BUILD_FILENAMES) > 0:
        for BUILD_FILENAME in BUILD_FILENAMES:
            if not BUILD_FILENAME == "":
                if "artifact" not in BUILD_FILENAME:
                    # move the binary to temp folder
                    move(os.path.join(".", BUILD_FILENAME),
                         os.path.join("..", "artifact", BUILD_FILENAME))

        # clean the git slate
        git_clean()

        # mv dirs from source code
        dirs = [
            os.path.join(".", ".git"),
            os.path.join(".", ".github"),
            os.path.join(".", ".gitattributes"),
            os.path.join(".", ".gitignore"),
            os.path.join(".", "html"),
            os.path.join(".", "resources", "ci")
        ]
        for dirname in dirs:
            if os.path.isdir(dirname):
                move(dirname, os.path.join("..", "build", dirname))

        for BUILD_FILENAME in BUILD_FILENAMES:
            if "artifact" not in BUILD_FILENAME:
                if os.path.isfile(
                        os.path.join("..", "artifact", BUILD_FILENAME)):
                    # move the binary back
                    move(os.path.join("..", "artifact", BUILD_FILENAME),
                         os.path.join(".", BUILD_FILENAME))
                    # Make Linux/Mac binary executable
                    if "linux" in env["OS_NAME"] or \
                        "ubuntu" in env["OS_NAME"] or \
                        "mac" in env["OS_NAME"] or \
                            "osx" in env["OS_NAME"]:
                        os.chmod(os.path.join(".", BUILD_FILENAME), 0o755)

        # .zip if windows
        # .tar.gz otherwise
        if len(BUILD_FILENAMES) > 1:
            ZIP_FILENAME = os.path.join("..", "deploy", env["REPO_NAME"])
        else:
            ZIP_FILENAME = os.path.join("..", "deploy",
                                        os.path.splitext(BUILD_FILENAME)[0])
        if env["OS_NAME"] == "windows":
            make_archive(ZIP_FILENAME, "zip")
            ZIP_FILENAME += ".zip"
        else:
            make_archive(ZIP_FILENAME, "gztar")
            ZIP_FILENAME += ".tar.gz"

        # mv dirs back
        for thisDir in dirs:
            if os.path.isdir(os.path.join("..", "build", thisDir)):
                move(os.path.join("..", "build", thisDir),
                     os.path.join(".", thisDir))

    for BUILD_FILENAME in BUILD_FILENAMES:
        if not BUILD_FILENAME == "":
            print(f"Build Filename: {BUILD_FILENAME}")
            print("Build Filesize: " + common.file_size(BUILD_FILENAME))
        else:
            print(f"No Build to prepare: {BUILD_FILENAME}")

    if not ZIP_FILENAME == "":
        print(f"Zip Filename:   {ZIP_FILENAME}")
        print("Zip Filesize:   " + common.file_size(ZIP_FILENAME))
    else:
        print(f"No Zip to prepare: {ZIP_FILENAME}")

    print(f"Git tag:        {env['GITHUB_TAG']}")

    if (len(BUILD_FILENAMES) == 0) or (ZIP_FILENAME == ""):
        exit(1)