Skip to content

Commit

Permalink
Merge pull request #4415 from xmake-io/makeself
Browse files Browse the repository at this point in the history
pack runself
  • Loading branch information
waruqi authored Nov 24, 2023
2 parents 16f74fe + 43ac546 commit 51efaa7
Show file tree
Hide file tree
Showing 20 changed files with 466 additions and 173 deletions.
18 changes: 1 addition & 17 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,12 @@ 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
Expand Down Expand Up @@ -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/upload-release-asset@v1.0.1
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/upload-release-asset@v1.0.1
Expand Down
44 changes: 25 additions & 19 deletions core/xpack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion scripts/makeppa
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 0 additions & 67 deletions scripts/makeself/build-runfile.sh

This file was deleted.

8 changes: 0 additions & 8 deletions scripts/makeself/header

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/makeself/lsm

This file was deleted.

23 changes: 18 additions & 5 deletions tests/plugins/pack/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions xmake/includes/xpack/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 22 additions & 6 deletions xmake/plugins/pack/archive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions xmake/plugins/pack/batchcmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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})
Expand Down
Loading

0 comments on commit 51efaa7

Please sign in to comment.