mirror of
https://gitee.com/openharmony/xts_tools
synced 2024-11-22 23:40:11 +00:00
move
Signed-off-by: 唐翔蕾 <328491512@qq.com>
This commit is contained in:
parent
697de0f0f8
commit
84a8879329
@ -1,125 +0,0 @@
|
||||
#!/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
|
||||
import logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
|
||||
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):
|
||||
logging.error(
|
||||
"Error: The {} in the following directory does not meet the requirements:"
|
||||
.format(filename))
|
||||
for prj in prject_list:
|
||||
logging.error(f"{prj[0]}, {prj[1]}")
|
||||
|
||||
|
||||
def check_hvigor_wrapper_js(root_dir, hvigor_prj_list):
|
||||
unmatch_info = []
|
||||
baseline_file = os.path.join(root_dir, 'hvigor-wrapper.js')
|
||||
baseline_md5 = get_file_md5(os.path.join(baseline_file))
|
||||
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')
|
||||
logging.error('Please copy from {}'.format(baseline_file))
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_hvigor_version(hvigor_prj_list):
|
||||
unmatch_prj_list = []
|
||||
baseline_version = '4.0.5'
|
||||
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')
|
||||
logging.error("Plesse use {}".format(baseline_version))
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_hvigorw_bat(root_dir, hvigor_prj_list):
|
||||
unmatch_info = []
|
||||
baseline_file = os.path.join(root_dir, 'hvigorw.bat')
|
||||
baseline_md5 = get_file_md5(os.path.join(baseline_file))
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigorw.bat')
|
||||
md5 = get_file_md5(filename)
|
||||
if md5 != baseline_md5:
|
||||
unmatch_info.append((md5, filename))
|
||||
|
||||
if len(unmatch_info):
|
||||
output_unmatched_project(unmatch_info, 'hvigorw.bat')
|
||||
logging.error('Please copy from {}'.format(baseline_file))
|
||||
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__)
|
||||
hvigor_check_dir = os.path.dirname(this_file)
|
||||
check_root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(this_file))))
|
||||
xts_suitename = os.environ.get('XTS_SUITENAME') if 'XTS_SUITENAME' in os.environ else os.environ.get('xts_suitename')
|
||||
check_root_dir = os.path.join(check_root_dir , xts_suitename)
|
||||
logging.info (f'check_root_dir : {check_root_dir}')
|
||||
|
||||
hvigor_prj_list = get_hvigor_prject_list(check_root_dir)
|
||||
js_valid = check_hvigor_wrapper_js(hvigor_check_dir, hvigor_prj_list)
|
||||
json_valid = check_hvigor_version(hvigor_prj_list)
|
||||
bat_valid = check_hvigorw_bat(hvigor_check_dir, hvigor_prj_list)
|
||||
|
||||
if not js_valid or not json_valid or not bat_valid:
|
||||
logging.error('hvigor format verification failed')
|
||||
sys.exit(1)
|
||||
logging.info('hvigor format verification passed')
|
||||
sys.exit(0)
|
133
standard_check/check_hvigor.py
Normal file
133
standard_check/check_hvigor.py
Normal file
@ -0,0 +1,133 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Copyright (c) 2024-2024 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 hashlib
|
||||
import json5
|
||||
|
||||
|
||||
class HvigorChecker:
|
||||
|
||||
def __init__(self, suite_name):
|
||||
self._current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
self._suite_name = suite_name
|
||||
self._xts_root_dir = os.path.realpath(os.path.join(self._current_dir, '../..', suite_name))
|
||||
print("_xts_root_dir={}".format(self._xts_root_dir))
|
||||
|
||||
def get_file_md5(self, 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(self, 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(self, 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])
|
||||
|
||||
def check_hvigor_wrapper_js(self, hvigor_prj_list):
|
||||
unmatch_info = []
|
||||
baseline_file = os.path.join(self._current_dir, 'hvigor-wrapper.js')
|
||||
baseline_md5 = self.get_file_md5(os.path.join(baseline_file))
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigor', 'hvigor-wrapper.js')
|
||||
md5 = self.get_file_md5(filename)
|
||||
if md5 != baseline_md5:
|
||||
unmatch_info.append((md5, filename))
|
||||
|
||||
if len(unmatch_info):
|
||||
self.output_unmatched_project(unmatch_info, 'hvigor-wrapper.js')
|
||||
print('Please copy from {}'.format(baseline_file))
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_hvigor_version(self, hvigor_prj_list):
|
||||
unmatch_prj_list = []
|
||||
baseline_version = '4.0.5'
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigor', 'hvigor-config.json5')
|
||||
version = self.get_hvigor_version(filename)
|
||||
if version != baseline_version:
|
||||
unmatch_prj_list.append((version, filename))
|
||||
|
||||
if len(unmatch_prj_list):
|
||||
self.output_unmatched_project(unmatch_prj_list, 'hvigor-config.json5')
|
||||
print("Plesse use {}".format(baseline_version))
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_hvigorw_bat(self, hvigor_prj_list):
|
||||
unmatch_info = []
|
||||
baseline_file = os.path.join(self._current_dir, 'hvigorw.bat')
|
||||
baseline_md5 = self.get_file_md5(os.path.join(baseline_file))
|
||||
for dir in hvigor_prj_list:
|
||||
filename = os.path.join(dir, 'hvigorw.bat')
|
||||
md5 = self.get_file_md5(filename)
|
||||
if md5 != baseline_md5:
|
||||
unmatch_info.append((md5, filename))
|
||||
|
||||
if len(unmatch_info):
|
||||
self.output_unmatched_project(unmatch_info, 'hvigorw.bat')
|
||||
print('Please copy from {}'.format(baseline_file))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_hvigor_prject_list(self):
|
||||
hvigor_prj_list = []
|
||||
for root, dirs, files in os.walk(self._xts_root_dir):
|
||||
if '.cxx' in dirs:
|
||||
dirs.remove('.cxx')
|
||||
for dir in dirs:
|
||||
if dir == 'hvigor':
|
||||
hvigor_prj_list.append(root)
|
||||
return hvigor_prj_list
|
||||
|
||||
|
||||
def main():
|
||||
suite_name = ""
|
||||
if 'XTS_SUITENAME' in os.environ:
|
||||
suite_name = os.environ.get('XTS_SUITENAME')
|
||||
elif 'xts_suitename' in os.environ:
|
||||
suite_name = os.environ.get('xts_suitename')
|
||||
else :
|
||||
suite_name = sys.argv[1]
|
||||
|
||||
obj = HvigorChecker(suite_name)
|
||||
|
||||
hvigor_prj_list = obj.get_hvigor_prject_list()
|
||||
|
||||
js_valid = obj.check_hvigor_wrapper_js(hvigor_prj_list)
|
||||
json_valid = obj.check_hvigor_version(hvigor_prj_list)
|
||||
bat_valid = obj.check_hvigorw_bat(hvigor_prj_list)
|
||||
|
||||
if not js_valid or not json_valid or not bat_valid:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
Loading…
Reference in New Issue
Block a user