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

Add support for adjust loaded source libname with shell env LUASTATIC… #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions luastatic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
local CC = os.getenv("CC") or "cc"
-- The nm used to determine whether a library is liblua or a Lua binary module.
local NM = os.getenv("NM") or "nm"
-- The lua source prefix for adjust libname
local SOURCE_PATH = os.getenv("LUASTATIC_SOURCE_PATH") or ""

local function file_exists(name)
local file = io.open(name, "r")
Expand Down Expand Up @@ -80,6 +82,23 @@ local function is_binary_library(extension)
extension == "dylib"
end

-- Prepare project prefix for adjust source path.
local lua_source_prefixes = {}
for v in SOURCE_PATH:gmatch("([^;]-);") do
lua_source_prefixes[#lua_source_prefixes + 1] = v:gsub("[\\/]", ".")
end

-- Adjust libname if path contains proj prefix
local function adjust_lib_name(path)
for _, prefix in ipairs(lua_source_prefixes) do
local s, e = path:find(prefix, 1, true)
if s == 1 and path:len() > e + 1 then
return path:sub(e + 1)
end
end
return path
end

-- Required Lua source files.
local lua_source_files = {}
-- Libraries for required Lua binary modules.
Expand Down Expand Up @@ -121,6 +140,7 @@ for i, name in ipairs(arg) do
info.dotpath_underscore = info.dotpath_noextension:gsub("[.-]", "_")

if i == 1 or is_source_file(extension) then
info.dotpath_noextension = adjust_lib_name(info.dotpath_noextension)
table.insert(lua_source_files, info)
elseif is_binary_library(extension) then
-- The library is either a Lua module or a library dependency.
Expand Down