summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-24 22:34:15 +0800
committerruki <[email protected]>2023-11-24 22:34:15 +0800
commitafbbacc9085b29e39cc13e00d5673202a70f7645 (patch)
tree6c5bbad30be4b526500989de84c617f0a0af1f40
parent9217b528138fe4384403c0b573e8617bdcc18358 (diff)
add sourcefiles for xpack
-rw-r--r--tests/plugins/pack/xmake.lua12
-rw-r--r--xmake/includes/xpack/xmake.lua12
-rw-r--r--xmake/plugins/pack/archive.lua28
-rw-r--r--xmake/plugins/pack/main.lua8
-rw-r--r--xmake/plugins/pack/nsis/main.lua2
-rw-r--r--xmake/plugins/pack/srctargz/main.lua26
-rw-r--r--xmake/plugins/pack/srczip/main.lua26
-rw-r--r--xmake/plugins/pack/xmake.lua2
-rw-r--r--xmake/plugins/pack/xpack.lua70
-rw-r--r--xmake/plugins/pack/xpack_component.lua21
-rw-r--r--xmake/scripts/xpack/runself/makeself.lsm11
-rwxr-xr-xxmake/scripts/xpack/runself/setup.sh1
12 files changed, 194 insertions, 25 deletions
diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/xmake.lua
index 5b34dec36..e8d2cdd53 100644
--- a/tests/plugins/pack/xmake.lua
+++ b/tests/plugins/pack/xmake.lua
@@ -19,17 +19,25 @@ target("foo")
add_packages("zlib")
xpack("test")
- set_formats("nsis", "zip", "targz", "runself")
+ set_formats("nsis", "zip", "targz", "srczip", "srctargz", "runself")
set_title("hello")
set_description("A test installer.")
set_homepage("https://xmake.io")
set_licensefile("LICENSE.md")
add_targets("test", "foo")
- set_basename("test-$(plat)-$(arch)-v$(version)")
add_installfiles("src/(assets/*.png)", {prefixdir = "images"})
+ add_sourcefiles("(src/**)")
set_iconfile("src/assets/xmake.ico")
add_components("LongPath")
+ on_load(function (package)
+ if package:from_source() then
+ package:set("basename", "test-$(plat)-src-v$(version)")
+ else
+ package:set("basename", "test-$(plat)-$(arch)-v$(version)")
+ end
+ end)
+
after_installcmd(function (package, batchcmds)
batchcmds:mkdir(package:installdir("resources"))
batchcmds:cp("src/assets/*.txt", package:installdir("resources"), {rootdir = "src"})
diff --git a/xmake/includes/xpack/xmake.lua b/xmake/includes/xpack/xmake.lua
index 345431ffc..8572b2a87 100644
--- a/xmake/includes/xpack/xmake.lua
+++ b/xmake/includes/xpack/xmake.lua
@@ -36,11 +36,13 @@ local apis = {
"xpack.set_title",
-- set package description
"xpack.set_description",
+ -- set input kind, e.g. binary, source
+ "xpack.set_inputkind",
-- set package copyright
"xpack.set_copyright",
-- set company name
"xpack.set_company",
- -- set package formats, e.g. nsis, deb, rpm, targz, zip, runself, ...
+ -- set package formats, e.g. nsis, deb, rpm, targz, zip, srctargz, srczip, runself, ...
-- we can also add custom formats
"xpack.set_formats",
-- set the base name of the output file
@@ -75,8 +77,14 @@ local apis = {
"xpack.set_iconfile",
-- set package license file, we will also get them from target
"xpack.set_licensefile",
+ -- add source files
+ "xpack.add_sourcefiles",
-- add install files, we will also get them from target
- "xpack.add_installfiles"
+ "xpack.add_installfiles",
+ -- add source files for component
+ "xpack_component.add_sourcefiles",
+ -- add install files for component
+ "xpack_component.add_installfiles"
},
script = {
-- add custom load script
diff --git a/xmake/plugins/pack/archive.lua b/xmake/plugins/pack/archive.lua
index 818404345..dd1861ca4 100644
--- a/xmake/plugins/pack/archive.lua
+++ b/xmake/plugins/pack/archive.lua
@@ -26,16 +26,32 @@ import("batchcmds")
-- pack archive package
function _pack_archive(package)
- -- do install
- batchcmds.get_installcmds(package):runcmds()
- for _, component in table.orderpairs(package:components()) do
- if component:get("default") ~= false then
- batchcmds.get_installcmds(component):runcmds()
+ -- archive source files
+ if package:from_source() then
+ local srcfiles, dstfiles = package:sourcefiles()
+ for idx, srcfile in ipairs(srcfiles) do
+ os.vcp(srcfile, dstfiles[idx])
+ end
+ for _, component in table.orderpairs(package:components()) do
+ if component:get("default") ~= false then
+ local srcfiles, dstfiles = component:sourcefiles()
+ for idx, srcfile in ipairs(srcfiles) do
+ os.vcp(srcfile, dstfiles[idx])
+ end
+ end
+ end
+ else
+ -- archive binary files
+ batchcmds.get_installcmds(package):runcmds()
+ for _, component in table.orderpairs(package:components()) do
+ if component:get("default") ~= false then
+ batchcmds.get_installcmds(component):runcmds()
+ end
end
end
-- archive install files
- local rootdir = package:rootdir()
+ local rootdir = package:from_source() and package:source_rootdir() or package:install_rootdir()
local oldir = os.cd(rootdir)
local archivefiles = os.files("**")
os.cd(oldir)
diff --git a/xmake/plugins/pack/main.lua b/xmake/plugins/pack/main.lua
index 3f145cf86..f89c84835 100644
--- a/xmake/plugins/pack/main.lua
+++ b/xmake/plugins/pack/main.lua
@@ -80,9 +80,11 @@ end
function _build_targets()
local targetnames = {}
for _, package in ipairs(xpack.packages()) do
- local targets = package:get("targets")
- if targets then
- table.join2(targetnames, targets)
+ if package:from_binary() then
+ local targets = package:get("targets")
+ if targets then
+ table.join2(targetnames, targets)
+ end
end
end
if #targetnames > 0 then
diff --git a/xmake/plugins/pack/nsis/main.lua b/xmake/plugins/pack/nsis/main.lua
index d7d69fdef..b8f6d4dc4 100644
--- a/xmake/plugins/pack/nsis/main.lua
+++ b/xmake/plugins/pack/nsis/main.lua
@@ -88,7 +88,7 @@ end
-- translate the file path
function _translate_filepath(package, filepath)
- return filepath:replace(package:rootdir(), "$InstDir", {plain = true})
+ return filepath:replace(package:install_rootdir(), "$InstDir", {plain = true})
end
-- get command string
diff --git a/xmake/plugins/pack/srctargz/main.lua b/xmake/plugins/pack/srctargz/main.lua
new file mode 100644
index 000000000..fe511bff9
--- /dev/null
+++ b/xmake/plugins/pack/srctargz/main.lua
@@ -0,0 +1,26 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file main.lua
+--
+
+-- imports
+import(".archive")
+
+function main(package)
+ archive(package)
+end
diff --git a/xmake/plugins/pack/srczip/main.lua b/xmake/plugins/pack/srczip/main.lua
new file mode 100644
index 000000000..fe511bff9
--- /dev/null
+++ b/xmake/plugins/pack/srczip/main.lua
@@ -0,0 +1,26 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file main.lua
+--
+
+-- imports
+import(".archive")
+
+function main(package)
+ archive(package)
+end
diff --git a/xmake/plugins/pack/xmake.lua b/xmake/plugins/pack/xmake.lua
index 3d7c02ddf..96b0d2070 100644
--- a/xmake/plugins/pack/xmake.lua
+++ b/xmake/plugins/pack/xmake.lua
@@ -32,7 +32,7 @@ task("pack")
"e.g.",
" - xmake pack -f nsis,deb,rpm",
"values:",
- values = {"nsis", "deb", "rpm", "runself", "targz", "zip"}},
+ values = {"nsis", "deb", "rpm", "runself", "targz", "zip", "srctargz", "srczip"}},
{},
{nil, "packages", "vs", nil, "The package names."}
}
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua
index 2fe43137a..4873e3fa1 100644
--- a/xmake/plugins/pack/xpack.lua
+++ b/xmake/plugins/pack/xpack.lua
@@ -225,6 +225,35 @@ function xpack:format()
return self._FORMAT
end
+-- get the input kind
+function xpack:inputkind()
+ local inputkind = self:get("inputkind")
+ if inputkind == nil then
+ local inputkinds = {
+ nsis = "binary",
+ zip = "binary",
+ targz = "binary",
+ srczip = "source",
+ srctargz = "source",
+ runself = "source",
+ deb = "source",
+ rpm = "source"
+ }
+ inputkind = inputkinds[self:format()] or "binary"
+ end
+ return inputkind
+end
+
+-- pack from source files?
+function xpack:from_source()
+ return self:inputkind() == "source"
+end
+
+-- pack from binary files?
+function xpack:from_binary()
+ return self:inputkind() == "binary"
+end
+
-- get the build directory
function xpack:buildir()
return path.join(config.buildir(), ".xpack", self:name())
@@ -244,6 +273,9 @@ function xpack:basename()
local basename = option.get("basename") or self:get("basename")
if basename == nil then
basename = self:name()
+ if self:from_source() then
+ basename = basename .. "-src"
+ end
local version = self:version()
if version then
basename = basename .. "-" .. version
@@ -336,10 +368,14 @@ function xpack:extension()
local extension = self:get("extension")
if extension == nil then
local extensions = {
- nsis = ".exe",
- zip = ".zip",
- targz = ".tar.gz",
- runself = ".sh"
+ nsis = ".exe",
+ zip = ".zip",
+ targz = ".tar.gz",
+ srczip = ".zip",
+ srctargz = ".tar.gz",
+ runself = ".sh",
+ deb = ".deb",
+ rpm = ".rpm"
}
extension = extensions[self:format()] or ""
end
@@ -466,15 +502,15 @@ function xpack:installfiles()
return self:_copiedfiles("installfiles", self:installdir())
end
--- get the root directory, this is just a temporary sandbox installation path,
+-- get the installed root directory, this is just a temporary sandbox installation path,
-- we may replace it with the actual installation path in the specfile
-function xpack:rootdir()
+function xpack:install_rootdir()
return path.join(self:buildir(), "installed", self:format())
end
-- get the installed directory
function xpack:installdir(...)
- local installdir = self:rootdir()
+ local installdir = self:install_rootdir()
local prefixdir = self:get("prefixdir")
if prefixdir then
installdir = path.join(installdir, prefixdir)
@@ -482,6 +518,26 @@ function xpack:installdir(...)
return path.normalize(path.join(installdir, ...))
end
+-- get the source files
+function xpack:sourcefiles()
+ return self:_copiedfiles("sourcefiles", self:sourcedir())
+end
+
+-- get the source root directory
+function xpack:source_rootdir()
+ return path.join(self:buildir(), "source", self:format())
+end
+
+-- get the source directory
+function xpack:sourcedir(...)
+ local sourcedir = self:source_rootdir()
+ local prefixdir = self:get("prefixdir")
+ if prefixdir then
+ sourcedir = path.join(sourcedir, prefixdir)
+ end
+ return path.normalize(path.join(sourcedir, ...))
+end
+
-- get the binary directory
function xpack:bindir()
local bindir = self:get("bindir")
diff --git a/xmake/plugins/pack/xpack_component.lua b/xmake/plugins/pack/xpack_component.lua
index 59d2fae8f..bb0f5f454 100644
--- a/xmake/plugins/pack/xpack_component.lua
+++ b/xmake/plugins/pack/xpack_component.lua
@@ -240,10 +240,10 @@ function xpack_component:installfiles()
return self:_copiedfiles("installfiles", self:package():installdir())
end
--- get the root directory, this is just a temporary sandbox installation path,
+-- get the installed root directory, this is just a temporary sandbox installation path,
-- we may replace it with the actual installation path in the specfile
-function xpack_component:rootdir()
- return self:package():rootdir()
+function xpack_component:install_rootdir()
+ return self:package():install_rootdir()
end
-- get the installed directory
@@ -251,6 +251,21 @@ function xpack_component:installdir(...)
return self:package():installdir(...)
end
+-- get the source files
+function xpack_component:sourcefiles()
+ return self:_copiedfiles("sourcefiles", self:package():sourcedir())
+end
+
+-- get the source root directory
+function xpack_component:source_rootdir()
+ return self:package():souece_rootdir()
+end
+
+-- get the source directory
+function xpack_component:sourcedir(...)
+ return self:package():sourcedir(...)
+end
+
-- get the binary directory
function xpack_component:bindir()
return self:package():bindir()
diff --git a/xmake/scripts/xpack/runself/makeself.lsm b/xmake/scripts/xpack/runself/makeself.lsm
new file mode 100644
index 000000000..f71ea98c7
--- /dev/null
+++ b/xmake/scripts/xpack/runself/makeself.lsm
@@ -0,0 +1,11 @@
+Begin3
+Title: ${PACKAGE_TITLE}
+Version: ${PACKAGE_VERSION}
+Description: ${PACKAGE_DESCRIPTION}
+Keywords: make build
+Author: ruki ([email protected])
+Maintained-by: ruki ([email protected])
+Original-site: ${PACKAGE_HOMEPAGE}
+Platform: Unix; Windows
+Copying-policy: ${PACKAGE_COPYRIGHT}
+End
diff --git a/xmake/scripts/xpack/runself/setup.sh b/xmake/scripts/xpack/runself/setup.sh
new file mode 100755
index 000000000..1a2485251
--- /dev/null
+++ b/xmake/scripts/xpack/runself/setup.sh
@@ -0,0 +1 @@
+#!/bin/sh