summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-24 23:09:46 +0800
committerGitHub <[email protected]>2023-11-24 23:09:46 +0800
commit51efaa718683a9bf18cd6859e60f1d5240c10c5d (patch)
tree0ae3485ef5434f8acfc70210b6910356aa5adfc5
parent16f74fe53b4c240c8bee69e1d06dc821067f2817 (diff)
parent43ac546cbd551bf06ae37a8211c8a65d9eadbb0b (diff)
Merge pull request #4415 from xmake-io/makeself
pack runself
-rw-r--r--.github/workflows/macos.yml18
-rw-r--r--core/xpack.lua44
-rwxr-xr-xscripts/makeppa2
-rwxr-xr-xscripts/makeself/build-runfile.sh67
-rw-r--r--scripts/makeself/header8
-rw-r--r--scripts/makeself/lsm15
-rw-r--r--tests/plugins/pack/xmake.lua23
-rw-r--r--xmake/includes/xpack/xmake.lua16
-rw-r--r--xmake/plugins/pack/archive.lua28
-rw-r--r--xmake/plugins/pack/batchcmds.lua6
-rw-r--r--xmake/plugins/pack/main.lua56
-rw-r--r--xmake/plugins/pack/nsis/main.lua2
-rw-r--r--xmake/plugins/pack/runself/main.lua185
-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.lua82
-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
20 files changed, 466 insertions, 173 deletions
diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml
index b35c61e1a..765bf1822 100644
--- a/.github/workflows/macos.yml
+++ b/.github/workflows/macos.yml
@@ -43,19 +43,14 @@ jobs:
brew install gnu-tar
gem install --no-document fpm
cd core
- xmake pack --autobuild=n --basename=xmake -o ../artifacts xmakesrc
+ xmake pack -y --autobuild=n --basename=xmake -o ../artifacts xmakesrc
cd ..
- scripts/makeself/build-runfile.sh
- uses: actions/upload-artifact@v2
with:
name: xmake-latest.gz.run
path: artifacts/xmake.gz.run
- uses: actions/upload-artifact@v2
with:
- name: xmake-latest.xz.run
- path: artifacts/xmake.xz.run
- - uses: actions/upload-artifact@v2
- with:
name: xmake-latest.tar.gz
path: artifacts/xmake.tar.gz
- uses: actions/upload-artifact@v2
@@ -99,17 +94,6 @@ jobs:
asset_name: xmake-${{ steps.tagName.outputs.tag }}.gz.run
asset_content_type: application/zip
- - name: Publish xz runfile
- if: github.event.action == 'published'
- uses: actions/[email protected]
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ github.event.release.upload_url }}
- asset_path: artifacts/xmake.xz.run
- asset_name: xmake-${{ steps.tagName.outputs.tag }}.xz.run
- asset_content_type: application/zip
-
- name: Publish gz archive
if: github.event.action == 'published'
uses: actions/[email protected]
diff --git a/core/xpack.lua b/core/xpack.lua
index bc2df257e..e789423c2 100644
--- a/core/xpack.lua
+++ b/core/xpack.lua
@@ -77,30 +77,36 @@ xpack_component("LongPath")
end)
xpack("xmakesrc")
- set_formats("zip", "targz")
+ set_formats("srczip", "srctargz", "runself")
set_basename("xmake-v$(version)")
+ set_prefixdir("xmake-$(version)")
before_package(function (package)
import("devel.git")
- local rootdir = path.join(os.tmpfile(package:name()) .. ".dir", "repo")
- os.tryrm(rootdir)
- os.cp(path.directory(os.projectdir()), rootdir)
+ local rootdir = path.join(os.tmpfile(package:basename()) .. ".dir", "repo")
+ if not os.isdir(rootdir) then
+ os.tryrm(rootdir)
+ os.cp(path.directory(os.projectdir()), rootdir)
- git.clean({repodir = rootdir, force = true, all = true})
- git.reset({repodir = rootdir, hard = true})
- if os.isfile(path.join(rootdir, ".gitmodules")) then
- git.submodule.clean({repodir = rootdir, force = true, all = true})
- git.submodule.reset({repodir = rootdir, hard = true})
+ git.clean({repodir = rootdir, force = true, all = true})
+ git.reset({repodir = rootdir, hard = true})
+ if os.isfile(path.join(rootdir, ".gitmodules")) then
+ git.submodule.clean({repodir = rootdir, force = true, all = true})
+ git.submodule.reset({repodir = rootdir, hard = true})
+ end
end
- local prefixdir = "xmake-" .. package:version()
- local extraconf = {rootdir = rootdir, prefixdir = prefixdir}
- package:add("installfiles", path.join(rootdir, "core/**|src/pdcurses/**|src/luajit/**|src/tbox/tbox/src/demo/**"), extraconf)
- package:add("installfiles", path.join(rootdir, "xmake/**"), extraconf)
- package:add("installfiles", path.join(rootdir, "*.md"), extraconf)
- package:add("installfiles", path.join(rootdir, "configure"), extraconf)
- package:add("installfiles", path.join(rootdir, "scripts/*.sh"), extraconf)
- package:add("installfiles", path.join(rootdir, "scripts/man/**"), extraconf)
- package:add("installfiles", path.join(rootdir, "scripts/debian/**"), extraconf)
- package:add("installfiles", path.join(rootdir, "scripts/msys/**"), extraconf)
+ local extraconf = {rootdir = rootdir}
+ package:add("sourcefiles", path.join(rootdir, "core/**|src/pdcurses/**|src/luajit/**|src/tbox/tbox/src/demo/**"), extraconf)
+ package:add("sourcefiles", path.join(rootdir, "xmake/**"), extraconf)
+ package:add("sourcefiles", path.join(rootdir, "*.md"), extraconf)
+ package:add("sourcefiles", path.join(rootdir, "configure"), extraconf)
+ package:add("sourcefiles", path.join(rootdir, "scripts/*.sh"), extraconf)
+ package:add("sourcefiles", path.join(rootdir, "scripts/man/**"), extraconf)
+ package:add("sourcefiles", path.join(rootdir, "scripts/debian/**"), extraconf)
+ package:add("sourcefiles", path.join(rootdir, "scripts/msys/**"), extraconf)
+ end)
+
+ on_installcmd(function (package, batchcmds)
+ batchcmds:runv("./scripts/get.sh", {"__local__"})
end)
diff --git a/scripts/makeppa b/scripts/makeppa
index 53b559e10..2cf5fcc24 100755
--- a/scripts/makeppa
+++ b/scripts/makeppa
@@ -32,7 +32,7 @@ basename=xmake-$version+$patch$serie
tarball=$workdir/$basename.tar.gz
if [ ! -f $tarball ]; then
cd core
- xmake pack --autobuild=n --formats=targz --basename=xmake -o ../artifacts xmakesrc || exit -1
+ xmake pack --autobuild=n -y --formats=srctargz --basename=xmake -o ../artifacts xmakesrc || exit -1
cd ..
cp ./artifacts/xmake.tar.gz $tarball
fi
diff --git a/scripts/makeself/build-runfile.sh b/scripts/makeself/build-runfile.sh
deleted file mode 100755
index d3149a2cd..000000000
--- a/scripts/makeself/build-runfile.sh
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/env bash
-
-# path constants
-cd "$(dirname "$0")/../.."
-xmakeroot=`pwd`
-buildroot=$xmakeroot/scripts/makeself
-artifactsdir=$xmakeroot/artifacts
-if [ ! -d $artifactsdir ]; then
- mkdir $artifactsdir
-fi
-tmpdir=/tmp/xmake-makeself
-if [ -d $tmpdir ]; then
- rm -rf $tmpdir
-fi
-mkdir -p $tmpdir
-
-# copy xmake repo to tmpdir/repo, remove git ignored files
-cp -r $xmakeroot $tmpdir/repo
-cd $tmpdir/repo || exit
-git reset --hard HEAD
-git clean -dfX
-git submodule foreach git clean -dfX
-
-# copy files to tmpdir/xmake
-mkdir -p $tmpdir/xmake/scripts
-cd $tmpdir/repo || exit
-cp -r ./xmake $tmpdir/xmake/xmake
-cp -r ./core $tmpdir/xmake
-cp ./scripts/*.sh $tmpdir/xmake/scripts
-cp ./*.md $tmpdir/xmake
-cp configure $tmpdir/xmake
-cd $tmpdir/xmake || exit
-rm -rf ./core/src/tbox/tbox/src/demo
-rm -rf ./core/src/tbox/tbox/src/tbox/platform/windows
-rm -rf ./core/src/pdcurses
-rm -rf ./core/src/luajit
-
-# prepare info texts
-cd $tmpdir
-cp $buildroot/* .
-version=`cat ./xmake/core/xmake.lua | grep -E "^set_version" | grep -oE "[0-9]*\.[0-9]*\.[0-9]*"`
-perl -pi -e "s/#xmake-version#/$version/g" ./header
-perl -pi -e "s/#xmake-version#/$version/g" ./lsm
-
-# make run file
-cd $tmpdir
-makeself_version="2.5.0"
-curl -fsSL https://github.com/megastep/makeself/releases/download/release-$makeself_version/makeself-$makeself_version.run -o ./makeself-$makeself_version.run
-sh ./makeself-$makeself_version.run
-./makeself-$makeself_version/makeself.sh \
- --gzip \
- --sha256 \
- --lsm ./lsm \
- --help-header ./header \
- ./xmake \
- $artifactsdir/xmake.gz.run \
- xmake-v$version-runfile \
- ./scripts/get.sh __local__
-./makeself-$makeself_version/makeself.sh \
- --xz \
- --sha256 \
- --lsm ./lsm \
- --help-header ./header \
- ./xmake \
- $artifactsdir/xmake.xz.run \
- xmake-v$version-runfile \
- ./scripts/get.sh __local__
diff --git a/scripts/makeself/header b/scripts/makeself/header
deleted file mode 100644
index f247ee7bd..000000000
--- a/scripts/makeself/header
+++ /dev/null
@@ -1,8 +0,0 @@
-xmake v#xmake-version#, A cross-platform build utility based on Lua
-Copyright (C) 2015-present Ruki Wang, tboox.org, xmake.io
- _
- __ ___ __ __ __ _| | ______
- \ \/ / | \/ |/ _ | |/ / __ \
- > < | \__/ | /_| | < ___/
- /_/\_\_|_| |_|\__ \|_|\_\____|
- by ruki, xmake.io
diff --git a/scripts/makeself/lsm b/scripts/makeself/lsm
deleted file mode 100644
index 012efa4a1..000000000
--- a/scripts/makeself/lsm
+++ /dev/null
@@ -1,15 +0,0 @@
-Begin3
-Title: xmake
-Version: #xmake-version#
-Description: xmake is a cross-platform build utility based on lua.
- The project focuses on making development and building easier and
- provides many features (e.g package, install, plugin, macro, action, option, task ...),
- so that any developer can quickly pick it up and
- enjoy a productivity boost when developing and building projects.
-Keywords: make build
-Author: ruki ([email protected])
-Maintained-by: ruki ([email protected])
-Original-site: https://xmake.io/
-Platform: Unix; Windows
-Copying-policy: Apache-2.0
-End
diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/xmake.lua
index a93fc18f6..33d50b3d2 100644
--- a/tests/plugins/pack/xmake.lua
+++ b/tests/plugins/pack/xmake.lua
@@ -19,21 +19,34 @@ target("foo")
add_packages("zlib")
xpack("test")
- set_formats("nsis", "zip", "targz")
+ set_formats("nsis", "zip", "targz", "srczip", "srctargz", "runself")
set_title("hello")
+ set_author("ruki")
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"})
- batchcmds:mkdir(package:installdir("stub"))
+ if package:from_source() then
+ batchcmds:runv("echo", {"hello"})
+ else
+ batchcmds:mkdir(package:installdir("resources"))
+ batchcmds:cp("src/assets/*.txt", package:installdir("resources"), {rootdir = "src"})
+ batchcmds:mkdir(package:installdir("stub"))
+ end
end)
after_uninstallcmd(function (package, batchcmds)
diff --git a/xmake/includes/xpack/xmake.lua b/xmake/includes/xpack/xmake.lua
index 345431ffc..c6ed04201 100644
--- a/xmake/includes/xpack/xmake.lua
+++ b/xmake/includes/xpack/xmake.lua
@@ -34,13 +34,19 @@ local apis = {
"xpack.set_homepage",
-- set package title
"xpack.set_title",
+ -- set author
+ "xpack.set_author",
+ -- set maintainer,
+ "xpack.set_maintainer",
-- 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 +81,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/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua
index 1b3023283..af55cc707 100644
--- a/xmake/plugins/pack/batchcmds.lua
+++ b/xmake/plugins/pack/batchcmds.lua
@@ -363,6 +363,9 @@ end
-- on install command
function _on_installcmd(package, batchcmds_)
+ if not package:from_binary() then
+ return
+ end
local srcfiles, dstfiles = package:installfiles()
for idx, srcfile in ipairs(srcfiles) do
batchcmds_:cp(srcfile, dstfiles[idx])
@@ -374,6 +377,9 @@ end
-- on uninstall command
function _on_uninstallcmd(package, batchcmds_)
+ if not package:from_binary() then
+ return
+ end
local _, dstfiles = package:installfiles()
for _, dstfile in ipairs(dstfiles) do
batchcmds_:rm(dstfile, {emptydirs = true})
diff --git a/xmake/plugins/pack/main.lua b/xmake/plugins/pack/main.lua
index 3f145cf86..c9576774f 100644
--- a/xmake/plugins/pack/main.lua
+++ b/xmake/plugins/pack/main.lua
@@ -26,6 +26,28 @@ import("private.service.remote_build.action", {alias = "remote_build_action"})
import("actions.build.main", {rootdir = os.programdir(), alias = "build_action"})
import("xpack")
+-- get packages
+function _get_packages()
+
+ -- get need formats
+ local formats_need = option.get("formats")
+ if formats_need then
+ formats_need = formats_need:split(",")
+ if formats_need[1] == "all" then
+ formats_need = nil
+ end
+ end
+
+ local packages = {}
+ for _, package in ipairs(xpack.packages()) do
+ if not formats_need or table.contains(formats_need, package:format()) then
+ table.insert(packages, package)
+ end
+ end
+ return packages
+end
+
+-- load package
function _load_package(package)
-- ensure build and output directories
@@ -39,50 +61,42 @@ function _load_package(package)
end
end
+-- pack the given package
function _on_package(package)
import(package:format())(package)
end
function _pack_package(package)
- -- get need formats
- local formats_need = option.get("formats")
- if formats_need then
- formats_need = formats_need:split(",")
- if formats_need[1] == "all" then
- formats_need = nil
- end
- end
-
-- do pack
local scripts = {
package:script("package_before"),
package:script("package", _on_package),
package:script("package_after")
}
- if not formats_need or table.contains(formats_need, package:format()) then
- _load_package(package)
- for i = 1, 3 do
- local script = scripts[i]
- if script ~= nil then
- script(package)
- end
+ _load_package(package)
+ for i = 1, 3 do
+ local script = scripts[i]
+ if script ~= nil then
+ script(package)
end
end
end
function _pack_packages()
- for _, package in ipairs(xpack.packages()) do
+ for _, package in ipairs(_get_packages()) do
_pack_package(package)
end
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)
+ for _, package in ipairs(_get_packages()) do
+ 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/runself/main.lua b/xmake/plugins/pack/runself/main.lua
new file mode 100644
index 000000000..8f25c3e80
--- /dev/null
+++ b/xmake/plugins/pack/runself/main.lua
@@ -0,0 +1,185 @@
+--!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("core.base.option")
+import("core.base.semver")
+import("lib.detect.find_tool")
+import("private.action.require.impl.packagenv")
+import("private.action.require.impl.install_packages")
+import(".batchcmds")
+
+-- get the makeself
+function _get_makeself()
+
+ -- enter the environments of makeself
+ local oldenvs = packagenv.enter("makeself")
+
+ -- find makeself
+ local packages = {}
+ local makeself = find_tool("makeself.sh")
+ if not makeself then
+ table.join2(packages, install_packages("makeself"))
+ end
+
+ -- enter the environments of installed packages
+ for _, instance in ipairs(packages) do
+ instance:envs_enter()
+ end
+
+ -- we need to force detect and flush detect cache after loading all environments
+ if not makeself then
+ 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
+
+-- write install command
+function _write_installcmd(package, scriptfile, cmd)
+ local opt = cmd.opt or {}
+ local kind = cmd.kind
+ if kind == "cp" then
+ local srcfiles = os.files(cmd.srcpath)
+ for _, srcfile in ipairs(srcfiles) do
+ -- the destination is directory? append the filename
+ local dstfile = cmd.dstpath
+ if #srcfiles > 1 or path.islastsep(dstfile) then
+ if opt.rootdir then
+ dstfile = path.join(dstfile, path.relative(srcfile, opt.rootdir))
+ else
+ dstfile = path.join(dstfile, path.filename(srcfile))
+ end
+ end
+ scriptfile:print("cp -p \"%s\" \"%s\"", srcfile, dstfile)
+ end
+ elseif kind == "rm" then
+ local filepath = cmd.filepath
+ scriptfile:print("rm -f \"%s\"", filepath)
+ elseif kind == "rmdir" then
+ local dir = cmd.dir
+ scriptfile:print("rm -rf \"%s\"", dir)
+ elseif kind == "mv" then
+ local srcpath = cmd.srcpath
+ local dstpath = cmd.dstpath
+ scriptfile:print("mv \"%s\" \"%s\"", srcfile, dstfile)
+ elseif kind == "cd" then
+ local dir = cmd.dir
+ scriptfile:print("cd \"%s\"", dir)
+ elseif kind == "mkdir" then
+ local dir = cmd.dir
+ scriptfile:print("mkdir -p \"%s\"", dir)
+ elseif cmd.program then
+ scriptfile:print("%s", os.args(table.join(cmd.program, cmd.argv)))
+ end
+end
+
+-- write install commands
+function _write_installcmds(package, scriptfile, cmds)
+ for _, cmd in ipairs(cmds) do
+ _write_installcmd(package, scriptfile, cmd)
+ end
+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)
+
+ -- archive source files
+ 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
+
+ -- generate the setup.sh script
+ local sourcedir = package:sourcedir()
+ local setupfile = path.join(sourcedir, "__setup__.sh")
+ os.cp(path.join(os.programdir(), "scripts", "xpack", "runself", "setup.sh"), setupfile)
+ local scriptfile = io.open(setupfile, "a+")
+ if scriptfile then
+ _write_installcmds(package, scriptfile, batchcmds.get_installcmds(package):cmds())
+ for _, component in table.orderpairs(package:components()) do
+ if component:get("default") ~= false then
+ _write_installcmds(package, scriptfile, batchcmds.get_installcmds(component):cmds())
+ end
+ end
+ scriptfile:close()
+ end
+
+ -- make package
+ os.vrunv(makeself, {"--gzip", "--sha256", "--lsm", specfile,
+ sourcedir, package:outputfile(), package:basename(), "./__setup__.sh"})
+end
+
+function main(package)
+
+ if is_subhost("windows") then
+ return
+ end
+
+ cprint("packing %s", package:outputfile())
+
+ -- get makeself
+ local makeself, oldenvs = _get_makeself()
+
+ -- pack runself package
+ _pack_runself(makeself.program, package)
+
+ -- done
+ os.setenvs(oldenvs)
+end
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 e5829fd45..64e9d77dc 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
@@ -264,6 +296,8 @@ function xpack:specvars()
PACKAGE_TITLE = self:title() or "",
PACKAGE_DESCRIPTION = self:description() or "",
PACKAGE_FILENAME = self:filename(),
+ PACKAGE_AUTHOR = self:get("author") or "",
+ PACKAGE_MAINTAINER = self:get("maintainer") or self:get("author") or "",
PACKAGE_HOMEPAGE = self:get("homepage") or "",
PACKAGE_COPYRIGHT = self:get("copyright") or "",
PACKAGE_COMPANY = self:get("company") or "",
@@ -336,9 +370,14 @@ function xpack:extension()
local extension = self:get("extension")
if extension == nil then
local extensions = {
- nsis = ".exe",
- zip = ".zip",
- targz = ".tar.gz"
+ nsis = ".exe",
+ zip = ".zip",
+ targz = ".tar.gz",
+ srczip = ".zip",
+ srctargz = ".tar.gz",
+ runself = ".gz.run",
+ deb = ".deb",
+ rpm = ".rpm"
}
extension = extensions[self:format()] or ""
end
@@ -465,22 +504,51 @@ 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 prefixdir = self:get("prefixdir")
+ local installdir = self:install_rootdir()
+ local prefixdir = self:prefixdir()
if prefixdir then
installdir = path.join(installdir, prefixdir)
end
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:prefixdir()
+ if prefixdir then
+ sourcedir = path.join(sourcedir, prefixdir)
+ end
+ return path.normalize(path.join(sourcedir, ...))
+end
+
+-- get the prefixdir
+function xpack:prefixdir()
+ local prefixdir = self:get("prefixdir")
+ if prefixdir then
+ return filter.handle(prefixdir, self)
+ end
+ return prefixdir
+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..206c302c5
--- /dev/null
+++ b/xmake/scripts/xpack/runself/makeself.lsm
@@ -0,0 +1,11 @@
+Begin3
+Title: ${PACKAGE_TITLE}
+Version: ${PACKAGE_VERSION}
+Description: ${PACKAGE_DESCRIPTION}
+Keywords: ${PACKAGE_NAME}
+Author: $(PACKAGE_AUTHOR)
+Maintained-by: $(PACKAGE_MAINTAINER)
+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