summaryrefslogtreecommitdiff
path: root/xmake/plugins
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 /xmake/plugins
parent9217b528138fe4384403c0b573e8617bdcc18358 (diff)
add sourcefiles for xpack
Diffstat (limited to 'xmake/plugins')
-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
8 files changed, 162 insertions, 21 deletions
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()