Beispiel #1
0
def show_help(params):
    proj_path = params["proj_path"]
    targets = target.get_all_targets(proj_path)

    if targets and len(targets) > 0:
        log.colored("List of available targets:\n", log.PURPLE)

        for target_item in targets:
            log.normal("  - {0}".format(target_item))
    else:
        log.error("No targets available")
Beispiel #2
0
def show_help(params):
    proj_path = params["proj_path"]
    targets = target.get_all_targets(proj_path)

    if targets and len(targets) > 0:
        l.colored("List of available targets:\n", l.MAGENTA)

        for target_item in targets:
            l.m("  - {0}".format(target_item))
    else:
        l.e("No targets available")
Beispiel #3
0
def setup(params):
    proj_path = params["proj_path"]
    targets = target.get_all_targets(proj_path)

    log.info("Creating default profile...")

    # create default profile
    runner.run(
        [
            "conan",
            "profile",
            "new",
            "default",
            "--detect",
            "--force",
        ],
        cwd=os.getcwd(),
    )

    # copy all targets profile
    log.info("Copying files...")

    if targets:
        for target_item in targets:
            files = file.find_files(
                os.path.join(
                    proj_path,
                    const.DIR_NAME_FILES,
                    const.DIR_NAME_FILES_TARGETS,
                    target_item,
                    const.DIR_NAME_FILES_TARGET_CONAN,
                    const.DIR_NAME_FILES_TARGET_CONAN_PROFILE,
                ),
                "*profile",
            )

            if files:
                conan_profile_dir = os.path.join(
                    file.home_dir(),
                    const.DIR_NAME_HOME_CONAN,
                    const.DIR_NAME_HOME_CONAN_PROFILES,
                )

                for item in files:
                    filename = os.path.basename(item)
                    log.info('Copying profile "{0}"...'.format(filename))

                    file.copy_file(item,
                                   os.path.join(conan_profile_dir, filename))

    # add darwin toolchain
    log.info("Adding darwin toolchain repository...")

    runner.run(
        [
            "conan",
            "remote",
            "add",
            "darwin-toolchain",
            "https://ezoredrepository.jfrog.io/artifactory/api/conan/conan-local",
            "--force",
        ],
        cwd=os.getcwd(),
    )

    log.ok()
Beispiel #4
0
def run(params):
    args = params["args"]
    proj_path = params["proj_path"]

    targets = target.get_all_targets(proj_path)

    show_target_list = False

    if len(args) > 0:
        target_item = args[0]
        args.pop(0)

        if target_item in targets:
            target_verbs = target.get_all_target_verbs(proj_path, target_item)
            target_verbs = list(
                util.filter_list(target_verbs, const.TARGET_VERBS_INTERNAL))

            show_target_verb_list = False

            if len(args) > 0:
                verb_name = args[0]

                if verb_name in target_verbs:
                    log.info('Running "{0}" on target "{1}"...'.format(
                        verb_name, target_item))

                    target_verb_folder = os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_item,
                        const.DIR_NAME_FILES_TARGET_VERBS,
                    )

                    params["target_name"] = target_item

                    runner.run_external(
                        path=target_verb_folder,
                        module_name=verb_name,
                        command_name="run",
                        command_params=params,
                        show_log=False,
                        show_error_log=True,
                        throw_error=True,
                    )
                else:
                    show_target_verb_list = True
            else:
                show_target_verb_list = True

            if show_target_verb_list:
                if target_verbs and len(target_verbs) > 0:
                    log.colored("List of available target verbs:\n",
                                log.PURPLE)

                    for target_verb in target_verbs:
                        log.normal("  - {0}".format(target_verb))
                else:
                    log.error("No target verbs available")
        else:
            show_target_list = True
    else:
        show_target_list = True

    if show_target_list:
        show_help(params)
