Beispiel #1
0
def upload(params):
    proj_path = params["proj_path"]
    target_name = params["target_name"]

    build_dir = os.path.join(proj_path, const.DIR_NAME_BUILD, target_name,
                             const.DIR_NAME_DIST)

    version = util.get_version(params, config)
    force = util.list_has_key(params["args"], "--force")
    dist_file_path = os.path.join(build_dir, const.FILE_NAME_DIST_PACKED)
    dist_file_name = const.FILE_NAME_DIST_PACKED
    dist_folder = target_name
    aws_key_id = os.getenv(const.AWS_KEY_ID_ENV)
    aws_secret_key = os.getenv(const.AWS_SECRET_KEY_ENV)
    aws_bucket_name = const.AWS_S3_BUCKET_NAME
    aws_bucket_path = "{0}/{1}".format(const.AWS_S3_BUCKET_PATH, target_name)

    aws.upload(
        proj_path=proj_path,
        version=version,
        force=force,
        dist_file_path=dist_file_path,
        dist_file_name=dist_file_name,
        dist_folder=dist_folder,
        aws_key_id=aws_key_id,
        aws_secret_key=aws_secret_key,
        aws_bucket_name=aws_bucket_name,
        aws_bucket_path=aws_bucket_path,
    )
Beispiel #2
0
def run(params):
    proj_path = params["proj_path"]
    target_name = params["target_name"]
    target_config = config.run(proj_path, target_name, params)

    archs = target_config["archs"]
    build_types = target_config["build_types"]
    install_headers = target_config["install_headers"]
    param_dry_run = util.list_has_key(params["args"], "--dry-run")

    if param_dry_run:
        log.info("Running in dry mode...")

    if archs and len(archs) > 0:
        for arch in archs:
            for build_type in build_types:
                log.info(
                    "Building for: {0}/{1}...".format(arch["conan_arch"], build_type)
                )

                # conan build
                build_dir = os.path.join(
                    proj_path,
                    const.DIR_NAME_BUILD,
                    target_name,
                    build_type,
                    arch["group"],
                    arch["conan_arch"],
                    const.DIR_NAME_BUILD_TARGET,
                )

                clean_build_dir = True

                if param_dry_run and os.path.isdir(build_dir):
                    clean_build_dir = False

                if clean_build_dir:
                    file.remove_dir(build_dir)
                    file.create_dir(build_dir)

                run_args = [
                    "conan",
                    "build",
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_CONAN,
                        const.DIR_NAME_FILES_TARGET_CONAN_RECIPE,
                        const.FILE_NAME_FILES_TARGET_CONAN_RECIPE_CONANFILE_PY,
                    ),
                    "--source-folder",
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_CMAKE,
                    ),
                    "--build-folder",
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_BUILD,
                        target_name,
                        build_type,
                        arch["group"],
                        arch["conan_arch"],
                        const.DIR_NAME_BUILD_TARGET,
                    ),
                    "--install-folder",
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_BUILD,
                        target_name,
                        build_type,
                        arch["group"],
                        arch["conan_arch"],
                        const.DIR_NAME_BUILD_CONAN,
                    ),
                ]

                runner.run(run_args, build_dir)

                # find correct info plist file
                plist_path1 = os.path.join(
                    proj_path,
                    const.DIR_NAME_BUILD,
                    target_name,
                    build_type,
                    arch["group"],
                    arch["conan_arch"],
                    const.DIR_NAME_BUILD_TARGET,
                    "lib",
                    "{0}.framework".format(target_config["project_name"]),
                    "Info.plist",
                )

                plist_path2 = os.path.join(
                    proj_path,
                    const.DIR_NAME_BUILD,
                    target_name,
                    build_type,
                    arch["group"],
                    arch["conan_arch"],
                    const.DIR_NAME_BUILD_TARGET,
                    "lib",
                    "{0}.framework".format(target_config["project_name"]),
                    "Versions",
                    "Current",
                    "Resources",
                    "Info.plist",
                )

                plist_path = ""

                if os.path.exists(plist_path1):
                    plist_path = plist_path1

                if os.path.exists(plist_path2):
                    plist_path = plist_path2

                # add minimum version inside plist
                runner.run(
                    [
                        "plutil",
                        "-replace",
                        "MinimumOSVersion",
                        "-string",
                        arch["min_version"],
                        plist_path,
                    ],
                    proj_path,
                )

                # add supported platform inside plist
                runner.run(
                    [
                        "plutil",
                        "-replace",
                        "CFBundleSupportedPlatforms",
                        "-json",
                        '[ "{0}" ]'.format(arch["supported_platform"]),
                        plist_path,
                    ],
                    proj_path,
                )

                # headers
                dist_headers_dir = os.path.join(
                    proj_path,
                    const.DIR_NAME_BUILD,
                    target_name,
                    build_type,
                    arch["group"],
                    arch["conan_arch"],
                    const.DIR_NAME_BUILD_TARGET,
                    "lib",
                    "{0}.framework".format(target_config["project_name"]),
                    "Headers",
                )

                file.create_dir(dist_headers_dir)

                if install_headers:
                    for header in install_headers:
                        source_header_dir = os.path.join(proj_path, header["path"])

                        if header["type"] == "dir":
                            file.copy_dir(
                                source_header_dir,
                                dist_headers_dir,
                                ignore_file=_header_ignore_list,
                                symlinks=True,
                            )
                        else:
                            log.error(
                                "Invalid type for install header list for {0}".format(
                                    target_name
                                )
                            )

                # modules
                support_modules_dir = os.path.join(
                    proj_path,
                    const.DIR_NAME_FILES,
                    const.DIR_NAME_FILES_TARGETS,
                    target_name,
                    "support",
                    "modules",
                )

                modules_dir = os.path.join(
                    proj_path,
                    const.DIR_NAME_BUILD,
                    target_name,
                    build_type,
                    arch["group"],
                    arch["conan_arch"],
                    const.DIR_NAME_BUILD_TARGET,
                    "lib",
                    "{0}.framework".format(target_config["project_name"]),
                    "Modules",
                )

                file.remove_dir(modules_dir)
                file.create_dir(modules_dir)

                file.copy_file(
                    os.path.join(support_modules_dir, "module.modulemap"),
                    os.path.join(modules_dir, "module.modulemap"),
                )

                # umbrella header
                build_headers_dir = os.path.join(
                    proj_path,
                    const.DIR_NAME_BUILD,
                    target_name,
                    build_type,
                    arch["group"],
                    arch["conan_arch"],
                    const.DIR_NAME_BUILD_TARGET,
                    "lib",
                    "{0}.framework".format(target_config["project_name"]),
                    "Headers",
                )

                header_files = file.find_files(build_headers_dir, "*.h")

                content = file.read_file(
                    os.path.join(support_modules_dir, "umbrella-header.h")
                )

                for header_file in header_files:
                    header_file = header_file.replace(build_headers_dir + "/", "")

                    content = content + '#import "{0}"\n'.format(header_file)

                if len(content) > 0:
                    umbrella_file = os.path.join(
                        build_headers_dir, target_config["umbrella_header"]
                    )

                    file.copy_file(
                        os.path.join(support_modules_dir, "umbrella-header.h"),
                        umbrella_file,
                    )

                    file.write_to_file(umbrella_file, content)
                else:
                    log.error(
                        "{0}".format(
                            "File not generated because framework headers is empty"
                        )
                    )

        log.ok()
    else:
        log.error('Arch list for "{0}" is invalid or empty'.format(target_name))
