summaryrefslogtreecommitdiff
path: root/xmake/rules/xcode/bundle/xmake.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-08 23:52:05 +0800
committerruki <[email protected]>2020-04-08 17:12:34 +0800
commitc044ba9a3ee4af1308632e08e9f78fb2974beda2 (patch)
tree32d222cf3d67724ea2bcd6a02d9f14acb28ec89d /xmake/rules/xcode/bundle/xmake.lua
parente3e74b6dccfa877981a26896519414eab44ee2a7 (diff)
improve xcode.framework/bundle rules
Diffstat (limited to 'xmake/rules/xcode/bundle/xmake.lua')
-rw-r--r--xmake/rules/xcode/bundle/xmake.lua71
1 files changed, 44 insertions, 27 deletions
diff --git a/xmake/rules/xcode/bundle/xmake.lua b/xmake/rules/xcode/bundle/xmake.lua
index 1e0ce3723..709feb51d 100644
--- a/xmake/rules/xcode/bundle/xmake.lua
+++ b/xmake/rules/xcode/bundle/xmake.lua
@@ -21,17 +21,30 @@
-- define rule: xcode bundle
rule("xcode.bundle")
+ -- support add_files("Info.plist")
+ add_deps("xcode.info_plist")
+
-- 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)
+ target:data_set("xcode.bundle.rootdir", bundledir)
+
+ -- get contents and resources directory
+ local contentsdir = bundledir
+ local resourcesdir = bundledir
+ if is_plat("macosx") then
+ contentsdir = path.join(bundledir, "Contents")
+ resourcesdir = path.join(bundledir, "Contents", "Resources")
+ end
+ target:data_set("xcode.bundle.contentsdir", contentsdir)
+ target:data_set("xcode.bundle.resourcesdir", resourcesdir)
-- set target info for bundle
target:set("filename", target:basename())
- target:set("targetdir", path.join(bundledir, "Contents", "MacOS"))
+ target:set("targetdir", path.join(contentsdir, "MacOS"))
-- generate binary as bundle, we cannot set `-shared` or `-dynamiclib`
target:set("kind", "binary")
@@ -41,41 +54,41 @@ rule("xcode.bundle")
target:add("cleanfiles", bundledir)
end)
- after_build(function (target)
+ after_build(function (target, opt)
-- imports
+ import("core.base.option")
+ import("core.theme.theme")
+ import("core.project.depend")
import("private.tools.codesign")
- -- generate Info.plist
- local function _gen_info_plist(info_plist_file)
- io.gsub(info_plist_file, "(%$%((.-)%))", function (_, variable)
- local maps =
- {
- DEVELOPMENT_LANGUAGE = "en",
- EXECUTABLE_NAME = target:basename(),
- PRODUCT_BUNDLE_IDENTIFIER = "org.tboox." .. target:name(),
- PRODUCT_NAME = target:name(),
- PRODUCT_BUNDLE_PACKAGE_TYPE = "BNDL", -- bundle
- CURRENT_PROJECT_VERSION = target:version() and tostring(target:version()) or "1.0"
- }
- return maps[variable]
- end)
- end
+ -- get bundle and resources directory
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
+ local resourcesdir = path.absolute(target:data("xcode.bundle.resourcesdir"))
- -- get bundle directory
- local bundledir = path.absolute(target:data("xcode.bundledir"))
+ -- need re-generate it?
+ local dependfile = target:dependfile(bundledir)
+ local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(dependfile)}) then
+ return
+ end
+
+ -- trace progress info
+ cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress)
+ if option.get("verbose") then
+ cprint("${dim color.build.target}generating.xcode.$(mode) %s", path.filename(bundledir))
+ else
+ cprint("${color.build.target}generating.xcode.$(mode) %s", path.filename(bundledir))
+ end
- -- copy resource files to the content directory
- local srcfiles, dstfiles = target:installfiles(path.join(bundledir, "Contents"))
+ -- copy resource files
+ local srcfiles, dstfiles = target:installfiles(resourcesdir)
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)
- if path.filename(srcfile) == "Info.plist" then
- _gen_info_plist(dstfile)
- end
end
i = i + 1
end
@@ -83,10 +96,14 @@ rule("xcode.bundle")
-- do codesign
codesign(bundledir, target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity"))
+
+ -- update files and values to the dependent file
+ dependinfo.files = {bundledir}
+ depend.save(dependinfo, dependfile)
end)
on_install(function (target)
- local bundledir = path.absolute(target:data("xcode.bundledir"))
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
local installdir = target:installdir()
if not os.isdir(installdir) then
os.mkdir(installdir)
@@ -95,7 +112,7 @@ rule("xcode.bundle")
end)
on_uninstall(function (target)
- local bundledir = path.absolute(target:data("xcode.bundledir"))
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
local installdir = target:installdir()
os.tryrm(path.join(installdir, path.filename(bundledir)))
end)