diff options
| author | ruki <[email protected]> | 2025-11-26 00:38:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-26 00:38:21 +0800 |
| commit | 79d611989dc8004733a4a81ef7124466788b79f4 (patch) | |
| tree | 4705336de6e11fface14883cc9114b6f8969cd06 | |
| parent | 76dc60d1552a0afe1faffd996a36a412e44d548d (diff) | |
add dmg xpack format
| -rw-r--r-- | tests/plugins/pack/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_hdiutil.lua | 64 | ||||
| -rw-r--r-- | xmake/plugins/pack/dmg/main.lua | 86 | ||||
| -rw-r--r-- | xmake/plugins/pack/xpack.lua | 3 |
4 files changed, 154 insertions, 1 deletions
diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/xmake.lua index cf07d8ca6..244bcaee6 100644 --- a/tests/plugins/pack/xmake.lua +++ b/tests/plugins/pack/xmake.lua @@ -19,7 +19,7 @@ target("foo") add_packages("zlib") xpack("test") - set_formats("nsis", "srpm", "rpm", "deb", "zip", "targz", "srczip", "srctargz", "runself", "wix") + set_formats("nsis", "srpm", "rpm", "deb", "zip", "targz", "srczip", "srctargz", "runself", "wix", "dmg") set_title("hello") set_author("ruki <[email protected]>") set_description("A test installer.") diff --git a/xmake/modules/detect/tools/find_hdiutil.lua b/xmake/modules/detect/tools/find_hdiutil.lua new file mode 100644 index 000000000..c2d0d2a3b --- /dev/null +++ b/xmake/modules/detect/tools/find_hdiutil.lua @@ -0,0 +1,64 @@ +--!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, Xmake Open Source Community. +-- +-- @author ruki +-- @file find_hdiutil.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find hdiutil +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local hdiutil = find_hdiutil() +-- local hdiutil, version = find_hdiutil({version = true}) +-- +-- @endcode +-- +function main(opt) + + -- only for macosx + if not is_host("macosx") then + return + end + + -- init options + opt = opt or {} + opt.check = opt.check or "help" + + -- find program + local program = find_program(opt.program or "hdiutil", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + opt.command = opt.command or "info" + opt.parse = opt.parse or function (output) + -- extract version from "framework : 671.140.2" or "driver : 671.140.2" + return output:match("framework%s*:%s*(%d+%.%d+%.%d+)") or output:match("driver%s*:%s*(%d+%.%d+%.%d+)") + end + version = find_programver(program, opt) + end + return program, version +end + diff --git a/xmake/plugins/pack/dmg/main.lua b/xmake/plugins/pack/dmg/main.lua new file mode 100644 index 000000000..51520c79c --- /dev/null +++ b/xmake/plugins/pack/dmg/main.lua @@ -0,0 +1,86 @@ +--!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, Xmake Open Source Community. +-- +-- @author ruki +-- @file main.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") +import(".batchcmds") + +-- pack dmg package +function _pack_dmg(package) + + -- check platform + assert(package:is_plat("macosx"), "dmg format only supports macOS platform!") + + -- get hdiutil + local hdiutil = find_tool("hdiutil") + assert(hdiutil, "hdiutil not found! Please install Xcode Command Line Tools.") + + -- 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 + + -- get install root directory + local rootdir = package:install_rootdir() + assert(os.isdir(rootdir), "install root directory not found: %s", rootdir) + + -- get output file + local outputfile = package:outputfile() + os.tryrm(outputfile) + + -- create temporary directory for DMG + local tmpdir = os.tmpfile() .. ".dir" + os.mkdir(tmpdir) + + -- copy files to temporary directory + local dmgname = path.basename(outputfile, ".dmg") + local dmgdir = path.join(tmpdir, dmgname) + os.cp(rootdir, dmgdir) + + -- create DMG using hdiutil + -- create a read-only DMG with UDZO format (compressed) + local argv = { + "create", + "-volname", package:title() or package:name() or dmgname, + "-srcfolder", dmgdir, + "-ov", + "-format", "UDZO", + outputfile + } + + -- run hdiutil + os.vrunv(hdiutil.program, argv) + + -- clean temporary directory + os.rm(tmpdir) + + -- verify DMG was created + assert(os.isfile(outputfile), "generate %s failed!", outputfile) +end + +function main(package) + cprint("packing %s .. ", package:outputfile()) + _pack_dmg(package) +end + diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua index 6382a7370..1e39d6a83 100644 --- a/xmake/plugins/pack/xpack.lua +++ b/xmake/plugins/pack/xpack.lua @@ -205,6 +205,7 @@ function xpack:inputkind() nsis = "binary", zip = "binary", targz = "binary", + dmg = "binary", srczip = "source", srctargz = "source", runself = "source", @@ -224,6 +225,7 @@ function xpack:outputkind() nsis = "binary", zip = "binary", targz = "binary", + dmg = "binary", srczip = "source", srctargz = "source", runself = "source", @@ -373,6 +375,7 @@ function xpack:extension() nsis = ".exe", zip = ".zip", targz = ".tar.gz", + dmg = ".dmg", srczip = ".zip", srctargz = ".tar.gz", runself = ".gz.run", |
