diff --git a/mindspore/core/utils/log_adapter.cc b/mindspore/core/utils/log_adapter.cc index 31e67383c9f..73030f4c6cb 100644 --- a/mindspore/core/utils/log_adapter.cc +++ b/mindspore/core/utils/log_adapter.cc @@ -680,33 +680,31 @@ const std::string GetSubModuleName(SubModuleId module_id) { } std::string GetTimeString() { - constexpr auto BUFLEN = 80; - char buf[BUFLEN] = {'\0'}; #if defined(_WIN32) || defined(_WIN64) time_t time_seconds = time(0); struct tm now_time; localtime_s(&now_time, &time_seconds); constexpr int base_year = 1900; - (void)snprintf(buf, BUFLEN, "%d-%d-%d %d:%d:%d", now_time.tm_year + base_year, now_time.tm_mon + 1, now_time.tm_mday, - now_time.tm_hour, now_time.tm_min, now_time.tm_sec); + std::stringstream ss; + ss << now_time.tm_year + base_year << "-" << now_time.tm_mon + 1 << "-" << now_time.tm_mday << " " << now_time.tm_hour + << ":" << now_time.tm_min << ":" << now_time.tm_sec; + return ss.str(); #else + constexpr auto BUFLEN = 80; + char buf[BUFLEN] = {'\0'}; struct timeval cur_time; (void)gettimeofday(&cur_time, nullptr); struct tm now; - constexpr size_t time_str_len = 19; + constexpr int width = 3; constexpr int64_t time_convert_unit = 1000; (void)localtime_r(&cur_time.tv_sec, &now); (void)strftime(buf, BUFLEN, "%Y-%m-%d-%H:%M:%S", &now); // format date and time -#ifdef __APPLE__ - constexpr auto fmt_str = ".%03lld.%03lld"; -#else - constexpr auto fmt_str = ".%03ld.%03ld"; + std::stringstream ss; + ss << "." << std::setfill('0') << std::setw(width) << cur_time.tv_usec / time_convert_unit << "." << std::setfill('0') + << std::setw(width) << cur_time.tv_usec % time_convert_unit; + return std::string(buf) + ss.str(); #endif - (void)snprintf(buf + time_str_len, BUFLEN - time_str_len, fmt_str, cur_time.tv_usec / time_convert_unit, - cur_time.tv_usec % time_convert_unit); -#endif - return std::string(buf); } } // namespace mindspore diff --git a/mindspore/lite/tools/common/flag_parser.cc b/mindspore/lite/tools/common/flag_parser.cc index efde8cf379a..6ce8c801b0f 100644 --- a/mindspore/lite/tools/common/flag_parser.cc +++ b/mindspore/lite/tools/common/flag_parser.cc @@ -162,7 +162,8 @@ std::string FlagParser::Usage(const Option &usgMsg) const { std::string flagName = flag->second.flagName; std::string helpInfo = flag->second.helpInfo; // parameter line - std::string thisLine = flagName == "help" ? " --" + flagName : " --" + flagName + "=VALUE"; + std::string thisLine = + (flagName == helpStr || flagName == versionStr) ? " --" + flagName : " --" + flagName + "=VALUE"; if (++i <= flags.size()) { // add parameter help message of each line thisLine += " " + helpInfo; diff --git a/mindspore/lite/tools/common/flag_parser.h b/mindspore/lite/tools/common/flag_parser.h index f8c0c655fae..9e056b56b93 100644 --- a/mindspore/lite/tools/common/flag_parser.h +++ b/mindspore/lite/tools/common/flag_parser.h @@ -30,7 +30,10 @@ struct Nothing {}; class FlagParser { public: - FlagParser() { AddFlag(&FlagParser::help, helpStr, "print usage message", ""); } + FlagParser() { + AddFlag(&FlagParser::help, helpStr, "print usage message", ""); + AddFlag(&FlagParser::version, versionStr, "print version", ""); + } virtual ~FlagParser() = default; @@ -59,6 +62,7 @@ class FlagParser { template void AddFlag(Option Flags::*t, const std::string &flagName, const std::string &helpInfo); bool help{}; + bool version{}; protected: template @@ -69,6 +73,7 @@ class FlagParser { std::string binName; Option usageMsg; std::string helpStr = "help"; + std::string versionStr = "version"; private: struct FlagInfo { diff --git a/scripts/build/option_proc_mindspore.sh b/scripts/build/option_proc_mindspore.sh index cca2d1228eb..9916093af47 100755 --- a/scripts/build/option_proc_mindspore.sh +++ b/scripts/build/option_proc_mindspore.sh @@ -39,12 +39,12 @@ build_option_proc_s() { check_on_off $OPTARG s if [[ "X$OPTARG" == "Xon" ]]; then - if [[ $USER_ENABLE_DUMP_IR == true ]]; then + if [[ "$USER_ENABLE_DUMP_IR" == true ]]; then echo "enable security, the dump ir is not available" usage exit 1 fi - if [[ $USER_ENABLE_DEBUGGER == true ]]; then + if [[ "$USER_ENABLE_DEBUGGER" == true ]]; then echo "enable security, the debugger is not available" usage exit 1 diff --git a/scripts/check_clang_format.sh b/scripts/check_clang_format.sh index 3e3e64cecb9..5c4c8e9f5ae 100755 --- a/scripts/check_clang_format.sh +++ b/scripts/check_clang_format.sh @@ -101,7 +101,7 @@ set +e # check format of files modified in the latest commit while read line; do - if [ ! -e ${line} ]; then + if [ ! -e "${line}" ]; then continue fi BASE_NAME=$(basename "${line}") diff --git a/scripts/check_tid.sh b/scripts/check_tid.sh index cfdad069c45..f06ffb7d9e4 100755 --- a/scripts/check_tid.sh +++ b/scripts/check_tid.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Copyright 2021-2022 Huawei Technologies 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. +# ============================================================================ + +set -e SCRIPT_DIR=$(dirname "$0") MS_DIR=$(realpath ${SCRIPT_DIR}/..) @@ -22,7 +38,7 @@ if [[ "$line" =~ .*\((.*)\,(.*)\).* ]] then CLASS_NAME=${BASH_REMATCH[2]}_${BASH_REMATCH[1]} TID=$(${HASH_EXE} ${CLASS_NAME}) -if [ ${TIDMAP[${TID}]+_} ]; then +if [ ${TIDMAP["${TID}"]+_} ]; then echo $line echo Same tid $TID is used by $CLASS_NAME and ${TIDMAP[${TID}]}. exit 1 diff --git a/scripts/lite_release_package.sh b/scripts/lite_release_package.sh index fa8527c3fc0..0ee6b58f570 100644 --- a/scripts/lite_release_package.sh +++ b/scripts/lite_release_package.sh @@ -22,14 +22,14 @@ function android_release_package() device=$2 pkg_name="mindspore-lite-${version}-android-${arch}" - rm -rf ${pkg_name} + [ -n "${pkg_name}" ] && rm -rf ${pkg_name} tar -xzf ${input_path}/android_${arch}/${device}/${pkg_name}.tar.gz # Copy java runtime to Android package cp ${input_path}/aar/mindspore-lite-*.aar ${pkg_name} mkdir -p ${output_path}/release/android/${device}/ tar -czf ${output_path}/release/android/${device}/${pkg_name}.tar.gz ${pkg_name} - rm -rf ${pkg_name} + [ -n "${pkg_name}" ] && rm -rf ${pkg_name} cd ${output_path}/release/android/${device}/ sha256sum ${pkg_name}.tar.gz > ${pkg_name}.tar.gz.sha256 } @@ -90,7 +90,7 @@ echo "Usage: bash lite_release_package.sh input_path output_path" input_path=$1 output_path=$2 -version=`ls ${input_path}/android_aarch64/npu/mindspore-lite-*-*.tar.gz | awk -F'/' '{print $NF}' | cut -d"-" -f3` +version=$(ls ${input_path}/android_aarch64/npu/mindspore-lite-*-*.tar.gz | awk -F'/' '{print $NF}' | cut -d"-" -f3) android_release_package aarch32 npu android_release_package aarch32 cpu