• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2024-2025 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14function(regenerate_and_check_stdlib)
15    # NOTE(ivan-tyulyandin): add array.sh and related generated files
16    # Preparations to check generated against used code equality
17    set(ESCOMPAT "stdlib/escompat")
18    set(ESCOMPAT_GEN_FILES "DataView.ets" "TypedUArrays.ets" "TypedArrays.ets" "Array.ets")
19    set(STD_CORE "stdlib/std/core")
20    set(STD_CORE_GEN_FILES "Function.ets" "Tuple.ets" "BuiltinArray.ets" "BuiltinArraySort.ets" "BuiltinArrayAlgorithms.ets")
21    set(STD_INTEROP "stdlib/std/interop/js")
22    set(STD_INTEROP_GEN_FILES "InteropTransferHelper.ets")
23    set(GEN_FILES )
24    foreach(file ${ESCOMPAT_GEN_FILES})
25        list(APPEND GEN_FILES "${ESCOMPAT}/${file}")
26    endforeach()
27    foreach(file ${STD_CORE_GEN_FILES})
28        list(APPEND GEN_FILES "${STD_CORE}/${file}")
29    endforeach()
30    foreach(file ${STD_INTEROP_GEN_FILES})
31        list(APPEND GEN_FILES "${STD_INTEROP}/${file}")
32    endforeach()
33
34    set(GEN_SCRIPTS "genlib.sh" )
35
36    message(STATUS "Generating part of StdLib")
37    set(GENPATH "${CMAKE_CURRENT_BINARY_DIR}/stdlib")
38    foreach(script ${GEN_SCRIPTS})
39        set(SCRIPT_FULL_PATH "${ETS_PLUGIN_SOURCE_DIR}/templates/stdlib/${script}")
40        message(STATUS ${SCRIPT_FULL_PATH})
41        execute_process(COMMAND ${SCRIPT_FULL_PATH} ${GENPATH} OUTPUT_QUIET RESULT_VARIABLE ret)
42        if(ret EQUAL "1")
43            message( FATAL_ERROR "Bad exit status of script \"${SCRIPT_FULL_PATH}\"")
44        endif()
45    endforeach()
46
47    # Check generated against used code equality
48    foreach(file ${GEN_FILES})
49        execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files
50            "${ETS_PLUGIN_SOURCE_DIR}/${file}" "${CMAKE_CURRENT_BINARY_DIR}/${file}"
51            RESULT_VARIABLE compare_result
52        )
53        if( NOT compare_result EQUAL 0)
54            message(FATAL_ERROR "Generated ${file} is not equal to currently used ${file}, fix and rerun generating script. "
55            "Checkout the guide: "
56            "https://gitee.com/OpenHarmony/arkcompiler_runtime_core/blob/master/static_core/plugins/ets/stdlib/README.md")
57        endif()
58    endforeach()
59endfunction()
60
61regenerate_and_check_stdlib()
62