Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless: Compile on Windows #3588

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Libraries/LibCore/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@

#include <LibCore/File.h>
#include <LibCore/System.h>
#include <fcntl.h>

#if !defined(AK_OS_WINDOWS)
# include <unistd.h>
#else
# include <WinSock2.h>
# define STDIN_FILENO _fileno(stdin)
# define STDOUT_FILENO _fileno(stdout)
# define STDERR_FILENO _fileno(stderr)
# include <AK/Windows.h>
#endif

namespace Core {
Expand Down
4 changes: 4 additions & 0 deletions Libraries/LibCore/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
# include <utime.h>
#else
# include "SocketAddressWindows.h"
# include <io.h>
# define O_CLOEXEC O_NOINHERIT
# define STDIN_FILENO _get_osfhandle(_fileno(stdin))
# define STDOUT_FILENO _get_osfhandle(_fileno(stdout))
# define STDERR_FILENO _get_osfhandle(_fileno(stderr))
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
using sighandler_t = void (*)(int);
Expand Down
5 changes: 5 additions & 0 deletions Libraries/LibCore/SystemWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,9 @@ u64 physical_memory_bytes()
return ms.ullTotalPhys;
}

ErrorOr<bool> isatty(int handle)
{
return GetFileType(to_handle(handle)) == FILE_TYPE_CHAR;
}

}
8 changes: 8 additions & 0 deletions UI/Headless/Fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class HttpEchoServerFixture final : public Fixture {

ErrorOr<void> HttpEchoServerFixture::setup(WebView::WebContentOptions& web_content_options)
{
#ifdef AK_OS_WINDOWS
VERIFY(0 && "Ladybird::HttpEchoServerFixture::setup is not implemented");
#else
auto const script_path = LexicalPath::join(s_fixtures_path, m_script_path);
auto const arguments = Vector { script_path.string(), "--directory", Ladybird::Application::the().test_root_path };

Expand Down Expand Up @@ -81,10 +84,14 @@ ErrorOr<void> HttpEchoServerFixture::setup(WebView::WebContentOptions& web_conte
warnln("Failed to read echo server port from buffer: '{}'", raw_output);

return {};
#endif
}

void HttpEchoServerFixture::teardown_impl()
{
#ifdef AK_OS_WINDOWS
VERIFY(0 && "Ladybird::HttpEchoServerFixture::teardown_impl is not implemented");
#else
VERIFY(m_process.has_value());

auto script_path = LexicalPath::join(s_fixtures_path, m_script_path);
Expand All @@ -98,6 +105,7 @@ void HttpEchoServerFixture::teardown_impl()
}

m_process = {};
#endif
}

void Fixture::initialize_fixtures()
Expand Down
4 changes: 2 additions & 2 deletions UI/Headless/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void run_dump_test(HeadlessWebView& view, Test& test, URL::URL const& url, int t
return TestResult::Pass;
}

auto const color_output = isatty(STDOUT_FILENO) ? Diff::ColorOutput::Yes : Diff::ColorOutput::No;
auto const color_output = TRY(Core::System::isatty(STDOUT_FILENO)) ? Diff::ColorOutput::Yes : Diff::ColorOutput::No;

if (color_output == Diff::ColorOutput::Yes)
outln("\n\033[33;1mTest failed\033[0m: {}", url);
Expand Down Expand Up @@ -531,7 +531,7 @@ ErrorOr<void> run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize
bool all_tests_ok = true;

// Keep clearing and reusing the same line if stdout is a TTY.
bool log_on_one_line = app.verbosity < Application::VERBOSITY_LEVEL_LOG_TEST_DURATION && isatty(STDOUT_FILENO) == 1;
bool log_on_one_line = app.verbosity < Application::VERBOSITY_LEVEL_LOG_TEST_DURATION && TRY(Core::System::isatty(STDOUT_FILENO));
outln("Running {} tests...", tests.size());

auto all_tests_complete = Core::Promise<Empty>::construct();
Expand Down
2 changes: 2 additions & 0 deletions UI/Headless/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ static ErrorOr<NonnullRefPtr<Core::Timer>> load_page_for_screenshot_and_exit(Cor

ErrorOr<int> serenity_main(Main::Arguments arguments)
{
AK::set_rich_debug_enabled(true);

WebView::platform_init();

auto app = Ladybird::Application::create(arguments, "about:newtab"sv);
Expand Down
Loading