summaryrefslogtreecommitdiff
path: root/xmake/rules/xcode
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-08 23:23:31 +0800
committerruki <[email protected]>2020-04-08 14:21:08 +0800
commit5ea1ffd7512c5dc2633acee56751ade0eed41365 (patch)
tree1e227c8925d3cb6d62f4432fef3518664127b806 /xmake/rules/xcode
parent088df3a0bbe2bd99b5d60a5a1f5fb54d4be1673d (diff)
build storyboard for xcode.app
Diffstat (limited to 'xmake/rules/xcode')
-rw-r--r--xmake/rules/xcode/application/build.lua11
-rw-r--r--xmake/rules/xcode/application/build_file.lua77
-rw-r--r--xmake/rules/xcode/application/install.lua2
-rw-r--r--xmake/rules/xcode/application/load.lua15
-rw-r--r--xmake/rules/xcode/application/uninstall.lua2
5 files changed, 92 insertions, 15 deletions
diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua
index 889748bfd..57f4c82b6 100644
--- a/xmake/rules/xcode/application/build.lua
+++ b/xmake/rules/xcode/application/build.lua
@@ -41,14 +41,9 @@ end
-- main entry
function main (target)
- -- 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
+ -- get app and contents directory
+ local appdir = path.absolute(target:data("xcode.app.rootdir"))
+ local contentsdir = path.absolute(target:data("xcode.app.contentsdir"))
-- copy PkgInfo to the contents directory
os.cp(path.join(os.programdir(), "scripts", "PkgInfo"), contentsdir)
diff --git a/xmake/rules/xcode/application/build_file.lua b/xmake/rules/xcode/application/build_file.lua
index e178e8b4c..ae867f3d7 100644
--- a/xmake/rules/xcode/application/build_file.lua
+++ b/xmake/rules/xcode/application/build_file.lua
@@ -18,7 +18,80 @@
-- @file build_file.lua
--
+-- imports
+import("core.base.option")
+import("core.theme.theme")
+import("core.project.depend")
+
+-- build *.xcassets file
+function _build_xcassets_file(target, sourcefile, opt)
+ -- TODO
+end
+
+-- build *.storyboard file
+function _build_storyboard_file(target, sourcefile, opt)
+
+ -- get xcode sdk directory
+ local xcode_sdkdir = assert(get_config("xcode"), "xcode not found!")
+ local xcode_usrdir = path.join(xcode_sdkdir, "Contents", "Developer", "usr")
+
+ -- get base.lproj
+ local base_lproj = path.join(target:autogendir(), "rules", "xcode", "storyboard", "Base.lproj")
+
+ -- get app resources directory
+ local resourcesdir = target:data("xcode.app.resourcesdir")
+
+ -- 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}compiling.xcode.storyboard %s", sourcefile)
+ else
+ cprint("${color.build.object}compiling.xcode.storyboard %s", sourcefile)
+ end
+
+ -- do compile
+ local argv = {"--errors", "--warnings", "--notices", "--auto-activate-custom-fonts", "--output-format", "human-readable-text"}
+ if is_plat("macosx") then
+ table.insert(argv, "--target-device")
+ table.insert(argv, "mac")
+ end
+ table.insert(argv, "--minimum-deployment-target")
+ table.insert(argv, get_config("target_minver"))
+ table.insert(argv, "--compilation-directory")
+ table.insert(argv, base_lproj)
+ table.insert(argv, sourcefile)
+ os.vrunv(path.join(xcode_usrdir, "bin", "ibtool"), argv, {envs = {XCODE_DEVELOPER_USR_PATH = xcode_usrdir}})
+
+ -- do link
+ argv = {"--errors", "--warnings", "--notices", "--auto-activate-custom-fonts", "--output-format", "human-readable-text"}
+ if is_plat("macosx") then
+ table.insert(argv, "--target-device")
+ table.insert(argv, "mac")
+ end
+ table.insert(argv, "--minimum-deployment-target")
+ table.insert(argv, get_config("target_minver"))
+ table.insert(argv, "--link")
+ table.insert(argv, resourcesdir)
+ table.insert(argv, path.join(base_lproj, path.filename(sourcefile) .. "c"))
+ os.vrunv(path.join(xcode_usrdir, "bin", "ibtool"), argv, {envs = {XCODE_DEVELOPER_USR_PATH = xcode_usrdir}})
+
+ -- update files and values to the dependent file
+ dependinfo.files = {sourcefile}
+ depend.save(dependinfo, dependfile)
+end
+
-- main entry
-function main (target, sourcefile)
- -- TODO print(sourcefile)
+function main (target, sourcefile, opt)
+ if sourcefile:endswith(".xcassets") then
+ _build_xcassets_file(target, sourcefile, opt)
+ elseif sourcefile:endswith(".storyboard") then
+ _build_storyboard_file(target, sourcefile, opt)
+ end
end
diff --git a/xmake/rules/xcode/application/install.lua b/xmake/rules/xcode/application/install.lua
index d34586cb7..1339e13de 100644
--- a/xmake/rules/xcode/application/install.lua
+++ b/xmake/rules/xcode/application/install.lua
@@ -20,7 +20,7 @@
-- main entry
function main (target)
- local appdir = path.absolute(target:data("xcode.appdir"))
+ local appdir = path.absolute(target:data("xcode.app.rootdir"))
local installdir = target:installdir()
if not os.isdir(installdir) then
os.mkdir(installdir)
diff --git a/xmake/rules/xcode/application/load.lua b/xmake/rules/xcode/application/load.lua
index 20a4cc39f..cb9da887a 100644
--- a/xmake/rules/xcode/application/load.lua
+++ b/xmake/rules/xcode/application/load.lua
@@ -24,13 +24,22 @@ function main (target)
-- get app directory
local targetdir = target:targetdir()
local appdir = path.join(targetdir, target:basename() .. ".app")
- target:data_set("xcode.appdir", appdir)
+ target:data_set("xcode.app.rootdir", appdir)
- -- set target info for app
+ -- get contents and resources directory
+ local contentsdir = appdir
+ if is_plat("macosx") then
+ contentsdir = path.join(appdir, "Contents")
+ end
+ local resourcesdir = path.join(contentsdir, "Resources")
+ target:data_set("xcode.app.contentsdir", contentsdir)
+ target:data_set("xcode.app.resourcesdir", resourcesdir)
+
+ -- set target directory for app
target:set("kind", "binary")
target:set("filename", target:basename())
if is_plat("macosx") then
- target:set("targetdir", path.join(appdir, "Contents", "MacOS"))
+ target:set("targetdir", path.join(contentsdir, "MacOS"))
else
target:set("targetdir", appdir)
end
diff --git a/xmake/rules/xcode/application/uninstall.lua b/xmake/rules/xcode/application/uninstall.lua
index 09370734b..a229faba6 100644
--- a/xmake/rules/xcode/application/uninstall.lua
+++ b/xmake/rules/xcode/application/uninstall.lua
@@ -20,7 +20,7 @@
-- main entry
function main (target)
- local appdir = path.absolute(target:data("xcode.appdir"))
+ local appdir = path.absolute(target:data("xcode.app.rootdir"))
local installdir = target:installdir()
os.tryrm(path.join(installdir, path.filename(appdir)))
end