lua/pack/pack.lua

90 lines
2.3 KiB
Lua
Raw Normal View History

2025-02-15 01:13:25 +08:00
local fs = require("lua_fs")
local path1 = "C:\\Program Files\\NSIS\\makensis.exe"
local path2 = "C:\\Program Files (x86)\\NSIS\\makensis.exe"
local version = "v0.1"
local package_name = "mlua"
local extern = ""
-- 确定使用哪个路径
local makensis_path = nil
if fs.exists(path2) then
makensis_path = path2
elseif fs.exists(path1) then
makensis_path = path1
else
print("Error: makensis.exe not found!")
return
end
-- 执行 xmake f -v 命令并获取输出
local handle = io.popen('cd .. && xmake f -v') -- 使用 io.popen 执行命令并获取输出句柄
if not handle then
print("xmake f -v 命令执行失败")
return
end
local output = handle:read("*a") -- 读取命令输出
handle:close() -- 关闭文件句柄
-- 匹配并提取 plat, arch 和 mode
local plat = string.match(output, "plat = (%S+)")
local arch = string.match(output, "arch = (%S+)")
local mode = string.match(output, "mode = (%S+)")
-- 打印结果
print("plat: " .. plat)
print("arch: " .. arch)
print("mode: " .. mode)
-- 获取当前脚本所在的目录
local cur = fs.get_current_directory()
local updir = fs.get_parent(cur)
local re_bin_dir = updir .. "/build/" .. plat .. "/" .. arch .. "/" .. mode
local bin_dir = fs.normalize(re_bin_dir)
print("bin_dir: " .. bin_dir)
local files = ""
local filenames = {"mlua.exe", "mluac.exe", "lua_fs.dll"}
local function add_files_to_list(arg_bin_dir)
for _, filename in ipairs(filenames) do
files = files .. "File \"" .. fs.append_path(arg_bin_dir, filename) .. "\"\n "
end
return files
end
add_files_to_list(bin_dir)
-- 打开文件
local file = io.open("pack.nsi", "r")
if not file then
print("文件打开失败")
return
end
-- 读取文件内容
local content = file:read("*all")
file:close()
local new_str = string.gsub(content, "REP_NAME", package_name)
new_str = string.gsub(new_str, "REP_BIN_FILE", package_name .. "-" .. version .. "-" .. arch .. extern)
new_str = string.gsub(new_str, ";REP_FILES", files)
print(new_str)
local f = io.open("tpack.nsi", "w")
if f then
f:write(new_str)
f:close()
print("success to save file tpack.nsi")
else
print("can't open file tpack.nsi")
end
local command = "\"\"" .. makensis_path .. "\" tpack.nsi\""
print("command: " .. command)
local result = os.execute(command)
os.remove("tpack.nsi")
print("End...")