mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
HackStudio: Change ProjectBuilder dependency declaration logic
Previously when generating the HackStudio CMake build file, we used all dependency libraries that are specified in target_link_libraries commands as the dependencies of a library. The recent addition of LibCryptSHA2 broke things because that library is not declared with serenity_lib like most other libraries (it uses special linking properties). This means that we don't declare it in the CMake file we generate. To fix this, we now filter the dependencies and only include libraries that we define in the build CMake file.
This commit is contained in:
parent
404daa0e33
commit
0367893e53
2 changed files with 50 additions and 14 deletions
|
@ -147,14 +147,45 @@ String ProjectBuilder::generate_cmake_file_content() const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.appendff("add_subdirectory({})\n", LexicalPath::dirname(m_serenity_component_cmake_file));
|
builder.appendff("add_subdirectory({})\n", LexicalPath::dirname(m_serenity_component_cmake_file));
|
||||||
generate_cmake_library_definitions(builder);
|
|
||||||
builder.append('\n');
|
auto defined_libraries = get_defined_libraries();
|
||||||
generate_cmake_library_dependencies(builder);
|
for (auto& library : defined_libraries) {
|
||||||
|
builder.appendff("add_library({} SHARED IMPORTED GLOBAL)\n", library.key);
|
||||||
|
builder.appendff("set_target_properties({} PROPERTIES IMPORTED_LOCATION {})\n", library.key, library.value->path);
|
||||||
|
|
||||||
|
if (library.key == "LibCStaticWithoutDeps"sv || library.key == "DumpLayoutTree"sv)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// We need to specify the dependencies for each defined library in CMake because some applications do not specify
|
||||||
|
// all of their direct dependencies in the CMakeLists file.
|
||||||
|
// For example, a target may directly use LibGFX but only specify LibGUI as a dependency (which in turn depends on LibGFX).
|
||||||
|
// In this example, if we don't specify the dependencies of LibGUI in the CMake file, linking will fail because of undefined LibGFX symbols.
|
||||||
|
builder.appendff("target_link_libraries({} INTERFACE {})\n", library.key, String::join(' ', library.value->dependencies));
|
||||||
|
}
|
||||||
|
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectBuilder::generate_cmake_library_definitions(StringBuilder& builder)
|
HashMap<String, NonnullOwnPtr<ProjectBuilder::LibraryInfo>> ProjectBuilder::get_defined_libraries()
|
||||||
|
{
|
||||||
|
HashMap<String, NonnullOwnPtr<ProjectBuilder::LibraryInfo>> libraries;
|
||||||
|
|
||||||
|
for_each_library_definition([&libraries](String name, String path) {
|
||||||
|
libraries.set(name, make<ProjectBuilder::LibraryInfo>(move(path)));
|
||||||
|
});
|
||||||
|
for_each_library_dependencies([&libraries](String name, Vector<StringView> const& dependencies) {
|
||||||
|
auto library = libraries.get(name);
|
||||||
|
if (!library.has_value())
|
||||||
|
return;
|
||||||
|
for (auto const& dependency : dependencies) {
|
||||||
|
if (libraries.contains(dependency))
|
||||||
|
library.value()->dependencies.append(dependency);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return libraries;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProjectBuilder::for_each_library_definition(Function<void(String, String)> func)
|
||||||
{
|
{
|
||||||
Vector<String> arguments = { "sh", "-c", "find Userland/Libraries -name CMakeLists.txt | xargs grep serenity_lib" };
|
Vector<String> arguments = { "sh", "-c", "find Userland/Libraries -name CMakeLists.txt | xargs grep serenity_lib" };
|
||||||
auto res = Core::command("/bin/sh", arguments, {});
|
auto res = Core::command("/bin/sh", arguments, {});
|
||||||
|
@ -165,7 +196,6 @@ void ProjectBuilder::generate_cmake_library_definitions(StringBuilder& builder)
|
||||||
|
|
||||||
static const Regex<ECMA262> parse_library_definition(R"~~~(.+:serenity_lib[c]?\((\w+) (\w+)\).*)~~~");
|
static const Regex<ECMA262> parse_library_definition(R"~~~(.+:serenity_lib[c]?\((\w+) (\w+)\).*)~~~");
|
||||||
for (auto& line : res.value().stdout.split('\n')) {
|
for (auto& line : res.value().stdout.split('\n')) {
|
||||||
|
|
||||||
RegexResult result;
|
RegexResult result;
|
||||||
if (!parse_library_definition.search(line, result))
|
if (!parse_library_definition.search(line, result))
|
||||||
continue;
|
continue;
|
||||||
|
@ -174,13 +204,15 @@ void ProjectBuilder::generate_cmake_library_definitions(StringBuilder& builder)
|
||||||
|
|
||||||
auto library_name = result.capture_group_matches.at(0).at(0).view.string_view();
|
auto library_name = result.capture_group_matches.at(0).at(0).view.string_view();
|
||||||
auto library_obj_name = result.capture_group_matches.at(0).at(1).view.string_view();
|
auto library_obj_name = result.capture_group_matches.at(0).at(1).view.string_view();
|
||||||
builder.appendff("add_library({} SHARED IMPORTED GLOBAL)\n", library_name);
|
|
||||||
auto so_path = String::formatted("{}.so", LexicalPath::join("/usr/lib"sv, String::formatted("lib{}", library_obj_name)).string());
|
auto so_path = String::formatted("{}.so", LexicalPath::join("/usr/lib"sv, String::formatted("lib{}", library_obj_name)).string());
|
||||||
builder.appendff("set_target_properties({} PROPERTIES IMPORTED_LOCATION {})\n", library_name, so_path);
|
func(library_name, so_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ssp is defined with "add_library" so it doesn't get picked up with the current logic for finding library definitions.
|
||||||
|
func("ssp", "/usr/lib/libssp.a");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectBuilder::generate_cmake_library_dependencies(StringBuilder& builder)
|
void ProjectBuilder::for_each_library_dependencies(Function<void(String, Vector<StringView>)> func)
|
||||||
{
|
{
|
||||||
Vector<String> arguments = { "sh", "-c", "find Userland/Libraries -name CMakeLists.txt | xargs grep target_link_libraries" };
|
Vector<String> arguments = { "sh", "-c", "find Userland/Libraries -name CMakeLists.txt | xargs grep target_link_libraries" };
|
||||||
auto res = Core::command("/bin/sh", arguments, {});
|
auto res = Core::command("/bin/sh", arguments, {});
|
||||||
|
@ -199,10 +231,9 @@ void ProjectBuilder::generate_cmake_library_dependencies(StringBuilder& builder)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto library_name = result.capture_group_matches.at(0).at(0).view.string_view();
|
auto library_name = result.capture_group_matches.at(0).at(0).view.string_view();
|
||||||
auto dependencies = result.capture_group_matches.at(0).at(1).view.string_view();
|
auto dependencies_string = result.capture_group_matches.at(0).at(1).view.string_view();
|
||||||
if (library_name == "LibCStaticWithoutDeps"sv || library_name == "DumpLayoutTree"sv)
|
|
||||||
continue;
|
func(library_name, dependencies_string.split_view(" "));
|
||||||
builder.appendff("target_link_libraries({} INTERFACE {})\n", library_name, dependencies);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,13 @@ private:
|
||||||
String generate_cmake_file_content() const;
|
String generate_cmake_file_content() const;
|
||||||
ErrorOr<void> update_active_file(StringView active_file);
|
ErrorOr<void> update_active_file(StringView active_file);
|
||||||
|
|
||||||
static void generate_cmake_library_definitions(StringBuilder&);
|
struct LibraryInfo {
|
||||||
static void generate_cmake_library_dependencies(StringBuilder&);
|
String path;
|
||||||
|
Vector<String> dependencies {};
|
||||||
|
};
|
||||||
|
static HashMap<String, NonnullOwnPtr<LibraryInfo>> get_defined_libraries();
|
||||||
|
static void for_each_library_definition(Function<void(String, String)>);
|
||||||
|
static void for_each_library_dependencies(Function<void(String, Vector<StringView>)>);
|
||||||
static ErrorOr<String> component_name(StringView cmake_file_path);
|
static ErrorOr<String> component_name(StringView cmake_file_path);
|
||||||
static ErrorOr<void> verify_cmake_is_installed();
|
static ErrorOr<void> verify_cmake_is_installed();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue