mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-16 05:51:55 +00:00
Meta: Add a file containing a list of all emoji file names
And add a verification step to the emoji data generator to ensure all emoji are listed in this file. This file will be used as a sources list in both the CMake and GN build systems. It is probably possible to generate this list. But in a first attempt, the CMake code to set the file as a dependency of a pseudo target, which would then parse the file and install the listed emoji was getting quite verbose and complicated. So for now, let's just maintain this list.
This commit is contained in:
parent
2f85620b43
commit
91cd43a7ac
Notes:
sideshowbarker
2024-07-17 08:42:05 +09:00
Author: https://github.com/trflynn89
Commit: 91cd43a7ac
Pull-request: https://github.com/SerenityOS/serenity/pull/23643
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/nico
3 changed files with 2038 additions and 3 deletions
|
@ -31,6 +31,7 @@ struct Emoji {
|
|||
struct EmojiData {
|
||||
UniqueStringStorage unique_strings;
|
||||
Vector<Emoji> emojis;
|
||||
Vector<String> emoji_file_list;
|
||||
};
|
||||
|
||||
static void set_image_path_for_emoji(StringView emoji_resource_path, EmojiData& emoji_data, Emoji& emoji)
|
||||
|
@ -168,6 +169,28 @@ static ErrorOr<void> parse_emoji_serenity_data(Core::InputBufferedFile& file, Em
|
|||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> parse_emoji_file_list(Core::InputBufferedFile& file, EmojiData& emoji_data)
|
||||
{
|
||||
HashTable<String> seen_emojis;
|
||||
Array<u8, 1024> buffer;
|
||||
|
||||
while (TRY(file.can_read_line())) {
|
||||
auto line = TRY(file.read_line(buffer));
|
||||
if (line.is_empty())
|
||||
continue;
|
||||
|
||||
if (seen_emojis.contains(line)) {
|
||||
warnln("\x1b[1;31mError!\x1b[0m Duplicate emoji \x1b[35m{}\x1b[0m listed in emoji-file-list.txt.", line);
|
||||
return Error::from_errno(EEXIST);
|
||||
}
|
||||
|
||||
emoji_data.emoji_file_list.append(TRY(String::from_utf8(line)));
|
||||
seen_emojis.set(emoji_data.emoji_file_list.last());
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> validate_emoji(StringView emoji_resource_path, EmojiData& emoji_data)
|
||||
{
|
||||
TRY(Core::Directory::for_each_entry(emoji_resource_path, Core::DirIterator::SkipDots, [&](auto& entry, auto&) -> ErrorOr<IterationDecision> {
|
||||
|
@ -197,6 +220,11 @@ static ErrorOr<void> validate_emoji(StringView emoji_resource_path, EmojiData& e
|
|||
return Error::from_errno(ENOENT);
|
||||
}
|
||||
|
||||
if (!emoji_data.emoji_file_list.contains_slow(lexical_path.string().view())) {
|
||||
warnln("\x1b[1;31mError!\x1b[0m Emoji entry for \x1b[35m{}\x1b[0m not found. Please check emoji-file-list.txt.", lexical_path);
|
||||
return Error::from_errno(ENOENT);
|
||||
}
|
||||
|
||||
return IterationDecision::Continue;
|
||||
}));
|
||||
|
||||
|
@ -385,6 +413,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
StringView generated_installation_path;
|
||||
StringView emoji_test_path;
|
||||
StringView emoji_serenity_path;
|
||||
StringView emoji_file_list_path;
|
||||
StringView emoji_resource_path;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
|
@ -393,6 +422,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
args_parser.add_option(generated_installation_path, "Path to the emoji.txt file to generate", "generated-installation-path", 'i', "generated-installation-path");
|
||||
args_parser.add_option(emoji_test_path, "Path to emoji-test.txt file", "emoji-test-path", 'e', "emoji-test-path");
|
||||
args_parser.add_option(emoji_serenity_path, "Path to emoji-serenity.txt file", "emoji-serenity-path", 's', "emoji-serenity-path");
|
||||
args_parser.add_option(emoji_file_list_path, "Path to the emoji-file-list.txt file", "emoji-file-list-path", 'f', "emoji-file-list-path");
|
||||
args_parser.add_option(emoji_resource_path, "Path to the /res/emoji directory", "emoji-resource-path", 'r', "emoji-resource-path");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
|
@ -403,10 +433,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
EmojiData emoji_data {};
|
||||
TRY(parse_emoji_test_data(*emoji_test_file, emoji_data));
|
||||
|
||||
if (!emoji_serenity_path.is_empty()) {
|
||||
if (!emoji_serenity_path.is_empty() && !emoji_file_list_path.is_empty()) {
|
||||
auto emoji_serenity_file = TRY(open_file(emoji_serenity_path, Core::File::OpenMode::Read));
|
||||
TRY(parse_emoji_serenity_data(*emoji_serenity_file, emoji_data));
|
||||
|
||||
auto emoji_file_list_file = TRY(open_file(emoji_file_list_path, Core::File::OpenMode::Read));
|
||||
TRY(parse_emoji_file_list(*emoji_file_list_file, emoji_data));
|
||||
|
||||
TRY(validate_emoji(emoji_resource_path, emoji_data));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue