diff options
Diffstat (limited to 'xmake/modules/utils')
| -rw-r--r-- | xmake/modules/utils/archive/extract.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/utils/ipa/install.lua | 49 | ||||
| -rw-r--r-- | xmake/modules/utils/ipa/package.lua | 75 | ||||
| -rw-r--r-- | xmake/modules/utils/ipa/resign.lua | 114 |
4 files changed, 239 insertions, 1 deletions
diff --git a/xmake/modules/utils/archive/extract.lua b/xmake/modules/utils/archive/extract.lua index 8d98e53b6..c800117d6 100644 --- a/xmake/modules/utils/archive/extract.lua +++ b/xmake/modules/utils/archive/extract.lua @@ -357,7 +357,7 @@ function main(archivefile, outputdir, opt) } -- get extension - local extension = get_archive_extension(archivefile) + local extension = opt.extension or get_archive_extension(archivefile) -- extract it return _extract(archivefile, outputdir, extension, extractors[extension], opt) diff --git a/xmake/modules/utils/ipa/install.lua b/xmake/modules/utils/ipa/install.lua new file mode 100644 index 000000000..d6a80311b --- /dev/null +++ b/xmake/modules/utils/ipa/install.lua @@ -0,0 +1,49 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file install.lua +-- + +-- imports +import("utils.ipa.package", {alias = "ipagen"}) +import("lib.detect.find_tool") + +-- main entry +function main (ipafile) + + -- check + assert(os.exists(ipafile), "%s not found!", ipafile) + + -- find ideviceinstaller + local ideviceinstaller = assert(find_tool("ideviceinstaller"), "ideviceinstaller not found!") + + -- is *.app directory? package it first + local istmp = false + if os.isdir(ipafile) then + local appdir = ipafile + ipafile = os.tmpfile() .. ".ipa" + ipagen(appdir, ipafile) + istmp = true + end + + -- do install + os.vrunv(ideviceinstaller.program, {"-i", ipafile}) + if istmp then + os.tryrm(ipafile) + end +end + diff --git a/xmake/modules/utils/ipa/package.lua b/xmake/modules/utils/ipa/package.lua new file mode 100644 index 000000000..0b3d6afcf --- /dev/null +++ b/xmake/modules/utils/ipa/package.lua @@ -0,0 +1,75 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file package.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") + +-- main entry +function main (appdir, ipafile, iconfile) + + -- check + assert(appdir) + assert(os.isdir(appdir), "%s not found!", appdir) + + -- find zip + local zip = find_tool("zip") + assert(zip, "zip not found!") + + -- get the .ipa file path + local appname = path.basename(appdir) + if not ipafile then + ipafile = path.join(path.directory(appdir), appname .. ".ipa") + end + ipafile = path.absolute(ipafile) + + -- the temporary directory + local tmpdir = path.join(os.tmpdir(), "ipagen", appname) + + -- clean the tmpdir first + os.rm(tmpdir) + + -- make the payload directory + os.mkdir(path.join(tmpdir, "Payload")) + + -- copy the .app directory into payload + os.cp(appdir, path.join(tmpdir, "Payload")) + + -- copy icon file to iTunesArtwork + if iconfile then + os.cp(iconfile, path.join(tmpdir, "iTunesArtwork")) + end + + -- generate .ipa file + local argv = {"-r", ipafile, "Payload"} + if iconfile then + table.insert(argv, "iTunesArtwork") + end + local oldir = os.cd(tmpdir) + os.vrunv(zip.program, argv) + os.cd(oldir) + + -- remove the temporary directory + os.rm(tmpdir) + + -- check + assert(os.isfile(ipafile), "generate %s failed!", ipafile) +end + diff --git a/xmake/modules/utils/ipa/resign.lua b/xmake/modules/utils/ipa/resign.lua new file mode 100644 index 000000000..e3c1dcf92 --- /dev/null +++ b/xmake/modules/utils/ipa/resign.lua @@ -0,0 +1,114 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file resign.lua +-- + +-- imports +import("lib.detect.find_tool") +import("lib.detect.find_directory") +import("utils.archive.extract") +import("private.tools.codesign") +import("utils.ipa.package", {alias = "ipagen"}) + +-- resign *.app directory +function _resign_app(appdir, codesign_identity, mobile_provision, bundle_identifier) + + -- get default codesign identity + if not codesign_identity then + for identity, _ in pairs(codesign.codesign_identities()) do + codesign_identity = identity + break + end + end + + -- get default mobile provision + if not mobile_provision then + for provision, _ in pairs(codesign.mobile_provisions()) do + mobile_provision = provision + break + end + end + + -- generate embedded.mobileprovision to *.app/embedded.mobileprovision + local mobile_provision_embedded = path.join(appdir, "embedded.mobileprovision") + 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 + + -- TODO replace bundle identifier of Info.plist + if bundle_identifier then + -- TODO + end + + -- do codesign + codesign(appdir, codesign_identity, mobile_provision) +end + +-- resign *.ipa file +function _resign_ipa(ipafile, codesign_identity, mobile_provision, bundle_identifier) + + -- get resigned ipa file + local ipafile_resigned = path.join(path.directory(ipafile), path.basename(ipafile) .. "_resign" .. path.extension(ipafile)) + + -- extract *.ipa file + local appdir = os.tmpfile() .. ".app" + extract(ipafile, appdir, {extension = ".zip"}) + + -- find real *.app directory + local appdir_real = find_directory("**.app", appdir) + if not appdir_real then + appdir_real = appdir + end + + -- resign *.app directory + _resign_app(appdir_real, codesign_identity, mobile_provision, bundle_identifier) + + -- re-generate *.ipa file + ipagen(appdir_real, ipafile_resigned) + + -- remove tmp files + os.tryrm(appdir) + + -- trace + cprint("output: ${bright}%s", ipafile_resigned) +end + +-- main entry +function main (filepath, codesign_identity, mobile_provision, bundle_identifier) + + -- check + assert(os.exists(filepath), "%s not found!", filepath) + + -- resign *.ipa or *.app application + if os.isfile(filepath) then + _resign_ipa(filepath, codesign_identity, mobile_provision, bundle_identifier) + else + _resign_app(filepath, codesign_identity, mobile_provision, bundle_identifier) + end + + -- ok + cprint("${color.success}resign ok!") +end + |
