summaryrefslogtreecommitdiff
path: root/xmake/rules/xcode
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-08 23:44:59 +0800
committerruki <[email protected]>2020-04-08 16:29:55 +0800
commitefe6609bb668d34a4beb5b9b06f36b7556796c7b (patch)
tree747263b31b08cb644fee54b24e855870564f06ae /xmake/rules/xcode
parentef120036428f173d235b1822a242173b12c7a6b8 (diff)
improve xcode.app rule
Diffstat (limited to 'xmake/rules/xcode')
-rw-r--r--xmake/rules/xcode/application/build.lua30
-rw-r--r--xmake/rules/xcode/application/xmake.lua4
-rw-r--r--xmake/rules/xcode/info_plist/xmake.lua77
-rw-r--r--xmake/rules/xcode/storyboard/xmake.lua6
-rw-r--r--xmake/rules/xcode/xcassets/xmake.lua6
5 files changed, 90 insertions, 33 deletions
diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua
index c67ef8058..73e49eff4 100644
--- a/xmake/rules/xcode/application/build.lua
+++ b/xmake/rules/xcode/application/build.lua
@@ -24,29 +24,12 @@ import("core.theme.theme")
import("core.project.depend")
import("private.tools.codesign")
--- generate Info.plist
-function _gen_info_plist(target, 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
-
-- main entry
function main (target, opt)
- -- get app and contents directory
+ -- get app and resources directory
local appdir = path.absolute(target:data("xcode.bundle.rootdir"))
- local contentsdir = path.absolute(target:data("xcode.bundle.contentsdir"))
+ local resourcesdir = path.absolute(target:data("xcode.bundle.resourcesdir"))
-- need re-compile it?
local dependfile = target:dependfile(appdir)
@@ -64,19 +47,16 @@ function main (target, opt)
end
-- copy PkgInfo to the contents directory
- os.cp(path.join(os.programdir(), "scripts", "PkgInfo"), contentsdir)
+ os.cp(path.join(os.programdir(), "scripts", "PkgInfo"), resourcesdir)
- -- copy resource files to the contents directory
- local srcfiles, dstfiles = target:installfiles(contentsdir)
+ -- copy resource files to the resources directory
+ 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(target, dstfile)
- end
end
i = i + 1
end
diff --git a/xmake/rules/xcode/application/xmake.lua b/xmake/rules/xcode/application/xmake.lua
index ac1624d73..08fac72e1 100644
--- a/xmake/rules/xcode/application/xmake.lua
+++ b/xmake/rules/xcode/application/xmake.lua
@@ -21,8 +21,8 @@
-- define rule: xcode application
rule("xcode.application")
- -- support add_files("*.storyboard", "*.xcassets")
- add_deps("xcode.storyboard", "xcode.xcassets")
+ -- support add_files("Info.plist", "*.storyboard", "*.xcassets")
+ add_deps("xcode.info_plist", "xcode.storyboard", "xcode.xcassets")
-- we must set kind before target.on_load(), may we will use target in on_load()
before_load("load")
diff --git a/xmake/rules/xcode/info_plist/xmake.lua b/xmake/rules/xcode/info_plist/xmake.lua
new file mode 100644
index 000000000..733079dcc
--- /dev/null
+++ b/xmake/rules/xcode/info_plist/xmake.lua
@@ -0,0 +1,77 @@
+--!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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define rule
+rule("xcode.info_plist")
+
+ -- support add_files("Info.plist")
+ set_extensions(".plist")
+
+ -- build Info.plist
+ on_build_file(function (target, sourcefile, opt)
+
+ -- imports
+ import("core.base.option")
+ import("core.theme.theme")
+ import("core.project.depend")
+
+ -- check
+ assert(path.filename(sourcefile) == "Info.plist", "we only support Info.plist file!")
+
+ -- get contents directory
+ local contentsdir = assert(target:data("xcode.bundle.contentsdir"), "contents directory not found!")
+
+ -- need re-compile it?
+ local dependfile = target:dependfile(sourcefile)
+ 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.object}processing.xcode.$(mode) %s", sourcefile)
+ else
+ cprint("${color.build.object}processing.xcode.$(mode) %s", sourcefile)
+ end
+
+ -- process and generate Info.plist
+ local info_plist_file = path.join(contentsdir, path.filename(sourcefile))
+ 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")
+ }
+
+ os.vcp(sourcefile, info_plist_file)
+ io.gsub(info_plist_file, "(%$%((.-)%))", function (_, variable)
+ return maps[variable]
+ end)
+
+ -- update files and values to the dependent file
+ dependinfo.files = {sourcefile}
+ depend.save(dependinfo, dependfile)
+ end)
diff --git a/xmake/rules/xcode/storyboard/xmake.lua b/xmake/rules/xcode/storyboard/xmake.lua
index 42e9d4965..3c0146a78 100644
--- a/xmake/rules/xcode/storyboard/xmake.lua
+++ b/xmake/rules/xcode/storyboard/xmake.lua
@@ -39,7 +39,7 @@ rule("xcode.storyboard")
-- get base.lproj
local base_lproj = path.join(target:autogendir(), "rules", "xcode", "storyboard", "Base.lproj")
- -- get app resources directory
+ -- get resources directory
local resourcesdir = assert(target:data("xcode.bundle.resourcesdir"), "resources directory not found!")
-- need re-compile it?
@@ -52,9 +52,9 @@ rule("xcode.storyboard")
-- 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.object}compiling.xcode.storyboard %s", sourcefile)
+ cprint("${dim color.build.object}compiling.xcode.$(mode) %s", sourcefile)
else
- cprint("${color.build.object}compiling.xcode.storyboard %s", sourcefile)
+ cprint("${color.build.object}compiling.xcode.$(mode) %s", sourcefile)
end
-- do compile
diff --git a/xmake/rules/xcode/xcassets/xmake.lua b/xmake/rules/xcode/xcassets/xmake.lua
index 9f38f0313..736675b64 100644
--- a/xmake/rules/xcode/xcassets/xmake.lua
+++ b/xmake/rules/xcode/xcassets/xmake.lua
@@ -36,7 +36,7 @@ rule("xcode.xcassets")
local xcode_sdkdir = assert(get_config("xcode"), "xcode not found!")
local xcode_usrdir = path.join(xcode_sdkdir, "Contents", "Developer", "usr")
- -- get app resources directory
+ -- get resources directory
local resourcesdir = assert(target:data("xcode.bundle.resourcesdir"), "resources directory not found!")
-- need re-compile it?
@@ -49,9 +49,9 @@ rule("xcode.xcassets")
-- 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.object}compiling.xcode.xcassets %s", sourcefile)
+ cprint("${dim color.build.object}compiling.xcode.$(mode) %s", sourcefile)
else
- cprint("${color.build.object}compiling.xcode.xcassets %s", sourcefile)
+ cprint("${color.build.object}compiling.xcode.$(mode) %s", sourcefile)
end
-- do compile