Beispiel #3
0
def run(params):
    proj_path = params["proj_path"]
    target_name = params["target_name"]
    target_config = config.run(proj_path, target_name, params)

    archs = target_config["archs"]
    build_types = target_config["build_types"]
    param_dry_run = util.list_has_key(params["args"], "--dry-run")

    if param_dry_run:
        log.info("Running in dry mode...")

    if archs and len(archs) > 0:
        for arch in archs:
            for build_type in build_types:
                log.info(
                    "Building for: {0}/{1}...".format(arch["conan_arch"], build_type)
                )

                # conan build
                build_dir = os.path.join(
                    proj_path,
                    const.DIR_NAME_BUILD,
                    target_name,
                    build_type,
                    arch["conan_arch"],
                    const.DIR_NAME_BUILD_TARGET,
                )

                clean_build_dir = True

                if param_dry_run and os.path.isdir(build_dir):
                    clean_build_dir = False

                if clean_build_dir:
                    file.remove_dir(build_dir)
                    file.create_dir(build_dir)

                run_args = [
                    "conan",
                    "build",
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_CONAN,
                        const.DIR_NAME_FILES_TARGET_CONAN_RECIPE,
                        const.FILE_NAME_FILES_TARGET_CONAN_RECIPE_CONANFILE_PY,
                    ),
                    "--source-folder",
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_FILES,
                        const.DIR_NAME_FILES_TARGETS,
                        target_name,
                        const.DIR_NAME_FILES_TARGET_CMAKE,
                    ),
                    "--build-folder",
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_BUILD,
                        target_name,
                        build_type,
                        arch["conan_arch"],
                        const.DIR_NAME_BUILD_TARGET,
                    ),
                    "--install-folder",
                    os.path.join(
                        proj_path,
                        const.DIR_NAME_BUILD,
                        target_name,
                        build_type,
                        arch["conan_arch"],
                        const.DIR_NAME_BUILD_CONAN,
                    ),
                ]

                runner.run(run_args, build_dir)

                # copy assets
                if "assets_dir" in target_config:
                    assets_dir = target_config["assets_dir"]

                    assets_dir = os.path.join(proj_path, assets_dir)

                    if os.path.isdir(assets_dir):
                        build_assets_dir = os.path.join(
                            build_dir, "bin", os.path.basename(assets_dir)
                        )

                        file.remove_dir(build_assets_dir)
                        file.copy_dir(assets_dir, build_assets_dir, symlinks=True)

        log.ok()
    else:
        log.error('Arch list for "{0}" is invalid or empty'.format(target_name))
