diff --git a/src/ac/acl/yocto_compile/__init__.py b/src/ac/acl/yocto_compile/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/ac/acl/yocto_compile/check_yocto_compile.py b/src/ac/acl/yocto_compile/check_yocto_compile.py new file mode 100644 index 0000000000000000000000000000000000000000..f09ce4c3d00c7d4c17e214b104e051b3275627bb --- /dev/null +++ b/src/ac/acl/yocto_compile/check_yocto_compile.py @@ -0,0 +1,105 @@ +# -*- encoding=utf-8 -*- +# ********************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. +# Author: WeiGang Zhang +# Create: 2021-11-09 +# Description: check yocto compile +# ********************************************************************************** + +import os +import shutil +import logging +import threading + +from src.ac.framework.ac_base import BaseCheck +from src.ac.framework.ac_result import FAILED, WARNING, SUCCESS +from src.ac.common.gitee_repo import GiteeRepo +from src.utils.shell_cmd import shell_cmd_live +from xml.etree import ElementTree + +logger = logging.getLogger("ac") + +def download(download_dir, repo, branch, revision): + gitee_url = "https://gitee.com/" + cmd = "cd {}; git clone {} -b {}".format(download_dir, os.path.join(gitee_url, repo), branch) + ret, _, _ = shell_cmd_live(cmd) + if ret: + logger.error("clone [{} {}] failed!", repo, branch) + return ret + cmd = "cd {}; git checkout {}".format(os.path.join(download_dir, repo), revision) + ret, _, _ = shell_cmd_live(cmd) + if ret: + logger.error("clone [{} {}] failed!", repo, branch) + return ret + +class CheckYoctoCompile(BaseCheck): + """ + check yocto compile + """ + def __init__(self, workspace, repo, conf): + super(CheckYoctoCompile, self).__init__(workspace, repo, conf) + + self._work_code_dir = os.path.join(workspace, "code") + + self._work_build_dir = os.path.join(workspace, "build") + + self._gr = GiteeRepo(self._repo, self._work_dir, self._work_code_dir) + + def download_code(self): + """ + download code + :return: + """ + manifest_url = "https:/gitee.com/harvey-rtos/openeuler-yocto_test.git" + cmd = "cd {}; git clone {}".format(self._work_code_dir, manifest_url) + ret, _, _ = shell_cmd_live(cmd) + if ret: + logger.error("clone manifest failed!") + return FAILED + manifest_file = os.path.join(self._work_code_dir, "openeuler-yocto_test/manifest.xml") + tree = ElementTree.parse(manifest_file) + root = tree.getroot() + for prj in root.iter('project'): + task = threading.Thread(target=download, args=(self._work_code_dir, prj.attirb['name'], prj.attrib['branch'], prj.attrib['revision'])) + task.setDaemon(True) + task.start() + + return SUCCESS + + def check_yocto_compile(self): + """ + check yocto compile + :return: + """ + scripts_url = "https://gitee.com/harvey-rtos/openeuler-yocto_test.git" + build_script = os.path.join(self._work_code_dir, "scripts") + cmd = "cd {}; git clone {}".format(build_script, script_url) + ret, _, _ = shell_cmd_live(cmd) + if ret: + logger.error("clone build script repo failed!") + return FAILED + cmd = "cd {}; sh {}".format(self._work_build_dir, os.path.join(build_script, "build.sh")) + ret, _, _ = shell_cmd_live(cmd) + if ret: + logger.error("compile failed!") + return FAILED + + return SUCCESS + + def __call__(self, *args, **kwargs): + """ + entry function + :param args: + :param kwargs: + :return: + """ + logger.info("check {} repo ...".format(self._repo)) + + _ = not os.path.exists(self._work_code_dir) and os.mkdir(self._work_code_dir) + _ = not os.path.exists(self._work_build_dir) and os.mkdir(self._work_build_dir) + try: + return self.start_check_with_order("yocto_compile") + finally: + shutil.rmtree(self._work_code_dir) + shutil.rmtree(self._work_build_dir) +