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

fix: Use os_uname() to check for Linux #686

Merged
merged 3 commits into from
Jan 17, 2024
Merged
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
1 change: 1 addition & 0 deletions deps/lua.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ add_executable(lua ${LUA_DIR}/lua.c)
IF(WIN32)
target_link_libraries(lua lualib)
ELSE()
target_compile_definitions(lualib PRIVATE LUA_USE_POSIX)
target_link_libraries(lua lualib ${LIBS})
SET_TARGET_PROPERTIES(lua PROPERTIES ENABLE_EXPORTS ON)
ENDIF(WIN32)
Expand Down
44 changes: 27 additions & 17 deletions lib/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,41 @@ else
usecolors = false
end

function utils.uvVersionGEQ(min_version)
if not min_version then return true end
local min_version_num = min_version
if type(min_version) == "string" then
local version_parts = {}
for part in min_version:gmatch("%d+") do
table.insert(version_parts, tonumber(part))
end
assert(#version_parts == 3, "malformed version string: " .. min_version)
min_version_num = version_parts[1]*0x10000 + version_parts[2]*0x100 + version_parts[3]
end
return uv.version() >= min_version_num
end

if _G.jit and _G.jit.os then
-- Luajit provides explicit platform detection
utils.isWindows = _G.jit.os == "Windows"
utils.isLinux = _G.jit.os == 'Linux'
else
-- Normal lua will only have \ for path separator on windows.
utils.isWindows = package.config:find("\\") and true or false
utils.isLinux = false

if not utils.isWindows then
local _os = os.getenv('RUNNER_OS') or os.getenv('OSTYPE')
if (_os and _os:lower():match('linux')) then
utils.isLinux = true
-- Use os_uname if it's available, fallback to popen
if utils.uvVersionGEQ("1.25.0") then
local uname = uv.os_uname()
utils.isLinux = uname.sysname:lower() == 'linux'
else
local popen_handle = io.popen('uname -s')
if popen_handle then
local uname_os = assert(popen_handle:read('*a'))
popen_handle:close()
utils.isLinux = uname_os:lower() == 'linux'
end
end
end
end
Expand Down Expand Up @@ -176,19 +200,5 @@ function utils.prettyPrint(...)
print(table.concat(arguments, "\t"))
end

function utils.uvVersionGEQ(min_version)
if not min_version then return true end
local min_version_num = min_version
if type(min_version) == "string" then
local version_parts = {}
for part in min_version:gmatch("%d+") do
table.insert(version_parts, tonumber(part))
end
assert(#version_parts == 3, "malformed version string: " .. min_version)
min_version_num = version_parts[1]*0x10000 + version_parts[2]*0x100 + version_parts[3]
end
return uv.version() >= min_version_num
end

return utils

Loading