Beispiel #4
0
def run(params):
    proj_path = params["proj_path"]
    target_name = params["target_name"]
    target_config = config.run(proj_path, target_name, params)
    archs = target_config["archs"]
    build_types = target_config["build_types"]

    no_framework = util.list_has_key(params["args"], "--no-framework")
    no_xcframework = util.list_has_key(params["args"], "--no-xcframework")

    # at least one need be generated
    if no_framework and no_xcframework:
        log.error(
            "You need let generate framework or xcframework, but both are disabled"
        )

    # remove dist folder for the target
    dist_dir = os.path.join(
        proj_path,
        const.DIR_NAME_DIST,
        target_name,
    )

    file.remove_dir(dist_dir)

    # generate framework
    if not no_framework:
        generate_framework(
            proj_path=proj_path,
            target_name=target_name,
            target_config=target_config,
            archs=archs,
            build_types=build_types,
        )

    # generate xcframework
    if not no_xcframework:
        generate_xcframework(
            proj_path=proj_path,
            target_name=target_name,
            target_config=target_config,
            archs=archs,
            build_types=build_types,
        )

    # add strip framework script (only required if final project use framework instead of xcframework)
    log.info("Adding strip framework script...")

    target_scripts_dir = os.path.join(
        const.DIR_NAME_FILES,
        const.DIR_NAME_FILES_TARGETS,
        target_name,
        const.DIR_NAME_SUPPORT,
        "scripts",
    )

    file.copy_dir(
        target_scripts_dir,
        os.path.join(
            const.DIR_NAME_DIST,
            target_name,
            "scripts",
        ),
    )

    # cocoapods
    log.info("Adding cocoapods script...")

    pod_file_path = os.path.join(
        const.DIR_NAME_FILES,
        const.DIR_NAME_FILES_TARGETS,
        target_name,
        const.DIR_NAME_SUPPORT,
        "cocoapods",
        "{0}.podspec".format(target_config["project_name"]),
    )

    target_pod_file_path = os.path.join(
        const.DIR_NAME_DIST,
        target_name,
        "{0}.podspec".format(target_config["project_name"]),
    )

    file.copy_file(
        pod_file_path,
        target_pod_file_path,
    )

    file.replace_in_file(target_pod_file_path, "{NAME}",
                         target_config["project_name"])
    file.replace_in_file(target_pod_file_path, "{VERSION}",
                         target_config["version"])

    # finish
    log.ok()