mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:37:34 +00:00
Meta: Add gn build rules for LibWeb
This commit is contained in:
parent
7b3d0fb002
commit
85c8cd5205
60 changed files with 1966 additions and 0 deletions
64
Meta/gn/build/embed_as_string_view.gni
Normal file
64
Meta/gn/build/embed_as_string_view.gni
Normal file
|
@ -0,0 +1,64 @@
|
|||
# This file introduces a template for calling embed_as_string_view.py.
|
||||
#
|
||||
# embed_as_string_view behaves like C++23 #embed, converting an input file into
|
||||
# an AK::StringView literal rather than a C-string literal. The literal will
|
||||
# be placed into a global variable, optionally with a namespace wrapping it.
|
||||
#
|
||||
# Note that the file must not contain any tokens that need to be escaped
|
||||
# in C++, or the script will fail to produce a valid C++ translation unit.
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# input (required) [string]
|
||||
#
|
||||
# output (required) [string]
|
||||
#
|
||||
# variable_name (required) [string]
|
||||
#
|
||||
# namespace (optional) [string]
|
||||
#
|
||||
# Example use:
|
||||
#
|
||||
# embed_as_string_view("embed_my_file") {
|
||||
# input = "MyFile.txt"
|
||||
# output = "$root_gen_dir/MyDirectory/MyFile.cpp"
|
||||
# variable_name = "my_file_contents"
|
||||
# namespace = "My::NS"
|
||||
# }
|
||||
|
||||
template("embed_as_string_view") {
|
||||
assert(defined(invoker.input), "must set 'input' in $target_name")
|
||||
assert(defined(invoker.output), "must set 'output' in $target_name")
|
||||
assert(defined(invoker.variable_name),
|
||||
"must set 'variable_name' in $target_name")
|
||||
|
||||
action(target_name) {
|
||||
script = "//Meta/gn/build/embed_as_string_view.py"
|
||||
|
||||
sources = [ invoker.input ]
|
||||
outputs = [ invoker.output ]
|
||||
args = [
|
||||
"-o",
|
||||
rebase_path(outputs[0], root_build_dir),
|
||||
"-n",
|
||||
invoker.variable_name,
|
||||
]
|
||||
if (defined(invoker.namespace)) {
|
||||
args += [
|
||||
"-s",
|
||||
invoker.namespace,
|
||||
]
|
||||
}
|
||||
args += [ rebase_path(sources[0], root_build_dir) ]
|
||||
|
||||
forward_variables_from(invoker,
|
||||
[
|
||||
"configs",
|
||||
"deps",
|
||||
"public_configs",
|
||||
"public_deps",
|
||||
"testonly",
|
||||
"visibility",
|
||||
])
|
||||
}
|
||||
}
|
38
Meta/gn/build/embed_as_string_view.py
Normal file
38
Meta/gn/build/embed_as_string_view.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
r"""
|
||||
Embeds a file into a StringView, a la #embed from C++23
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
epilog=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument('input', help='input file to stringify')
|
||||
parser.add_argument('-o', '--output', required=True,
|
||||
help='output file')
|
||||
parser.add_argument('-n', '--variable-name', required=True,
|
||||
help='name of the C++ variable')
|
||||
parser.add_argument('-s', '--namespace', required=False,
|
||||
help='C++ namespace to put the string into')
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.output, 'w') as f:
|
||||
f.write("#include <AK/StringView.h>\n")
|
||||
if args.namespace:
|
||||
f.write(f"namespace {args.namespace} {{\n")
|
||||
f.write(f"extern StringView {args.variable_name};\n")
|
||||
f.write(f"StringView {args.variable_name} = R\"~~~(")
|
||||
with open(args.input, 'r') as input:
|
||||
for line in input.readlines():
|
||||
f.write(f"{line}")
|
||||
f.write(")~~~\"sv;\n")
|
||||
if args.namespace:
|
||||
f.write("}\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
Loading…
Add table
Add a link
Reference in a new issue