diff options
| author | ruki <[email protected]> | 2023-11-24 00:46:17 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-11-24 00:46:17 +0800 |
| commit | 4725c68c0ea12f684646c6cba4844c189051ae4a (patch) | |
| tree | 7efdee551e8277be8e4f6e37c413b16d65536b3d | |
| parent | 95195e3199a3e03e66e6be94bf14c83c694cc8ff (diff) | |
add makeself cmd
| -rw-r--r-- | core/xpack.lua | 2 | ||||
| -rw-r--r-- | tests/plugins/pack/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/pack/runself/main.lua | 46 | ||||
| -rw-r--r-- | xmake/plugins/pack/xpack.lua | 3 |
4 files changed, 45 insertions, 8 deletions
diff --git a/core/xpack.lua b/core/xpack.lua index bc2df257e..b8dcdc5c5 100644 --- a/core/xpack.lua +++ b/core/xpack.lua @@ -77,7 +77,7 @@ xpack_component("LongPath") end) xpack("xmakesrc") - set_formats("zip", "targz") + set_formats("zip", "targz", "runself") set_basename("xmake-v$(version)") before_package(function (package) import("devel.git") diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/xmake.lua index a93fc18f6..5b34dec36 100644 --- a/tests/plugins/pack/xmake.lua +++ b/tests/plugins/pack/xmake.lua @@ -19,7 +19,7 @@ target("foo") add_packages("zlib") xpack("test") - set_formats("nsis", "zip", "targz") + set_formats("nsis", "zip", "targz", "runself") set_title("hello") set_description("A test installer.") set_homepage("https://xmake.io") diff --git a/xmake/plugins/pack/runself/main.lua b/xmake/plugins/pack/runself/main.lua index aaf267454..b45b20e33 100644 --- a/xmake/plugins/pack/runself/main.lua +++ b/xmake/plugins/pack/runself/main.lua @@ -34,7 +34,7 @@ function _get_makeself() -- find makeself local packages = {} - local makeself = find_tool("makeself") + local makeself = find_tool("makeself.sh") if not makeself then table.join2(packages, install_packages("makeself")) end @@ -46,20 +46,58 @@ function _get_makeself() -- we need to force detect and flush detect cache after loading all environments if not makeself then - makeself = find_tool("makeself", {force = true}) + makeself = find_tool("makeself.sh", {force = true}) end assert(makeself, "makeself not found!") return makeself, oldenvs end +-- get specvars +function _get_specvars(package) + local specvars = table.clone(package:specvars()) + return specvars +end + -- pack runself package function _pack_runself(makeself, package) + + -- install the initial specfile + local specfile = package:specfile() + if not os.isfile(specfile) then + local specfile_template = path.join(os.programdir(), "scripts", "xpack", "runself", "makeself.lsm") + os.cp(specfile_template, specfile) + end + + -- replace variables in specfile + local specvars = _get_specvars(package) + local pattern = package:extraconf("specfile", "pattern") or "%${([^\n]-)}" + io.gsub(specfile, "(" .. pattern .. ")", function(_, name) + name = name:trim() + local value = specvars[name] + if type(value) == "function" then + value = value() + end + if value ~= nil then + dprint(" > replace %s -> %s", name, value) + end + if type(value) == "table" then + dprint("invalid variable value", value) + end + return value + end) + + local archivedir = package:buildir() + local setupfile = path.join(package:buildir(), "setup.sh") + io.writefile(setupfile, [[#!/bin/bash + echo hello]]) + + -- make package + os.vrunv(makeself, {"--gzip", "--sha256", "--lsm", specfile, archivedir, package:outputfile(), "setup.sh", "hello"}) end function main(package) - -- only for windows - if not is_subhost("windows") then + if is_subhost("windows") then return end diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua index 6715fb178..2fe43137a 100644 --- a/xmake/plugins/pack/xpack.lua +++ b/xmake/plugins/pack/xpack.lua @@ -325,8 +325,7 @@ end -- get the specfile path function xpack:specfile() local extensions = { - nsis = ".nsi", - runself = ".sh" + nsis = ".nsi" } local extension = extensions[self:format()] or ".spec" return self:get("specfile") or path.join(self:buildir(), self:basename() .. extension) |
