diff --git a/scripts/context.py b/scripts/context.py index 3f47439..9c3bc85 100644 --- a/scripts/context.py +++ b/scripts/context.py @@ -31,6 +31,11 @@ class Context: sdk_version: str = "" sdk_prolink_version: str = "" + out_project: str = "" + out_debug_apk: str = "" + out_release_apk: str = "" + out_release_aab: str = "" + @classmethod def from_json(cls, json_str: str): data = json.loads(json_str) diff --git a/scripts/project_build.py b/scripts/project_build.py index bf96b41..776c665 100644 --- a/scripts/project_build.py +++ b/scripts/project_build.py @@ -1,10 +1,17 @@ import os.path from scripts.task import Task -from utils import SystemUtils, CommandUtils +from utils import SystemUtils, CommandUtils, TimeUtils, FileUtils from utils.logger_utils import app_logger +def find_path(dir_path: str, suffix: str) -> str: + l = list(filter(lambda x: x.endswith(suffix), os.listdir(dir_path))) + if not l: + raise FileNotFoundError("No such file or directory") + return os.path.join(dir_path, l[0]) + + class ProjectBuild(Task): """ assembleLawnWithQuickstepPlay @@ -30,7 +37,35 @@ class ProjectBuild(Task): app_logger().debug(f"build aab return_code = {return_code} stdout = {stdout} stderr = {stderr}") def execute(self): + self.init() + self.save_project() self.build_apk() self.build_aab() - + self.copy_to_out() pass + + def init(self): + file_name = f"{self.context.get_app_name()}_{self.context.package_name}_{self.context.version_display_name}({self.context.version_code})_{self.context.local_repo_branch}({self.context.local_repo_commit[:5]})_{TimeUtils.get_current_time_str()}" + self.context.out_project = os.path.join("out", f"{file_name}.zip") + self.context.out_debug_apk = os.path.join("out", f"{file_name}_debug.apk") + self.context.out_release_apk = os.path.join("out", f"{file_name}_release.apk") + self.context.out_release_aab = os.path.join("out", f"{file_name}_release.aab") + pass + + def copy_to_out(self): + app_logger().debug(f"copy_to_out start.") + target = f"{self.context.temp_project_path}{os.sep}build{os.sep}outputs{os.sep}apk{os.sep}lawnWithQuickstepPlay{os.sep}debug" + FileUtils.copy(find_path(target, "apk"), self.context.out_debug_apk) + app_logger().debug(f"copy_to_out debug apk = {self.context.out_debug_apk}") + target = f"{self.context.temp_project_path}{os.sep}build{os.sep}outputs{os.sep}apk{os.sep}lawnWithQuickstepPlay{os.sep}release" + FileUtils.copy(find_path(target, "apk"), self.context.out_release_apk) + app_logger().debug(f"copy_to_out release apk = {self.context.out_release_apk}") + target = f"{self.context.temp_project_path}{os.sep}build{os.sep}outputs{os.sep}bundle{os.sep}lawnWithQuickstepPlayRelease" + FileUtils.copy(find_path(target, "aab"), self.context.out_release_aab) + app_logger().debug(f"copy_to_out end.") + pass + + def save_project(self): + app_logger().debug(f"save project {self.context.out_project} start.") + FileUtils.compress(self.context.temp_project_path, self.context.out_project) + app_logger().debug(f"save project {self.context.out_project} end.")