mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 09:21:57 -05:00
Meta: Make embed_as_string_view.py produce Strings instead
This is only used for CSS style sheets. One case wants it as a String, and the others don't care, but will in future also want to have the source as a String. (cherry picked from commit 8cbc2116162764479edeec78e4b2b7c41447b643; amended to fix conflicts in two cmake files, due to serenity still having more code_generators, and still buildling OutOfProcessWebView.cpp. Also kept embed_as_string_view because it's used by stringify_gml. Did this by giving embed_as_string.py a --type= argument that defaults to string but can also be set to string-view.)
This commit is contained in:
parent
abf7a72545
commit
5d86305596
9 changed files with 63 additions and 30 deletions
|
@ -2,6 +2,27 @@
|
||||||
# Functions for generating sources using host tools
|
# Functions for generating sources using host tools
|
||||||
#
|
#
|
||||||
|
|
||||||
|
function(embed_as_string name source_file output source_variable_name)
|
||||||
|
cmake_parse_arguments(PARSE_ARGV 4 EMBED_STRING_VIEW "" "NAMESPACE" "")
|
||||||
|
set(namespace_arg "")
|
||||||
|
if (EMBED_STRING_VIEW_NAMESPACE)
|
||||||
|
set(namespace_arg "-s ${EMBED_STRING_VIEW_NAMESPACE}")
|
||||||
|
endif()
|
||||||
|
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${output}"
|
||||||
|
COMMAND "${Python3_EXECUTABLE}" "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string.py" "${source_file}" -o "${output}.tmp" -n "${source_variable_name}" ${namespace_arg}
|
||||||
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${output}.tmp" "${output}"
|
||||||
|
COMMAND "${CMAKE_COMMAND}" -E remove "${output}.tmp"
|
||||||
|
VERBATIM
|
||||||
|
DEPENDS "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string.py"
|
||||||
|
MAIN_DEPENDENCY "${source_file}"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target("generate_${name}" DEPENDS "${output}")
|
||||||
|
add_dependencies(all_generated "generate_${name}")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(embed_as_string_view name source_file output source_variable_name)
|
function(embed_as_string_view name source_file output source_variable_name)
|
||||||
cmake_parse_arguments(PARSE_ARGV 4 EMBED_STRING_VIEW "" "NAMESPACE" "")
|
cmake_parse_arguments(PARSE_ARGV 4 EMBED_STRING_VIEW "" "NAMESPACE" "")
|
||||||
set(namespace_arg "")
|
set(namespace_arg "")
|
||||||
|
@ -11,11 +32,11 @@ function(embed_as_string_view name source_file output source_variable_name)
|
||||||
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${output}"
|
OUTPUT "${output}"
|
||||||
COMMAND "${Python3_EXECUTABLE}" "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string_view.py" "${source_file}" -o "${output}.tmp" -n "${source_variable_name}" ${namespace_arg}
|
COMMAND "${Python3_EXECUTABLE}" "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string.py" --type=string-view "${source_file}" -o "${output}.tmp" -n "${source_variable_name}" ${namespace_arg}
|
||||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${output}.tmp" "${output}"
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${output}.tmp" "${output}"
|
||||||
COMMAND "${CMAKE_COMMAND}" -E remove "${output}.tmp"
|
COMMAND "${CMAKE_COMMAND}" -E remove "${output}.tmp"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
DEPENDS "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string_view.py"
|
DEPENDS "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string.py"
|
||||||
MAIN_DEPENDENCY "${source_file}"
|
MAIN_DEPENDENCY "${source_file}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ function (generate_css_implementation)
|
||||||
arguments -j "${LIBWEB_INPUT_FOLDER}/CSS/Keywords.json"
|
arguments -j "${LIBWEB_INPUT_FOLDER}/CSS/Keywords.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
embed_as_string_view(
|
embed_as_string(
|
||||||
"DefaultStyleSheetSource.cpp"
|
"DefaultStyleSheetSource.cpp"
|
||||||
"${LIBWEB_INPUT_FOLDER}/CSS/Default.css"
|
"${LIBWEB_INPUT_FOLDER}/CSS/Default.css"
|
||||||
"CSS/DefaultStyleSheetSource.cpp"
|
"CSS/DefaultStyleSheetSource.cpp"
|
||||||
|
@ -72,7 +72,7 @@ function (generate_css_implementation)
|
||||||
NAMESPACE "Web::CSS"
|
NAMESPACE "Web::CSS"
|
||||||
)
|
)
|
||||||
|
|
||||||
embed_as_string_view(
|
embed_as_string(
|
||||||
"QuirksModeStyleSheetSource.cpp"
|
"QuirksModeStyleSheetSource.cpp"
|
||||||
"${LIBWEB_INPUT_FOLDER}/CSS/QuirksMode.css"
|
"${LIBWEB_INPUT_FOLDER}/CSS/QuirksMode.css"
|
||||||
"CSS/QuirksModeStyleSheetSource.cpp"
|
"CSS/QuirksModeStyleSheetSource.cpp"
|
||||||
|
@ -80,7 +80,7 @@ function (generate_css_implementation)
|
||||||
NAMESPACE "Web::CSS"
|
NAMESPACE "Web::CSS"
|
||||||
)
|
)
|
||||||
|
|
||||||
embed_as_string_view(
|
embed_as_string(
|
||||||
"MathMLStyleSheetSource.cpp"
|
"MathMLStyleSheetSource.cpp"
|
||||||
"${LIBWEB_INPUT_FOLDER}/MathML/Default.css"
|
"${LIBWEB_INPUT_FOLDER}/MathML/Default.css"
|
||||||
"MathML/MathMLStyleSheetSource.cpp"
|
"MathML/MathMLStyleSheetSource.cpp"
|
||||||
|
@ -88,7 +88,7 @@ function (generate_css_implementation)
|
||||||
NAMESPACE "Web::CSS"
|
NAMESPACE "Web::CSS"
|
||||||
)
|
)
|
||||||
|
|
||||||
embed_as_string_view(
|
embed_as_string(
|
||||||
"SVGStyleSheetSource.cpp"
|
"SVGStyleSheetSource.cpp"
|
||||||
"${LIBWEB_INPUT_FOLDER}/SVG/Default.css"
|
"${LIBWEB_INPUT_FOLDER}/SVG/Default.css"
|
||||||
"SVG/SVGStyleSheetSource.cpp"
|
"SVG/SVGStyleSheetSource.cpp"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
r"""
|
r"""
|
||||||
Embeds a file into a StringView, a la #embed from C++23
|
Embeds a file as a String or StringView, a la #embed from C++23
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -12,6 +12,8 @@ def main():
|
||||||
epilog=__doc__,
|
epilog=__doc__,
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
parser.add_argument('input', help='input file to stringify')
|
parser.add_argument('input', help='input file to stringify')
|
||||||
|
parser.add_argument('--type', choices=['string', 'string-view'],
|
||||||
|
default='string')
|
||||||
parser.add_argument('-o', '--output', required=True,
|
parser.add_argument('-o', '--output', required=True,
|
||||||
help='output file')
|
help='output file')
|
||||||
parser.add_argument('-n', '--variable-name', required=True,
|
parser.add_argument('-n', '--variable-name', required=True,
|
||||||
|
@ -21,15 +23,25 @@ def main():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
with open(args.output, 'w') as f:
|
with open(args.output, 'w') as f:
|
||||||
f.write("#include <AK/StringView.h>\n")
|
if args.type == 'string':
|
||||||
|
f.write("#include <AK/String.h>\n")
|
||||||
|
elif args.type == 'string-view':
|
||||||
|
f.write("#include <AK/StringView.h>\n")
|
||||||
if args.namespace:
|
if args.namespace:
|
||||||
f.write(f"namespace {args.namespace} {{\n")
|
f.write(f"namespace {args.namespace} {{\n")
|
||||||
f.write(f"extern StringView {args.variable_name};\n")
|
if args.type == 'string':
|
||||||
f.write(f"StringView {args.variable_name} = R\"~~~(")
|
f.write(f"extern String {args.variable_name};\n")
|
||||||
|
f.write(f"String {args.variable_name} = R\"~~~(")
|
||||||
|
elif args.type == 'string-view':
|
||||||
|
f.write(f"extern StringView {args.variable_name};\n")
|
||||||
|
f.write(f"StringView {args.variable_name} = R\"~~~(")
|
||||||
with open(args.input, 'r') as input:
|
with open(args.input, 'r') as input:
|
||||||
for line in input.readlines():
|
for line in input.readlines():
|
||||||
f.write(f"{line}")
|
f.write(f"{line}")
|
||||||
f.write(")~~~\"sv;\n")
|
if args.type == 'string':
|
||||||
|
f.write(")~~~\"_string;\n")
|
||||||
|
elif args.type == 'string-view':
|
||||||
|
f.write(")~~~\"sv;\n")
|
||||||
if args.namespace:
|
if args.namespace:
|
||||||
f.write("}\n")
|
f.write("}\n")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# This file introduces a template for calling embed_as_string_view.py.
|
# This file introduces a template for calling embed_as_string.py.
|
||||||
#
|
#
|
||||||
# embed_as_string_view behaves like C++23 #embed, converting an input file into
|
# embed_as_string behaves like C++23 #embed, converting an input file into
|
||||||
# an AK::StringView literal rather than a C-string literal. The literal will
|
# 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.
|
# be placed into a global variable, optionally with a namespace wrapping it.
|
||||||
#
|
#
|
||||||
|
@ -19,21 +19,21 @@
|
||||||
#
|
#
|
||||||
# Example use:
|
# Example use:
|
||||||
#
|
#
|
||||||
# embed_as_string_view("embed_my_file") {
|
# embed_as_string("embed_my_file") {
|
||||||
# input = "MyFile.txt"
|
# input = "MyFile.txt"
|
||||||
# output = "$root_gen_dir/MyDirectory/MyFile.cpp"
|
# output = "$root_gen_dir/MyDirectory/MyFile.cpp"
|
||||||
# variable_name = "my_file_contents"
|
# variable_name = "my_file_contents"
|
||||||
# namespace = "My::NS"
|
# namespace = "My::NS"
|
||||||
# }
|
# }
|
||||||
|
|
||||||
template("embed_as_string_view") {
|
template("embed_as_string") {
|
||||||
assert(defined(invoker.input), "must set 'input' in $target_name")
|
assert(defined(invoker.input), "must set 'input' in $target_name")
|
||||||
assert(defined(invoker.output), "must set 'output' in $target_name")
|
assert(defined(invoker.output), "must set 'output' in $target_name")
|
||||||
assert(defined(invoker.variable_name),
|
assert(defined(invoker.variable_name),
|
||||||
"must set 'variable_name' in $target_name")
|
"must set 'variable_name' in $target_name")
|
||||||
|
|
||||||
action(target_name) {
|
action(target_name) {
|
||||||
script = "//Meta/embed_as_string_view.py"
|
script = "//Meta/embed_as_string.py"
|
||||||
|
|
||||||
sources = [ invoker.input ]
|
sources = [ invoker.input ]
|
||||||
outputs = [ invoker.output ]
|
outputs = [ invoker.output ]
|
|
@ -1,5 +1,5 @@
|
||||||
import("//Meta/gn/build/compiled_action.gni")
|
import("//Meta/gn/build/compiled_action.gni")
|
||||||
import("//Meta/gn/build/embed_as_string_view.gni")
|
import("//Meta/gn/build/embed_as_string.gni")
|
||||||
import("generate_idl_bindings.gni")
|
import("generate_idl_bindings.gni")
|
||||||
import("idl_files.gni")
|
import("idl_files.gni")
|
||||||
|
|
||||||
|
@ -220,28 +220,28 @@ compiled_action("generate_css_keyword") {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
embed_as_string_view("generate_default_stylesheet_source") {
|
embed_as_string("generate_default_stylesheet_source") {
|
||||||
input = "CSS/Default.css"
|
input = "CSS/Default.css"
|
||||||
output = "$target_gen_dir/CSS/DefaultStyleSheetSource.cpp"
|
output = "$target_gen_dir/CSS/DefaultStyleSheetSource.cpp"
|
||||||
variable_name = "default_stylesheet_source"
|
variable_name = "default_stylesheet_source"
|
||||||
namespace = "Web::CSS"
|
namespace = "Web::CSS"
|
||||||
}
|
}
|
||||||
|
|
||||||
embed_as_string_view("generate_mathml_stylesheet_source") {
|
embed_as_string("generate_mathml_stylesheet_source") {
|
||||||
input = "MathML/Default.css"
|
input = "MathML/Default.css"
|
||||||
output = "$target_gen_dir/MathML/MathMLStyleSheetSource.cpp"
|
output = "$target_gen_dir/MathML/MathMLStyleSheetSource.cpp"
|
||||||
variable_name = "mathml_stylesheet_source"
|
variable_name = "mathml_stylesheet_source"
|
||||||
namespace = "Web::CSS"
|
namespace = "Web::CSS"
|
||||||
}
|
}
|
||||||
|
|
||||||
embed_as_string_view("generate_svg_stylesheet_source") {
|
embed_as_string("generate_svg_stylesheet_source") {
|
||||||
input = "SVG/Default.css"
|
input = "SVG/Default.css"
|
||||||
output = "$target_gen_dir/SVG/SVGStyleSheetSource.cpp"
|
output = "$target_gen_dir/SVG/SVGStyleSheetSource.cpp"
|
||||||
variable_name = "svg_stylesheet_source"
|
variable_name = "svg_stylesheet_source"
|
||||||
namespace = "Web::CSS"
|
namespace = "Web::CSS"
|
||||||
}
|
}
|
||||||
|
|
||||||
embed_as_string_view("generate_quirks_mode_stylesheet_source") {
|
embed_as_string("generate_quirks_mode_stylesheet_source") {
|
||||||
input = "CSS/QuirksMode.css"
|
input = "CSS/QuirksMode.css"
|
||||||
output = "$target_gen_dir/CSS/QuirksModeStyleSheetSource.cpp"
|
output = "$target_gen_dir/CSS/QuirksModeStyleSheetSource.cpp"
|
||||||
variable_name = "quirks_mode_stylesheet_source"
|
variable_name = "quirks_mode_stylesheet_source"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import("//Meta/gn/build/compiled_action.gni")
|
import("//Meta/gn/build/compiled_action.gni")
|
||||||
import("//Meta/gn/build/download_cache.gni")
|
import("//Meta/gn/build/download_cache.gni")
|
||||||
import("//Meta/gn/build/download_file.gni")
|
import("//Meta/gn/build/download_file.gni")
|
||||||
import("//Meta/gn/build/embed_as_string_view.gni")
|
import("//Meta/gn/build/embed_as_string.gni")
|
||||||
|
|
||||||
declare_args() {
|
declare_args() {
|
||||||
# If true, Download public suffix list from GitHub.
|
# If true, Download public suffix list from GitHub.
|
||||||
|
@ -106,7 +106,7 @@ compiled_action("UIProcessServerEndpoint") {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
embed_as_string_view("generate_native_stylesheet_source") {
|
embed_as_string("generate_native_stylesheet_source") {
|
||||||
input = "Native.css"
|
input = "Native.css"
|
||||||
output = "$target_gen_dir/NativeStyleSheetSource.cpp"
|
output = "$target_gen_dir/NativeStyleSheetSource.cpp"
|
||||||
variable_name = "native_stylesheet_source"
|
variable_name = "native_stylesheet_source"
|
||||||
|
|
|
@ -224,7 +224,7 @@ static CSSStyleSheet& default_stylesheet(DOM::Document const& document)
|
||||||
{
|
{
|
||||||
static JS::Handle<CSSStyleSheet> sheet;
|
static JS::Handle<CSSStyleSheet> sheet;
|
||||||
if (!sheet.cell()) {
|
if (!sheet.cell()) {
|
||||||
extern StringView default_stylesheet_source;
|
extern String default_stylesheet_source;
|
||||||
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), default_stylesheet_source));
|
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), default_stylesheet_source));
|
||||||
}
|
}
|
||||||
return *sheet;
|
return *sheet;
|
||||||
|
@ -234,7 +234,7 @@ static CSSStyleSheet& quirks_mode_stylesheet(DOM::Document const& document)
|
||||||
{
|
{
|
||||||
static JS::Handle<CSSStyleSheet> sheet;
|
static JS::Handle<CSSStyleSheet> sheet;
|
||||||
if (!sheet.cell()) {
|
if (!sheet.cell()) {
|
||||||
extern StringView quirks_mode_stylesheet_source;
|
extern String quirks_mode_stylesheet_source;
|
||||||
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), quirks_mode_stylesheet_source));
|
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), quirks_mode_stylesheet_source));
|
||||||
}
|
}
|
||||||
return *sheet;
|
return *sheet;
|
||||||
|
@ -244,7 +244,7 @@ static CSSStyleSheet& mathml_stylesheet(DOM::Document const& document)
|
||||||
{
|
{
|
||||||
static JS::Handle<CSSStyleSheet> sheet;
|
static JS::Handle<CSSStyleSheet> sheet;
|
||||||
if (!sheet.cell()) {
|
if (!sheet.cell()) {
|
||||||
extern StringView mathml_stylesheet_source;
|
extern String mathml_stylesheet_source;
|
||||||
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), mathml_stylesheet_source));
|
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), mathml_stylesheet_source));
|
||||||
}
|
}
|
||||||
return *sheet;
|
return *sheet;
|
||||||
|
@ -254,7 +254,7 @@ static CSSStyleSheet& svg_stylesheet(DOM::Document const& document)
|
||||||
{
|
{
|
||||||
static JS::Handle<CSSStyleSheet> sheet;
|
static JS::Handle<CSSStyleSheet> sheet;
|
||||||
if (!sheet.cell()) {
|
if (!sheet.cell()) {
|
||||||
extern StringView svg_stylesheet_source;
|
extern String svg_stylesheet_source;
|
||||||
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), svg_stylesheet_source));
|
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), svg_stylesheet_source));
|
||||||
}
|
}
|
||||||
return *sheet;
|
return *sheet;
|
||||||
|
|
|
@ -25,7 +25,7 @@ if (SERENITYOS)
|
||||||
list(APPEND SOURCES OutOfProcessWebView.cpp)
|
list(APPEND SOURCES OutOfProcessWebView.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
embed_as_string_view(
|
embed_as_string(
|
||||||
"NativeStyleSheetSource.cpp"
|
"NativeStyleSheetSource.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Native.css"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Native.css"
|
||||||
"NativeStyleSheetSource.cpp"
|
"NativeStyleSheetSource.cpp"
|
||||||
|
|
|
@ -624,8 +624,8 @@ void ViewImplementation::set_user_style_sheet(String source)
|
||||||
|
|
||||||
void ViewImplementation::use_native_user_style_sheet()
|
void ViewImplementation::use_native_user_style_sheet()
|
||||||
{
|
{
|
||||||
extern StringView native_stylesheet_source;
|
extern String native_stylesheet_source;
|
||||||
set_user_style_sheet(MUST(String::from_utf8(native_stylesheet_source)));
|
set_user_style_sheet(native_stylesheet_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewImplementation::enable_inspector_prototype()
|
void ViewImplementation::enable_inspector_prototype()
|
||||||
|
|
Loading…
Reference in a new issue