# Copyright (c) 2026 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Data layout under build dir (paths in arktsconfig are resolved to absolutes when es2panda loads the config).
set(RFPA_DATA_DIR "${CMAKE_CURRENT_BINARY_DIR}/relative_file_path_alias_data")
file(MAKE_DIRECTORY "${RFPA_DATA_DIR}/src/mod")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/entry.ets" "${RFPA_DATA_DIR}/src/mod/entry.ets" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/decl_entry.d.ets" "${RFPA_DATA_DIR}/src/mod/decl_entry.d.ets" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/flat_file.ets" "${RFPA_DATA_DIR}/flat_file.ets" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/flat_decl_file.d.ets" "${RFPA_DATA_DIR}/flat_decl_file.d.ets" COPYONLY)

get_filename_component(ETS_STDLIB_JSON_PATH "${PANDA_ROOT}/plugins/ets/stdlib/std" ABSOLUTE)
get_filename_component(ETS_ESCOMPAT_JSON_PATH "${PANDA_ROOT}/plugins/ets/stdlib/escompat" ABSOLUTE)
# JSON / compiler accept forward slashes on all host platforms
string(REPLACE "\\" "/" ETS_STDLIB_JSON_PATH "${ETS_STDLIB_JSON_PATH}")
string(REPLACE "\\" "/" ETS_ESCOMPAT_JSON_PATH "${ETS_ESCOMPAT_JSON_PATH}")

configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/arktsconfig.in.json"
    "${RFPA_DATA_DIR}/arktsconfig.json"
    @ONLY
)

set(RFPA_CONFIG_H "${ES2PANDA_BINARY_ROOT}/relative_file_path_alias_paths.h")
string(REPLACE "\\" "/" RFPA_DATA_DIR_FWD "${RFPA_DATA_DIR}")
file(WRITE "${RFPA_CONFIG_H}"
"/* Generated by CMake: do not edit */
#pragma once
static constexpr const char RFPA_DATA_DIR[] = \"${RFPA_DATA_DIR_FWD}\";
")

ets2panda_add_gtest(relative_file_path_alias_test
    CPP_SOURCES
        relative_file_path_alias_test.cpp
)
