add:初步添加打包lua脚本。
This commit is contained in:
parent
4f9e055d10
commit
2e3f39138e
4
.gitignore
vendored
4
.gitignore
vendored
@ -4,4 +4,6 @@ build
|
||||
cmake-*
|
||||
auto_build
|
||||
export
|
||||
.xmake
|
||||
.xmake
|
||||
*.exe
|
||||
*.dll
|
38
fs/lib.cxx
38
fs/lib.cxx
@ -1,5 +1,5 @@
|
||||
#include "lib.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#ifdef USE_BOOST_FILESYSTEM
|
||||
#include <boost/filesystem.hpp>
|
||||
@ -22,6 +22,7 @@ static const luaL_Reg lua_fs[] = {{"exists", exists},
|
||||
{"get_parent", get_parent},
|
||||
{"append_path", append_path},
|
||||
{"mkdir", mkdir},
|
||||
{"normalize", normalize},
|
||||
{NULL, NULL}};
|
||||
|
||||
int luaopen_lua_fs(lua_State* L)
|
||||
@ -30,6 +31,20 @@ int luaopen_lua_fs(lua_State* L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static std::string replace(const std::string& str, const std::string& from, const std::string& to)
|
||||
{
|
||||
if (from.empty()) {
|
||||
return str;
|
||||
}
|
||||
std::string result = str;
|
||||
size_t startPos = 0;
|
||||
while ((startPos = result.find(from, startPos)) != std::string::npos) {
|
||||
result.replace(startPos, from.length(), to);
|
||||
startPos += to.length();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// @brief 创建文件夹
|
||||
/// @param path string 路径或者文件夹名称
|
||||
/// @return boolean
|
||||
@ -62,6 +77,27 @@ int get_parent(lua_State* L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// @brief 规范化路径
|
||||
/// @param path string 路径
|
||||
/// @return string
|
||||
int normalize(lua_State* L)
|
||||
{
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
#ifdef _WIN32
|
||||
std::string normalized = replace(path, "/", "\\");
|
||||
if (!normalized.empty() && normalized.back() == '\\') {
|
||||
normalized.pop_back();
|
||||
}
|
||||
#else
|
||||
std::string normalized = replace(path, "\\", "/");
|
||||
if (!normalized.empty() && normalized.back() == '/') {
|
||||
normalized.pop_back();
|
||||
}
|
||||
#endif
|
||||
lua_pushstring(L, normalized.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// @brief 拼接路径
|
||||
/// @param path string 基本路径
|
||||
/// @param append string 添加路径
|
||||
|
1
fs/lib.h
1
fs/lib.h
@ -29,6 +29,7 @@ LIB_API int get_current_directory(lua_State* L);
|
||||
LIB_API int get_parent(lua_State* L);
|
||||
LIB_API int append_path(lua_State* L);
|
||||
LIB_API int mkdir(lua_State* L);
|
||||
LIB_API int normalize(lua_State* L);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
89
pack/pack.lua
Normal file
89
pack/pack.lua
Normal file
@ -0,0 +1,89 @@
|
||||
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...")
|
||||
|
82
pack/pack.nsi
Normal file
82
pack/pack.nsi
Normal file
@ -0,0 +1,82 @@
|
||||
;NSIS Modern User Interface
|
||||
;Welcome/Finish Page Example Script
|
||||
;Written by Joost Verburg
|
||||
|
||||
;--------------------------------
|
||||
;Include Modern UI
|
||||
|
||||
!include "MUI2.nsh"
|
||||
|
||||
;--------------------------------
|
||||
;General
|
||||
|
||||
!define ProgramName "REP_NAME"
|
||||
Name "${ProgramName}"
|
||||
OutFile "REP_BIN_FILE.exe"
|
||||
Unicode True
|
||||
InstallDir "$LOCALAPPDATA\${ProgramName}"
|
||||
RequestExecutionLevel user
|
||||
|
||||
;--------------------------------
|
||||
;Interface Settings
|
||||
|
||||
!define MUI_ABORTWARNING
|
||||
|
||||
;--------------------------------
|
||||
;Pages
|
||||
|
||||
!insertmacro MUI_PAGE_WELCOME
|
||||
;!insertmacro MUI_PAGE_LICENSE "REP_LICENSE"
|
||||
!insertmacro MUI_PAGE_COMPONENTS
|
||||
!insertmacro MUI_PAGE_DIRECTORY
|
||||
!insertmacro MUI_PAGE_INSTFILES
|
||||
!insertmacro MUI_PAGE_FINISH
|
||||
|
||||
!insertmacro MUI_UNPAGE_WELCOME
|
||||
!insertmacro MUI_UNPAGE_CONFIRM
|
||||
!insertmacro MUI_UNPAGE_INSTFILES
|
||||
!insertmacro MUI_UNPAGE_FINISH
|
||||
|
||||
;--------------------------------
|
||||
;Languages
|
||||
!insertmacro MUI_LANGUAGE "SimpChinese"
|
||||
|
||||
;--------------------------------
|
||||
;Installer Sections
|
||||
|
||||
Section "REP_NAME" All
|
||||
|
||||
SetOutPath "$INSTDIR"
|
||||
|
||||
;ADD YOUR OWN FILES HERE...
|
||||
;REP_FILES
|
||||
;Create uninstaller
|
||||
WriteUninstaller "$INSTDIR\Uninstall.exe"
|
||||
|
||||
SectionEnd
|
||||
|
||||
;--------------------------------
|
||||
;Descriptions
|
||||
|
||||
;Language strings
|
||||
LangString DESC_All 2052 "install all main files."
|
||||
|
||||
;Assign language strings to sections
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
|
||||
!insertmacro MUI_DESCRIPTION_TEXT ${All} $(DESC_All)
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
||||
|
||||
;--------------------------------
|
||||
;Uninstaller Section
|
||||
|
||||
Section "Uninstall"
|
||||
|
||||
;ADD YOUR OWN FILES HERE...
|
||||
|
||||
Delete "$INSTDIR\Uninstall.exe"
|
||||
|
||||
RMDir "$INSTDIR"
|
||||
|
||||
DeleteRegKey /ifempty HKCU "Software\${ProgramName}"
|
||||
|
||||
SectionEnd
|
Loading…
x
Reference in New Issue
Block a user