已合并
Adapt to the -f capability provided by the CI project. #607
Adapt to the -f capability provided by the CI project. #607
已合并
pengcheng1024创建于 2月27日
2 个文件变更+110-2
Mbuild.sh+45-2
@@ -11,9 +11,9 @@
11 11 
12set -e12set -e
13 13 
14-SUPPORTED_SHORT_OPTS=("h" "j" "t" "p")14+SUPPORTED_SHORT_OPTS=("h" "j" "t" "p" "f")
15SUPPORTED_LONG_OPTS=(15SUPPORTED_LONG_OPTS=(
16- "help" "cov" "cache" "pkg" "asan" "make_clean" "cann_3rd_lib_path" "test" "cann_path" "adv_test" "basic_test_one" "basic_test_two" "basic_test_three" "build-type" "extra-cmake-args"16+ "help" "cov" "cache" "pkg" "asan" "make_clean" "cann_3rd_lib_path" "test" "cann_path" "adv_test" "basic_test_one" "basic_test_two" "basic_test_three" "build-type" "extra-cmake-args" "changed_file"
17)17)
18 18 
19CURRENT_DIR=$(dirname $(readlink -f ${BASH_SOURCE[0]}))19CURRENT_DIR=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
@@ -27,6 +27,8 @@ BUILD_TYPE="Release"
27ENABLE_BUILD_DEVICE=ON27ENABLE_BUILD_DEVICE=ON
28USE_CXX11_ABI=028USE_CXX11_ABI=0
29CMAKE_TOOLCHAIN_FILE_VAL=""29CMAKE_TOOLCHAIN_FILE_VAL=""
30+CHANGED_FILES=""
31+CI_MODE=FALSE
30 32 
31dotted_line="----------------------------------------------------------------"33dotted_line="----------------------------------------------------------------"
32 34 
@@ -105,6 +107,7 @@ usage() {
105 echo " --make_clean Clean build artifacts"107 echo " --make_clean Clean build artifacts"
106 echo " --build-type=<TYPE>"108 echo " --build-type=<TYPE>"
107 echo " Specify build type (TYPE options: Release/Debug), Default:Release"109 echo " Specify build type (TYPE options: Release/Debug), Default:Release"
110+ echo " -f, --changed_file Set the changed files for CI mode, eg: -f change_file.txt"
108}111}
109 112 
110parse_cmake_extra_args() {113parse_cmake_extra_args() {
@@ -405,6 +408,16 @@ set_options() {
405 check_param_j408 check_param_j
406 shift 2409 shift 2
407 ;;410 ;;
411+ -f)
412+ CHANGED_FILES="$2"
413+ CI_MODE=TRUE
414+ shift 2
415+ ;;
416+ --changed_file=*)
417+ CHANGED_FILES="${1#*=}"
418+ CI_MODE=TRUE
419+ shift
420+ ;;
408 --build-type=*)421 --build-type=*)
409 BUILD_TYPE="${1#*=}"422 BUILD_TYPE="${1#*=}"
410 check_param_test_build_type423 check_param_test_build_type
@@ -516,6 +529,32 @@ function build_test_part() {
516 return 0529 return 0
517}530}
518 531 
532+set_ci_mode() {
533+ if [[ "$CHANGED_FILES" != /* ]]; then
534+ CHANGED_FILES=${CURRENT_DIR}/$CHANGED_FILES
535+ fi
536+ log "[INFO] CI mode: changed file path is $CHANGED_FILES"
537+ log "[INFO] CI mode: context in changed file: "
538+ cat $CHANGED_FILES
539+ 
540+ if [[ -n "$CHANGED_FILES" ]]; then
541+ log "[INFO] CI mode: processing changed files for CI mode."
542+ # 调用 parse_changed_files.py 解析修改的文件
543+ local parse_script="${CURRENT_DIR}/scripts/util/parse_changed_files.py"
544+ if [[ ! -f "$parse_script" ]]; then
545+ log "[ERROR] CI mode: parse_changed_files.py not found at $parse_script"
546+ exit 1
547+ fi
548+ 
549+ SKIP_COMPILE_AND_TEST=$(python3 "$parse_script" "$CHANGED_FILES")
550+ if [[ "${SKIP_COMPILE_AND_TEST}" == "TRUE" ]]; then
551+ log "[INFO] CI mode: No need to compile and test."
552+ exit 200
553+ fi
554+ log "[INFO] CI mode: need compile and test for CI mode."
555+ fi
556+}
557+ 
519main() {558main() {
520 check_param_with_help "$@"559 check_param_with_help "$@"
521 set_options "$@"560 set_options "$@"
@@ -557,6 +596,10 @@ main() {
557 596 
558 cd ${BUILD_DIR}597 cd ${BUILD_DIR}
559 598 
599+ if [[ "${CI_MODE}" == "TRUE" ]]; then
600+ set_ci_mode
601+ fi
602+ 
560 if [ -n "${TEST}" ]; then603 if [ -n "${TEST}" ]; then
561 build_test604 build_test
562 elif [ -n "$TEST_PART" ]; then605 elif [ -n "$TEST_PART" ]; then
@@ -0,0 +1,65 @@
1+#!/usr/bin/python3
2+# coding=utf-8
3+ 
4+# ----------------------------------------------------------------------------------------------------------
5+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
6+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
7+# CANN Open Software License Agreement Version 2.0 (the "License").
8+# Please refer to the License for details. You may not use this file except in compliance with the License.
9+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
10+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
11+# See LICENSE in the root of the software repository for the full text of the License.
12+# ----------------------------------------------------------------------------------------------------------
13+ 
14+import os
15+import sys
16+ 
17+ 
18+def file_filter(path):
19+ """
20+ Determine if the file contains files that do not require compilation.
21+ """
22+ key_words = ['.md', 'OWNERS', 'LICENSE', 'classify_rule.yaml', 'examples', 'docs']
23+ for key_word in key_words:
24+ if key_word in path:
25+ return True
26+ return False
27+ 
28+ 
29+def main():
30+ """"
31+ get change info from ci, CI_MODE=True, ci will write 'get diff >/change_file.txt'
32+ Return whether to skip compilation.
33+ """
34+ if len(sys.argv) < 2:
35+ return "FALSE"
36+ 
37+ changed_files_arg = sys.argv[1]
38+ try:
39+ # 读取修改的文件列表
40+ if os.path.isfile(changed_files_arg) and changed_files_arg.endswith('.txt'):
41+ with open(changed_files_arg, 'r') as f:
42+ changed_files = [line.strip() for line in f.readlines() if line.strip()]
43+ elif ',' in changed_files_arg:
44+ changed_files = [f.strip() for f in changed_files_arg.split(',') if f.strip()]
45+ else:
46+ changed_files = [changed_files_arg.strip()]
47+ except BaseException as err:
48+ return "FALSE"
49+ finally:
50+ pass
51+ 
52+ if not changed_files:
53+ return "FALSE"
54+ 
55+ need_skip = True
56+ for file_path in changed_files:
57+ need_skip = need_skip and file_filter(file_path)
58+ if not need_skip:
59+ return "FALSE"
60+ 
61+ return "TRUE"
62+ 
63+ 
64+if __name__ == '__main__':
65+ sys.stdout.write(main())