• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4#
5# Copyright (c) 2020 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20import sys
21import importlib
22import subprocess
23
24
25def check_output(cmd, **kwargs):
26    process = subprocess.Popen(cmd,
27                               stdout=subprocess.PIPE,
28                               stderr=subprocess.STDOUT,
29                               universal_newlines=True,
30                               **kwargs)
31    for line in iter(process.stdout.readline, ''):
32        sys.stdout.write(line)
33        sys.stdout.flush()
34
35    process.wait()
36    ret_code = process.returncode
37
38    return ret_code
39
40
41def set_root_path(path):
42    sys.path.insert(0, os.path.join(path, 'build/lite'))
43    module = importlib.import_module('hb_internal.set.set')
44    return module.set_root_path(root_path=path)
45
46
47def build(path, args_list):
48    cmd = ['python3', 'build/lite/hb/__main__.py', 'build'] + args_list
49    return check_output(cmd, cwd=path)
50
51
52def main():
53    root_path = os.path.dirname(os.path.abspath(__file__))
54    ret_code = set_root_path(root_path)
55    if ret_code != 0:
56        return ret_code
57    return build(root_path, sys.argv[1:])
58
59
60if __name__ == "__main__":
61    sys.exit(main())
62