mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:57:35 +00:00
HackStudio: Use ProjectBuilder to build and run the current project
This enables building and running standalone serenity components from Hack Studio :^)
This commit is contained in:
parent
bb6324a9a9
commit
be81278634
3 changed files with 29 additions and 17 deletions
|
@ -162,6 +162,8 @@ HackStudioWidget::HackStudioWidget(String path_to_project)
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
m_project_builder = make<ProjectBuilder>(*m_terminal_wrapper, *m_project);
|
||||
}
|
||||
|
||||
void HackStudioWidget::update_actions()
|
||||
|
@ -923,20 +925,20 @@ String HackStudioWidget::get_project_executable_path() const
|
|||
return String::formatted("{}/{}", m_project->root_path(), LexicalPath::basename(m_project->root_path()));
|
||||
}
|
||||
|
||||
void HackStudioWidget::build(TerminalWrapper& wrapper)
|
||||
void HackStudioWidget::build()
|
||||
{
|
||||
if (active_file().ends_with(".js"))
|
||||
wrapper.run_command(String::formatted("js -A {}", active_file()));
|
||||
else
|
||||
wrapper.run_command("make");
|
||||
auto result = m_project_builder->build(active_file());
|
||||
if (result.is_error()) {
|
||||
GUI::MessageBox::show(window(), String::formatted("{}", result.error()), "Build failed", GUI::MessageBox::Type::Error);
|
||||
}
|
||||
}
|
||||
|
||||
void HackStudioWidget::run(TerminalWrapper& wrapper)
|
||||
void HackStudioWidget::run()
|
||||
{
|
||||
if (active_file().ends_with(".js"))
|
||||
wrapper.run_command(String::formatted("js {}", active_file()));
|
||||
else
|
||||
wrapper.run_command("make run");
|
||||
auto result = m_project_builder->run(active_file());
|
||||
if (result.is_error()) {
|
||||
GUI::MessageBox::show(window(), String::formatted("{}", result.error()), "Run failed", GUI::MessageBox::Type::Error);
|
||||
}
|
||||
}
|
||||
|
||||
void HackStudioWidget::hide_action_tabs()
|
||||
|
@ -1065,7 +1067,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_build_action()
|
|||
return;
|
||||
|
||||
reveal_action_tab(*m_terminal_wrapper);
|
||||
build(*m_terminal_wrapper);
|
||||
build();
|
||||
m_stop_action->set_enabled(true);
|
||||
});
|
||||
}
|
||||
|
@ -1074,7 +1076,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_run_action()
|
|||
{
|
||||
return GUI::Action::create("&Run", { Mod_Ctrl, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/program-run.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
|
||||
reveal_action_tab(*m_terminal_wrapper);
|
||||
run(*m_terminal_wrapper);
|
||||
run();
|
||||
m_stop_action->set_enabled(true);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "Git/GitWidget.h"
|
||||
#include "Locator.h"
|
||||
#include "Project.h"
|
||||
#include "ProjectBuilder.h"
|
||||
#include "ProjectFile.h"
|
||||
#include "TerminalWrapper.h"
|
||||
#include "ToDoEntriesWidget.h"
|
||||
|
@ -133,8 +134,8 @@ private:
|
|||
void create_project_tab(GUI::Widget& parent);
|
||||
void configure_project_tree_view();
|
||||
|
||||
void run(TerminalWrapper& wrapper);
|
||||
void build(TerminalWrapper& wrapper);
|
||||
void run();
|
||||
void build();
|
||||
|
||||
void hide_action_tabs();
|
||||
bool any_document_is_dirty() const;
|
||||
|
@ -228,5 +229,6 @@ private:
|
|||
|
||||
Mode m_mode { Mode::Code };
|
||||
OwnPtr<Coredump::Inspector> m_coredump_inspector;
|
||||
OwnPtr<ProjectBuilder> m_project_builder;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -158,9 +158,13 @@ void ProjectBuilder::generate_cmake_library_definitions(StringBuilder& builder)
|
|||
{
|
||||
Vector<String> arguments = { "sh", "-c", "find Userland/Libraries -name CMakeLists.txt | xargs grep serenity_lib" };
|
||||
auto res = Core::command("/bin/sh", arguments, {});
|
||||
if (res.is_error()) {
|
||||
warnln("{}", res.error());
|
||||
return;
|
||||
}
|
||||
|
||||
static const Regex<ECMA262> parse_library_definition(R"~~~(.+:serenity_lib[c]?\((\w+) (\w+)\).*)~~~");
|
||||
for (auto& line : res->stdout.split('\n')) {
|
||||
for (auto& line : res.value().stdout.split('\n')) {
|
||||
|
||||
RegexResult result;
|
||||
if (!parse_library_definition.search(line, result))
|
||||
|
@ -180,9 +184,13 @@ void ProjectBuilder::generate_cmake_library_dependencies(StringBuilder& builder)
|
|||
{
|
||||
Vector<String> arguments = { "sh", "-c", "find Userland/Libraries -name CMakeLists.txt | xargs grep target_link_libraries" };
|
||||
auto res = Core::command("/bin/sh", arguments, {});
|
||||
if (res.is_error()) {
|
||||
warnln("{}", res.error());
|
||||
return;
|
||||
}
|
||||
|
||||
static const Regex<ECMA262> parse_library_definition(R"~~~(.+:target_link_libraries\((\w+) ([\w\s]+)\).*)~~~");
|
||||
for (auto& line : res->stdout.split('\n')) {
|
||||
for (auto& line : res.value().stdout.split('\n')) {
|
||||
|
||||
RegexResult result;
|
||||
if (!parse_library_definition.search(line, result))
|
||||
|
@ -201,7 +209,7 @@ void ProjectBuilder::generate_cmake_library_dependencies(StringBuilder& builder)
|
|||
ErrorOr<void> ProjectBuilder::verify_cmake_is_installed()
|
||||
{
|
||||
auto res = Core::command("cmake --version", {});
|
||||
if (res.has_value() && res->exit_code == 0)
|
||||
if (!res.is_error() && res.value().exit_code == 0)
|
||||
return {};
|
||||
return Error::from_string_literal("CMake port is not installed"sv);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue