build.py 3.7 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/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.
#

from collections import defaultdict

from hb.build.build_process import Build
from hb.set.set import set_product
P
pilipala195 已提交
23
from hb.common.device import Device
M
mamingshuai 已提交
24 25 26 27 28 29 30 31 32 33 34 35


def add_options(parser):
    parser.add_argument('component', help='name of the component', nargs='*',
                        default=[])
    parser.add_argument('-b', '--build_type', help='release or debug version',
                        nargs=1, default=['debug'])
    parser.add_argument('-c', '--compiler', help='specify compiler',
                        nargs=1, default=['clang'])
    parser.add_argument('-t', '--test', help='compile test suit', nargs='*')
    parser.add_argument('--dmverity', help='Enable dmverity',
                        action="store_true")
P
pilipala195 已提交
36 37
    parser.add_argument('--tee', help='Enable tee',
                        action="store_true")
M
mamingshuai 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    parser.add_argument('-p', '--product', help='build a specified product '
                        'with {product_name}@{company}, eg: camera@huawei',
                        nargs=1, default=[])
    parser.add_argument('-f', '--full',
                        help='full code compilation', action='store_true')
    parser.add_argument('-n', '--ndk', help='compile ndk',
                        action='store_true')
    parser.add_argument('-T', '--target', help='Compile single target',
                        nargs='*', default=[])
    parser.add_argument('-v', '--verbose',
                        help='show all command lines while building',
                        action='store_true')
    parser.add_argument('-shs', '--sign_haps_by_server',
                        help='sign haps by server', action='store_true')


def exec_command(args):
    build = Build()
    cmd_args = defaultdict(list)

    if len(args.component):
        build.target = args.component[0]

    build.register_args('ohos_build_type', args.build_type[0])

    if args.test is not None:
        build.test = args.test

    if args.dmverity:
        build.register_args('enable_ohos_security_dmverity',
                            'true',
                            quota=False)
P
pilipala195 已提交
70 71 72 73 74
        build.config.fs_attr.add('dmverity_enable')

    if args.tee:
        build.register_args('tee_enable', 'true', quota=False)
        build.config.fs_attr.add('tee_enable')
M
mamingshuai 已提交
75 76 77 78 79

    if len(args.product):
        product, company = args.product[0].split('@')
        set_product(product_name=product, company=company)

P
pilipala195 已提交
80 81
    build.compiler = Device.get_compiler(build.config.device_path)

M
mamingshuai 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    if args.ndk:
        build.register_args('ohos_build_ndk', 'true', quota=False)

    if hasattr(args, 'target') and len(args.target):
        build.register_args('ohos_build_target', args.target)

    if hasattr(args, 'verbose') and args.verbose:
        cmd_args['gn'].append('-v')
        cmd_args['ninja'].append('-v')

    if hasattr(args, 'ninja'):
        return build.build(args.full, ninja=args.ninja)

    if args.sign_haps_by_server:
        build.register_args('ohos_sign_haps_by_server',
                            'true',
                            quota=False)

    return build.build(args.full, cmd_args=cmd_args)