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"] log.info("Packaging...") if archs and len(archs) > 0: for arch in archs: for build_type in build_types: log.info("Copying for: {0}/{1}...".format( arch["conan_arch"], build_type)) # create folders dist_dir = os.path.join( proj_path, const.DIR_NAME_DIST, target_name, build_type, arch["conan_arch"], ) file.remove_dir(dist_dir) file.create_dir(dist_dir) build_dir = os.path.join( proj_path, const.DIR_NAME_BUILD, target_name, build_type, arch["conan_arch"], const.DIR_NAME_BUILD_TARGET, "bin", ) # copy files file.copy_all_inside(build_dir, dist_dir) log.ok() else: log.error( 'Arch list for "{0}" is invalid or empty'.format(target_name))
def setup(params): proj_path = params["proj_path"] # version version = util.get_arg_value("--version", params["args"]) if not version or len(version) == 0: version = const.GLUECODE_TOOL_VERSION log.info("Glue code tool version: {0}".format(version)) # check tool folder tool_dir = os.path.join(proj_path, const.DIR_NAME_BUILD, const.DIR_NAME_GLUECODE) file.remove_dir(tool_dir) file.create_dir(tool_dir) # prepare tool data tool_file_path = gluecode.get_tool_path(params) if util.is_windows_platform(): file_url = "https://github.com/cross-language-cpp/djinni-generator/releases/download/v{0}/djinni.bat".format( version) else: file_url = "https://github.com/cross-language-cpp/djinni-generator/releases/download/v{0}/djinni".format( version) # prepare tool data try: net.download(file_url, tool_file_path) # add executable permission st = os.stat(tool_file_path) os.chmod(tool_file_path, st.st_mode | stat.S_IEXEC) except Exception as e: log.error("Error when download file {0}: {1}".format(file_url, e)) log.ok()
def generate(proj_path, target_name, version, source_files): # version if not version or len(version) == 0: log.error("You need define version name (parameter: --version)") log.info("Version defined: {0}".format(version)) # build dir build_dir = os.path.join(proj_path, const.DIR_NAME_BUILD, target_name, const.DIR_NAME_DIST) log.info("Removing old files...") file.remove_dir(build_dir) file.create_dir(build_dir) # pack files log.info("Packing {0} files...".format(len(source_files))) dist_file = os.path.join(build_dir, const.FILE_NAME_DIST_PACKED) tar_files(dist_file, source_files) log.ok("")
def download( proj_path, version, dist_file_path, dist_file_name, dist_folder, aws_s3_url ): # version if not version or len(version) == 0: log.error("You need define version name (parameter: --version)") log.info("Version defined: {0}".format(version)) # remove file log.info("Removing old file...") file.remove_file(dist_file_path) # download file log.info("Downloading {0} file...".format(dist_file_name)) file_url = "{0}/{1}/{2}".format(aws_s3_url, version, dist_file_name) try: net.download(file_url, dist_file_path) except Exception as e: log.error("Error when download file {0}: {1}".format(file_url, e)) # remove old files and unpack current file log.info("Removing old folder...") file.create_dir(os.path.join(proj_path, const.DIR_NAME_DIST)) file.remove_dir(os.path.join(proj_path, const.DIR_NAME_DIST, dist_folder)) log.info("Unpacking downloaded file...") pack.unpack( dist_file_path, os.path.join(proj_path, const.DIR_NAME_DIST, dist_folder) ) log.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"] 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 install build_dir = os.path.join( proj_path, const.DIR_NAME_BUILD, target_name, build_type, arch["conan_arch"], const.DIR_NAME_BUILD_CONAN, ) file.remove_dir(build_dir) file.create_dir(build_dir) # main run args run_args = [ "conan", "install", 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, ), "--profile", arch["conan_profile"], "-s", "arch={0}".format(arch["conan_arch"]), "-s", "build_type={0}".format(build_type), "-o", "ezored_arch={0}".format(arch["conan_arch"]), "-o", "ezored_name={0}".format(target_config["project_name"]), "-o", "ezored_version={0}".format(target_config["version"]), ] # extra run args if util.is_macos_platform(): run_args.append("-s"), run_args.append("os.version={0}".format( arch["min_version"])) # final run args run_args.append("--build=missing") run_args.append("--update") runner.run(run_args, build_dir) log.ok() else: log.error( '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 = 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))
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"] 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 install build_dir = os.path.join( proj_path, const.DIR_NAME_BUILD, target_name, build_type, arch["group"], arch["conan_arch"], const.DIR_NAME_BUILD_CONAN, ) file.remove_dir(build_dir) file.create_dir(build_dir) run_args = [ "conan", "install", 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, ), "-pr:b", target.get_build_profile(), "-pr:h", arch["conan_profile"], "-s:h", "arch={0}".format(arch["conan_arch"]), "-s:h", "build_type={0}".format(build_type), "-s:h", "os.version={0}".format(arch["min_version"]), "-s:b", "os.version={0}".format( (arch["build_min_version"] if "build_min_version" in arch else None)), "-o", "ezored_arch={0}".format(arch["conan_arch"]), "-o", "ezored_name={0}".format(target_config["project_name"]), "-o", "ezored_version={0}".format(target_config["version"]), "-o", "ezored_group={0}".format(arch["group"]), "-o", "darwin-toolchain:enable_bitcode={0}".format( (arch["enable_bitcode"] if "enable_bitcode" in arch else None)), "-o", "darwin-toolchain:enable_arc={0}".format( (arch["enable_arc"] if "enable_arc" in arch else None)), "-o", "darwin-toolchain:enable_visibility={0}".format( (arch["enable_visibility"] if "enable_visibility" in arch else None)), "--build=missing", "--update", ] runner.run(run_args, build_dir) log.ok() else: log.error( '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"] 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))
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" log.info("Creating AAR library...") if archs and len(archs) > 0: if build_types and len(build_types) > 0: for build_type in build_types: log.info("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") file.remove_dir(android_library_build_dir) file.create_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", ) file.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", ) file.replace_in_file(build_gradle_file, "{VERSION}", target_config["version"]) file.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", ) file.copy_all_inside( 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 file.dir_exists(module_dir): file.copy_all_inside( 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 file.dir_exists(module_dir): file.copy_all_inside( 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"], ) file.copy_all_inside(compiled_arch_dir, target_arch_dir) # build aar android_module_dir = os.path.join( android_library_build_dir, android_module_name, ) if util.is_windows_platform(): 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), ] runner.run(run_args, 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) file.remove_dir(dist_dir) file.copy_all_inside(arr_dir, dist_dir) log.ok() else: log.info('Build type list for "{0}" is invalid or empty'.format( target_name)) else: log.info('Arch list for "{0}" is invalid or empty'.format(target_name))