• 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        # Set the path of your deveco studio
32        self.deveco_path = r"xxx/DevEco Studio"
33        self.cmd_prefix = os.path.join(self.deveco_path, 'tools', 'hvigor', 'bin', 'hvigorw.js')
34        self.node_js_path = os.path.join(self.deveco_path, 'tools', 'node', 'node.exe')
35        self.jbr_path = os.path.join(self.deveco_path, 'jbr')
36
37        self.output_split = "_"
38        self.ide_filename = ["AS", "DevEco"]
39        self.debug_or_release = ["Debug", "Release"]
40        self.build_type_of_log = ["full_then_incremental", "add_code_and_ui"]
41        self.log_filename = ["size_all.csv", "size_avg.csv",
42                             "time_all.csv", "time_avg.csv"]
43        self.error_filename = 'error.log'
44        self.ide = IdeType.DevEco
45        self.incremental_code_str = "let index = 5 + 6\n"
46        self.incremental_code_start_pos = "let index = 5 + 6\n"
47        self.incremental_code_end_pos = 'this.num = num'
48        self.preview_debug_suffix = ['--mode', 'module', '-p', 'module=entry@default', '-p', 'product=default', '-p',
49                                     'buildMode=release', 'assembleHap', '--verbose-analyze', '--parallel',
50                                     '--incremental', '--daemon', '--info']
51        self.preview_release_suffix = ['--mode', 'module', '-p', 'module=entry@default', '-p', 'product=default', '-p',
52                                       'buildMode=release', 'assembleHap', '--verbose-analyze', '--parallel',
53                                       '--incremental', '--daemon', '--info']
54        self.preview_build = False,
55        self.preview_cache_path = ['entry', '.preview']
56        self.cmd_debug_suffix = ['--mode', 'module', '-p', 'product=default', 'module=entry@default', '-p',
57                                 'buildMode=debug', 'assembleHap', '--info', '--verbose-analyze', '--parallel',
58                                 '--incremental', '--daemon']
59        self.cmd_release_suffix = ['--mode', 'module', '-p', 'product=default', 'module=entry@default', '-p',
60                                   'buildMode=release', 'assembleHap', '--info', '--verbose-analyze', '--parallel',
61                                   '--incremental', '--daemon']
62        self.debug_package_path = r'entry/build/default/outputs/default/entry-default-signed.hap'
63        self.release_package_path = r'entry/build/default/outputs/default/entry-default-unsigned.hap'
64        self.incremental_code_path = r'entry/src/main/ets/pages/Index.ets'
65        self.json5_path = r'build-profile.json5'
66
67        # build serveral times then calculate the average value
68        self.build_times = 3
69        # Debug this script fastly with skipping building and will use test data.
70        # Use test_report.json to test the build succeed case.
71        # Use test_error_report.json the build failed case.
72        # Use '' to run the real build.
73        self.developing_test_data_path = ''
74
75    # If Default config is not what you need, you can set here!
76    application_configs = dict(
77        [
78            (
79                "FTB", dict
80                    (
81                        project_path=r"D:/FTB",
82                        name='FTB',
83                    )
84            ),
85            (
86                "FDY", dict
87                    (
88                        project_path=r"D:/FDY",
89                        name='FDY',
90                    )
91            ),
92            (
93                "FWX", dict
94                    (
95                        project_path=r"D:/FWX",
96                        name='FWX',
97                    )
98            ),
99            (
100                "HelloWorld", dict
101                    (
102                        # The following params must be set according you environment
103                        project_path=r"D:/HelloWorld",
104                        name='HelloWorld',
105
106                        # The following params is not neccessary to be modified
107                        preview_build=True
108                        debug_package_path=r'entry/build/default/outputs/default/entry-default-unsigned.hap',
109                        release_package_path=r'entry/build/default/outputs/default/entry-default-unsigned.hap',
110                        incremental_code_path=r'entry/src/main/ets/pages/Index.ets',
111                        incremental_code_end_pos='build() {',
112                        incremental_code_str="a: number=5 + 6\n",
113                        incremental_code_start_pos="a: number=5 + 6\n",
114
115                        # This app will show the time costs in html
116                        # you can setting this as a global setting to show all applications.
117                        show_time_detail_filter=["createProgram", "arkTSLinter", "tsProgramEmit",
118                            "generate content and source map information", "write obfuscated source code",
119                            "write source map (async)", "generate merged abc by es2abc (async)", "total build cost"
120                        ]
121                    )
122            )
123        ]
124    )
125
126
127def get_config(index):
128    config = Config()
129    res = config.application_configs.get(index)
130    if not res:
131        print("No key in config, please check: " + index)
132        return res
133    for k in res:
134        setattr(config, k, res[k])
135    if not hasattr(config, 'name'):
136        setattr(config, 'name', os.path.basename(config.project_path))
137    return config
138
139
140def get_html_prefix():
141    return '<html><body><table width="100%" border=1 cellspacing=0 cellpadding=0 align="center">' + \
142           '<tr><th bgcolor="SlateBlue"><font size="5">Daily Performance Test</font></th></tr></table>' + \
143           '<font size="5" color=red>{}' + \
144           '<img src="cid:performance10"><img src="cid:performance11">' + \
145           '<img src="cid:performance00"><img src="cid:performance01">' + \
146           '<img src="cid:performance02"><img src="cid:performance12">' + \
147           '<img src="cid:performance30"><img src="cid:performance31">' + \
148           '<img src="cid:performance40"><img src="cid:performance41">'
149
150def get_html_suffix():
151    return '</body></html>'
152
153
154class BuildMode():
155    DEBUG = 0
156    RELEASE = 1
157
158
159class LogType():
160    FULL = 0
161    INCREMENTAL = 1
162    PREVIEW = 2
163    SIZE = 3
164    OBFUSCATION = 4
165
166
167class MailPicConfig():
168    mail_data_path = os.path.join(
169        os.path.dirname(os.path.abspath(__file__)),
170        'mail_data',
171    )
172
173    html_file_path = os.path.join(
174        mail_data_path,
175        "email_msg.html"
176    )
177
178    attach_path = os.path.join(
179        mail_data_path,
180        "performance_logs.zip"
181    )
182
183    # Count of days which will be add into the email picture
184    mail_pic_table_name = {
185        BuildMode.DEBUG: {
186            LogType.FULL: os.path.join(mail_data_path, 'debug_full_time.csv'),
187            LogType.INCREMENTAL: os.path.join(mail_data_path, 'debug_incremental_time.csv'),
188            LogType.PREVIEW: os.path.join(mail_data_path, 'debug_preview_model_build_time.csv'),
189            LogType.SIZE: os.path.join(mail_data_path, 'debug_size.csv')
190        },
191        BuildMode.RELEASE: {
192            LogType.FULL: os.path.join(mail_data_path, 'release_full_time.csv'),
193            LogType.INCREMENTAL: os.path.join(mail_data_path, 'release_incremental_time.csv'),
194            LogType.PREVIEW: os.path.join(mail_data_path, 'release_preview_model_build_time.csv'),
195            LogType.SIZE: os.path.join(mail_data_path, 'release_size.csv')
196        }
197    }
198
199    mail_pic_name = {
200        BuildMode.DEBUG: {
201            LogType.FULL: os.path.join(mail_data_path, 'debug_full_time.jpg'),
202            LogType.INCREMENTAL: os.path.join(mail_data_path, 'debug_incremental_time.jpg'),
203            LogType.PREVIEW: os.path.join(mail_data_path, 'debug_preview_model_build_time.jpg'),
204            LogType.SIZE: os.path.join(mail_data_path, 'debug_size.jpg')
205        },
206        BuildMode.RELEASE: {
207            LogType.FULL: os.path.join(mail_data_path, 'release_full_time.jpg'),
208            LogType.INCREMENTAL: os.path.join(mail_data_path, 'release_incremental_time.jpg'),
209            LogType.PREVIEW: os.path.join(mail_data_path, 'release_preview_model_build_time.jpg'),
210            LogType.SIZE: os.path.join(mail_data_path, 'release_size.jpg')
211        }
212    }
213
214    mail_pic_table_label = {
215        BuildMode.DEBUG: {
216            LogType.FULL: 'Debug Full Build',
217            LogType.INCREMENTAL: 'Debug Incremental Build',
218            LogType.PREVIEW: 'Debug Preview Model Build',
219            LogType.SIZE: 'Debug Full Build size'
220        },
221        BuildMode.RELEASE: {
222            LogType.FULL: 'Release Full Build',
223            LogType.INCREMENTAL: 'Release Incremental Time',
224            LogType.PREVIEW: 'Release Preview Model Build',
225            LogType.SIZE: 'Release Full Build size'
226        }
227    }