diff options
| author | ruki <[email protected]> | 2023-11-10 22:55:10 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-11-10 22:55:10 +0800 |
| commit | ff33f52afebb41b4d281e9b4f7c9c6711a1e422c (patch) | |
| tree | d7e9c6c2a5b36bf27c28944932b5f47465409e8b | |
| parent | 28197467e651b9a92d7076a56783eb00b3dfaeb2 (diff) | |
get specfile
| -rw-r--r-- | xmake/includes/xpack/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/plugins/pack/main.lua | 3 | ||||
| -rw-r--r-- | xmake/plugins/pack/nsis/main.lua | 17 | ||||
| -rw-r--r-- | xmake/plugins/pack/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/pack/xpack.lua | 56 |
5 files changed, 78 insertions, 4 deletions
diff --git a/xmake/includes/xpack/xmake.lua b/xmake/includes/xpack/xmake.lua index a6a3f1cea..6d6cb99ec 100644 --- a/xmake/includes/xpack/xmake.lua +++ b/xmake/includes/xpack/xmake.lua @@ -38,6 +38,10 @@ local apis = { "xpack.set_license", -- set package formats, e.g. nsis, deb, rpm, targz, zip, runself, ... "xpack.set_formats", + -- set the base name of the output file + "xpack.set_basename", + -- set the spec file path + "xpack.set_specfile", -- add targets to be packaged "xpack.add_targets", -- add install files, we will also get them from target diff --git a/xmake/plugins/pack/main.lua b/xmake/plugins/pack/main.lua index 513888061..1da430d24 100644 --- a/xmake/plugins/pack/main.lua +++ b/xmake/plugins/pack/main.lua @@ -28,7 +28,8 @@ import("xpack") function _pack_package(package) assert(package:formats(), "xpack(%s): formats not found, please use `set_formats()` to set it.", package:name()) for _, format in package:formats():keys() do - import(format)(package, {format = format}) + package:format_set(format) + import(format)(package) end end diff --git a/xmake/plugins/pack/nsis/main.lua b/xmake/plugins/pack/nsis/main.lua index e672ce03f..24bd371f7 100644 --- a/xmake/plugins/pack/nsis/main.lua +++ b/xmake/plugins/pack/nsis/main.lua @@ -53,9 +53,23 @@ end -- pack nsis package function _pack_nsis(makensis, package, opt) + + -- install the initial specfile + local specfile = package:specfile() + if not os.isfile(specfile) then + local specfile_template = path.join(os.programdir(), "scripts", "xpack", "nsis", "makensis.nsi") + os.cp(specfile_template, specfile) + end + + -- generate specfile print("xpack(%s)", package:name()) print(" description: %s", package:description()) print(" installcmd: ", package:script("installcmd")) + + -- ./nsis/makensis.exe /DMAJOR=$($version.ProductMajorPart) + -- /DMINOR=$($version.ProductMinorPart) + -- /DALTER=$($version.ProductBuildPart) /DBUILD=$($($version.ProductVersion + -- -split '\+')[1]) /D${{ matrix.arch }} .\scripts\installer.nsi end function main(package, opt) @@ -63,6 +77,9 @@ function main(package, opt) -- get makensis local makensis, oldenvs = _get_makensis() + -- clean the build directory first + os.tryrm(package:buildir()) + -- pack nsis package _pack_nsis(makensis.program, package, opt) diff --git a/xmake/plugins/pack/xmake.lua b/xmake/plugins/pack/xmake.lua index a8cce7762..4bbd7f4bf 100644 --- a/xmake/plugins/pack/xmake.lua +++ b/xmake/plugins/pack/xmake.lua @@ -25,7 +25,7 @@ task("pack") usage = "xmake pack [options] [names]", description = "Pack binary installation packages.", options = { - {'o', "output", "kv", nil, "The output directory. (default: build/xpack)"}, + {'o', "outputdir", "kv", nil, "The output directory. (default: build/xpack)"}, {'f', "formats", "kv", "all", "Pack the given package formats.", "e.g.", " - xmake pack -f nsis,deb,rpm", diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua index 680b75d6d..2ffe725be 100644 --- a/xmake/plugins/pack/xpack.lua +++ b/xmake/plugins/pack/xpack.lua @@ -171,7 +171,7 @@ function xpack:formats() end -- has the given format? -function xpack:has_format(...) +function xpack:format_has(...) local formats = self:formats() for _, v in ipairs(table.pack(...)) do if v and formats:has(v) then @@ -180,6 +180,58 @@ function xpack:has_format(...) end end +-- set the current format +function xpack:format_set(format) + self._FORMAT = format +end + +-- get the current format +function xpack:format() + return self._FORMAT +end + +-- get the build directory +function xpack:buildir() + return path.join(config.buildir(), ".xpack", self:name(), self:format()) +end + +-- get the output directory +function xpack:outputdir() + local outputdir = option.get("outputdir") + if outputdir == nil then + outputdir = path.join(config.buildir(), "xpack", self:name(), self:format()) + end + return outputdir +end + +-- get the basename +function xpack:basename() + return self:get("basename") or self:name() +end + +-- get the specfile path +function xpack:specfile() + local extensions = { + nsis = ".nsi" + } + local extension = extensions[self:format()] or ".spec" + return self:get("specfile") or path.join(self:buildir(), self:basename() .. extension) +end + +-- get the output filename +function xpack:filename() + local extensions = { + nsis = ".exe" + } + local extension = extensions[self:format()] or "" + return self:basename() .. extension +end + +-- get the output file +function xpack:outputfile() + return path.join(self:outputdir(), self:filename()) +end + -- new a xpack function _new(name, info) return xpack {name, info} @@ -213,7 +265,7 @@ function packages() end if need then local instance = _new(name, scope) - if not formats_need or instance:has_format(table.unpack(formats_need)) then + if not formats_need or instance:format_has(table.unpack(formats_need)) then packages[name] = instance end end |
