From a32f9d5c92d5c0d017c9fc4d738bfda3328c0f23 Mon Sep 17 00:00:00 2001 From: zhangweigang Date: Sat, 6 Nov 2021 15:50:37 +0800 Subject: [PATCH 1/5] rename check dir Signed-off-by: zhangweigang --- src/ac/acl/yocto_compile/__init__.py | 0 .../acl/yocto_compile/check_yocto_compile.py | 96 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/ac/acl/yocto_compile/__init__.py create mode 100644 src/ac/acl/yocto_compile/check_yocto_compile.py diff --git a/src/ac/acl/yocto_compile/__init__.py b/src/ac/acl/yocto_compile/__init__.py new file mode 100644 index 0000000..e69de29 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 0000000..adac651 --- /dev/null +++ b/src/ac/acl/yocto_compile/check_yocto_compile.py @@ -0,0 +1,96 @@ +# -*- encoding=utf-8 -*- +# ********************************************************************************** +# Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. +# Author: WeiGang Zhang +# Create: 2021-11-06 +# Description: check yocto compile +# ********************************************************************************** + +import os +import shutil +import logging + +from src.proxy.git_proxy import GitProxy +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.ac.common.linter import LinterCheck +from src.ac.common.rpm_spec_adapter import RPMSpecAdapter + +logger = logging.getLogger("ac") + + +class CheckYoctoCompile(BaseCheck): + """ + check yocto compile + """ + def __init__(self, workspace, repo, conf): + super(CheckCodeStyle, 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 check_yocto_compile(self): + """ + check yocto compile + :return: + """ + #gp = GitProxy(self._work_dir) + #diff_files = gp.diff_files_between_commits("HEAD~1", "HEAD~0") + #logger.debug("diff files: {}".format(diff_files)) + + + return SUCCESS + + def prepare_init_env(self): + """ + prepare build word dir + :return: + """ + + return SUCCESS + + @classmethod + def check_code_file(cls, file_path): + """ + 检查代码风格 + :param file_path: + :return: + """ + if GiteeRepo.is_py_file(file_path): + rs = LinterCheck.check_python(file_path) + elif GiteeRepo.is_go_file(file_path): + rs = LinterCheck.check_golang(file_path) + elif GiteeRepo.is_c_cplusplus_file(file_path): + rs = LinterCheck.check_c_cplusplus(file_path) + else: + logger.error("error when arrive here, unsupport file {}".format(file_path)) + return SUCCESS + + logger.info("Linter: {:<40} {}".format(file_path, rs)) + if rs.get("F", 0) > 0: + return FAILED + + if rs.get("W", 0) > 0 or rs.get("E", 0) > 0: + return WARNING + + 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_build_dir) and os.mkdir(self._work_build_dir) + try: + return self.start_check_with_order("yocto_compile") + finally: + shutil.rmtree(self._work_build_dir) -- Gitee From d44c99e9b9741cabaffd3e9d03c5d881abafee27 Mon Sep 17 00:00:00 2001 From: zhangweigang Date: Mon, 8 Nov 2021 16:34:02 +0800 Subject: [PATCH 2/5] modify yocto compile code Signed-off-by: zhangweigang --- .../acl/yocto_compile/check_yocto_compile.py | 50 +++++-------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/src/ac/acl/yocto_compile/check_yocto_compile.py b/src/ac/acl/yocto_compile/check_yocto_compile.py index adac651..ade30d9 100644 --- a/src/ac/acl/yocto_compile/check_yocto_compile.py +++ b/src/ac/acl/yocto_compile/check_yocto_compile.py @@ -10,12 +10,11 @@ import os import shutil import logging -from src.proxy.git_proxy import GitProxy 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.ac.common.linter import LinterCheck -from src.ac.common.rpm_spec_adapter import RPMSpecAdapter +from src.utils.shell_cmd import shell_cmd_live +from xml.etree import ElementTree logger = logging.getLogger("ac") @@ -25,7 +24,7 @@ class CheckYoctoCompile(BaseCheck): check yocto compile """ def __init__(self, workspace, repo, conf): - super(CheckCodeStyle, self).__init__(workspace, repo, conf) + super(CheckYoctoCompile, self).__init__(workspace, repo, conf) self._work_code_dir = os.path.join(workspace, "code") @@ -33,51 +32,24 @@ class CheckYoctoCompile(BaseCheck): self._gr = GiteeRepo(self._repo, self._work_dir, self._work_code_dir) - - def check_yocto_compile(self): + def download_code(self): """ - check yocto compile + download code :return: """ - #gp = GitProxy(self._work_dir) - #diff_files = gp.diff_files_between_commits("HEAD~1", "HEAD~0") - #logger.debug("diff files: {}".format(diff_files)) - return SUCCESS - def prepare_init_env(self): - """ - prepare build word dir - :return: - """ - - return SUCCESS - - @classmethod - def check_code_file(cls, file_path): + def check_yocto_compile(self): """ - 检查代码风格 - :param file_path: + check yocto compile :return: """ - if GiteeRepo.is_py_file(file_path): - rs = LinterCheck.check_python(file_path) - elif GiteeRepo.is_go_file(file_path): - rs = LinterCheck.check_golang(file_path) - elif GiteeRepo.is_c_cplusplus_file(file_path): - rs = LinterCheck.check_c_cplusplus(file_path) - else: - logger.error("error when arrive here, unsupport file {}".format(file_path)) - return SUCCESS - - logger.info("Linter: {:<40} {}".format(file_path, rs)) - if rs.get("F", 0) > 0: + #gp = GitProxy(self._work_dir) + + if not self.download_code(): return FAILED - if rs.get("W", 0) > 0 or rs.get("E", 0) > 0: - return WARNING - return SUCCESS def __call__(self, *args, **kwargs): @@ -89,8 +61,10 @@ class CheckYoctoCompile(BaseCheck): """ 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) -- Gitee From c08b9434ae240547d370a2c3917a71acf87fa951 Mon Sep 17 00:00:00 2001 From: zhangweigang Date: Tue, 9 Nov 2021 21:29:15 +0800 Subject: [PATCH 3/5] modify yocto compile code Signed-off-by: zhangweigang --- .../acl/yocto_compile/check_yocto_compile.py | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/ac/acl/yocto_compile/check_yocto_compile.py b/src/ac/acl/yocto_compile/check_yocto_compile.py index ade30d9..517d689 100644 --- a/src/ac/acl/yocto_compile/check_yocto_compile.py +++ b/src/ac/acl/yocto_compile/check_yocto_compile.py @@ -9,6 +9,7 @@ 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 @@ -18,6 +19,18 @@ 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): """ @@ -37,17 +50,38 @@ class CheckYoctoCompile(BaseCheck): 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: - """ - #gp = GitProxy(self._work_dir) - - if not self.download_code(): + """ + 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 -- Gitee From dd81ce202fb0bf9d0a231f02c537d4bb05c5f3ff Mon Sep 17 00:00:00 2001 From: zhangweigang Date: Tue, 9 Nov 2021 21:39:31 +0800 Subject: [PATCH 4/5] modify compile code Signed-off-by: zhangweigang --- src/ac/acl/yocto_compile/check_yocto_compile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ac/acl/yocto_compile/check_yocto_compile.py b/src/ac/acl/yocto_compile/check_yocto_compile.py index 517d689..6784442 100644 --- a/src/ac/acl/yocto_compile/check_yocto_compile.py +++ b/src/ac/acl/yocto_compile/check_yocto_compile.py @@ -102,3 +102,4 @@ class CheckYoctoCompile(BaseCheck): finally: shutil.rmtree(self._work_code_dir) shutil.rmtree(self._work_build_dir) + -- Gitee From b2334dc39f5ef27523faaedf9d8316fdc7a9c562 Mon Sep 17 00:00:00 2001 From: zhangweigang Date: Tue, 9 Nov 2021 21:41:27 +0800 Subject: [PATCH 5/5] modify compile code Signed-off-by: zhangweigang --- src/ac/acl/yocto_compile/check_yocto_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ac/acl/yocto_compile/check_yocto_compile.py b/src/ac/acl/yocto_compile/check_yocto_compile.py index 6784442..f09ce4c 100644 --- a/src/ac/acl/yocto_compile/check_yocto_compile.py +++ b/src/ac/acl/yocto_compile/check_yocto_compile.py @@ -2,7 +2,7 @@ # ********************************************************************************** # Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. # Author: WeiGang Zhang -# Create: 2021-11-06 +# Create: 2021-11-09 # Description: check yocto compile # ********************************************************************************** -- Gitee