1# Copyright (c) 2024 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.sts" "TypedUArrays.sts" "TypedArrays.sts" "Array.sts") 19 set(STD_CORE "stdlib/std/core") 20 set(STD_CORE_GEN_FILES "Function.sts" "BuiltinArray.sts" "BuiltinArraySort.sts" "BuiltinArrayAlgorithms.sts") 21 set(GEN_FILES ) 22 foreach(file ${ESCOMPAT_GEN_FILES}) 23 list(APPEND GEN_FILES "${ESCOMPAT}/${file}") 24 endforeach() 25 foreach(file ${STD_CORE_GEN_FILES}) 26 list(APPEND GEN_FILES "${STD_CORE}/${file}") 27 endforeach() 28 29 set(GEN_SCRIPTS "genlib.sh" ) 30 31 message(STATUS "Generating part of StdLib") 32 set(GENPATH "${CMAKE_CURRENT_BINARY_DIR}/stdlib") 33 foreach(script ${GEN_SCRIPTS}) 34 set(SCRIPT_FULL_PATH "${ETS_PLUGIN_SOURCE_DIR}/templates/stdlib/${script}") 35 message(STATUS ${SCRIPT_FULL_PATH}) 36 execute_process(COMMAND ${SCRIPT_FULL_PATH} ${GENPATH} OUTPUT_QUIET RESULT_VARIABLE ret) 37 if(ret EQUAL "1") 38 message( FATAL_ERROR "Bad exit status of script \"${SCRIPT_FULL_PATH}\"") 39 endif() 40 endforeach() 41 42 # Check generated against used code equality 43 foreach(file ${GEN_FILES}) 44 execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files 45 "${ETS_PLUGIN_SOURCE_DIR}/${file}" "${CMAKE_CURRENT_BINARY_DIR}/${file}" 46 RESULT_VARIABLE compare_result 47 ) 48 if( NOT compare_result EQUAL 0) 49 message(FATAL_ERROR "Generated ${file} is not equal to currently used ${file}, fix and rerun generating script. " 50 "Checkout the guide: " 51 "https://gitee.com/OpenHarmony/arkcompiler_runtime_core/blob/master/static_core/plugins/ets/stdlib/README.md") 52 endif() 53 endforeach() 54endfunction() 55 56regenerate_and_check_stdlib() 57