| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # This file introduces a template that allows you to compile a given JavaScript |
| # source file for use with quickjs. |
| # |
| # Parameters |
| # |
| # source (required) |
| # A JS file to compile. |
| # |
| # module |
| # Set to true if quickjs should treat this source as a JavaScript module. |
| |
| import("//build/compiled_action.gni") |
| |
| template("compiled_js") { |
| generate_target = "${target_name}_gen" |
| generated_file = "${target_gen_dir}/${target_name}.c" |
| |
| compiled_action(generate_target) { |
| tool = "//third_party/quickjs:qjsc" |
| inputs = [ |
| invoker.source, |
| ] |
| outputs = [ |
| generated_file, |
| ] |
| args = [ |
| "-c", |
| "-o", |
| rebase_path(generated_file, root_build_dir), |
| ] |
| if (defined(invoker.module) && invoker.module) { |
| args += [ "-m" ] |
| } |
| if (defined(invoker.extra_args)) { |
| args += invoker.extra_args |
| } |
| |
| args += [ rebase_path(invoker.source) ] |
| } |
| |
| source_set(target_name) { |
| sources = [ |
| generated_file, |
| ] |
| deps = [ |
| ":${generate_target}", |
| ] |
| } |
| } |