• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright (c) 2023 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import os
18
19
20class IdeType():
21    AS = 1
22    DevEco = 2
23
24
25class Config():
26    send_mail = True
27    run_list = ["HelloWorld"]
28
29    def __init__(self):
30        # Default config settings for all projects, if it's not what you need, config them in application_configs
31        self.cmd_prefix = r"hvigorw.bat"
32
33        self.output_split = "_"
34        self.ide_filename = ["AS", "DevEco"]
35        self.debug_or_release = ["Debug", "Release"]
36        self.build_type_of_log = ["full_then_incremental", "add_code_and_ui"]
37        self.log_filename = ["size_all.csv", "size_avg.csv",
38                             "time_all.csv", "time_avg.csv"]
39        self.error_filename = 'error.log'
40        self.ide = IdeType.DevEco
41        self.incremental_code_str = "let index = 5 + 6\n"
42        self.incremental_code_start_pos = "let index = 5 + 6\n"
43        self.incremental_code_end_pos = 'this.num = num'
44        self.cmd_debug_suffix = r' --mode module -p product=default module=entry@default -p' + \
45            ' buildMode=debug assembleHap --info --verbose-analyze --parallel --incremental --daemon'
46        self.cmd_release_suffix = r' --mode module -p product=default module=entry@default -p' + \
47            ' buildMode=release assembleHap --info --verbose-analyze --parallel --incremental --daemon'
48        self.debug_package_path = r'entry/build/default/outputs/default/entry-default-signed.hap'
49        self.release_package_path = r'entry/build/default/outputs/default/entry-default-unsigned.hap'
50        self.incremental_code_path = r'entry/src/main/ets/pages/Index.ets'
51        self.json5_path = r'build-profile.json5'
52
53        # build serveral times then calculate the average value
54        self.build_times = 3
55        # Debug this script fastly with skipping building and will use test data.
56        # Use test_report.json to test the build succeed case.
57        # Use test_error_report.json the build failed case.
58        # Use '' to run the real build.
59        self.developing_test_data_path = ''
60        # set your node_js path, it should be the same to the setting in your IDE
61        self.node_js_path = r"xxx/nodejs"
62        # Must set according environment
63        self.jbr_path = r'xxx/DevEco Studio/jbr'
64
65    # If Default config is not what you need, you can set here!
66    application_configs = dict(
67        [
68            (
69                "FTB", dict
70                    (
71                        project_path=r"D:/FTB",
72                        name='FTB',
73                    )
74            ),
75            (
76                "FDY", dict
77                    (
78                        project_path=r"D:/FDY",
79                        name='FDY',
80                    )
81            ),
82            (
83                "FWX", dict
84                    (
85                        project_path=r"D:/FWX",
86                        name='FWX',
87                    )
88            ),
89            (
90                "HelloWorld", dict
91                    (
92                        # The following params must be set according you environment
93                        project_path=r"D:/HelloWorld",
94                        name='HelloWorld',
95
96                        # The following params is not neccessary to be modified
97                        debug_package_path=r'entry/build/default/outputs/default/entry-default-unsigned.hap',
98                        release_package_path=r'entry/build/default/outputs/default/entry-default-unsigned.hap',
99                        incremental_code_path=r'entry/src/main/ets/pages/Index.ets',
100                        incremental_code_end_pos='build() {',
101                        incremental_code_str="a: number=5 + 6\n",
102                        incremental_code_start_pos="a: number=5 + 6\n",
103
104                        # This app will show the time costs in html
105                        # you can setting this as a global setting to show all applications.
106                        show_time_detail_filter=["createProgram", "arkTSLinter", "tsProgramEmit",
107                            "generate content and source map information", "write obfuscated source code",
108                            "write source map (async)", "generate merged abc by es2abc (async)", "total build cost"
109                        ]
110                    )
111            )
112        ]
113    )
114
115
116def get_config(index):
117    config = Config()
118    res = config.application_configs.get(index)
119    if not res:
120        print("No key in config, please check: " + index)
121        return res
122    for k in res:
123        setattr(config, k, res[k])
124    if not hasattr(config, 'name'):
125        setattr(config, 'name', os.path.basename(config.project_path))
126    return config
127
128
129def get_html_prefix():
130    return '<html><body><table width="100%" border=1 cellspacing=0 cellpadding=0 align="center">' + \
131           '<tr><th bgcolor="SlateBlue"><font size="5">Daily Performance Test</font></th></tr></table>' + \
132           '<font size="5" color=red>{}' + \
133           '<img src="cid:performance10"><img src="cid:performance11">' + \
134           '<img src="cid:performance00"><img src="cid:performance01">' + \
135           '<img src="cid:performance02"><img src="cid:performance12">'
136
137
138
139def get_html_suffix():
140    return '</body></html>'
141
142
143class BuildMode():
144    DEBUG = 0
145    RELEASE = 1
146
147
148class LogType():
149    FULL = 0
150    INCREMENTAL = 1
151    SIZE = 2
152
153
154class MailPicConfig():
155    mail_data_path = os.path.join(
156        os.path.dirname(os.path.abspath(__file__)),
157        'mail_data',
158    )
159
160    html_file_path = os.path.join(
161        mail_data_path,
162        "email_msg.html"
163    )
164
165    attach_path = os.path.join(
166        mail_data_path,
167        "performance_logs.zip"
168    )
169
170    # Count of days which will be add into the email picture
171    mail_pic_table_name = {
172        BuildMode.DEBUG: {
173            LogType.FULL: os.path.join(mail_data_path, 'debug_full_time.csv'),
174            LogType.INCREMENTAL: os.path.join(mail_data_path, 'debug_incremental_time.csv'),
175            LogType.SIZE: os.path.join(mail_data_path, 'debug_size.csv')
176        },
177        BuildMode.RELEASE:{
178            LogType.FULL: os.path.join(mail_data_path, 'release_full_time.csv'),
179            LogType.INCREMENTAL: os.path.join(mail_data_path, 'release_incremental_time.csv'),
180            LogType.SIZE: os.path.join(mail_data_path, 'release_size.csv')
181        }
182    }
183
184    mail_pic_name = {
185        BuildMode.DEBUG: {
186            LogType.FULL:os.path.join(mail_data_path, 'debug_full_time.jpg'),
187            LogType.INCREMENTAL: os.path.join(mail_data_path, 'debug_incremental_time.jpg'),
188            LogType.SIZE: os.path.join(mail_data_path, 'debug_size.jpg')
189        },
190        BuildMode.RELEASE:{
191            LogType.FULL: os.path.join(mail_data_path, 'release_full_time.jpg'),
192            LogType.INCREMENTAL: os.path.join(mail_data_path, 'release_incremental_time.jpg'),
193            LogType.SIZE: os.path.join(mail_data_path, 'release_size.jpg')
194        }
195    }
196
197    mail_pic_table_lable = {
198        BuildMode.DEBUG: {
199            LogType.FULL: 'Debug Full Build',
200            LogType.INCREMENTAL: 'Debug Incremental Build',
201            LogType.SIZE: 'Debug Full Build size'
202        },
203        BuildMode.RELEASE:{
204            LogType.FULL: 'Release Full Build',
205            LogType.INCREMENTAL: 'Release Incremental Time',
206            LogType.SIZE: 'Release Full Build size'
207        }
208    }