# Copyright (c) 2022-2025 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.
# You may obtain a copy of the License at
#
#     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.

import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
import("//foundation/arkui/ace_engine/build/ace_gen_obj.gni")

template("gen_js_src_binary") {
  es2abc_gen_abc("gen_abc_" + target_name) {
    src_js = rebase_path(invoker.js_source)
    dst_file = rebase_path(target_out_dir + "/" +
                           get_path_info(invoker.js_source, "name") + ".abc")
    in_puts = [ invoker.js_source ]
    out_puts = [ target_out_dir + "/" +
                 get_path_info(invoker.js_source, "name") + ".abc" ]
    extra_args = [ "--module" ]
  }

  gen_obj(target_name + "_js") {
    input = invoker.js_source

    if (is_mac || is_mingw) {
      output = target_out_dir + "/" + invoker.target_name + "_js.c"
    } else {
      output = target_out_dir + "/" + invoker.target_name + "_js.o"
    }

    snapshot_dep = []
  }

  gen_obj(target_name + "_abc") {
    input =
        get_label_info(":gen_abc_" + invoker.target_name, "target_out_dir") +
        "/" + get_path_info(invoker.js_source, "name") + ".abc"

    if (is_mac || is_mingw) {
      output = target_out_dir + "/" + invoker.target_name + "_abc.c"
    } else {
      output = target_out_dir + "/" + invoker.target_name + "_abc.o"
    }

    snapshot_dep = [ ":gen_abc_" + invoker.target_name ]
  }
}