Beispiel #5
0
def code_format(params):
    proj_path = params["proj_path"]
    targets = target.get_all_targets(proj_path)

    # format c++ files
    has_tool = check_cpp_formatter()

    if has_tool:
        path_list = [
            {
                "path":
                os.path.join(proj_path, const.DIR_NAME_FILES,
                             const.DIR_NAME_FILES_MODULES),
                "patterns": ["*.cpp", "*.hpp", "*.c", "*.h", "*.m", "*.mm"],
            },
            {
                "path": os.path.join(proj_path, const.DIR_NAME_PROJECTS,
                                     "others"),
                "patterns": ["*.cpp", "*.hpp", "*.c", "*.h", "*.m", "*.mm"],
            },
            {
                "path": os.path.join(proj_path, const.DIR_NAME_PROJECTS,
                                     "android"),
                "patterns": ["*.cpp", "*.hpp", "*.c", "*.h", "*.m", "*.mm"],
            },
            {
                "path":
                os.path.join(proj_path, const.DIR_NAME_PROJECTS, "ios",
                             "Sample", "Sample"),
                "patterns": ["*.cpp", "*.hpp", "*.c", "*.h", "*.m", "*.mm"],
            },
        ]

        if path_list:
            l.i("Formating C++ files...")

            for path_list_item in path_list:
                patterns = path_list_item["patterns"]

                for pattern_item in patterns:
                    files = f.find_files(path_list_item["path"],
                                         pattern_item,
                                         recursive=True)

                    for file_item in files:
                        l.i("Formatting file: {0}...".format(
                            os.path.relpath(file_item)))

                        run_args = [
                            "clang-format", "-style", "file", "-i", file_item
                        ]

                        r.run(run_args, cwd=proj_path)

            l.ok()
        else:
            l.e("No C++ files found to format")

    # format python files
    has_tool = check_python_formatter()

    if has_tool:
        path_list = [
            {
                "path": os.path.join(proj_path, "make.py"),
            },
            {
                "path": os.path.join(proj_path, const.DIR_NAME_FILES),
                "patterns": ["*.py"],
            },
        ]

        if path_list:
            l.i("Formating Python files...")

            for path_list_item in path_list:
                patterns = (path_list_item["patterns"]
                            if "patterns" in path_list_item else None)

                if patterns:
                    for pattern_item in patterns:
                        files = f.find_files(path_list_item["path"],
                                             pattern_item,
                                             recursive=True)

                        for file_item in files:
                            l.i("Formatting file: {0}...".format(
                                os.path.relpath(file_item)))

                            run_args = ["black", "-q", file_item]

                            r.run(run_args, cwd=proj_path)
                else:
                    file_item = (path_list_item["path"]
                                 if "path" in path_list_item else None)

                    if file_item:
                        l.i("Formatting file: {0}...".format(
                            os.path.relpath(file_item)))

                        run_args = ["black", "-q", file_item]

                        r.run(run_args, cwd=proj_path)

            l.ok()
        else:
            l.e("No Python files found to format")

    # format cmake files
    has_tool = check_cmake_formatter()

    if has_tool:
        path_list = [
            {
                "path":
                os.path.join(proj_path, const.DIR_NAME_FILES,
                             const.DIR_NAME_FILES_MODULES),
                "patterns": ["*.cmake"],
            },
            {
                "path":
                os.path.join(proj_path, const.DIR_NAME_FILES,
                             const.DIR_NAME_FILES_MODULES),
                "patterns": ["CMakeLists.txt"],
            },
            {
                "path":
                os.path.join(proj_path, const.DIR_NAME_FILES,
                             const.DIR_NAME_FILES_COMMON),
                "patterns": ["*.cmake"],
            },
            {
                "path":
                os.path.join(proj_path, const.DIR_NAME_FILES,
                             const.DIR_NAME_FILES_COMMON),
                "patterns": ["CMakeLists.txt"],
            },
        ]

        for target_name in targets:
            path_list.extend([
                {
                    "path":
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_CMAKE,
                    ),
                    "patterns": ["*.cmake"],
                },
                {
                    "path":
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_CMAKE,
                    ),
                    "patterns": ["CMakeLists.txt"],
                },
                {
                    "path":
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_CONAN,
                    ),
                    "patterns": ["*.cmake"],
                },
                {
                    "path":
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_CONAN,
                    ),
                    "patterns": ["CMakeLists.txt"],
                },
                {
                    "path":
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_SUPPORT,
                    ),
                    "patterns": ["*.cmake"],
                },
                {
                    "path":
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_SUPPORT,
                    ),
                    "patterns": ["CMakeLists.txt"],
                },
                {
                    "path":
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_VERBS,
                    ),
                    "patterns": ["*.cmake"],
                },
                {
                    "path":
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_VERBS,
                    ),
                    "patterns": ["CMakeLists.txt"],
                },
            ])

        if path_list:
            l.i("Formating CMake files...")

            for path_list_item in path_list:
                patterns = path_list_item["patterns"]

                for pattern_item in patterns:
                    files = f.find_files(path_list_item["path"],
                                         pattern_item,
                                         recursive=True)

                    for file_item in files:
                        l.i("Formatting file: {0}...".format(
                            os.path.relpath(file_item)))

                        run_args = [
                            "cmake-format",
                            "-c",
                            ".cmake-format",
                            "-i",
                            file_item,
                        ]

                        r.run(run_args, cwd=proj_path)

            l.ok()
        else:
            l.e("No CMake files found to format")