mirror of
https://gitee.com/openharmony/xts_tools
synced 2024-11-26 17:40:54 +00:00
commit
27f728d7ca
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())
|
15
standard_check/hvigor-wrapper.js
Executable file
15
standard_check/hvigor-wrapper.js
Executable file
File diff suppressed because one or more lines are too long
63
standard_check/hvigorw.bat
Executable file
63
standard_check/hvigorw.bat
Executable file
@ -0,0 +1,63 @@
|
||||
@rem Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem http://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@echo off
|
||||
@rem
|
||||
@rem -------------------------------------------------------------------
|
||||
@rem Hvigor startup script for Windows, version 1.0.0
|
||||
@rem
|
||||
@rem Required ENV vars:
|
||||
@rem ------------------
|
||||
@rem NODE_HOME - location of a Node home dir
|
||||
@rem or
|
||||
@rem Add %NODE_HOME%/bin to the PATH environment variable
|
||||
@rem -------------------------------------------------------------------
|
||||
@rem
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
set APP_BASE_NAME=%~n0
|
||||
set NODE_EXE_PATH=""
|
||||
set APP_HOME=.
|
||||
set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js
|
||||
set NODE_EXE=node.exe
|
||||
@rem set NODE_OPTS="--max-old-space-size=4096"
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
if not defined NODE_OPTS set NODE_OPTS="--"
|
||||
|
||||
@rem Find node.exe
|
||||
if defined NODE_HOME (
|
||||
set NODE_HOME=%NODE_HOME:"=%
|
||||
set "PATH=%PATH%;%NODE_HOME%"
|
||||
set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE%
|
||||
)
|
||||
|
||||
%NODE_EXE% --version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
"%NODE_EXE%" "%NODE_OPTS%" "%WRAPPER_MODULE_PATH%" %*
|
||||
) else if exist "%NODE_EXE_PATH%" (
|
||||
"%NODE_EXE_PATH%" "%NODE_OPTS%" "%WRAPPER_MODULE_PATH%" %*
|
||||
) else (
|
||||
echo.
|
||||
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the NODE_HOME variable in your environment to match the
|
||||
echo location of your NodeJs installation.
|
||||
)
|
||||
|
||||
if "%ERRORLEVEL%" == "0"(
|
||||
if "%OS%" == "Windows_NT" endlocal
|
||||
) else (
|
||||
exit /b %ERRORLEVEL%
|
||||
)
|
Loading…
Reference in New Issue
Block a user