diff options
| author | ruki <[email protected]> | 2020-04-08 23:52:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-04-08 17:12:34 +0800 |
| commit | c044ba9a3ee4af1308632e08e9f78fb2974beda2 (patch) | |
| tree | 32d222cf3d67724ea2bcd6a02d9f14acb28ec89d | |
| parent | e3e74b6dccfa877981a26896519414eab44ee2a7 (diff) | |
improve xcode.framework/bundle rules
| -rw-r--r-- | tests/projects/objc/bundle/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/xcode/bundle/xmake.lua | 71 | ||||
| -rw-r--r-- | xmake/rules/xcode/framework/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/templates/objc++/bundle/project/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/templates/objc++/framework/project/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/templates/objc/bundle/project/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/templates/objc/framework/project/xmake.lua | 2 |
7 files changed, 50 insertions, 33 deletions
diff --git a/tests/projects/objc/bundle/xmake.lua b/tests/projects/objc/bundle/xmake.lua index f184201e5..e19df303c 100644 --- a/tests/projects/objc/bundle/xmake.lua +++ b/tests/projects/objc/bundle/xmake.lua @@ -3,5 +3,5 @@ add_rules("mode.debug", "mode.release") target("test") add_rules("xcode.bundle") add_files("src/test.m") - add_installfiles("src/Info.plist") + add_files("src/Info.plist") 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) diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua index 686ab2bb3..7be68cbd0 100644 --- a/xmake/rules/xcode/framework/xmake.lua +++ b/xmake/rules/xcode/framework/xmake.lua @@ -111,7 +111,7 @@ rule("xcode.framework") os.mv(path.join(contentsdir, "Headers.tmp", target:basename()), headersdir) os.rm(path.join(contentsdir, "Headers.tmp")) - -- copy resource files to the framework directory + -- copy resource files local srcfiles, dstfiles = target:installfiles(resourcesdir) if srcfiles and dstfiles then local i = 1 diff --git a/xmake/templates/objc++/bundle/project/xmake.lua b/xmake/templates/objc++/bundle/project/xmake.lua index 6b2b52909..364e27278 100644 --- a/xmake/templates/objc++/bundle/project/xmake.lua +++ b/xmake/templates/objc++/bundle/project/xmake.lua @@ -3,7 +3,7 @@ add_rules("mode.debug", "mode.release") target("${TARGETNAME}") add_rules("xcode.bundle") add_files("src/*.mm") + add_files("src/Info.plist") add_headerfiles("src/*.h") - add_installfiles("src/Info.plist") ${FAQ} diff --git a/xmake/templates/objc++/framework/project/xmake.lua b/xmake/templates/objc++/framework/project/xmake.lua index dec94f0ca..db61439df 100644 --- a/xmake/templates/objc++/framework/project/xmake.lua +++ b/xmake/templates/objc++/framework/project/xmake.lua @@ -3,7 +3,7 @@ add_rules("mode.debug", "mode.release") target("${TARGETNAME}") add_rules("xcode.framework") add_files("src/*.mm") + add_files("src/Info.plist") add_headerfiles("src/*.h") - add_installfiles("src/Info.plist") ${FAQ} diff --git a/xmake/templates/objc/bundle/project/xmake.lua b/xmake/templates/objc/bundle/project/xmake.lua index 7bd25c678..088994340 100644 --- a/xmake/templates/objc/bundle/project/xmake.lua +++ b/xmake/templates/objc/bundle/project/xmake.lua @@ -3,7 +3,7 @@ add_rules("mode.debug", "mode.release") target("${TARGETNAME}") add_rules("xcode.bundle") add_files("src/*.m") + add_files("src/Info.plist") add_headerfiles("src/*.h") - add_installfiles("src/Info.plist") ${FAQ} diff --git a/xmake/templates/objc/framework/project/xmake.lua b/xmake/templates/objc/framework/project/xmake.lua index 758bf2314..ad8e30290 100644 --- a/xmake/templates/objc/framework/project/xmake.lua +++ b/xmake/templates/objc/framework/project/xmake.lua @@ -3,7 +3,7 @@ add_rules("mode.debug", "mode.release") target("${TARGETNAME}") add_rules("xcode.framework") add_files("src/*.m") + add_files("src/Info.plist") add_headerfiles("src/*.h") - add_installfiles("src/Info.plist") ${FAQ} |
