提交 4049fcf3 编写于 作者: O openharmony_ci 提交者: Gitee

!20 add hap build script

Merge pull request !20 from stefanDu/duyadong_20201208093446
# Copyright (c) 2020 Huawei Device Co., Ltd.
# 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.
declare_args() {
hapsigner = "developtools/hapsigntoolv2.jar"
packtool = "developtools/hmos_app_packing_tool.jar"
jks_file = "//base/security/frameworks/app_verify/OpenHarmonyCer/OpenHarmony.jks"
cert_file = "//base/security/frameworks/app_verify/OpenHarmonyCer/OpenHarmony.cer"
default_hap_signature_algorithm = "SHA256withECDSA"
privatekey = "OpenHarmony Software Signature"
keystorepasswd = "123456"
}
template("hap_pack") {
assert(defined(invoker.cert_profile), "cert_profile in required.")
assert(defined(invoker.hap_name), "hap_name in required.")
unsignhap_path = "$root_out_dir/system/internal/unsigned_${invoker.hap_name}.hap"
signhap_path = "$root_out_dir/system/internal/${invoker.hap_name}.hap"
action(target_name){
if (defined(invoker.deps)) {
deps = []
deps += invoker.deps
}
script = "//build/lite/hap_pack.py"
args = [
"--packing-tool-path",
packtool
]
if (defined(invoker.mode)) {
args += [
"--mode",
invoker.mode
]
}
if (defined(invoker.json_path)) {
args += [
"--json-path",
rebase_path(invoker.json_path)
]
}
if (defined(invoker.resources_path)) {
args += [
"--resources-path",
rebase_path(invoker.resources_path)
]
}
if (defined(invoker.assets_path)) {
args += [
"--assets-path",
rebase_path(invoker.assets_path)
]
}
if (defined(invoker.lib_path)) {
args += [
"--lib-path",
rebase_path(invoker.lib_path)
]
}
if (defined(invoker.shared_libs_path)) {
args += [
"--shared-libs-path",
rebase_path(invoker.shared_libs_path)
]
}
if (defined(invoker.ability_so_path)) {
args += [
"--ability-so-path",
rebase_path(invoker.ability_so_path)
]
}
if (defined(invoker.index_path)) {
args += [
"--index-path",
rebase_path(invoker.index_path)
]
}
if (defined(invoker.force)) {
args += [
"--force",
invoker.force
]
}
args += [
"--signtool-path",
hapsigner,
"--privatekey",
privatekey,
"--sign-algo",
default_hap_signature_algorithm,
"--unsignhap-path",
rebase_path(unsignhap_path),
"--signhap-path",
rebase_path(signhap_path),
"--jks-path",
rebase_path(jks_file),
"--cert-path",
rebase_path(cert_file),
]
if (defined(invoker.cert_profile)) {
args += [
"--cert-profile",
rebase_path(invoker.cert_profile)
]
}
outputs = [ "$target_out_dir/${target_name}_build_log.txt" ]
}
}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020 Huawei Device Co., Ltd.
# 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.
#
import sys
import os
import argparse
import subprocess
import shutil
import zipfile
def cmd_popen(cmd):
proc = subprocess.Popen(cmd)
proc.wait()
ret_code = proc.returncode
if ret_code != 0:
print("hap warning: {} failed, return code is {}"
.format(cmd, ret_code))
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--packing-tool-path', help='packing tool path ')
parser.add_argument('--mode', help='package mode')
parser.add_argument('--json-path', help='profile')
parser.add_argument('--resources-path', help='resources')
parser.add_argument('--assets-path', help='assets')
parser.add_argument('--lib-path', help='lib')
parser.add_argument('--shared-libs-path', help='shared-libs')
parser.add_argument('--ability-so-path', help='ability so')
parser.add_argument('--index-path', help='index')
parser.add_argument('--unsignhap-path', help='unsignhap path')
parser.add_argument('--force', help='force')
parser.add_argument('--signtool-path', help='sign tool path')
parser.add_argument('--signhap-path', help='sign hap path')
parser.add_argument('--privatekey', help='privatekey')
parser.add_argument('--sign-algo', help='sign algo')
parser.add_argument('--cert-profile', help='cert profile')
parser.add_argument('--jks-path', help='jks path')
parser.add_argument('--cert-path', help='cert path')
args = parser.parse_args()
return args
def hap_packing(args):
if not args.packing_tool_path:
print('hap warning: packing tool path empty')
return
packing_tool_path = os.path.join(os.environ['HOME'],
args.packing_tool_path)
packing_cmd = ['java', '-jar', packing_tool_path]
cmd_dict = {'--mode': args.mode,
'--json-path': args.json_path,
'--resources-path': args.resources_path,
'--assets-path': args.assets_path,
'--lib-path': args.lib_path,
'--shared-libs-path': args.shared_libs_path,
'--ability-so-path': args.ability_so_path,
'--index-path': args.index_path,
'--out-path': args.unsignhap_path,
'--force': args.force}
for key, value in cmd_dict.items():
if value:
packing_cmd.extend([key, value])
cmd_popen(packing_cmd)
def hap_signing(args):
user_name = ''
password = ''
if not args.signtool_path:
print('hap warning: signing tool path empty')
return
signtool_path = os.path.join(os.environ['HOME'], args.signtool_path)
#The default password of the key is 123456.
# You are advised to use a key and certificate management tool (
# such as keytool) to change the default password.
# For details, see section "Application Signature Verification
# Development Guide" in the Security Subsystem Development Guide.
signing_cmd = ['java', '-jar', signtool_path, 'sign', '-mode',
'localjks', '-profileSigned', '1', '-keystorepasswd',
'123456', '-keyaliaspasswd', '123456']
cmd_dict = {'-privatekey': args.privatekey,
'-inputFile': args.unsignhap_path,
'-outputFile': args.signhap_path,
'-signAlg': args.sign_algo,
'-profile': args.cert_profile,
'-keystore': args.jks_path,
'-certpath': args.cert_path}
for key, value in cmd_dict.items():
if value:
signing_cmd.extend([key, value])
cmd_popen(signing_cmd)
def main():
args = parse_args()
hap_packing(args)
if os.path.exists(args.unsignhap_path):
hap_signing(args)
os.remove(args.unsignhap_path)
if __name__ == '__main__':
sys.exit(main())
...@@ -257,7 +257,10 @@ ...@@ -257,7 +257,10 @@
"targets": [ "targets": [
"//applications/sample/camera/app:camera_app", "//applications/sample/camera/app:camera_app",
"//applications/sample/camera/communication:sample", "//applications/sample/camera/communication:sample",
"//applications/sample/camera/hap:copy_hap" "//applications/sample/camera/launcher:launcher",
"//applications/sample/camera/cameraApp:cameraApp",
"//applications/sample/camera/setting:setting",
"//applications/sample/camera/gallery:gallery"
], ],
"features": [], "features": [],
"deps": { "deps": {
......
...@@ -17,7 +17,10 @@ ...@@ -17,7 +17,10 @@
"component": [ "component": [
{ "name": "camera", "dir": "//applications/sample/camera/app:camera_app", "features":[] }, { "name": "camera", "dir": "//applications/sample/camera/app:camera_app", "features":[] },
{ "name": "communication", "dir": "//applications/sample/camera/communication:sample", "features":[] }, { "name": "communication", "dir": "//applications/sample/camera/communication:sample", "features":[] },
{ "name": "hap", "dir": "//applications/sample/camera/hap:copy_hap", "features":[] } { "name": "launcher", "dir": "//applications/sample/camera/launcher:launcher", "features":[] },
{ "name": "cameraApp", "dir": "//applications/sample/camera/cameraApp:cameraApp", "features":[] },
{ "name": "setting", "dir": "//applications/sample/camera/setting:setting", "features":[] },
{ "name": "gallery", "dir": "//applications/sample/camera/gallery:gallery", "features":[] }
] ]
}, },
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册