From 79d611989dc8004733a4a81ef7124466788b79f4 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 26 Nov 2025 00:38:21 +0800 Subject: add dmg xpack format --- tests/plugins/pack/xmake.lua | 2 +- xmake/modules/detect/tools/find_hdiutil.lua | 64 +++++++++++++++++++++ xmake/plugins/pack/dmg/main.lua | 86 +++++++++++++++++++++++++++++ xmake/plugins/pack/xpack.lua | 3 + 4 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 xmake/modules/detect/tools/find_hdiutil.lua create mode 100644 xmake/plugins/pack/dmg/main.lua 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 ") 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", -- cgit v1.3.1 From 7a15f43c268a3cd192fedbcf6f0a65ab80f1646d Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 26 Nov 2025 00:49:39 +0800 Subject: add pack macapp test --- tests/plugins/pack/.gitignore | 8 - tests/plugins/pack/LICENSE.md | 203 --------------------- tests/plugins/pack/console/.gitignore | 8 + tests/plugins/pack/console/LICENSE.md | 203 +++++++++++++++++++++ tests/plugins/pack/console/include/foo/foo.h | 0 tests/plugins/pack/console/include/test.h | 0 tests/plugins/pack/console/src/assets/file1.txt | 1 + tests/plugins/pack/console/src/assets/file2.txt | 1 + tests/plugins/pack/console/src/assets/img1.png | 0 tests/plugins/pack/console/src/assets/img2.png | 0 tests/plugins/pack/console/src/assets/xmake.ico | Bin 0 -> 119943 bytes tests/plugins/pack/console/src/main.cpp | 8 + tests/plugins/pack/console/src/xmake.rc | 1 + tests/plugins/pack/console/xmake.lua | 74 ++++++++ tests/plugins/pack/include/foo/foo.h | 0 tests/plugins/pack/include/test.h | 0 tests/plugins/pack/macapp/src/AppDelegate.h | 15 ++ tests/plugins/pack/macapp/src/AppDelegate.m | 28 +++ .../AppIcon.appiconset/Contents.json | 59 ++++++ .../pack/macapp/src/Assets.xcassets/Contents.json | 7 + .../pack/macapp/src/Base.lproj/Main.storyboard | 73 ++++++++ tests/plugins/pack/macapp/src/Info.plist | 39 ++++ tests/plugins/pack/macapp/src/ViewController.h | 15 ++ tests/plugins/pack/macapp/src/ViewController.m | 28 +++ tests/plugins/pack/macapp/src/main.m | 17 ++ tests/plugins/pack/macapp/xmake.lua | 19 ++ tests/plugins/pack/src/assets/file1.txt | 1 - tests/plugins/pack/src/assets/file2.txt | 1 - tests/plugins/pack/src/assets/img1.png | 0 tests/plugins/pack/src/assets/img2.png | 0 tests/plugins/pack/src/assets/xmake.ico | Bin 119943 -> 0 bytes tests/plugins/pack/src/main.cpp | 8 - tests/plugins/pack/src/xmake.rc | 1 - tests/plugins/pack/xmake.lua | 74 -------- 34 files changed, 596 insertions(+), 296 deletions(-) delete mode 100644 tests/plugins/pack/.gitignore delete mode 100644 tests/plugins/pack/LICENSE.md create mode 100644 tests/plugins/pack/console/.gitignore create mode 100644 tests/plugins/pack/console/LICENSE.md create mode 100644 tests/plugins/pack/console/include/foo/foo.h create mode 100644 tests/plugins/pack/console/include/test.h create mode 100644 tests/plugins/pack/console/src/assets/file1.txt create mode 100644 tests/plugins/pack/console/src/assets/file2.txt create mode 100644 tests/plugins/pack/console/src/assets/img1.png create mode 100644 tests/plugins/pack/console/src/assets/img2.png create mode 100644 tests/plugins/pack/console/src/assets/xmake.ico create mode 100644 tests/plugins/pack/console/src/main.cpp create mode 100644 tests/plugins/pack/console/src/xmake.rc create mode 100644 tests/plugins/pack/console/xmake.lua delete mode 100644 tests/plugins/pack/include/foo/foo.h delete mode 100644 tests/plugins/pack/include/test.h create mode 100644 tests/plugins/pack/macapp/src/AppDelegate.h create mode 100644 tests/plugins/pack/macapp/src/AppDelegate.m create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/Contents.json create mode 100644 tests/plugins/pack/macapp/src/Base.lproj/Main.storyboard create mode 100644 tests/plugins/pack/macapp/src/Info.plist create mode 100644 tests/plugins/pack/macapp/src/ViewController.h create mode 100644 tests/plugins/pack/macapp/src/ViewController.m create mode 100644 tests/plugins/pack/macapp/src/main.m create mode 100644 tests/plugins/pack/macapp/xmake.lua delete mode 100644 tests/plugins/pack/src/assets/file1.txt delete mode 100644 tests/plugins/pack/src/assets/file2.txt delete mode 100644 tests/plugins/pack/src/assets/img1.png delete mode 100644 tests/plugins/pack/src/assets/img2.png delete mode 100644 tests/plugins/pack/src/assets/xmake.ico delete mode 100644 tests/plugins/pack/src/main.cpp delete mode 100644 tests/plugins/pack/src/xmake.rc delete mode 100644 tests/plugins/pack/xmake.lua diff --git a/tests/plugins/pack/.gitignore b/tests/plugins/pack/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/plugins/pack/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/plugins/pack/LICENSE.md b/tests/plugins/pack/LICENSE.md deleted file mode 100644 index fe2ff7e48..000000000 --- a/tests/plugins/pack/LICENSE.md +++ /dev/null @@ -1,203 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2015-present Xmake Open Source Community - - 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. - diff --git a/tests/plugins/pack/console/.gitignore b/tests/plugins/pack/console/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/plugins/pack/console/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/plugins/pack/console/LICENSE.md b/tests/plugins/pack/console/LICENSE.md new file mode 100644 index 000000000..fe2ff7e48 --- /dev/null +++ b/tests/plugins/pack/console/LICENSE.md @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2015-present Xmake Open Source Community + + 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. + diff --git a/tests/plugins/pack/console/include/foo/foo.h b/tests/plugins/pack/console/include/foo/foo.h new file mode 100644 index 000000000..e69de29bb diff --git a/tests/plugins/pack/console/include/test.h b/tests/plugins/pack/console/include/test.h new file mode 100644 index 000000000..e69de29bb diff --git a/tests/plugins/pack/console/src/assets/file1.txt b/tests/plugins/pack/console/src/assets/file1.txt new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/tests/plugins/pack/console/src/assets/file1.txt @@ -0,0 +1 @@ +hello diff --git a/tests/plugins/pack/console/src/assets/file2.txt b/tests/plugins/pack/console/src/assets/file2.txt new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/tests/plugins/pack/console/src/assets/file2.txt @@ -0,0 +1 @@ +hello diff --git a/tests/plugins/pack/console/src/assets/img1.png b/tests/plugins/pack/console/src/assets/img1.png new file mode 100644 index 000000000..e69de29bb diff --git a/tests/plugins/pack/console/src/assets/img2.png b/tests/plugins/pack/console/src/assets/img2.png new file mode 100644 index 000000000..e69de29bb diff --git a/tests/plugins/pack/console/src/assets/xmake.ico b/tests/plugins/pack/console/src/assets/xmake.ico new file mode 100644 index 000000000..52c8ef389 Binary files /dev/null and b/tests/plugins/pack/console/src/assets/xmake.ico differ diff --git a/tests/plugins/pack/console/src/main.cpp b/tests/plugins/pack/console/src/main.cpp new file mode 100644 index 000000000..55d2f380a --- /dev/null +++ b/tests/plugins/pack/console/src/main.cpp @@ -0,0 +1,8 @@ +#include + +using namespace std; + +int main(int argc, char **argv) { + cout << "hello world!" << endl; + return 0; +} diff --git a/tests/plugins/pack/console/src/xmake.rc b/tests/plugins/pack/console/src/xmake.rc new file mode 100644 index 000000000..3a2783607 --- /dev/null +++ b/tests/plugins/pack/console/src/xmake.rc @@ -0,0 +1 @@ +IDI_APP ICON DISCARDABLE "assets/xmake.ico" diff --git a/tests/plugins/pack/console/xmake.lua b/tests/plugins/pack/console/xmake.lua new file mode 100644 index 000000000..244bcaee6 --- /dev/null +++ b/tests/plugins/pack/console/xmake.lua @@ -0,0 +1,74 @@ +set_version("1.0.0") +add_rules("mode.debug", "mode.release") + +includes("@builtin/xpack") + +add_requires("zlib", {configs = {shared = true}}) + +target("test") + set_kind("binary") + add_files("src/*.cpp") + if is_plat("windows") then + add_files("src/*.rc") + end + +target("foo") + set_kind("shared") + add_files("src/*.cpp") + add_headerfiles("include/(*.h)") + add_packages("zlib") + +xpack("test") + set_formats("nsis", "srpm", "rpm", "deb", "zip", "targz", "srczip", "srctargz", "runself", "wix", "dmg") + set_title("hello") + set_author("ruki ") + set_description("A test installer.") + set_homepage("https://xmake.io") + set_license("Apache-2.0") + set_licensefile("LICENSE.md") + add_targets("test", "foo") + add_installfiles("src/(assets/*.png)", {prefixdir = "images"}) + add_sourcefiles("(src/**)") + add_sourcefiles("xmake.lua") + set_iconfile("src/assets/xmake.ico") + add_components("LongPath") + + on_load(function (package) + if package:with_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) + if package:format() == "runself" 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) + batchcmds:rmdir(package:installdir("resources")) + batchcmds:rmdir(package:installdir("stub")) + end) + +xpack_component("LongPath") + set_default(false) + set_title("Enable Long Path") + set_description("Increases the maximum path length limit, up to 32,767 characters (before 256).") + on_installcmd(function (component, batchcmds) + batchcmds:rawcmd("wix", [[ + + + + ]]) + batchcmds:rawcmd("nsis", [[ + ${If} $NoAdmin == "false" + ; Enable long path + WriteRegDWORD ${HKLM} "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1 + ${EndIf}]]) + end) diff --git a/tests/plugins/pack/include/foo/foo.h b/tests/plugins/pack/include/foo/foo.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/plugins/pack/include/test.h b/tests/plugins/pack/include/test.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/plugins/pack/macapp/src/AppDelegate.h b/tests/plugins/pack/macapp/src/AppDelegate.h new file mode 100644 index 000000000..413f74ce4 --- /dev/null +++ b/tests/plugins/pack/macapp/src/AppDelegate.h @@ -0,0 +1,15 @@ +// +// AppDelegate.h +// macapp +// +// Created by ruki on 2020/4/4. +// Copyright © 2020 tboox. All rights reserved. +// + +#import + +@interface AppDelegate : NSObject + + +@end + diff --git a/tests/plugins/pack/macapp/src/AppDelegate.m b/tests/plugins/pack/macapp/src/AppDelegate.m new file mode 100644 index 000000000..b6c5d02ab --- /dev/null +++ b/tests/plugins/pack/macapp/src/AppDelegate.m @@ -0,0 +1,28 @@ +// +// AppDelegate.m +// macapp +// +// Created by ruki on 2020/4/4. +// Copyright © 2020 tboox. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + // Insert code here to initialize your application +} + + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + // Insert code here to tear down your application +} + + +@end + diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/Contents.json b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..9d5c8a516 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,59 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} + diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/Contents.json b/tests/plugins/pack/macapp/src/Assets.xcassets/Contents.json new file mode 100644 index 000000000..7afcdfaf8 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/Contents.json @@ -0,0 +1,7 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} + diff --git a/tests/plugins/pack/macapp/src/Base.lproj/Main.storyboard b/tests/plugins/pack/macapp/src/Base.lproj/Main.storyboard new file mode 100644 index 000000000..dd1212a78 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Base.lproj/Main.storyboard @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/plugins/pack/macapp/src/Info.plist b/tests/plugins/pack/macapp/src/Info.plist new file mode 100644 index 000000000..f111cb4c3 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Info.plist @@ -0,0 +1,39 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundleDisplayName + $(PRODUCT_DISPLAY_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2020 tboox. All rights reserved. + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + NSSupportsAutomaticTermination + + NSSupportsSuddenTermination + + + + diff --git a/tests/plugins/pack/macapp/src/ViewController.h b/tests/plugins/pack/macapp/src/ViewController.h new file mode 100644 index 000000000..41858ce17 --- /dev/null +++ b/tests/plugins/pack/macapp/src/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// macapp +// +// Created by ruki on 2020/4/4. +// Copyright © 2020 tboox. All rights reserved. +// + +#import + +@interface ViewController : NSViewController + + +@end + diff --git a/tests/plugins/pack/macapp/src/ViewController.m b/tests/plugins/pack/macapp/src/ViewController.m new file mode 100644 index 000000000..23f78028d --- /dev/null +++ b/tests/plugins/pack/macapp/src/ViewController.m @@ -0,0 +1,28 @@ +// +// ViewController.m +// macapp +// +// Created by ruki on 2020/4/4. +// Copyright © 2020 tboox. All rights reserved. +// + +#import "ViewController.h" + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + // Do any additional setup after loading the view. +} + + +- (void)setRepresentedObject:(id)representedObject { + [super setRepresentedObject:representedObject]; + + // Update the view, if already loaded. +} + + +@end + diff --git a/tests/plugins/pack/macapp/src/main.m b/tests/plugins/pack/macapp/src/main.m new file mode 100644 index 000000000..01b588b66 --- /dev/null +++ b/tests/plugins/pack/macapp/src/main.m @@ -0,0 +1,17 @@ +// +// main.m +// macapp +// +// Created by ruki on 2020/4/4. +// Copyright © 2020 tboox. All rights reserved. +// + +#import + +int main(int argc, const char * argv[]) { + @autoreleasepool { + // Setup code that might create autoreleased objects goes here. + } + return NSApplicationMain(argc, argv); +} + diff --git a/tests/plugins/pack/macapp/xmake.lua b/tests/plugins/pack/macapp/xmake.lua new file mode 100644 index 000000000..4dd391ae0 --- /dev/null +++ b/tests/plugins/pack/macapp/xmake.lua @@ -0,0 +1,19 @@ +set_version("1.0.0") +add_rules("mode.debug", "mode.release") + +includes("@builtin/xpack") + +target("macapp") + add_rules("xcode.application") + add_files("src/*.m", "src/**.storyboard", "src/*.xcassets") + add_files("src/Info.plist") + +xpack("macapp") + set_formats("dmg") + set_title("MacApp Test") + set_author("ruki ") + set_description("A test macOS application installer.") + set_homepage("https://xmake.io") + set_license("Apache-2.0") + add_targets("macapp") + diff --git a/tests/plugins/pack/src/assets/file1.txt b/tests/plugins/pack/src/assets/file1.txt deleted file mode 100644 index ce0136250..000000000 --- a/tests/plugins/pack/src/assets/file1.txt +++ /dev/null @@ -1 +0,0 @@ -hello diff --git a/tests/plugins/pack/src/assets/file2.txt b/tests/plugins/pack/src/assets/file2.txt deleted file mode 100644 index ce0136250..000000000 --- a/tests/plugins/pack/src/assets/file2.txt +++ /dev/null @@ -1 +0,0 @@ -hello diff --git a/tests/plugins/pack/src/assets/img1.png b/tests/plugins/pack/src/assets/img1.png deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/plugins/pack/src/assets/img2.png b/tests/plugins/pack/src/assets/img2.png deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/plugins/pack/src/assets/xmake.ico b/tests/plugins/pack/src/assets/xmake.ico deleted file mode 100644 index 52c8ef389..000000000 Binary files a/tests/plugins/pack/src/assets/xmake.ico and /dev/null differ diff --git a/tests/plugins/pack/src/main.cpp b/tests/plugins/pack/src/main.cpp deleted file mode 100644 index 55d2f380a..000000000 --- a/tests/plugins/pack/src/main.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -using namespace std; - -int main(int argc, char **argv) { - cout << "hello world!" << endl; - return 0; -} diff --git a/tests/plugins/pack/src/xmake.rc b/tests/plugins/pack/src/xmake.rc deleted file mode 100644 index 3a2783607..000000000 --- a/tests/plugins/pack/src/xmake.rc +++ /dev/null @@ -1 +0,0 @@ -IDI_APP ICON DISCARDABLE "assets/xmake.ico" diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/xmake.lua deleted file mode 100644 index 244bcaee6..000000000 --- a/tests/plugins/pack/xmake.lua +++ /dev/null @@ -1,74 +0,0 @@ -set_version("1.0.0") -add_rules("mode.debug", "mode.release") - -includes("@builtin/xpack") - -add_requires("zlib", {configs = {shared = true}}) - -target("test") - set_kind("binary") - add_files("src/*.cpp") - if is_plat("windows") then - add_files("src/*.rc") - end - -target("foo") - set_kind("shared") - add_files("src/*.cpp") - add_headerfiles("include/(*.h)") - add_packages("zlib") - -xpack("test") - set_formats("nsis", "srpm", "rpm", "deb", "zip", "targz", "srczip", "srctargz", "runself", "wix", "dmg") - set_title("hello") - set_author("ruki ") - set_description("A test installer.") - set_homepage("https://xmake.io") - set_license("Apache-2.0") - set_licensefile("LICENSE.md") - add_targets("test", "foo") - add_installfiles("src/(assets/*.png)", {prefixdir = "images"}) - add_sourcefiles("(src/**)") - add_sourcefiles("xmake.lua") - set_iconfile("src/assets/xmake.ico") - add_components("LongPath") - - on_load(function (package) - if package:with_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) - if package:format() == "runself" 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) - batchcmds:rmdir(package:installdir("resources")) - batchcmds:rmdir(package:installdir("stub")) - end) - -xpack_component("LongPath") - set_default(false) - set_title("Enable Long Path") - set_description("Increases the maximum path length limit, up to 32,767 characters (before 256).") - on_installcmd(function (component, batchcmds) - batchcmds:rawcmd("wix", [[ - - - - ]]) - batchcmds:rawcmd("nsis", [[ - ${If} $NoAdmin == "false" - ; Enable long path - WriteRegDWORD ${HKLM} "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1 - ${EndIf}]]) - end) -- cgit v1.3.1 From fb1111bb6fae0f6bab1d9be1464e06af8e1ba5f1 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 26 Nov 2025 22:29:42 +0800 Subject: pack mac app --- xmake/rules/xcode/application/xmake.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xmake/rules/xcode/application/xmake.lua b/xmake/rules/xcode/application/xmake.lua index ecffaeeac..d809261c5 100644 --- a/xmake/rules/xcode/application/xmake.lua +++ b/xmake/rules/xcode/application/xmake.lua @@ -36,6 +36,9 @@ rule("xcode.application") -- install application on_install("install") + -- install application for xpack + after_installcmd("installcmd") + -- uninstall application on_uninstall("uninstall") -- cgit v1.3.1 From 46c195785c1d52841df7500f40bba59c144cd536 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 26 Nov 2025 22:32:19 +0800 Subject: add installcmd --- xmake/rules/xcode/application/installcmd.lua | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 xmake/rules/xcode/application/installcmd.lua diff --git a/xmake/rules/xcode/application/installcmd.lua b/xmake/rules/xcode/application/installcmd.lua new file mode 100644 index 000000000..39d64ab1c --- /dev/null +++ b/xmake/rules/xcode/application/installcmd.lua @@ -0,0 +1,48 @@ +--!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 installcmd.lua +-- + +-- install application for xpack +function main(target, batchcmds, opt) + local package = opt.package + + -- only for macosx when packing dmg + if not target:is_plat("macosx") then + return + end + + -- get app directory + local appdir = target:data("xcode.bundle.rootdir") + if not appdir or not os.isdir(appdir) then + return + end + + -- get install directory + -- for dmg packing, we install .app to the root of install directory + local installdir = package:installdir() + if not installdir then + return + end + + -- copy .app to install directory + local appname = path.filename(appdir) + local dstappdir = path.join(installdir, appname) + batchcmds:cp(appdir, dstappdir, {symlink = true}) +end + -- cgit v1.3.1 From fe96cdcbaa858ebcec0935d42b3409487e05e511 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 26 Nov 2025 22:32:50 +0800 Subject: use builddir --- xmake/plugins/pack/dmg/main.lua | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/xmake/plugins/pack/dmg/main.lua b/xmake/plugins/pack/dmg/main.lua index 51520c79c..54fb30f5a 100644 --- a/xmake/plugins/pack/dmg/main.lua +++ b/xmake/plugins/pack/dmg/main.lua @@ -49,21 +49,23 @@ function _pack_dmg(package) local outputfile = package:outputfile() os.tryrm(outputfile) - -- create temporary directory for DMG - local tmpdir = os.tmpfile() .. ".dir" - os.mkdir(tmpdir) + -- create directory for DMG in builddir + local builddir = package:builddir() + local dmgdir = path.join(builddir, "dmg") + os.tryrm(dmgdir) + os.mkdir(dmgdir) - -- copy files to temporary directory + -- copy files to DMG directory local dmgname = path.basename(outputfile, ".dmg") - local dmgdir = path.join(tmpdir, dmgname) - os.cp(rootdir, dmgdir) + local dmgcontentdir = path.join(dmgdir, dmgname) + os.cp(rootdir, dmgcontentdir) -- 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, + "-srcfolder", dmgcontentdir, "-ov", "-format", "UDZO", outputfile @@ -72,9 +74,6 @@ function _pack_dmg(package) -- 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 -- cgit v1.3.1 From eba4c503ccaf873a87ec1f867ba3dffd98b45800 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 26 Nov 2025 22:35:21 +0800 Subject: improve app/on_installcmd --- xmake/plugins/pack/batchcmds.lua | 22 ++++++++++++++++++++++ xmake/rules/xcode/application/installcmd.lua | 24 +++++++++++++++++++++++- xmake/rules/xcode/application/xmake.lua | 2 +- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua index b67d66b5b..09b42d7c9 100644 --- a/xmake/plugins/pack/batchcmds.lua +++ b/xmake/plugins/pack/batchcmds.lua @@ -334,6 +334,17 @@ function _on_target_installcmd(target, batchcmds_, opt) return end + -- check if target rules have on_installcmd, use rule's logic first + local done = false + for _, r in ipairs(target:orderules()) do + local on_installcmd = r:script("installcmd") + if on_installcmd then + on_installcmd(target, batchcmds_, opt) + done = true + end + end + if done then return end + -- install target binaries local scripts = { binary = _on_target_installcmd_binary, @@ -416,6 +427,17 @@ function _on_target_uninstallcmd(target, batchcmds_, opt) return end + -- check if target rules have on_uninstallcmd, use rule's logic first + local done = false + for _, r in ipairs(target:orderules()) do + local on_uninstallcmd = r:script("uninstallcmd") + if on_uninstallcmd then + on_uninstallcmd(target, batchcmds_, opt) + done = true + end + end + if done then return end + -- uninstall target binaries local scripts = { binary = _on_target_uninstallcmd_binary, diff --git a/xmake/rules/xcode/application/installcmd.lua b/xmake/rules/xcode/application/installcmd.lua index 39d64ab1c..c08a0fede 100644 --- a/xmake/rules/xcode/application/installcmd.lua +++ b/xmake/rules/xcode/application/installcmd.lua @@ -22,11 +22,16 @@ function main(target, batchcmds, opt) local package = opt.package - -- only for macosx when packing dmg + -- only for macosx when packing if not target:is_plat("macosx") then return end + -- only for xpack (package exists) + if not package then + return + end + -- get app directory local appdir = target:data("xcode.bundle.rootdir") if not appdir or not os.isdir(appdir) then @@ -44,5 +49,22 @@ function main(target, batchcmds, opt) local appname = path.filename(appdir) local dstappdir = path.join(installdir, appname) batchcmds:cp(appdir, dstappdir, {symlink = true}) + + -- install target files (skip binary installation) + local srcfiles, dstfiles = target:installfiles(installdir) + if srcfiles and dstfiles then + for idx, srcfile in ipairs(srcfiles) do + batchcmds:cp(srcfile, dstfiles[idx], {symlink = true}) + end + end + -- install dependent target files + for _, dep in ipairs(target:orderdeps()) do + local srcfiles, dstfiles = dep:installfiles(installdir, {interface = true}) + if srcfiles and dstfiles then + for idx, srcfile in ipairs(srcfiles) do + batchcmds:cp(srcfile, dstfiles[idx], {symlink = true}) + end + end + end end diff --git a/xmake/rules/xcode/application/xmake.lua b/xmake/rules/xcode/application/xmake.lua index d809261c5..8af79a585 100644 --- a/xmake/rules/xcode/application/xmake.lua +++ b/xmake/rules/xcode/application/xmake.lua @@ -37,7 +37,7 @@ rule("xcode.application") on_install("install") -- install application for xpack - after_installcmd("installcmd") + on_installcmd("installcmd") -- uninstall application on_uninstall("uninstall") -- cgit v1.3.1 From 2a9075318d77e8c7fe514754873be61ec9f2cd7d Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 26 Nov 2025 22:37:40 +0800 Subject: add icon in macapp --- .../Assets.xcassets/AppIcon.appiconset/Contents.json | 10 ++++++++++ .../AppIcon.appiconset/icon_128x128.png | Bin 0 -> 11992 bytes .../AppIcon.appiconset/icon_128x128@2x.png | Bin 0 -> 24378 bytes .../Assets.xcassets/AppIcon.appiconset/icon_16x16.png | Bin 0 -> 1377 bytes .../AppIcon.appiconset/icon_16x16@2x.png | Bin 0 -> 2478 bytes .../AppIcon.appiconset/icon_256x256.png | Bin 0 -> 24378 bytes .../AppIcon.appiconset/icon_256x256@2x.png | Bin 0 -> 91627 bytes .../Assets.xcassets/AppIcon.appiconset/icon_32x32.png | Bin 0 -> 2478 bytes .../AppIcon.appiconset/icon_32x32@2x.png | Bin 0 -> 5022 bytes .../AppIcon.appiconset/icon_512x512.png | Bin 0 -> 91627 bytes .../AppIcon.appiconset/icon_512x512@2x.png | Bin 0 -> 269353 bytes tests/plugins/pack/macapp/src/Info.plist | 2 +- tests/plugins/pack/macapp/src/assets/xmake.ico | Bin 0 -> 119943 bytes xmake/rules/xcode/application/build.lua | 2 -- 14 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_128x128.png create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_16x16.png create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_256x256.png create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_32x32.png create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_512x512.png create mode 100644 tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png create mode 100644 tests/plugins/pack/macapp/src/assets/xmake.ico diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/Contents.json b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/Contents.json index 9d5c8a516..6fa879752 100644 --- a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,51 +1,61 @@ { "images" : [ { + "filename" : "icon_16x16.png", "idiom" : "mac", "size" : "16x16", "scale" : "1x" }, { + "filename" : "icon_16x16@2x.png", "idiom" : "mac", "size" : "16x16", "scale" : "2x" }, { + "filename" : "icon_32x32.png", "idiom" : "mac", "size" : "32x32", "scale" : "1x" }, { + "filename" : "icon_32x32@2x.png", "idiom" : "mac", "size" : "32x32", "scale" : "2x" }, { + "filename" : "icon_128x128.png", "idiom" : "mac", "size" : "128x128", "scale" : "1x" }, { + "filename" : "icon_128x128@2x.png", "idiom" : "mac", "size" : "128x128", "scale" : "2x" }, { + "filename" : "icon_256x256.png", "idiom" : "mac", "size" : "256x256", "scale" : "1x" }, { + "filename" : "icon_256x256@2x.png", "idiom" : "mac", "size" : "256x256", "scale" : "2x" }, { + "filename" : "icon_512x512.png", "idiom" : "mac", "size" : "512x512", "scale" : "1x" }, { + "filename" : "icon_512x512@2x.png", "idiom" : "mac", "size" : "512x512", "scale" : "2x" diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_128x128.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_128x128.png new file mode 100644 index 000000000..5d787b620 Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_128x128.png differ diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png new file mode 100644 index 000000000..be7f6c4f2 Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png differ diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_16x16.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_16x16.png new file mode 100644 index 000000000..8b2771975 Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_16x16.png differ diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png new file mode 100644 index 000000000..331c7af96 Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png differ diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_256x256.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_256x256.png new file mode 100644 index 000000000..be7f6c4f2 Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_256x256.png differ diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png new file mode 100644 index 000000000..a5677925b Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png differ diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_32x32.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_32x32.png new file mode 100644 index 000000000..331c7af96 Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_32x32.png differ diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png new file mode 100644 index 000000000..c8e5ac0c2 Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png differ diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_512x512.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_512x512.png new file mode 100644 index 000000000..a5677925b Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_512x512.png differ diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png new file mode 100644 index 000000000..d6533fea6 Binary files /dev/null and b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png differ diff --git a/tests/plugins/pack/macapp/src/Info.plist b/tests/plugins/pack/macapp/src/Info.plist index f111cb4c3..477a62fd7 100644 --- a/tests/plugins/pack/macapp/src/Info.plist +++ b/tests/plugins/pack/macapp/src/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIconFile - + AppIcon CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion diff --git a/tests/plugins/pack/macapp/src/assets/xmake.ico b/tests/plugins/pack/macapp/src/assets/xmake.ico new file mode 100644 index 000000000..52c8ef389 Binary files /dev/null and b/tests/plugins/pack/macapp/src/assets/xmake.ico differ diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index a98baf57a..8ea734d28 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -24,8 +24,6 @@ import("core.theme.theme") import("core.project.depend") import("private.tools.codesign") import("utils.progress") - --- main entry function main (target, opt) -- get app and resources directory -- cgit v1.3.1 From 29ec59fdd5478d14aed635022630a5f1ff492e7c Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 26 Nov 2025 22:38:52 +0800 Subject: update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2239420ee..43a99dff5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### New features + +* [#7062](https://github.com/xmake-io/xmake/pull/7062): Add dmg xpack format for macOS application packaging + ## v3.0.5 ### New features @@ -2191,6 +2195,10 @@ ## master (开发中) +### 新特性 + +* [#7062](https://github.com/xmake-io/xmake/pull/7062): 添加 dmg xpack 格式,支持 macOS 应用程序打包 + ## v3.0.5 ### 新特性 -- cgit v1.3.1