1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:07:43 +00:00

HackStudio: Put the Build directory inside the Serenity repository

Previously, the build directory for building serenity components was a
temporary directory in /tmp which was generated whenever a different
serenity component was built.

Instead of doing that, Hack Studio now simply uses the Build/ directory
inside the Serenity repository, similar to what is done in host builds.

This makes it so we don't re-build when switching back and forth between
different components.
It also makes it easier to inspect the build products.
This commit is contained in:
Itamar 2022-02-12 12:02:42 +02:00 committed by Andreas Kling
parent 83688d0610
commit 506c13d143
2 changed files with 17 additions and 11 deletions

View file

@ -64,7 +64,7 @@ ErrorOr<void> ProjectBuilder::run(StringView active_file)
ErrorOr<void> ProjectBuilder::run_serenity_component()
{
auto relative_path_to_dir = LexicalPath::relative_path(LexicalPath::dirname(m_serenity_component_cmake_file), m_project_root);
m_terminal->run_command(LexicalPath::join(relative_path_to_dir, m_serenity_component_name).string(), LexicalPath::join(m_build_directory->path(), "Build").string());
m_terminal->run_command(LexicalPath::join(relative_path_to_dir, m_serenity_component_name).string(), build_directory());
return {};
}
@ -80,9 +80,6 @@ ErrorOr<void> ProjectBuilder::update_active_file(StringView active_file)
if (m_serenity_component_cmake_file == cmake_file.value())
return {};
if (!m_serenity_component_cmake_file.is_null())
m_build_directory.clear();
m_serenity_component_cmake_file = cmake_file.value();
m_serenity_component_name = TRY(component_name(m_serenity_component_cmake_file));
@ -92,7 +89,7 @@ ErrorOr<void> ProjectBuilder::update_active_file(StringView active_file)
ErrorOr<void> ProjectBuilder::build_serenity_component()
{
m_terminal->run_command(String::formatted("make {}", m_serenity_component_name), LexicalPath::join(m_build_directory->path(), "Build"sv).string(), TerminalWrapper::WaitForExit::Yes);
m_terminal->run_command(String::formatted("make {}", m_serenity_component_name), build_directory(), TerminalWrapper::WaitForExit::Yes);
if (m_terminal->child_exit_status() == 0)
return {};
return Error::from_string_literal("Make failed"sv);
@ -112,19 +109,23 @@ ErrorOr<String> ProjectBuilder::component_name(StringView cmake_file_path)
ErrorOr<void> ProjectBuilder::initialize_build_directory()
{
m_build_directory = Core::TempFile::create(Core::TempFile::Type::Directory);
if (mkdir(LexicalPath::join(m_build_directory->path(), "Build").string().characters(), 0700)) {
return Error::from_errno(errno);
if (!Core::File::exists(build_directory())) {
if (mkdir(LexicalPath::join(build_directory()).string().characters(), 0700)) {
return Error::from_errno(errno);
}
}
auto cmake_file_path = LexicalPath::join(m_build_directory->path(), "CMakeLists.txt").string();
auto cmake_file_path = LexicalPath::join(build_directory(), "CMakeLists.txt").string();
if (Core::File::exists(cmake_file_path))
MUST(Core::File::remove(cmake_file_path, Core::File::RecursionMode::Disallowed, false));
auto cmake_file = TRY(Core::File::open(cmake_file_path, Core::OpenMode::WriteOnly));
cmake_file->write(generate_cmake_file_content());
m_terminal->run_command(String::formatted("cmake -S {} -DHACKSTUDIO_BUILD=ON -DHACKSTUDIO_BUILD_CMAKE_FILE={}"
" -DENABLE_UNICODE_DATABASE_DOWNLOAD=OFF",
m_project_root, cmake_file_path),
LexicalPath::join(m_build_directory->path(), "Build"sv).string(), TerminalWrapper::WaitForExit::Yes);
build_directory(), TerminalWrapper::WaitForExit::Yes);
if (m_terminal->child_exit_status() == 0)
return {};
@ -245,4 +246,9 @@ ErrorOr<void> ProjectBuilder::verify_cmake_is_installed()
return Error::from_string_literal("CMake port is not installed"sv);
}
String ProjectBuilder::build_directory() const
{
return LexicalPath::join(m_project_root, "Build"sv).string();
}
}