xts_hats/check_hvigor.py
f00829171 a02ebbb85f add check for hvigor
Signed-off-by: f00829171 <chris.feng@huawei.com>
2024-04-29 09:47:54 +08:00

102 lines
3.0 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2020-2021 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.
"""
import os
import sys
import subprocess
import hashlib
import json5
def get_file_md5(file_path):
hash_md5 = hashlib.md5()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
def get_hvigor_version(json_file):
with open(json_file, 'r') as f:
data = json5.load(f)
return data.get('hvigorVersion')
return "0.0.0"
def output_unmatched_project(prject_list, filename):
print("")
print(
"Error: The {} in the following directory does not meet the requirements:"
.format(filename))
for prj in prject_list:
print(prj[0], prj[1])
print("")
def check_hvigor_wrapper_js(hvigor_prj_list):
unmatch_info = []
baseline_md5 = "558a3eec8ee9e753b63f99abe79c0ec3"
for dir in hvigor_prj_list:
filename = os.path.join(dir, 'hvigor', 'hvigor-wrapper.js')
md5 = get_file_md5(filename)
if md5 != baseline_md5:
unmatch_info.append((md5, filename))
if len(unmatch_info):
output_unmatched_project(unmatch_info, 'hvigor-wrapper.js')
print('Please copy from {}'.format('test/xts/acts/arkcompiler/ecmanewfeatures/hvigor/hvigor-wrapper.js'))
return False
return True
def check_hvigor_version(hvigor_prj_list):
unmatch_prj_list = []
baseline_version = '4.0.2'
for dir in hvigor_prj_list:
filename = os.path.join(dir, 'hvigor', 'hvigor-config.json5')
version = get_hvigor_version(filename)
if version != baseline_version:
unmatch_prj_list.append((version, filename))
if len(unmatch_prj_list):
output_unmatched_project(unmatch_prj_list, 'hvigor-config.json5')
print("Plesse use {}".format(baseline_version))
return False
return True
def get_hvigor_prject_list(directory):
hvigor_prj_list = []
for root, dirs, files in os.walk(directory):
for dir in dirs:
if dir == 'hvigor':
hvigor_prj_list.append(root)
return hvigor_prj_list
if __name__ == "__main__":
this_file = os.path.realpath(__file__)
curr_dir = os.path.dirname(this_file)
hvigor_prj_list = get_hvigor_prject_list(curr_dir)
js_valid = check_hvigor_wrapper_js(hvigor_prj_list)
json_valid = check_hvigor_version(hvigor_prj_list)
if not js_valid or not json_valid:
sys.exit(1)
sys.exit(0)