diff options
| author | ruki <[email protected]> | 2020-04-05 15:53:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-04-05 15:53:37 +0800 |
| commit | b6436a2df4a37f82e38723711937743daceb5367 (patch) | |
| tree | 8e923537a4d6d2ded571ac5f27797466c5009cce | |
| parent | 4f7b37fa0ab9afa8b21b2c19980683c0eef60e8c (diff) | |
improve codesign
| -rw-r--r-- | xmake/modules/private/tools/codesign.lua | 42 | ||||
| -rw-r--r-- | xmake/rules/xcode/application/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/xcode/bundle/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/xcode/framework/xmake.lua | 2 |
4 files changed, 43 insertions, 5 deletions
diff --git a/xmake/modules/private/tools/codesign.lua b/xmake/modules/private/tools/codesign.lua index b9b7f05a0..c0eee25b2 100644 --- a/xmake/modules/private/tools/codesign.lua +++ b/xmake/modules/private/tools/codesign.lua @@ -21,8 +21,36 @@ -- imports import("lib.detect.find_tool") +-- get codesign identities +function _get_codesign_identities() + local identities = _g.identities + if identities == nil then + identities = {} + local results = try { function() return os.iorun("/usr/bin/security find-identity -v -p codesigning") end } + if not results then + results = try { function() return os.iorun("/usr/bin/security find-identity") end } + if results then + local splitinfo = results:split("Valid identities only", {plain = true}) + if splitinfo and #splitinfo > 1 then + results = splitinfo[2] + end + end + end + if results then + for _, line in ipairs(results:split('\n', {plain = true})) do + local sign, identity = line:match("%) (%w+) \"(.+)\"") + if sign and identity then + identities[identity] = sign + end + end + end + _g.identities = identities or false + end + return identities or nil +end + -- main entry -function main (programdir) +function main (programdir, codesign_identity) -- get codesign local codesign = find_tool("codesign") @@ -37,10 +65,20 @@ function main (programdir) codesign_allocate = path.join(xcode_sdkdir, "Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate") end + -- get codesign + local sign = "-" + if codesign_identity then + local identities = _get_codesign_identities() + if identities then + sign = identities[codesign_identity] + assert(sign, "codesign: invalid sign identity(%s)!", codesign_identity) + end + end + -- do sign local argv = {"--force", "--timestamp=none"} table.insert(argv, "--sign") - table.insert(argv, "-") + table.insert(argv, sign) table.insert(argv, programdir) os.vrunv(codesign.program, argv, {envs = {CODESIGN_ALLOCATE = codesign_allocate}}) end diff --git a/xmake/rules/xcode/application/xmake.lua b/xmake/rules/xcode/application/xmake.lua index 0cd4ae2bd..510ab143d 100644 --- a/xmake/rules/xcode/application/xmake.lua +++ b/xmake/rules/xcode/application/xmake.lua @@ -93,7 +93,7 @@ rule("xcode.application") end -- do codesign - codesign(appdir) + codesign(appdir, target:values("xcode.codesign_identity")) end) on_install(function (target) diff --git a/xmake/rules/xcode/bundle/xmake.lua b/xmake/rules/xcode/bundle/xmake.lua index 97b2e9966..3a9f6144c 100644 --- a/xmake/rules/xcode/bundle/xmake.lua +++ b/xmake/rules/xcode/bundle/xmake.lua @@ -82,7 +82,7 @@ rule("xcode.bundle") end -- do codesign - codesign(bundledir) + codesign(bundledir, target:values("xcode.codesign_identity")) end) on_install(function (target) diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua index 6cc5ec1c7..a502abdeb 100644 --- a/xmake/rules/xcode/framework/xmake.lua +++ b/xmake/rules/xcode/framework/xmake.lua @@ -134,7 +134,7 @@ rule("xcode.framework") os.cd(oldir) -- do codesign - codesign(path.join(frameworkdir, "Versions", "A")) + codesign(path.join(frameworkdir, "Versions", "A"), target:values("xcode.codesign_identity")) end) on_install(function (target) |
