summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-10 23:47:05 +0800
committerruki <[email protected]>2020-04-10 16:42:34 +0800
commit2f8ba83840b41de28e7aebd5d12ee35a2bc0c8a1 (patch)
treea5c550f454c7391a561410dbb3576094027da076
parentb25009c38659c92aec90184a1cf803f7e1dcf4b1 (diff)
add ipa.resign/install/package utils
-rw-r--r--xmake/modules/utils/archive/extract.lua2
-rw-r--r--xmake/modules/utils/ipa/install.lua49
-rw-r--r--xmake/modules/utils/ipa/package.lua (renamed from xmake/modules/private/tools/ipagen.lua)2
-rw-r--r--xmake/modules/utils/ipa/resign.lua114
-rw-r--r--xmake/rules/xcode/application/install.lua6
-rw-r--r--xmake/rules/xcode/application/package.lua2
6 files changed, 168 insertions, 7 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/private/tools/ipagen.lua b/xmake/modules/utils/ipa/package.lua
index 00dfa266c..0b3d6afcf 100644
--- a/xmake/modules/private/tools/ipagen.lua
+++ b/xmake/modules/utils/ipa/package.lua
@@ -15,7 +15,7 @@
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
--
-- @author ruki
--- @file ipdagen.lua
+-- @file package.lua
--
-- imports
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
+
diff --git a/xmake/rules/xcode/application/install.lua b/xmake/rules/xcode/application/install.lua
index 2b2c5069b..529e99360 100644
--- a/xmake/rules/xcode/application/install.lua
+++ b/xmake/rules/xcode/application/install.lua
@@ -21,6 +21,7 @@
-- imports
import("core.base.task")
import("lib.detect.find_tool")
+import("utils.ipa.install", {alias = "install_ipa"})
-- install for ios
function _install_for_ios(target)
@@ -35,11 +36,8 @@ function _install_for_ios(target)
end
assert(os.isfile(ipafile), "please run `xmake package` first!")
- -- find ideviceinstaller
- local ideviceinstaller = assert(find_tool("ideviceinstaller"), "ideviceinstaller not found!")
-
-- do install
- os.vrunv(ideviceinstaller.program, {"-i", ipafile})
+ install_ipa(ipafile)
end
-- install for macosx
diff --git a/xmake/rules/xcode/application/package.lua b/xmake/rules/xcode/application/package.lua
index 059b7b219..48d4debb6 100644
--- a/xmake/rules/xcode/application/package.lua
+++ b/xmake/rules/xcode/application/package.lua
@@ -19,7 +19,7 @@
--
-- imports
-import("private.tools.ipagen")
+import("utils.ipa.package", {alias = "ipagen"})
-- package for ios
function _package_for_ios(target)