diff options
| author | ruki <[email protected]> | 2020-04-05 23:49:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-04-05 23:49:55 +0800 |
| commit | 89415ed089e1ea087c334fa057cc440dddb65dfd (patch) | |
| tree | 40b89f40968601acf2a0b778208a371ac6ee8a93 | |
| parent | 6a67eb4ca0b1b8f375b0aa190fb85bca8477b595 (diff) | |
improve xcode.application rule
| -rw-r--r-- | tests/projects/objc/macapp/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 10 | ||||
| -rw-r--r-- | xmake/rules/xcode/application/xmake.lua | 109 |
3 files changed, 24 insertions, 97 deletions
diff --git a/tests/projects/objc/macapp/xmake.lua b/tests/projects/objc/macapp/xmake.lua index bf1b1fef8..3413e3389 100644 --- a/tests/projects/objc/macapp/xmake.lua +++ b/tests/projects/objc/macapp/xmake.lua @@ -2,5 +2,5 @@ add_rules("mode.debug", "mode.release") target("test") add_rules("xcode.application") - add_files("src/*.m") + add_files("src/*.m", "src/**.storyboard", "src/*.xcassets") add_installfiles("src/Info.plist") diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 51eef59b9..e91f09408 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -979,8 +979,14 @@ function _instance:sourcefiles() deleted = true end - -- match source files - local results = os.match(file) + -- find source files + local results = os.files(file) + if #results == 0 then + -- attempt to find source directories if maybe compile it as directory with the custom rules + if #self:filerules(file) > 0 then + results = os.dirs(file) + end + end if #results == 0 then local sourceinfo = (self:get("__sourceinfo_files") or {})[file] or {} utils.warning("cannot match %s(%s).%s_files(\"%s\") at %s:%d", self:type(), self:name(), utils.ifelse(deleted, "del", "add"), file, sourceinfo.file or "", sourceinfo.line or -1) diff --git a/xmake/rules/xcode/application/xmake.lua b/xmake/rules/xcode/application/xmake.lua index 781ece19f..75cae682d 100644 --- a/xmake/rules/xcode/application/xmake.lua +++ b/xmake/rules/xcode/application/xmake.lua @@ -21,103 +21,24 @@ -- define rule: xcode application (TODO developing) rule("xcode.application") - -- we must set kind before target.on_load(), may we will use target in on_load() - before_load(function (target) - - -- get app directory - local targetdir = target:targetdir() - local appdir = path.join(targetdir, target:basename() .. ".app") - target:data_set("xcode.appdir", appdir) - - -- set target info for app - target:set("kind", "binary") - target:set("filename", target:basename()) - if is_plat("macosx") then - target:set("targetdir", path.join(appdir, "Contents", "MacOS")) - else - target:set("targetdir", appdir) - end - - -- add frameworks - if is_plat("macosx") then - target:add("frameworks", "AppKit") - else - target:add("frameworks", "UIKit") - end - - -- register clean files for `xmake clean` - target:add("cleanfiles", appdir) - end) - - after_build(function (target) - - -- imports - import("private.tools.codesign") + -- support add_files("*.storyboard") + set_extensions(".storyboard", ".xcassets") - -- 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 = "APPL", -- application - CURRENT_PROJECT_VERSION = target:version() and tostring(target:version()) or "1.0", - MACOSX_DEPLOYMENT_TARGET = get_config("target_minver") - } - return maps[variable] - end) - end - - -- get app directory - local appdir = path.absolute(target:data("xcode.appdir")) - - -- get contents directory - local contentsdir = appdir - if is_plat("macosx") then - contentsdir = path.join(appdir, "Contents") - end - - -- copy PkgInfo to the contents directory - os.cp(path.join(os.programdir(), "scripts", "PkgInfo"), contentsdir) - - -- copy resource files to the contents directory - local srcfiles, dstfiles = target:installfiles(contentsdir) - 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 - end + -- we must set kind before target.on_load(), may we will use target in on_load() + before_load("load") - -- do codesign - codesign(appdir, target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity")) - end) + -- build *.storyboard and *.xcassets + on_build_file("build_file") - on_install(function (target) - local appdir = path.absolute(target:data("xcode.appdir")) - local installdir = target:installdir() - if not os.isdir(installdir) then - os.mkdir(installdir) - end - os.vcp(appdir, installdir) - end) + -- build *.app + after_build("build") - on_uninstall(function (target) - local appdir = path.absolute(target:data("xcode.appdir")) - local installdir = target:installdir() - os.tryrm(path.join(installdir, path.filename(appdir))) - end) + -- package *.app to *.ipa (iphoneos) or *.dmg (macosx) + on_package("package") + + -- install application + on_install("install") - -- disable package - on_package(function (target) end) + -- uninstall application + on_uninstall("uninstall") |
