diff options
| author | ruki <[email protected]> | 2020-04-10 23:22:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-04-10 14:12:28 +0800 |
| commit | 2bce9eea2793ef8c91a6be9a1b90d25791b9b29e (patch) | |
| tree | dcbb3817f64c2f8883e4a76820499d8df49539ee | |
| parent | 382a874962650828a0c17c061f83c7b6b80f41a4 (diff) | |
add entitlements for codesign/app
| -rw-r--r-- | xmake/modules/detect/sdks/find_xcode.lua | 25 | ||||
| -rw-r--r-- | xmake/modules/private/tools/codesign.lua | 73 | ||||
| -rw-r--r-- | xmake/platforms/iphoneos/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/macosx/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/watchos/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/xcode/application/build.lua | 2 |
6 files changed, 100 insertions, 6 deletions
diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua index 429fdfc8a..213a90133 100644 --- a/xmake/modules/detect/sdks/find_xcode.lua +++ b/xmake/modules/detect/sdks/find_xcode.lua @@ -94,8 +94,21 @@ function _find_xcode(sdkdir, xcode_sdkver, plat, arch) end end - -- ok? - return {sdkdir = sdkdir, sdkver = sdkver, codesign_identity = codesign_identity} + -- find mobile provision only for iphoneos + local mobile_provision = config.get("xcode_mobile_provision") + if mobile_provision == nil then -- we will disable mobile_provision if be false + mobile_provision = global.get("xcode_mobile_provision") + end + if mobile_provision == nil and is_plat("iphoneos") then + local mobile_provisions = codesign.mobile_provisions() + if mobile_provisions then + for provision, _ in pairs(mobile_provisions) do + mobile_provision = provision + break + end + end + end + return {sdkdir = sdkdir, sdkver = sdkver, codesign_identity = codesign_identity, mobile_provision = mobile_provision} end -- find xcode toolchain @@ -136,6 +149,7 @@ function main(sdkdir, opt) config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) config.set("xcode_sdkver", xcode.sdkver, {force = true, readonly = true}) config.set("xcode_codesign_identity", xcode.codesign_identity, {force = true, readonly = true}) + config.set("xcode_mobile_provision", xcode.mobile_provision, {force = true, readonly = true}) -- trace if opt.verbose or option.get("verbose") then @@ -146,6 +160,13 @@ function main(sdkdir, opt) else cprint("checking for the Codesign Identity of Xcode ... ${color.nothing}${text.nothing}") end + if is_plat("iphoneos") then + if xcode.mobile_provision then + cprint("checking for the Mobile Provision of Xcode ... ${color.success}%s", xcode.mobile_provision) + else + cprint("checking for the Mobile Provision of Xcode ... ${color.nothing}${text.nothing}") + end + end end else diff --git a/xmake/modules/private/tools/codesign.lua b/xmake/modules/private/tools/codesign.lua index 3f068cfbc..5631312ee 100644 --- a/xmake/modules/private/tools/codesign.lua +++ b/xmake/modules/private/tools/codesign.lua @@ -21,6 +21,28 @@ -- imports import("lib.detect.find_tool") +-- get mobile provision name +function _get_mobile_provision_name(provision) + local p = provision:find("<key>Name</key>", 1, true) + if p then + local e = provision:find("</string>", p, true) + if e then + return provision:sub(p, e + 9):match("<string>(.*)</string>") + end + end +end + +-- get mobile provision entitlements +function _get_mobile_provision_entitlements(provision) + local p = provision:find("<key>Entitlements</key>", 1, true) + if p then + local e = provision:find("</dict>", p, true) + if e then + return provision:sub(p, e + 7):match("(<dict>.*</dict>)") + end + end +end + -- get codesign identities function codesign_identities() local identities = _g.identities @@ -56,15 +78,37 @@ function mobile_provisions() mobile_provisions = {} local files = os.files("~/Library/MobileDevice/Provisioning Profiles/*.mobileprovision") for _, file in ipairs(files) do - mobile_provisions[path.basename(file)] = file + local results = try { function() return os.iorunv("/usr/bin/security", {"cms", "-D", "-i", file}) end } + if results then + local name = _get_mobile_provision_name(results) + if name then + mobile_provisions[name] = results + end + end end _g.mobile_provisions = mobile_provisions or false end return mobile_provisions or nil end +-- dump all information of codesign +function dump() + + -- only for macosx + assert(is_host("macosx"), "codesign: only support for macOS!") + + -- do dump + print("==================================== codesign identities ====================================") + print(codesign_identities()) + print("===================================== mobile provisions =====================================") + print(mobile_provisions()) +end + -- main entry -function main (programdir, codesign_identity) +function main (programdir, codesign_identity, mobile_provision) + + -- only for macosx + assert(is_host("macosx"), "codesign: only support for macOS!") -- get codesign local codesign = find_tool("codesign") @@ -89,16 +133,39 @@ function main (programdir, codesign_identity) end end + -- get entitlements for mobile + local entitlements + if mobile_provision then + local provisions = mobile_provisions() + if provisions then + mobile_provision = provisions[mobile_provision] + if mobile_provision then + local entitlements_data = _get_mobile_provision_entitlements(mobile_provision) + if entitlements_data then + entitlements = os.tmpfile() .. ".plist" + io.writefile(entitlements, string.format([[<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +%s +</plist> +]], entitlements_data)) + end + end + end + end + -- do sign local argv = {"--force", "--timestamp=none"} table.insert(argv, "--sign") table.insert(argv, sign) - local entitlements -- TODO if entitlements then table.insert(argv, "--entitlements") table.insert(argv, entitlements) end table.insert(argv, programdir) os.vrunv(codesign.program, argv, {envs = {CODESIGN_ALLOCATE = codesign_allocate}}) + if entitlements then + os.tryrm(entitlements) + end end diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 3f7ec53c8..ff8e1b3cd 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -50,6 +50,7 @@ platform("iphoneos") , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } + , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } } @@ -58,6 +59,7 @@ platform("iphoneos") {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } + , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } } } diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 611a8b5c5..d057712de 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -53,6 +53,7 @@ platform("macosx") , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } + , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } @@ -66,6 +67,7 @@ platform("macosx") {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } + , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 955a5077b..da8dc4f6d 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -50,6 +50,7 @@ platform("watchos") , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } + , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } } @@ -58,6 +59,7 @@ platform("watchos") {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } + , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } } } diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index 39f4feadf..103ddd228 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -63,7 +63,7 @@ function main (target, opt) end -- do codesign - codesign(bundledir, target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity")) + codesign(bundledir, target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity"), target:values("xcode.mobile_provision") or get_config("xcode_mobile_provision")) -- update files and values to the dependent file dependinfo.files = {bundledir} |
