#!/bin/bash # Copyright (c) Hisilicon Technologies Co., Ltd.. 2012-2019. All rights reserved. # Description: sync version script # Author: sdk # Create: 2022-03-03 set -e SDK_DIR="$(pwd)" SYNC_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=sync_version.h # get /drv/sync version SYNC_VER=$(get_version_by_path "${SYNC_DIR_ARRAY[*]}") SYNC_API_VER="static td_uchar g_sync_version[] =" echo "/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2012-2019. All rights reserved. * Description: sync version * Author: sdk * Create: 2019-04-13 */ " > $VER_FILE echo "#ifndef __SYNC_VERSION_H_" >> $VER_FILE echo "#define __SYNC_VERSION_H_" >> $VER_FILE echo "" >> $VER_FILE #echo $SYNC_API_VER " \"" $SYNC_VER "\";" >> $VER_FILE echo $SYNC_API_VER " \"" $SYNC_VER "\";" >> $VER_FILE echo "" >> $VER_FILE echo "#endif" >> $VER_FILE sed -i 's/\"\ /\"/g' ./sync_version.h sed -i 's/\ \"/\"/g' ./sync_version.h echo "==============$0 finish==============" } gen_version