diff --git a/Userland/DevTools/HackStudio/ProjectBuilder.cpp b/Userland/DevTools/HackStudio/ProjectBuilder.cpp index cf1b919c6c..2148f43c86 100644 --- a/Userland/DevTools/HackStudio/ProjectBuilder.cpp +++ b/Userland/DevTools/HackStudio/ProjectBuilder.cpp @@ -64,7 +64,7 @@ ErrorOr ProjectBuilder::run(StringView active_file) ErrorOr 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 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 ProjectBuilder::update_active_file(StringView active_file) ErrorOr 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 ProjectBuilder::component_name(StringView cmake_file_path) ErrorOr 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 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(); +} + } diff --git a/Userland/DevTools/HackStudio/ProjectBuilder.h b/Userland/DevTools/HackStudio/ProjectBuilder.h index 93a6a69dd4..d7d1a00f16 100644 --- a/Userland/DevTools/HackStudio/ProjectBuilder.h +++ b/Userland/DevTools/HackStudio/ProjectBuilder.h @@ -36,6 +36,7 @@ private: Optional find_cmake_file_for(StringView file_path) const; String generate_cmake_file_content() const; ErrorOr update_active_file(StringView active_file); + String build_directory() const; struct LibraryInfo { String path; @@ -50,7 +51,6 @@ private: String m_project_root; NonnullRefPtr m_terminal; IsSerenityRepo m_is_serenity { IsSerenityRepo::No }; - OwnPtr m_build_directory; String m_serenity_component_cmake_file; String m_serenity_component_name; };