#!/bin/bash # Copyright (c) Hisilicon Technologies Co., Ltd.. 2012-2019. All rights reserved. # Description: rm version script # Author: sdk # Create: 2022-03-03 set -e SDK_DIR="$(pwd)" RM_DIR_ARRAY=("$SDK_DIR") function get_version_by_path() { maxtime=0 verstr="" COMMIT_CMD_DATA="git log --date=format:'%Y-%m-%d %H:%M:%S' | grep 'Date' | head -n 1" #COMMIT_CMD_CIID="git log --abbrev-commit | grep 'Change-Id:' | head -n 1" COMMIT_CMD_CIID="$(git log --abbrev-commit | grep 'Change-Id:' | head -n 1 | awk -F" " '{print $2}')" arr=$1 for dir in ${arr[*]} do cd $dir time=$(git log --date=format:'%Y-%m-%d %H:%M:%S' | grep "Date" | head -n 1 | awk '{print $2,$3}') timenum=$(date -d "$time" +%s) if [ $timenum -gt $maxtime ]; then #str1=$(eval $COMMIT_CMD_DATA) str2="$COMMIT_CMD_CIID" verstr="${str2#* } ${str1#*:}" #verstr="${str2#* }" maxtime=$timenum fi done echo $verstr } function gen_version() { VER_FILE=rm_version.h # get /drv/rm version RM_VER=$(get_version_by_path "${RM_DIR_ARRAY[*]}") RM_API_VER="static td_uchar g_rm_version[] =" echo "/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2012-2019. All rights reserved. * Description: rm version * Author: sdk * Create: 2019-04-13 */ " > $VER_FILE echo "#ifndef __RM_VERSION_H_" >> $VER_FILE echo "#define __RM_VERSION_H_" >> $VER_FILE echo "" >> $VER_FILE #echo $RM_API_VER " \"" $RM_VER "\";" >> $VER_FILE echo $RM_API_VER " \"" $RM_VER "\";" >> $VER_FILE echo "" >> $VER_FILE echo "#endif" >> $VER_FILE sed -i 's/\"\ /\"/g' ./rm_version.h sed -i 's/\ \"/\"/g' ./rm_version.h echo "==============$0 finish==============" } gen_version