summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-08 23:50:43 +0800
committerruki <[email protected]>2020-04-08 17:04:23 +0800
commite3e74b6dccfa877981a26896519414eab44ee2a7 (patch)
tree33e8c246483638206ef18a607cc59f28fb44a17c
parentefe6609bb668d34a4beb5b9b06f36b7556796c7b (diff)
improve xcode.framework rules
-rw-r--r--tests/projects/objc/framework/xmake.lua2
-rw-r--r--xmake/rules/xcode/application/build.lua12
-rw-r--r--xmake/rules/xcode/application/install.lua4
-rw-r--r--xmake/rules/xcode/application/load.lua18
-rw-r--r--xmake/rules/xcode/application/uninstall.lua4
-rw-r--r--xmake/rules/xcode/framework/xmake.lua94
-rw-r--r--xmake/rules/xcode/info_plist/xmake.lua13
7 files changed, 84 insertions, 63 deletions
diff --git a/tests/projects/objc/framework/xmake.lua b/tests/projects/objc/framework/xmake.lua
index 530fa53f8..1a66bff4b 100644
--- a/tests/projects/objc/framework/xmake.lua
+++ b/tests/projects/objc/framework/xmake.lua
@@ -3,8 +3,8 @@ add_rules("mode.debug", "mode.release")
target("test")
add_rules("xcode.framework")
add_files("src/test.m")
+ add_files("src/Info.plist")
add_headerfiles("src/*.h")
- add_installfiles("src/Info.plist")
target("demo")
set_kind("binary")
diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua
index 73e49eff4..39f4feadf 100644
--- a/xmake/rules/xcode/application/build.lua
+++ b/xmake/rules/xcode/application/build.lua
@@ -28,11 +28,11 @@ import("private.tools.codesign")
function main (target, opt)
-- get app and resources directory
- local appdir = path.absolute(target:data("xcode.bundle.rootdir"))
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
local resourcesdir = path.absolute(target:data("xcode.bundle.resourcesdir"))
-- need re-compile it?
- local dependfile = target:dependfile(appdir)
+ 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
@@ -41,9 +41,9 @@ function main (target, opt)
-- 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.app %s", path.filename(appdir))
+ cprint("${dim color.build.target}generating.xcode.$(mode) %s", path.filename(bundledir))
else
- cprint("${color.build.target}generating.xcode.app %s", path.filename(appdir))
+ cprint("${color.build.target}generating.xcode.$(mode) %s", path.filename(bundledir))
end
-- copy PkgInfo to the contents directory
@@ -63,10 +63,10 @@ function main (target, opt)
end
-- do codesign
- codesign(appdir, target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity"))
+ codesign(bundledir, target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity"))
-- update files and values to the dependent file
- dependinfo.files = {appdir}
+ dependinfo.files = {bundledir}
depend.save(dependinfo, dependfile)
end
diff --git a/xmake/rules/xcode/application/install.lua b/xmake/rules/xcode/application/install.lua
index 76a20e731..f235870ec 100644
--- a/xmake/rules/xcode/application/install.lua
+++ b/xmake/rules/xcode/application/install.lua
@@ -20,10 +20,10 @@
-- main entry
function main (target)
- local appdir = path.absolute(target:data("xcode.bundle.rootdir"))
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
local installdir = target:installdir()
if not os.isdir(installdir) then
os.mkdir(installdir)
end
- os.vcp(appdir, installdir)
+ os.vcp(bundledir, installdir)
end
diff --git a/xmake/rules/xcode/application/load.lua b/xmake/rules/xcode/application/load.lua
index d3026948e..071b94901 100644
--- a/xmake/rules/xcode/application/load.lua
+++ b/xmake/rules/xcode/application/load.lua
@@ -21,17 +21,17 @@
-- main entry
function main (target)
- -- get app directory
+ -- get bundle directory
local targetdir = target:targetdir()
- local appdir = path.join(targetdir, target:basename() .. ".app")
- target:data_set("xcode.bundle.rootdir", appdir)
+ local bundledir = path.join(targetdir, target:basename() .. ".app")
+ target:data_set("xcode.bundle.rootdir", bundledir)
-- get contents and resources directory
- local contentsdir = appdir
- local resourcesdir = appdir
+ local contentsdir = bundledir
+ local resourcesdir = bundledir
if is_plat("macosx") then
- contentsdir = path.join(appdir, "Contents")
- resourcesdir = path.join(appdir, "Contents", "Resources")
+ 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)
@@ -42,7 +42,7 @@ function main (target)
if is_plat("macosx") then
target:set("targetdir", path.join(contentsdir, "MacOS"))
else
- target:set("targetdir", appdir)
+ target:set("targetdir", bundledir)
end
-- add frameworks
@@ -53,5 +53,5 @@ function main (target)
end
-- register clean files for `xmake clean`
- target:add("cleanfiles", appdir)
+ target:add("cleanfiles", bundledir)
end
diff --git a/xmake/rules/xcode/application/uninstall.lua b/xmake/rules/xcode/application/uninstall.lua
index 4a95cb05e..1f9edb008 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.bundle.rootdir"))
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
local installdir = target:installdir()
- os.tryrm(path.join(installdir, path.filename(appdir)))
+ 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 097a42ff7..686ab2bb3 100644
--- a/xmake/rules/xcode/framework/xmake.lua
+++ b/xmake/rules/xcode/framework/xmake.lua
@@ -21,34 +21,44 @@
-- define rule: xcode framework
rule("xcode.framework")
+ -- 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 framework directory
local targetdir = target:targetdir()
- local frameworkdir = path.join(targetdir, target:basename() .. ".framework")
- target:data_set("xcode.frameworkdir", frameworkdir)
+ local bundledir = path.join(targetdir, target:basename() .. ".framework")
+ target:data_set("xcode.bundle.rootdir", bundledir)
+
+ -- get contents and resources directory
+ local contentsdir = path.join(bundledir, "Versions", "A")
+ local resourcesdir = path.join(bundledir, "Versions", "A", "Resources")
+ target:data_set("xcode.bundle.contentsdir", contentsdir)
+ target:data_set("xcode.bundle.resourcesdir", resourcesdir)
-- set target info for framework
target:set("kind", "shared")
target:set("filename", target:basename())
- target:set("targetdir", path.join(frameworkdir, "Versions", "A"))
+ target:set("targetdir", contentsdir)
-- export frameworks for `add_deps()`
target:data_set("inherit.links", false) -- disable to inherit links, @see rule("utils.inherit.links")
target:add("frameworks", target:basename(), {interface = true})
target:add("frameworkdirs", targetdir, {interface = true})
- target:add("includedirs", path.join(frameworkdir, "Versions", "A", "Headers.tmp"), {interface = true})
+ target:add("includedirs", path.join(contentsdir, "Headers.tmp"), {interface = true})
-- register clean files for `xmake clean`
- target:add("cleanfiles", frameworkdir)
+ target:add("cleanfiles", bundledir)
end)
before_build(function (target)
-- get framework directory
- local frameworkdir = path.absolute(target:data("xcode.frameworkdir"))
- local headersdir = path.join(frameworkdir, "Versions", "A", "Headers.tmp", target:basename())
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
+ local contentsdir = path.absolute(target:data("xcode.bundle.contentsdir"))
+ local headersdir = path.join(contentsdir, "Headers.tmp", target:basename())
-- copy header files to the framework directory
local srcheaders, dstheaders = target:headerfiles(headersdir)
@@ -67,36 +77,39 @@ rule("xcode.framework")
end
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 = "FMWK", -- framework
- CURRENT_PROJECT_VERSION = target:version() and tostring(target:version()) or "1.0"
- }
- return maps[variable]
- end)
- end
-
-- get framework directory
- local frameworkdir = path.absolute(target:data("xcode.frameworkdir"))
- local headersdir = path.join(frameworkdir, "Versions", "A", "Headers")
- local resourcesdir = path.join(frameworkdir, "Versions", "A", "Resources")
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
+ local contentsdir = target:data("xcode.bundle.contentsdir")
+ local resourcesdir = target:data("xcode.bundle.resourcesdir")
+ local headersdir = path.join(contentsdir, "Headers")
+
+ -- 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
-- move header files
os.tryrm(headersdir)
- os.mv(path.join(frameworkdir, "Versions", "A", "Headers.tmp", target:basename()), headersdir)
- os.rm(path.join(frameworkdir, "Versions", "A", "Headers.tmp"))
+ os.mv(path.join(contentsdir, "Headers.tmp", target:basename()), headersdir)
+ os.rm(path.join(contentsdir, "Headers.tmp"))
-- copy resource files to the framework directory
local srcfiles, dstfiles = target:installfiles(resourcesdir)
@@ -106,9 +119,6 @@ rule("xcode.framework")
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
@@ -118,13 +128,13 @@ rule("xcode.framework")
end
-- link Versions/Current -> Versions/A
- local oldir = os.cd(path.join(frameworkdir, "Versions"))
+ local oldir = os.cd(path.join(bundledir, "Versions"))
os.tryrm("Current")
os.ln("A", "Current")
- -- link frameworkdir/* -> Versions/Current/*
+ -- link bundledir/* -> Versions/Current/*
local target_filename = path.filename(target:targetfile())
- os.cd(frameworkdir)
+ os.cd(bundledir)
os.tryrm("Headers")
os.tryrm("Resources")
os.tryrm(target_filename)
@@ -134,22 +144,26 @@ rule("xcode.framework")
os.cd(oldir)
-- do codesign
- codesign(path.join(frameworkdir, "Versions", "A"), target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity"))
+ codesign(contentsdir, 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 frameworkdir = path.absolute(target:data("xcode.frameworkdir"))
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
local installdir = target:installdir()
if not os.isdir(installdir) then
os.mkdir(installdir)
end
- os.vcp(frameworkdir, installdir)
+ os.vcp(bundledir, installdir)
end)
on_uninstall(function (target)
- local frameworkdir = path.absolute(target:data("xcode.frameworkdir"))
+ local bundledir = path.absolute(target:data("xcode.bundle.rootdir"))
local installdir = target:installdir()
- os.tryrm(path.join(installdir, path.filename(frameworkdir)))
+ os.tryrm(path.join(installdir, path.filename(bundledir)))
end)
-- disable package
diff --git a/xmake/rules/xcode/info_plist/xmake.lua b/xmake/rules/xcode/info_plist/xmake.lua
index 733079dcc..d499ec954 100644
--- a/xmake/rules/xcode/info_plist/xmake.lua
+++ b/xmake/rules/xcode/info_plist/xmake.lua
@@ -35,8 +35,9 @@ rule("xcode.info_plist")
-- check
assert(path.filename(sourcefile) == "Info.plist", "we only support Info.plist file!")
- -- get contents directory
+ -- get contents and resources directory
local contentsdir = assert(target:data("xcode.bundle.contentsdir"), "contents directory not found!")
+ local resourcesdir = assert(target:data("xcode.bundle.resourcesdir"), "resources directory not found!")
-- need re-compile it?
local dependfile = target:dependfile(sourcefile)
@@ -54,17 +55,23 @@ rule("xcode.info_plist")
end
-- process and generate Info.plist
- local info_plist_file = path.join(contentsdir, path.filename(sourcefile))
+ local info_plist_file = path.join(target:rule("xcode.framework") and resourcesdir or 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")
}
+ if target:rule("xcode.bundle") then
+ maps.PRODUCT_BUNDLE_PACKAGE_TYPE = "BNDL"
+ elseif target:rule("xcode.framework") then
+ maps.PRODUCT_BUNDLE_PACKAGE_TYPE = "FMWK"
+ elseif target:rule("xcode.application") then
+ maps.PRODUCT_BUNDLE_PACKAGE_TYPE = "APPL"
+ end
os.vcp(sourcefile, info_plist_file)
io.gsub(info_plist_file, "(%$%((.-)%))", function (_, variable)