def run(params): l.i("Cleaning...") proj_path = params["proj_path"] f.remove_dir(os.path.join(proj_path, "build")) f.remove_files(proj_path, "*.pyc", recursive=True) f.remove_files(proj_path, "*.zip", recursive=True) f.remove_files(proj_path, "*.tar", recursive=True) f.remove_files(proj_path, "*.tar.gz", recursive=True) f.remove_files(proj_path, "Thumbs.db", recursive=True) f.remove_files(proj_path, ".DS_Store", recursive=True) f.remove_dirs(proj_path, "__pycache__", recursive=True) l.ok()
def generate(params): proj_path = params["proj_path"] module_data = params["module_data"] if not module_data: l.e("Module data is invalid") # check required tool gluecode_tool_path = get_tool_path(params) if not os.path.isfile(gluecode_tool_path): l.e("Glue code tool was not found: {0}".format(gluecode_tool_path, )) # module data module_name = module_data["name"] tool_params = module_data["tool_params"] module_dir = os.path.join( proj_path, const.DIR_NAME_FILES, const.DIR_NAME_FILES_MODULES, module_name, const.DIR_NAME_GLUECODE, ) # clean old generated src f.remove_dir(os.path.join(module_dir, "generated-src")) f.remove_dir(os.path.join(module_dir, "yaml")) # run runner_args = [] runner_args.extend([gluecode_tool_path]) runner_args.extend(tool_params) r.run( args=" ".join(runner_args), cwd=module_dir, shell=True, )
def download_dist_file( proj_path, version, dist_file_path, dist_file_name, dist_folder, dist_file_url ): # version if not version or len(version) == 0: l.e("You need define version name (parameter: --version)") l.i("Version defined: {0}".format(version)) # remove file l.i("Removing old file...") f.remove_file(dist_file_path) # download file l.i("Downloading {0} file...".format(dist_file_name)) file_url = "{0}/{1}/{2}".format(dist_file_url, version, dist_file_name) try: f.create_dir(os.path.dirname(dist_file_path)) n.download(file_url, dist_file_path) except Exception as e: l.e("Error when download file {0}: {1}".format(file_url, e)) # remove old files and unpack current file l.i("Removing old folder...") f.create_dir(os.path.join(proj_path, const.DIR_NAME_DIST)) f.remove_dir(os.path.join(proj_path, const.DIR_NAME_DIST, dist_folder)) l.i("Unpacking downloaded file...") pack.unpack( dist_file_path, os.path.join(proj_path, const.DIR_NAME_DIST, dist_folder) ) l.ok()
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"] android_module_name = "library" l.i("Creating AAR library...") if archs and len(archs) > 0: if build_types and len(build_types) > 0: for build_type in build_types: l.i("Creating AAR library for: {0}...".format(build_type)) build_dir = os.path.join( proj_path, const.DIR_NAME_BUILD, target_name, build_type ) # copy library project template android_library_build_dir = os.path.join(build_dir, "aar") f.recreate_dir(android_library_build_dir) android_project_dir = os.path.join( proj_path, const.DIR_NAME_FILES, const.DIR_NAME_FILES_TARGETS, target_name, const.DIR_NAME_FILES_TARGET_SUPPORT, "android-aar-project", ) f.copy_dir( android_project_dir, android_library_build_dir, symlinks=True, ) # replace data build_gradle_file = os.path.join( android_library_build_dir, "library", "build.gradle", ) f.replace_in_file( build_gradle_file, "{VERSION}", target_config["version"] ) f.replace_in_file( build_gradle_file, "{VERSION_CODE}", target_config["version_code"] ) # copy support lib files gluecode_support_lib_dir = os.path.join( proj_path, const.DIR_NAME_FILES, const.DIR_NAME_FILES_MODULES, "support-lib", ) f.copy_all( os.path.join(gluecode_support_lib_dir, "java"), os.path.join( android_library_build_dir, android_module_name, "src", "main", "java", ), ) # copy all modules glue code files modules_dir = os.path.join( proj_path, const.DIR_NAME_FILES, const.DIR_NAME_FILES_MODULES, ) modules = module.get_list(proj_path) for m in modules: module_dir = os.path.join( modules_dir, m, const.DIR_NAME_GLUECODE, "generated-src", "java", ) if f.dir_exists(module_dir): f.copy_all( module_dir, os.path.join( android_library_build_dir, android_module_name, "src", "main", "java", ), ) # copy all modules implementation files modules_dir = os.path.join( proj_path, const.DIR_NAME_FILES, const.DIR_NAME_FILES_MODULES, ) modules = module.get_list(proj_path) for m in modules: module_dir = os.path.join( modules_dir, m, "implementation", "java", ) if f.dir_exists(module_dir): f.copy_all( module_dir, os.path.join( android_library_build_dir, android_module_name, "src", "main", "java", ), ) # copy all native libraries for arch in archs: compiled_arch_dir = os.path.join( build_dir, arch["conan_arch"], const.DIR_NAME_BUILD_TARGET, "lib", ) target_arch_dir = os.path.join( android_library_build_dir, "library", "src", "main", "jniLibs", arch["arch"], ) f.copy_all(compiled_arch_dir, target_arch_dir) # build aar android_module_dir = os.path.join( android_library_build_dir, android_module_name, ) if p.is_windows(): run_args = [ os.path.join("..", "gradlew.bat"), "bundle{0}Aar".format(build_type), ] else: run_args = [ os.path.join("..", "gradlew"), "bundle{0}Aar".format(build_type), ] r.run(run_args, cwd=android_module_dir) # copy files arr_dir = os.path.join( android_library_build_dir, android_module_name, "build", "outputs", "aar", ) dist_dir = os.path.join( proj_path, const.DIR_NAME_DIST, target_name, build_type ) f.remove_dir(dist_dir) f.copy_all(arr_dir, dist_dir) l.ok() else: l.i('Build type list for "{0}" is invalid or empty'.format(target_name)) else: l.i('Arch list for "{0}" is invalid or empty'.format(target_name))
def generate_xcframework(proj_path, target_name, target_config, archs, build_types): l.i("Packaging xcframework...") if archs and len(archs) > 0: if build_types and len(build_types) > 0: for build_type in build_types: l.i("Generating for: {0}...".format(build_type)) # generate group list groups = [] groups_command = [] for arch in archs: if not arch["group"] in groups: groups.append(arch["group"]) if len(groups) == 0: l.e("Group list are empty, make sure you have defined group name for each arch in config file for this target" ) # generate framework for each group for group in groups: # get first framework data for current group base_framework_arch = None for arch in archs: if arch["group"] == group: base_framework_arch = arch if not base_framework_arch: l.e("Group framework was not found: {0}".format(group)) # copy base framework framework_dir = os.path.join( proj_path, const.DIR_NAME_BUILD, target_name, build_type, base_framework_arch["group"], base_framework_arch["conan_arch"], const.DIR_NAME_BUILD_TARGET, "lib", "{0}.framework".format(target_config["project_name"]), ) group_xcframework_dir = os.path.join( proj_path, const.DIR_NAME_BUILD, target_name, build_type, group, "xcframework", "{0}.framework".format(target_config["project_name"]), ) f.remove_dir(group_xcframework_dir) f.copy_all( framework_dir, group_xcframework_dir, ) # generate single framework for group lipo_archs_args = [] for arch in archs: if arch["group"] == group: lipo_archs_args.append( 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"]), target_config["project_name"], )) lipo_args = [ "lipo", "-create", "-output", ] if f.dir_exists( os.path.join( group_xcframework_dir, "Versions", )): lipo_args.extend([ os.path.join( group_xcframework_dir, "Versions", "A", target_config["project_name"], ), ]) else: lipo_args.extend([ os.path.join( group_xcframework_dir, target_config["project_name"], ), ]) lipo_args.extend(lipo_archs_args) r.run(lipo_args, proj_path) # add final framework to group groups_command.append("-framework") groups_command.append(group_xcframework_dir) # generate xcframework xcframework_dir = os.path.join( proj_path, const.DIR_NAME_DIST, target_name, build_type, "{0}.xcframework".format(target_config["project_name"]), ) f.remove_dir(xcframework_dir) xcodebuild_command = ["xcodebuild", "-create-xcframework"] xcodebuild_command += groups_command xcodebuild_command += ["-output", xcframework_dir] r.run(xcodebuild_command, proj_path) # check file l.i("Checking file for: {0}...".format(build_type)) r.run(["ls", xcframework_dir], proj_path) else: l.i('Build type list for "{0}" is invalid or empty'.format( target_name)) else: l.i('Arch list for "{0}" is invalid or empty'.format(target_name))
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 = ls.list_has_value(params["args"], "--no-framework") no_xcframework = ls.list_has_value(params["args"], "--no-xcframework") # at least one need be generated if no_framework and no_xcframework: l.e("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, ) f.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) l.i("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", ) f.copy_dir( target_scripts_dir, os.path.join( const.DIR_NAME_DIST, target_name, "scripts", ), symlinks=True, ) # cocoapods l.i("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"]), ) f.copy_file( pod_file_path, target_pod_file_path, ) # xcframework group dir if not no_xcframework: if build_types and len(build_types) > 0: for build_type in build_types: xcframework_dir = os.path.join( dist_dir, build_type, "{0}.xcframework".format(target_config["project_name"]), ) found_dirs = f.find_dirs(xcframework_dir, "*") if found_dirs: first_group = os.path.basename(found_dirs[0]) f.replace_in_file( target_pod_file_path, "{XCFRAMEWORK_" + build_type.upper() + "_GROUP_DIR}", first_group, ) f.replace_in_file(target_pod_file_path, "{NAME}", target_config["project_name"]) f.replace_in_file(target_pod_file_path, "{VERSION}", target_config["version"]) # finish l.ok()
def generate_framework(proj_path, target_name, target_config, archs, build_types): l.i("Packaging framework...") if archs and len(archs) > 0: if build_types and len(build_types) > 0: for build_type in build_types: l.i("Copying for: {0}...".format(build_type)) # copy first folder for base framework_dir = os.path.join( proj_path, const.DIR_NAME_BUILD, target_name, build_type, archs[0]["group"], archs[0]["conan_arch"], const.DIR_NAME_BUILD_TARGET, "lib", "{0}.framework".format(target_config["project_name"]), ) dist_dir = os.path.join( proj_path, const.DIR_NAME_DIST, target_name, build_type, "{0}.framework".format(target_config["project_name"]), ) f.remove_dir(dist_dir) f.copy_dir( framework_dir, dist_dir, symlinks=True, ) # update info plist file plist_path = os.path.join( proj_path, const.DIR_NAME_DIST, target_name, build_type, "{0}.framework".format(target_config["project_name"]), "Info.plist", ) if os.path.exists(plist_path): # remove supported platforms inside plist r.run( [ "plutil", "-remove", "CFBundleSupportedPlatforms", plist_path, ], proj_path, ) # lipo lipo_archs_args = [] for arch in archs: if is_valid_group(arch["group"]): lipo_archs_args.append( 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"]), target_config["project_name"], )) lipo_args = [ "lipo", "-create", "-output", ] if f.dir_exists(os.path.join( dist_dir, "Versions", )): lipo_args.extend([ os.path.join( dist_dir, "Versions", "A", target_config["project_name"], ), ]) else: lipo_args.extend([ os.path.join( dist_dir, target_config["project_name"], ), ]) lipo_args.extend(lipo_archs_args) r.run(lipo_args, proj_path) # check file l.i("Checking file for: {0}...".format(build_type)) r.run( [ "file", os.path.join(dist_dir, target_config["project_name"]) ], proj_path, ) else: l.i('Build type list for "{0}" is invalid or empty'.format( target_name)) else: l.i('Arch list for "{0}" is invalid or empty'.format(target_name))
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 = ls.list_has_value(params["args"], "--dry-run") if param_dry_run: l.i("Running in dry mode...") if archs and len(archs) > 0: for arch in archs: for build_type in build_types: l.i("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: f.recreate_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, ), ] r.run(run_args, cwd=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)) f.remove_dir(build_assets_dir) f.copy_dir(assets_dir, build_assets_dir, symlinks=True) l.ok() else: l.e('Arch list for "{0}" is invalid or empty'.format(target_name))