Enable -Wexit-time-destructors for all in-tree library targets and update process-lifetime library statics so they no longer register exit-time destructors. Long-lived caches, lookup tables, singleton registries, and generated constants now use NeverDestroyed or leaked references where the data is intended to live until process exit. Update LibWeb, LibLine, and the binding generators so regenerated sources follow the same rule instead of reintroducing destructed statics.
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
r"""
|
|
Embeds a file into a String, 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", encoding="utf-8") as f:
|
|
f.write("#include <AK/String.h>\n")
|
|
if args.namespace:
|
|
f.write(f"namespace {args.namespace} {{\n")
|
|
f.write(f"extern String const& {args.variable_name};\n")
|
|
f.write(f'String const& {args.variable_name} = *new String(R"~~~(')
|
|
with open(args.input, "r", encoding="utf-8") as input:
|
|
for line in input.readlines():
|
|
f.write(f"{line}")
|
|
f.write(')~~~"_string);\n')
|
|
if args.namespace:
|
|
f.write("}\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|