blob: 050d131fa2c4c422cc77f4c3732c0600b0635ba7 [file] [log] [blame]
# Copyright 2023 The Dawn & Tint Authors
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Adapted from https://source.chromium.org/chromium/chromium/src/+/main:build/win/message_compiler.gni;l=1?q=message_compiler.gni&sq=&ss=chromium
# To support cross-compilation from a non-Windows host to a Windows target,
# the files generated by mc.exe are expected to be copied and committed
# to "../win_build_output/". When running this script, the files in this
# directory are copied to $output_dir. On Windows hosts, the script will
# run mc.exe against the input source files, and validate that the generated
# files match what's in "../win_build_output/", failing if they do not.
# If mismatched, presumably the source files have changed, and the newly
# generated files should be copied and committed to "../win_build_output/".
#
# sources
# List of message files to process.
#
# deps, public_deps, visibility
# Normal meaning.
template("message_compiler") {
extra_args = []
if (defined(invoker.extra_args)) {
extra_args = invoker.extra_args
}
output_dir = "$target_gen_dir"
if (defined(invoker.output_dir)) {
output_dir = invoker.output_dir
}
action_foreach(target_name) {
forward_variables_from(invoker, [ "visibility" ])
script = "build/message_compiler.py"
outputs = [
"$output_dir/{{source_name_part}}.h",
"$output_dir/{{source_name_part}}.rc",
]
args = [
# The first argument is the environment file saved to the build
# directory. This is required because the Windows toolchain setup saves
# the VC paths and such so that running "mc.exe" will work with the
# configured toolchain. This file is in the root build dir.
"environment.$current_cpu",
# Where to put the header.
"-h",
rebase_path(output_dir, root_build_dir),
# Where to put the .rc file.
"-r",
rebase_path(output_dir, root_build_dir),
# Input is Unicode.
"-u",
]
args += extra_args
args += [ "{{source}}" ]
forward_variables_from(invoker,
[
"deps",
"public_deps",
"sources",
])
}
}