def get_all_target_verbs(proj_path, target_name): results = [] target_verbs_list = f.find_files( os.path.join( proj_path, const.DIR_NAME_FILES, const.DIR_NAME_FILES_TARGETS, target_name, const.DIR_NAME_FILES_TARGET_VERBS, ), "*.py", ) if target_verbs_list: for verb_file in target_verbs_list: verb_name = os.path.basename(verb_file) verb_name = os.path.splitext(verb_name)[0] if verb_name: results.append(verb_name) results.sort() return results
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 = 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["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: 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["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, ), ] r.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", "A", "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 r.run( [ "plutil", "-replace", "MinimumOSVersion", "-string", arch["min_version"], plist_path, ], proj_path, ) # add supported platform inside plist r.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", ) f.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": f.copy_dir( source_header_dir, dist_headers_dir, ignore_file=_header_ignore_list, symlinks=True, ) else: l.e("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", ) f.recreate_dir(modules_dir) f.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 = f.find_files( build_headers_dir, "*.h", recursive=True, ) content = f.get_file_contents( 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"]) f.copy_file( os.path.join(support_modules_dir, "umbrella-header.h"), umbrella_file, ) f.set_file_content(umbrella_file, content) else: l.e("{0}".format( "File not generated because framework headers is empty" )) l.ok() else: l.e('Arch list for "{0}" is invalid or empty'.format(target_name))
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")
def setup(params): proj_path = params["proj_path"] targets = target.get_all_targets(proj_path) l.i("Creating default profile...") # create default profile r.run( [ "conan", "profile", "new", "default", "--detect", "--force", ], cwd=os.getcwd(), ) # copy all targets profile l.i("Copying files...") if targets: for target_item in targets: files = f.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( f.home_dir(), const.DIR_NAME_HOME_CONAN, const.DIR_NAME_HOME_CONAN_PROFILES, ) for item in files: filename = os.path.basename(item) l.i('Copying profile "{0}"...'.format(filename)) f.copy_file(item, os.path.join(conan_profile_dir, filename)) # add darwin toolchain l.i("Adding darwin toolchain repository...") r.run( [ "conan", "remote", "add", "darwin-toolchain", "https://ezoredrepository.jfrog.io/artifactory/api/conan/conan-local", "--force", ], cwd=os.getcwd(), ) l.ok()