diff options
| author | ruki <[email protected]> | 2024-06-14 00:48:53 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-06-14 00:48:53 +0800 |
| commit | ff6a2cbe45b52d618e8f2a71f4579d43a980accb (patch) | |
| tree | b409cc6e64c938659a4b5fc9f9337c61aea6bfd8 /xmake/plugins/pack/deb/main.lua | |
| parent | 3b8e94caf543e97492c08120c041b351e8ee9de5 (diff) | |
replace some specfiles for deb
Diffstat (limited to 'xmake/plugins/pack/deb/main.lua')
| -rw-r--r-- | xmake/plugins/pack/deb/main.lua | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/xmake/plugins/pack/deb/main.lua b/xmake/plugins/pack/deb/main.lua index 7bd0c68ce..8a470af33 100644 --- a/xmake/plugins/pack/deb/main.lua +++ b/xmake/plugins/pack/deb/main.lua @@ -36,7 +36,13 @@ end -- get archive file function _get_archivefile(package) - return path.absolute(path.join(package:buildir(), package:basename() .. ".orig.tar.gz")) + return path.absolute(path.join(package:buildir(), package:name() .. "_" .. package:version() .. ".orig.tar.gz")) +end + +-- get specvars +function _get_specvars(package) + local specvars = table.clone(package:specvars()) + return specvars end -- pack deb package @@ -44,11 +50,31 @@ function _pack_deb(debuild, package) local buildir = package:buildir() local workdir = path.join(buildir, "working") - -- install the initial specfile - local specfile = path.join(workdir, "debian") - if not os.isdir(specfile) then - local specfile_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "deb", "debian") - os.cp(specfile_template, specfile) + -- install the initial debian directory + local debiandir = path.join(workdir, "debian") + if not os.isdir(debiandir) then + local debiandir_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "deb", "debian") + os.cp(debiandir_template, debiandir) + end + + -- replace variables in specfile + local specvars = _get_specvars(package) + local pattern = package:extraconf("specfile", "pattern") or "%${([^\n]-)}" + for _, specfile in ipairs(os.files(path.join(debiandir, "**"))) do + 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("[%s]: > replace %s -> %s", path.filename(specfile), name, value) + end + if type(value) == "table" then + dprint("invalid variable value", value) + end + return value + end) end -- archive source files |
