Added detection of Microsoft WSL/WSL2 Linux flavors.
Added tracing of the platform detection.
This commit is contained in:
parent
2c76c42baa
commit
33b63b35a2
2 changed files with 25 additions and 2 deletions
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
|
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
@ -15,12 +17,15 @@ static auto s_platform_flavor = PlatformFlavor::Uninitialized;
|
||||||
void detect_platform()
|
void detect_platform()
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Platform: Windows";
|
||||||
s_platform = Platform::Windows;
|
s_platform = Platform::Windows;
|
||||||
s_platform_flavor = PlatformFlavor::Generic;
|
s_platform_flavor = PlatformFlavor::Generic;
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Platform: OSX";
|
||||||
s_platform = Platform::OSX;
|
s_platform = Platform::OSX;
|
||||||
s_platform_flavor = PlatformFlavor::Generic;
|
s_platform_flavor = PlatformFlavor::Generic;
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Platform: Linux";
|
||||||
s_platform = Platform::Linux;
|
s_platform = Platform::Linux;
|
||||||
s_platform_flavor = PlatformFlavor::GenericLinux;
|
s_platform_flavor = PlatformFlavor::GenericLinux;
|
||||||
// Test for Chromium.
|
// Test for Chromium.
|
||||||
|
@ -29,16 +34,30 @@ void detect_platform()
|
||||||
if (f) {
|
if (f) {
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
// Read the 1st line.
|
// Read the 1st line.
|
||||||
if (::fgets(buf, 4096, f) && strstr(buf, "Chromium OS") != nullptr)
|
if (::fgets(buf, 4096, f))
|
||||||
s_platform_flavor = PlatformFlavor::LinuxOnChromium;
|
if (strstr(buf, "Chromium OS") != nullptr) {
|
||||||
|
s_platform_flavor = PlatformFlavor::LinuxOnChromium;
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: LinuxOnChromium";
|
||||||
|
} else if (strstr(buf, "microsoft") != nullptr || strstr(buf, "Microsoft") != nullptr) {
|
||||||
|
if (boost::filesystem::exists("/run/WSL") && getenv("WSL_INTEROP") != nullptr) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: WSL2";
|
||||||
|
s_platform_flavor = PlatformFlavor::WSL2;
|
||||||
|
} else {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Platform flavor: WSL";
|
||||||
|
s_platform_flavor = PlatformFlavor::WSL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
::fclose(f);
|
::fclose(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif defined(__OpenBSD__)
|
#elif defined(__OpenBSD__)
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Platform: OpenBSD";
|
||||||
s_platform = Platform::BSDUnix;
|
s_platform = Platform::BSDUnix;
|
||||||
s_platform_flavor = PlatformFlavor::OpenBSD;
|
s_platform_flavor = PlatformFlavor::OpenBSD;
|
||||||
#else
|
#else
|
||||||
// This should not happen.
|
// This should not happen.
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "Platform: Unknown";
|
||||||
static_assert(false, "Unknown platform detected");
|
static_assert(false, "Unknown platform detected");
|
||||||
s_platform = Platform::Unknown;
|
s_platform = Platform::Unknown;
|
||||||
s_platform_flavor = PlatformFlavor::Unknown;
|
s_platform_flavor = PlatformFlavor::Unknown;
|
||||||
|
|
|
@ -23,6 +23,10 @@ enum class PlatformFlavor
|
||||||
// For Platform::Linux
|
// For Platform::Linux
|
||||||
GenericLinux,
|
GenericLinux,
|
||||||
LinuxOnChromium,
|
LinuxOnChromium,
|
||||||
|
// Microsoft's Windows on Linux (Linux kernel simulated on NTFS kernel)
|
||||||
|
WSL,
|
||||||
|
// Microsoft's Windows on Linux, version 2 (virtual machine)
|
||||||
|
WSL2,
|
||||||
// For Platform::BSDUnix
|
// For Platform::BSDUnix
|
||||||
OpenBSD,
|
OpenBSD,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue