diff options
| author | ruki <[email protected]> | 2025-11-26 11:33:49 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-26 11:33:49 +0800 |
| commit | e7cd3c2c12d3d51ffef3d2aa9885bfef9db8d650 (patch) | |
| tree | 01bf3737ff18ffb3d6b663c781d2cc9dbd8541d1 | |
| parent | 76dc60d1552a0afe1faffd996a36a412e44d548d (diff) | |
| parent | 29ec59fdd5478d14aed635022630a5f1ff492e7c (diff) | |
Merge pull request #7062 from xmake-io/dmg
Add dmg xpack format
41 files changed, 566 insertions, 3 deletions
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 ### 新特性 diff --git a/tests/plugins/pack/.gitignore b/tests/plugins/pack/console/.gitignore index 152105761..152105761 100644 --- a/tests/plugins/pack/.gitignore +++ b/tests/plugins/pack/console/.gitignore diff --git a/tests/plugins/pack/LICENSE.md b/tests/plugins/pack/console/LICENSE.md index fe2ff7e48..fe2ff7e48 100644 --- a/tests/plugins/pack/LICENSE.md +++ b/tests/plugins/pack/console/LICENSE.md diff --git a/tests/plugins/pack/include/foo/foo.h b/tests/plugins/pack/console/include/foo/foo.h index e69de29bb..e69de29bb 100644 --- a/tests/plugins/pack/include/foo/foo.h +++ b/tests/plugins/pack/console/include/foo/foo.h diff --git a/tests/plugins/pack/include/test.h b/tests/plugins/pack/console/include/test.h index e69de29bb..e69de29bb 100644 --- a/tests/plugins/pack/include/test.h +++ b/tests/plugins/pack/console/include/test.h diff --git a/tests/plugins/pack/src/assets/file1.txt b/tests/plugins/pack/console/src/assets/file1.txt index ce0136250..ce0136250 100644 --- a/tests/plugins/pack/src/assets/file1.txt +++ b/tests/plugins/pack/console/src/assets/file1.txt diff --git a/tests/plugins/pack/src/assets/file2.txt b/tests/plugins/pack/console/src/assets/file2.txt index ce0136250..ce0136250 100644 --- a/tests/plugins/pack/src/assets/file2.txt +++ b/tests/plugins/pack/console/src/assets/file2.txt diff --git a/tests/plugins/pack/src/assets/img1.png b/tests/plugins/pack/console/src/assets/img1.png index e69de29bb..e69de29bb 100644 --- a/tests/plugins/pack/src/assets/img1.png +++ b/tests/plugins/pack/console/src/assets/img1.png diff --git a/tests/plugins/pack/src/assets/img2.png b/tests/plugins/pack/console/src/assets/img2.png index e69de29bb..e69de29bb 100644 --- a/tests/plugins/pack/src/assets/img2.png +++ b/tests/plugins/pack/console/src/assets/img2.png diff --git a/tests/plugins/pack/src/assets/xmake.ico b/tests/plugins/pack/console/src/assets/xmake.ico Binary files differindex 52c8ef389..52c8ef389 100644 --- a/tests/plugins/pack/src/assets/xmake.ico +++ b/tests/plugins/pack/console/src/assets/xmake.ico diff --git a/tests/plugins/pack/src/main.cpp b/tests/plugins/pack/console/src/main.cpp index 55d2f380a..55d2f380a 100644 --- a/tests/plugins/pack/src/main.cpp +++ b/tests/plugins/pack/console/src/main.cpp diff --git a/tests/plugins/pack/src/xmake.rc b/tests/plugins/pack/console/src/xmake.rc index 3a2783607..3a2783607 100644 --- a/tests/plugins/pack/src/xmake.rc +++ b/tests/plugins/pack/console/src/xmake.rc diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/console/xmake.lua index cf07d8ca6..244bcaee6 100644 --- a/tests/plugins/pack/xmake.lua +++ b/tests/plugins/pack/console/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/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 <Cocoa/Cocoa.h> + +@interface AppDelegate : NSObject <NSApplicationDelegate> + + +@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..6fa879752 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,69 @@ +{ + "images" : [ + { + "filename" : "icon_16x16.png", + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "filename" : "[email protected]", + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "filename" : "icon_32x32.png", + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "filename" : "[email protected]", + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "filename" : "icon_128x128.png", + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "filename" : "[email protected]", + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "filename" : "icon_256x256.png", + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "filename" : "[email protected]", + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "filename" : "icon_512x512.png", + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "filename" : "[email protected]", + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} + 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 Binary files differnew file mode 100644 index 000000000..5d787b620 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_128x128.png diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] Binary files differnew file mode 100644 index 000000000..be7f6c4f2 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] 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 Binary files differnew file mode 100644 index 000000000..8b2771975 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_16x16.png diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] Binary files differnew file mode 100644 index 000000000..331c7af96 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] 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 Binary files differnew file mode 100644 index 000000000..be7f6c4f2 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_256x256.png diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] Binary files differnew file mode 100644 index 000000000..a5677925b --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] 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 Binary files differnew file mode 100644 index 000000000..331c7af96 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_32x32.png diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] Binary files differnew file mode 100644 index 000000000..c8e5ac0c2 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] 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 Binary files differnew file mode 100644 index 000000000..a5677925b --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/icon_512x512.png diff --git a/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] Binary files differnew file mode 100644 index 000000000..d6533fea6 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Assets.xcassets/AppIcon.appiconset/[email protected] 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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11134" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS"> + <dependencies> + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/> + </dependencies> + <scenes> + <!--Application--> + <scene sceneID="JPo-4y-FX3"> + <objects> + <application id="hnw-xV-0zn" sceneMemberID="viewController"> + <menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6"> + <items> + <menuItem title="macapp" id="1Xt-HY-uBw"> + <modifierMask key="keyEquivalentModifierMask"/> + <menu key="submenu" title="macapp" systemMenu="apple" id="uQy-DD-JDr"> + <items> + <menuItem title="About macapp" id="5kV-Vb-QxS"> + <modifierMask key="keyEquivalentModifierMask"/> + </menuItem> + <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/> + <menuItem title="Quit macapp" keyEquivalent="q" id="4sb-4s-VLi"> + </menuItem> + </items> + </menu> + </menuItem> + </items> + </menu> + <connections> + <outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/> + </connections> + </application> + <customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider=""/> + <customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="75" y="0.0"/> + </scene> + <!--Window Controller--> + <scene sceneID="R2V-B0-nI4"> + <objects> + <windowController id="B8D-0N-5wS" sceneMemberID="viewController"> + <window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA"> + <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> + <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> + <rect key="contentRect" x="196" y="240" width="480" height="270"/> + <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/> + <connections> + <outlet property="delegate" destination="B8D-0N-5wS" id="98r-iN-zZc"/> + </connections> + </window> + <connections> + <segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/> + </connections> + </windowController> + <customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="75" y="250"/> + </scene> + <!--View Controller--> + <scene sceneID="hIz-AP-VOD"> + <objects> + <viewController id="XfG-lQ-9wD" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController"> + <view key="view" id="m2S-Jp-Qdl"> + <rect key="frame" x="0.0" y="0.0" width="480" height="270"/> + <autoresizingMask key="autoresizingMask"/> + </view> + </viewController> + <customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="75" y="655"/> + </scene> + </scenes> +</document> + diff --git a/tests/plugins/pack/macapp/src/Info.plist b/tests/plugins/pack/macapp/src/Info.plist new file mode 100644 index 000000000..477a62fd7 --- /dev/null +++ b/tests/plugins/pack/macapp/src/Info.plist @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>$(DEVELOPMENT_LANGUAGE)</string> + <key>CFBundleExecutable</key> + <string>$(EXECUTABLE_NAME)</string> + <key>CFBundleIconFile</key> + <string>AppIcon</string> + <key>CFBundleIdentifier</key> + <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>$(PRODUCT_NAME)</string> + <key>CFBundleDisplayName</key> + <string>$(PRODUCT_DISPLAY_NAME)</string> + <key>CFBundlePackageType</key> + <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> + <key>LSMinimumSystemVersion</key> + <string>$(MACOSX_DEPLOYMENT_TARGET)</string> + <key>NSHumanReadableCopyright</key> + <string>Copyright © 2020 tboox. All rights reserved.</string> + <key>NSMainStoryboardFile</key> + <string>Main</string> + <key>NSPrincipalClass</key> + <string>NSApplication</string> + <key>NSSupportsAutomaticTermination</key> + <true/> + <key>NSSupportsSuddenTermination</key> + <true/> +</dict> +</plist> + 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 <Cocoa/Cocoa.h> + +@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/assets/xmake.ico b/tests/plugins/pack/macapp/src/assets/xmake.ico Binary files differnew file mode 100644 index 000000000..52c8ef389 --- /dev/null +++ b/tests/plugins/pack/macapp/src/assets/xmake.ico 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 <Cocoa/Cocoa.h> + +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 <[email protected]>") + set_description("A test macOS application installer.") + set_homepage("https://xmake.io") + set_license("Apache-2.0") + add_targets("macapp") + 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/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/plugins/pack/dmg/main.lua b/xmake/plugins/pack/dmg/main.lua new file mode 100644 index 000000000..54fb30f5a --- /dev/null +++ b/xmake/plugins/pack/dmg/main.lua @@ -0,0 +1,85 @@ +--!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 directory for DMG in builddir + local builddir = package:builddir() + local dmgdir = path.join(builddir, "dmg") + os.tryrm(dmgdir) + os.mkdir(dmgdir) + + -- copy files to DMG directory + local dmgname = path.basename(outputfile, ".dmg") + 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", dmgcontentdir, + "-ov", + "-format", "UDZO", + outputfile + } + + -- run hdiutil + os.vrunv(hdiutil.program, argv) + + -- 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", 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 diff --git a/xmake/rules/xcode/application/installcmd.lua b/xmake/rules/xcode/application/installcmd.lua new file mode 100644 index 000000000..c08a0fede --- /dev/null +++ b/xmake/rules/xcode/application/installcmd.lua @@ -0,0 +1,70 @@ +--!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 + 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 + 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}) + + -- 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 ecffaeeac..8af79a585 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 + on_installcmd("installcmd") + -- uninstall application on_uninstall("uninstall") |
