diff options
| author | ruki <[email protected]> | 2025-09-19 23:51:40 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-19 23:51:40 +0800 |
| commit | ca784dc5ed3be5a75e787c9711da8fdf619df619 (patch) | |
| tree | 20e9df17f1446788597ae692cebbee31db8700d9 | |
| parent | 4ca5b7977c312b8e87336c4392d35885b863df48 (diff) | |
| parent | 286b5301449d1cd26c07c05d37d39fe424e678c0 (diff) | |
Merge pull request #6832 from xmake-io/sign
optimize codesign
| -rw-r--r-- | tests/projects/objc/macapp/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_xcode.lua | 42 | ||||
| -rw-r--r-- | xmake/modules/private/tools/codesign.lua | 45 | ||||
| -rw-r--r-- | xmake/rules/qt/deploy/macosx.lua | 3 | ||||
| -rw-r--r-- | xmake/rules/xcode/application/build.lua | 21 | ||||
| -rw-r--r-- | xmake/rules/xcode/bundle/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/xcode/framework/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/check.lua | 14 |
8 files changed, 67 insertions, 65 deletions
diff --git a/tests/projects/objc/macapp/xmake.lua b/tests/projects/objc/macapp/xmake.lua index 71e2af16b..16f1e249d 100644 --- a/tests/projects/objc/macapp/xmake.lua +++ b/tests/projects/objc/macapp/xmake.lua @@ -2,9 +2,6 @@ add_rules("mode.debug", "mode.release") rule("test") add_deps("xcode.application") - after_build(function () - print("xxx") - end) target("test") add_rules("xcode.application") diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua index 6382ae577..22025da1d 100644 --- a/xmake/modules/detect/sdks/find_xcode.lua +++ b/xmake/modules/detect/sdks/find_xcode.lua @@ -120,47 +120,7 @@ function _find_xcode(sdkdir, opt) -- find the target minver local target_minver = _find_target_minver(sdkdir, sdkver, opt) - - -- find codesign - local codesign_identity, mobile_provision - if opt.find_codesign then - - -- find codesign identity - codesign_identity = config.get("xcode_codesign_identity") - if codesign_identity == nil then -- we will disable codesign_identity if be false - codesign_identity = global.get("xcode_codesign_identity") - end - if codesign_identity == nil then - local codesign_identities = codesign.codesign_identities() - if codesign_identities then - for identity, _ in pairs(codesign_identities) do - codesign_identity = identity - break - end - end - end - - -- find mobile provision only for iphoneos - if opt.plat == "iphoneos" then - local mobile_provisions = codesign.mobile_provisions() - if mobile_provisions then - 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 then - for provision, _ in pairs(mobile_provisions) do - mobile_provision = provision - break - end - -- valid mobile provision not found? reset it - elseif not mobile_provisions[mobile_provision] then - mobile_provision = nil - end - end - end - end - return {sdkdir = sdkdir, sdkver = sdkver, target_minver = target_minver, codesign_identity = codesign_identity, mobile_provision = mobile_provision} + return {sdkdir = sdkdir, sdkver = sdkver, target_minver = target_minver} end -- find xcode toolchain diff --git a/xmake/modules/private/tools/codesign.lua b/xmake/modules/private/tools/codesign.lua index f38b3e073..8a1cd10b0 100644 --- a/xmake/modules/private/tools/codesign.lua +++ b/xmake/modules/private/tools/codesign.lua @@ -20,6 +20,8 @@ -- imports import("lib.detect.find_tool") +import("core.base.global") +import("core.project.config") import("core.cache.global_detectcache") -- get mobile provision name @@ -134,8 +136,47 @@ function unsign(programdir) os.vrunv(codesign.program, {"--remove-signature", programdir}) end --- main entry -function main (programdir, codesign_identity, mobile_provision, opt) +-- get the current codesign identity of xcode +function xcode_codesign_identity() + local codesign_identity = config.get("xcode_codesign_identity") + if codesign_identity == nil then -- we will disable codesign_identity if be false + codesign_identity = global.get("xcode_codesign_identity") + end + if codesign_identity == nil then + local identities = codesign_identities() + if identities then + for identity, _ in pairs(identities) do + codesign_identity = identity + break + end + end + end + return codesign_identity +end + +-- get the current mobile provision of xcode +function xcode_mobile_provision() + 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 + + local provisions = mobile_provisions() + if provisions then + if mobile_provision == nil then + for provision, _ in pairs(provisions) do + mobile_provision = provision + break + end + -- valid mobile provision not found? reset it + elseif not provisions[mobile_provision] then + mobile_provision = nil + end + end + return mobile_provision +end + +function main(programdir, codesign_identity, mobile_provision, opt) -- only for macosx opt = opt or {} diff --git a/xmake/rules/qt/deploy/macosx.lua b/xmake/rules/qt/deploy/macosx.lua index 73f3910fe..6507d7032 100644 --- a/xmake/rules/qt/deploy/macosx.lua +++ b/xmake/rules/qt/deploy/macosx.lua @@ -28,6 +28,7 @@ import("lib.detect.find_file") import("lib.detect.find_path") import("detect.sdks.find_qt") import("utils.progress") +import("private.tools.codesign") -- save Info.plist function _save_info_plist(target, info_plist_file) @@ -136,7 +137,7 @@ function main(target, opt) if qmldir then table.insert(argv, "-qmldir=" .. qmldir) end - local codesign_identity = target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity") + local codesign_identity = target:values("xcode.codesign_identity") or codesign.xcode_codesign_identity() if codesign_identity then -- e.g. "Apple Development: [email protected] (T3NA4MRVPU)" table.insert(argv, "-codesign=" .. codesign_identity) diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index 74a8b2431..a98baf57a 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -86,21 +86,24 @@ function main (target, opt) end -- generate embedded.mobileprovision to *.app/embedded.mobileprovision + local mobile_provision local mobile_provision_embedded = path.join(bundledir, "embedded.mobileprovision") - local mobile_provision = target:values("xcode.mobile_provision") or get_config("xcode_mobile_provision") - if mobile_provision and target:is_plat("iphoneos") then - os.tryrm(mobile_provision_embedded) - local provisions = codesign.mobile_provisions() - if provisions then - local mobile_provision_data = provisions[mobile_provision] - if mobile_provision_data then - io.writefile(mobile_provision_embedded, mobile_provision_data) + if target:is_plat("iphoneos") then + mobile_provision = target:values("xcode.mobile_provision") or codesign.xcode_mobile_provision() + if mobile_provision then + os.tryrm(mobile_provision_embedded) + local provisions = codesign.mobile_provisions() + if provisions then + local mobile_provision_data = provisions[mobile_provision] + if mobile_provision_data then + io.writefile(mobile_provision_embedded, mobile_provision_data) + end end end end -- do codesign - local codesign_identity = target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity") + local codesign_identity = target:values("xcode.codesign_identity") or codesign.xcode_codesign_identity() if target:is_plat("macosx") or (target:is_plat("iphoneos") and target:is_arch("x86_64", "i386")) then codesign_identity = nil end diff --git a/xmake/rules/xcode/bundle/xmake.lua b/xmake/rules/xcode/bundle/xmake.lua index 9d697e3cf..bb3bed28f 100644 --- a/xmake/rules/xcode/bundle/xmake.lua +++ b/xmake/rules/xcode/bundle/xmake.lua @@ -103,7 +103,7 @@ rule("xcode.bundle") end -- do codesign - local codesign_identity = target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity") + local codesign_identity = target:values("xcode.codesign_identity") or codesign.xcode_codesign_identity() if target:is_plat("macosx") or (target:is_plat("iphoneos") and target:is_arch("x86_64", "i386")) then codesign_identity = nil end diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua index 4e849f51b..2f0d47b87 100644 --- a/xmake/rules/xcode/framework/xmake.lua +++ b/xmake/rules/xcode/framework/xmake.lua @@ -156,7 +156,7 @@ rule("xcode.framework") -- do codesign, only for dynamic library if target:is_shared() then - local codesign_identity = target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity") + local codesign_identity = target:values("xcode.codesign_identity") or codesign.xcode_codesign_identity() if target:is_plat("macosx") or (target:is_plat("iphoneos") and target:is_arch("x86_64", "i386")) then codesign_identity = nil end diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 5cc0ace73..9e172af8d 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -23,6 +23,7 @@ import("core.base.option") import("core.project.config") import("detect.sdks.find_xcode") import("private.utils.executable_path") +import("private.tools.codesign") -- main entry function main(toolchain) @@ -41,7 +42,6 @@ function main(toolchain) -- find xcode local xcode_sdkver = toolchain:config("xcode_sdkver") or config.get("xcode_sdkver") local xcode = find_xcode(config.get("xcode"), {force = true, verbose = true, - find_codesign = toolchain:is_global(), sdkver = xcode_sdkver, appledev = appledev, plat = toolchain:plat(), @@ -55,22 +55,22 @@ function main(toolchain) xcode_sdkver = xcode.sdkver if toolchain:is_global() then config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) - config.set("xcode_mobile_provision", xcode.mobile_provision, {force = true, readonly = true}) - config.set("xcode_codesign_identity", xcode.codesign_identity, {force = true, readonly = true}) if xcode.sdkdir then cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir) else cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}") end if option.get("verbose") then - if xcode.codesign_identity then - cprint("checking for Codesign Identity of Xcode ... ${color.success}%s", xcode.codesign_identity) + local codesign_identity = codesign.xcode_codesign_identity() + if codesign_identity then + cprint("checking for Codesign Identity of Xcode ... ${color.success}%s", codesign_identity) else cprint("checking for Codesign Identity of Xcode ... ${color.nothing}${text.nothing}") end if toolchain:is_plat("iphoneos") then - if xcode.mobile_provision then - cprint("checking for Mobile Provision of Xcode ... ${color.success}%s", xcode.mobile_provision) + local mobile_provision = codesign.xcode_mobile_provision() + if mobile_provision then + cprint("checking for Mobile Provision of Xcode ... ${color.success}%s", mobile_provision) else cprint("checking for Mobile Provision of Xcode ... ${color.nothing}${text.nothing}") end |
