From 2c45f780aef38b6436b8dc14a484c102888ed212 Mon Sep 17 00:00:00 2001 From: bergamot88 Date: Tue, 19 Aug 2025 19:30:06 +0300 Subject: [PATCH] Update ninja_wrapper Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICV2ZH Description: Create ninja_wrapper Testing: All required pre-merge tests passed. Results are available in the internal CI Signed-off-by: Tokmakov Alexander --- static_core/plugins/ets/tests/CMakeLists.txt | 15 ++- static_core/scripts/ninja_wrapper | 111 +++++++++++++++++-- 2 files changed, 115 insertions(+), 11 deletions(-) diff --git a/static_core/plugins/ets/tests/CMakeLists.txt b/static_core/plugins/ets/tests/CMakeLists.txt index 3840dee537..5ec2fe344a 100644 --- a/static_core/plugins/ets/tests/CMakeLists.txt +++ b/static_core/plugins/ets/tests/CMakeLists.txt @@ -621,13 +621,21 @@ add_custom_target(ets_time02_tests) add_custom_target(ets_time03_tests) add_custom_target(ets_time04_tests) add_custom_target(ets_time05_tests) +add_custom_target(ets_time06_tests) +add_custom_target(ets_time07_tests) +add_custom_target(ets_time08_tests) +add_custom_target(ets_time09_tests) add_dependencies(ets_tests ets_time01_tests ets_time02_tests ets_time03_tests ets_time04_tests - ets_time05_tests) + ets_time05_tests + ets_time06_tests + ets_time07_tests + ets_time08_tests + ets_time09_tests) function(add_target_to_group group test_target) if (TARGET ${test_target}) @@ -671,3 +679,8 @@ add_target_to_group(ets_time04_tests ets_run_int_ets_code_tests) add_target_to_group(ets_time05_tests ets_run_int_ets_code_tests) # ---- end of groups by time + +add_target_to_group(ets_time06_tests ani_tests) +add_target_to_group(ets_time07_tests sampler_ani_test_suite) +add_target_to_group(ets_time08_tests es2panda_gtests) +add_target_to_group(ets_time09_tests compiler_tests) diff --git a/static_core/scripts/ninja_wrapper b/static_core/scripts/ninja_wrapper index 5302fa8a2c..5dc1e81545 100755 --- a/static_core/scripts/ninja_wrapper +++ b/static_core/scripts/ninja_wrapper @@ -24,14 +24,39 @@ after_double_dash=false parent_dir=$(dirname "$PWD") current_dir_name=$(basename "$PWD") -for arg in "$@"; do - if [[ "$arg" == "--" ]]; then - after_double_dash=true - elif [[ "$after_double_dash" == true ]]; then - extra_args+=("$arg") - else - main_args+=("$arg") - fi +save_source_files_for_each_target=false +verbose=false +chapters="" +chapter_id="" + +while [[ $# -gt 0 ]]; do + case $1 in + -ssf|--save-source-files-for-each-target) + save_source_files_for_each_target=true + shift + ;; + -v|--verbose) + verbose=true + shift + ;; + --chapters) + chapters="$2" + shift 2 + ;; + --chapter-id) + chapter_id="$2" + shift 2 + ;; + --) + shift + extra_args=("$@") + break + ;; + -*) + echo "Unknown option: $1" >&2 + exit 1 + ;; + esac done if [[ ${#extra_args[@]} -gt 0 ]]; then @@ -42,9 +67,16 @@ if [[ ${#extra_args[@]} -gt 0 ]]; then ninja_targets+=("$arg") fi done + if [[ "${verbose}" == "true" ]]; then + echo "===========================================" + echo "[INFO] Ninja flags: ${ninja_flags[@]}" + echo "===========================================" + echo "[INFO] Ninja targets: ${ninja_targets[@]}" + echo "===========================================" + fi fi -if [[ "${main_args[@]}" == *"save_source_files_for_each_target"* ]]; then +if [[ "${save_source_files_for_each_target}" == "true" ]]; then for target in "${ninja_targets[@]}"; do file_name="$PWD/component_${target}_component_cpp_files.txt" ninja -t commands ${target} | grep 'c++.*\.cpp' | awk '{print $NF}' > ${file_name} @@ -54,5 +86,64 @@ if [[ "${main_args[@]}" == *"save_source_files_for_each_target"* ]]; then done fi +split_array() { + local -n arr=$1 + local parts=$2 + local part_id=$3 + + local total=${#arr[@]} + local part_size=$(( (total + parts - 1) / parts )) + local start=$((part_id * part_size)) + local end=$((start + part_size)) + + if [[ $end -gt $total ]]; then + end=$total + fi + + if [[ $start -lt $end ]]; then + printf "%s\n" "${arr[@]:$start:$((end - start))}" + fi +} + +sort_array() { + local -n src_arr=$1 + local -n dst_arr=$2 + local IFS=$'\n' + dst_arr=($(LC_ALL=C sort <<<"${src_arr[*]}")) +} + +if [[ -n "${chapters}" ]]; then + targets_first_layer=() + targets_second_layer=() + for arg in "${extra_args[@]}"; do + if [[ "${arg}" = *"test"* ]]; then + mapfile -t targets1 < <(ninja -t query "${arg}" | awk '/^ input:/ {in_input=1; next} + /^ [a-zA-Z]+:/ {in_input=0} + in_input && /^ [^ ]/ && $1 != "phony" {print $1}') + targets_first_layer+=("${targets1[@]}") + fi + done + for arg in "${targets_first_layer[@]}"; do + mapfile -t targets2 < <(ninja -t query "${arg}" | awk '/^ input:/ {in_input=1; next} + /^ [a-zA-Z]+:/ {in_input=0} + in_input && /^ [^ ]/ && $1 != "phony" {print $1}') + targets_second_layer+=("${targets2[@]}") + done + sort_array targets_second_layer sorted_array + selected_targets=$(split_array sorted_array "${chapters}" "${chapter_id}") + ninja_targets=(${selected_targets[@]}) + + if [[ "${verbose}" == "true" ]]; then + echo "[INFO] Result of first call 'ninja -t query': ${targets_first_layer[@]}" + echo "===========================================" + echo "[INFO] Result of second call 'ninja -t query': ${targets_second_layer[@]}" + echo "===========================================" + echo "[INFO] Result after sorting: ${sorted_array[@]}" + echo "===========================================" + echo "[INFO] Ninja targets is: ${ninja_targets[@]}" + echo "===========================================" + fi +fi + set -x -ninja ${extra_args[@]} +ninja ${ninja_flags[@]} ${ninja_targets[@]} -- Gitee