mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +00:00
Meta: Make embed_as_string_view.py
usable by CMake builds :^)
This commit is contained in:
parent
4ead33d8fc
commit
af4642c826
3 changed files with 21 additions and 1 deletions
38
Meta/embed_as_string_view.py
Normal file
38
Meta/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