diff --git a/build_ext_components.py b/build_ext_components.py index 2cf36089bae9a318298699f0a695507ebe941bba..9900c94f44125e2313f71150a72c346e6756d3b0 100755 --- a/build_ext_components.py +++ b/build_ext_components.py @@ -22,9 +22,11 @@ import argparse import shlex from tempfile import NamedTemporaryFile from shutil import copyfile +from datetime import datetime def cmd_exec(command, temp_file, error_log_path): + start_time = datetime.now().replace(microsecond=0) cmd = shlex.split(command) proc = subprocess.Popen(cmd, @@ -40,6 +42,8 @@ def cmd_exec(command, temp_file, error_log_path): os.remove(temp_file.name) return ret_code + end_time = datetime.now().replace(microsecond=0) + temp_file.write(f'cmd:{command}\ncost time:{end_time-start_time}\n') return ret_code diff --git a/hb/__init__.py b/hb/__init__.py index 511901f8d60aa8b929498bc4b94658a96cbd110e..e63868fba48e1b130f9c4eaf4cacbb78be51db3a 100755 --- a/hb/__init__.py +++ b/hb/__init__.py @@ -42,4 +42,4 @@ CONFIG_STRUCT = { "device_path": None, "patch_cache": None } -VERSION = '0.4.1' +VERSION = '0.4.2' diff --git a/hb/build/build_process.py b/hb/build/build_process.py index 8bbfddc129b4ec197fd8662333418acc74444e37..39b5a46c51c8cd551f36e5daea6eec88631b54cc 100755 --- a/hb/build/build_process.py +++ b/hb/build/build_process.py @@ -26,6 +26,7 @@ from hb.common.utils import remove_path from hb.common.utils import hb_info from hb.common.utils import hb_warning from hb.common.utils import OHOSException +from hb.common.utils import get_current_time from hb.common.config import Config from hb.cts.cts import CTS from hb.common.device import Device @@ -34,6 +35,7 @@ from hb.build.fs_process import Packer from hb.build.patch_process import Patch from distutils.spawn import find_executable + class Build(): def __init__(self, component=None): self.config = Config() @@ -45,6 +47,7 @@ class Build(): self._test = None self.target = component + self.start_time = get_current_time() self.check_in_device() @property @@ -102,6 +105,10 @@ class Build(): else: raise OHOSException('Error: wrong input of test') + @property + def build_time(self): + return get_current_time() - self.start_time + def register_args(self, args_name, args_value, quota=True): quota = False if args_value in ['true', 'false'] else quota if quota: @@ -129,6 +136,7 @@ class Build(): exec_cmd(cmd_args) hb_info(f'{os.path.basename(self.config.out_path)} build success') + hb_info(f'cost time: {self.build_time}') return 0 def get_cmd(self, full_compile, patch, ninja): diff --git a/hb/common/utils.py b/hb/common/utils.py index 5a7bed39db7885ef8398d53be7c74243515879a0..e80eda6f1225174b9200f204edeb1c6ead41f5da 100755 --- a/hb/common/utils.py +++ b/hb/common/utils.py @@ -183,11 +183,12 @@ def args_factory(args_dict): return args -def get_current_time(type='timestamp'): +def get_current_time(type='default'): if type == 'timestamp': return int(datetime.utcnow().timestamp() * 1000) if type == 'datetime': return datetime.now().strftime('%Y-%m-%d %H:%M:%S') + return datetime.now().replace(microsecond=0) def hb_info(msg): diff --git a/hb/set/set.py b/hb/set/set.py index 0351223dcc4560f42a46cc4e8955b644c723d3ff..5e1d31d68ba0f1a53af9f68681f23402d9d7a868 100755 --- a/hb/set/set.py +++ b/hb/set/set.py @@ -20,6 +20,8 @@ import os from hb.common.config import Config from hb.common.utils import get_input +from hb.common.utils import OHOSException +from hb.common.utils import hb_info from hb.common.product import Product from hb.common.device import Device @@ -47,7 +49,11 @@ def exec_command(args): def set_root_path(root_path=None): config = Config() if root_path is None: - root_path = get_input('[OHOS INFO] Input code path: ') + try: + hb_info(f'hb root path: {config.root_path}') + return 0 + except OHOSException: + root_path = get_input('[OHOS INFO] Input code path: ') config.root_path = root_path return 0