summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-04 21:27:21 +0800
committerruki <[email protected]>2020-04-04 21:27:21 +0800
commitdb450e5497761c5def6cab798d7fabfc4316214a (patch)
treec1cd45f6a8ab9988854168c63040c3f6011cb1dd
parentd656204be63f729a9e7b60f509af1fc3450726cc (diff)
add xcode.bundle rule
-rw-r--r--tests/projects/objc/bundle/src/Info.plist46
-rw-r--r--tests/projects/objc/bundle/src/main.m11
-rw-r--r--tests/projects/objc/bundle/xmake.lua5
-rw-r--r--xmake/rules/xcode/bundle/xmake.lua55
4 files changed, 102 insertions, 15 deletions
diff --git a/tests/projects/objc/bundle/src/Info.plist b/tests/projects/objc/bundle/src/Info.plist
new file mode 100644
index 000000000..090a794fb
--- /dev/null
+++ b/tests/projects/objc/bundle/src/Info.plist
@@ -0,0 +1,46 @@
+<?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>BuildMachineOSBuild</key>
+ <string>18G95</string>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>test</string>
+ <key>CFBundleIdentifier</key>
+ <string>org.tboox.test</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>test</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSupportedPlatforms</key>
+ <array>
+ <string>MacOSX</string>
+ </array>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>DTCompiler</key>
+ <string>com.apple.compilers.llvm.clang.1_0</string>
+ <key>DTPlatformBuild</key>
+ <string>11B52</string>
+ <key>DTPlatformVersion</key>
+ <string>GM</string>
+ <key>DTSDKBuild</key>
+ <string>19B81</string>
+ <key>DTSDKName</key>
+ <string>macosx10.15</string>
+ <key>DTXcode</key>
+ <string>1120</string>
+ <key>DTXcodeBuild</key>
+ <string>11B52</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>10.14</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>Copyright © 2020 tboox. All rights reserved.</string>
+</dict>
+</plist>
diff --git a/tests/projects/objc/bundle/src/main.m b/tests/projects/objc/bundle/src/main.m
deleted file mode 100644
index e3fa72dbf..000000000
--- a/tests/projects/objc/bundle/src/main.m
+++ /dev/null
@@ -1,11 +0,0 @@
-#import <Foundation/Foundation.h>
-#import <test/test.h>
-
-int main(int argc, char** argv)
-{
- @autoreleasepool
- {
- NSLog(@"add(1, 2): %d", add(1, 2));
- }
- return 0;
-}
diff --git a/tests/projects/objc/bundle/xmake.lua b/tests/projects/objc/bundle/xmake.lua
index e8d0738ce..f184201e5 100644
--- a/tests/projects/objc/bundle/xmake.lua
+++ b/tests/projects/objc/bundle/xmake.lua
@@ -3,8 +3,5 @@ add_rules("mode.debug", "mode.release")
target("test")
add_rules("xcode.bundle")
add_files("src/test.m")
+ add_installfiles("src/Info.plist")
-target("demo")
- set_kind("binary")
- add_deps("test")
- add_files("src/main.m")
diff --git a/xmake/rules/xcode/bundle/xmake.lua b/xmake/rules/xcode/bundle/xmake.lua
index e3b146c69..2e486cffd 100644
--- a/xmake/rules/xcode/bundle/xmake.lua
+++ b/xmake/rules/xcode/bundle/xmake.lua
@@ -23,6 +23,61 @@ rule("xcode.bundle")
-- we must set kind before target.on_load(), may we will use target in on_load()
before_load(function (target)
+
+ -- get bundle directory
+ local targetdir = target:targetdir()
+ local bundledir = path.join(targetdir, target:basename() .. ".bundle")
+ target:data_set("xcode.bundledir", bundledir)
+
+ -- set target info for bundle
target:set("kind", "shared")
+ target:set("filename", target:basename())
+ target:set("targetdir", path.join(bundledir, "Contents", "MacOS"))
+
+ -- register clean files for `xmake clean`
+ target:add("cleanfiles", bundledir)
end)
+ after_build(function (target)
+
+ -- imports
+ import("private.tools.codesign")
+
+ -- get bundle directory
+ local bundledir = path.absolute(target:data("xcode.bundledir"))
+
+ -- copy resource files to the content directory
+ local srcfiles, dstfiles = target:installfiles(path.join(bundledir, "Contents"))
+ if srcfiles and dstfiles then
+ local i = 1
+ for _, srcfile in ipairs(srcfiles) do
+ local dstfile = dstfiles[i]
+ if dstfile then
+ os.vcp(srcfile, dstfile)
+ end
+ i = i + 1
+ end
+ end
+
+ -- do codesign
+ codesign(bundledir)
+ end)
+
+ on_install(function (target)
+ local bundledir = path.absolute(target:data("xcode.bundledir"))
+ local installdir = target:installdir()
+ if not os.isdir(installdir) then
+ os.mkdir(installdir)
+ end
+ os.vcp(bundledir, installdir)
+ end)
+
+ on_uninstall(function (target)
+ local bundledir = path.absolute(target:data("xcode.bundledir"))
+ local installdir = target:installdir()
+ os.tryrm(path.join(installdir, path.filename(bundledir)))
+ end)
+
+ -- disable package
+ on_package(function (target) end)
+