Linuxの下でC/C++バージョンは自動スクリプトを発表します
5631 ワード
ソフトウェアリリースにはソフトウェアバージョン管理の原則があります.ここではLinuxのC/C++プロジェクトのリリース方式と結びつけて、動的バージョン管理スクリプトを自動的に統合する方法を簡単に紹介します.
ソフトウェア・バージョンのリリース・キーソフトウェア・バージョン管理の原則から、次のキーに注意する必要があります.
==』マスターバージョン(VER_MAJOR):プロジェクト(製品)責任者メンテナンス
==』マイナーバージョン(VER_MINOR):技術(バージョン)インタフェース担当者メンテナンス
==』バージョン番号(VER_REVISION):コードライブラリ自動アップグレード更新
==』コンパイル日(BUILD_DATE):コンパイルマシンのシステム日付
==』コンパイル時間(BUILD_TIME):コンパイルマシンのシステム時間
==』コンパイルID(BUILD_ID):コンパイル一意コード
==』コンパイラ(AUTOR_NAME):コンパイラパブリッシャ
==』連絡先(AUTOR_CONTATT):コンパイル配布者連絡先
動的バージョン管理スクリプト
==プライマリ・バージョン、セカンダリ・バージョン、連絡先のカスタマイズをサポート
==』パブリッシャーまたはパブリッシングアカウントのカスタマイズをサポート
==バージョン番号、コンパイル日、コンパイル時間の動的取得をサポート
==自動生成version.c/version.h(version.hは関数プロトタイプ定義に用いられ、直接アプリケーションでincludeすればよい.)
動的に生成されたバージョンコード
SVNバージョンライブラリルートで実行
version.c
version.h
DEMOサンプル統合バージョン管理
main.c
上記versionとmainプログラムのコンパイル、実行
ソフトウェア・バージョンのリリース・キーソフトウェア・バージョン管理の原則から、次のキーに注意する必要があります.
==』マスターバージョン(VER_MAJOR):プロジェクト(製品)責任者メンテナンス
==』マイナーバージョン(VER_MINOR):技術(バージョン)インタフェース担当者メンテナンス
==』バージョン番号(VER_REVISION):コードライブラリ自動アップグレード更新
==』コンパイル日(BUILD_DATE):コンパイルマシンのシステム日付
==』コンパイル時間(BUILD_TIME):コンパイルマシンのシステム時間
==』コンパイルID(BUILD_ID):コンパイル一意コード
==』コンパイラ(AUTOR_NAME):コンパイラパブリッシャ
==』連絡先(AUTOR_CONTATT):コンパイル配布者連絡先
動的バージョン管理スクリプト
==プライマリ・バージョン、セカンダリ・バージョン、連絡先のカスタマイズをサポート
==』パブリッシャーまたはパブリッシングアカウントのカスタマイズをサポート
==バージョン番号、コンパイル日、コンパイル時間の動的取得をサポート
==自動生成version.c/version.h(version.hは関数プロトタイプ定義に用いられ、直接アプリケーションでincludeすればよい.)
#!/bin/bash
# parameter check
if [ $# -ne 4 ] && [ $# -ne 5 ]
then
echo "usage($#): $0 major_num minor_num DEBUG/RELEASE e-mail author"
echo " or: $0 major_num minor_num DEBUG/RELEASE e-mail"
exit
fi
# function
version()
{
BUILD_DATE=`date "+%Y-%m-%d"`
BUILD_TIME=`date "+%R:%S"`
VERSION_NUM=`svn info|grep Revision |cut --delimiter=" " -f2`
cat > version.c <<EEEEEEE
#include "stdio.h"
#include "version.h"
#define VER_MAJOR $1
#define VER_MINOR $2
#define VER_REVISION $VERSION_NUM
#define VER_DR_FLAG "$3"
#define VER_BUILD_DATE "$BUILD_DATE"
#define VER_BUILD_TIME "$BUILD_TIME"
#define AUTHOR_CONTACT "$4"
#define AUTHOR_NAME "$5"
#define VERSION_ALL "$3_${BUILD_DATE}_${BUILD_TIME}_v$1_$2_$VERSION_NUM"
char *get_version()
{
return VERSION_ALL;
}
char *get_ver_author()
{
return AUTHOR_NAME;
}
char *get_ver_author_contact()
{
return AUTHOR_CONTACT;
}
char *get_ver_flag()
{
return VER_DR_FLAG;
}
char *get_build_date()
{
return VER_BUILD_DATE;
}
char *get_build_time()
{
return VER_BUILD_TIME;
}
int get_ver_major()
{
return VER_MAJOR;
}
int get_ver_minor()
{
return VER_MINOR;
}
int get_ver_rev()
{
return VER_REVISION;
}
EEEEEEE
cat > version.h <<EEEEEEE
#ifndef __VERSION_H__
#define __VERSION_H__
char *get_version();
char *get_ver_author();
char *get_ver_author_contact();
char *get_ver_flag();
char *get_build_date();
char *get_build_time();
int get_ver_major();
int get_ver_minor();
int get_ver_rev();
#endif /* __VERSION_H__ */
EEEEEEE
}
# print
echo "###############################"
echo "######### $0 "
echo "######### Major Number: $1"
echo "######### Minor Number: $2"
echo "######### D/R Flag: $3"
echo "######### Contact: $4"
if [ $# -eq 4 ]
then
AUTHOR=`who | cut --delimiter=" " -f1`
else
AUTHOR=$5
fi
echo "######### Author: $AUTHOR"
version $1 $2 $3 $4 $AUTHOR
if [ $? -eq 0 ]
then
echo "######### Done! "
else
"######### Failed! "
fi
echo "###############################"
動的に生成されたバージョンコード
SVNバージョンライブラリルートで実行
# ./version.sh 1 2 DEBUG [email protected] lida
###############################
######### ../version.sh
######### Major Number: 1
######### Minor Number: 2
######### D/R Flag: DEBUG
######### Contact: [email protected]
######### Author: lida
######### Done!
###############################
version.c
#include "stdio.h"
#include "version.h"
#define VER_MAJOR 1
#define VER_MINOR 2
#define VER_REVISION 271
#define VER_DR_FLAG "DEBUG"
#define VER_BUILD_DATE "2016-05-10"
#define VER_BUILD_TIME "18:29:35"
#define AUTHOR_CONTACT "[email protected]"
#define AUTHOR_NAME "lida"
#define VERSION_ALL "DEBUG_2016-05-10_18:29:35_v1_2_271"
char *get_version()
{
return VERSION_ALL;
}
char *get_ver_author()
{
return AUTHOR_NAME;
}
char *get_ver_author_contact()
{
return AUTHOR_CONTACT;
}
char *get_ver_flag()
{
return VER_DR_FLAG;
}
char *get_build_date()
{
return VER_BUILD_DATE;
}
char *get_build_time()
{
return VER_BUILD_TIME;
}
int get_ver_major()
{
return VER_MAJOR;
}
int get_ver_minor()
{
return VER_MINOR;
}
int get_ver_rev()
{
return VER_REVISION;
}
version.h
#ifndef __VERSION_H__
#define __VERSION_H__
char *get_version();
char *get_ver_author();
char *get_ver_author_contact();
char *get_ver_flag();
char *get_build_date();
char *get_build_time();
int get_ver_major();
int get_ver_minor();
int get_ver_rev();
#endif /* __VERSION_H__ */
DEMOサンプル統合バージョン管理
main.c
#include <stdio.h>
#include "version.h"
void main()
{
printf("get_version: %s
",get_version());
printf("get_ver_author: %s
",get_ver_author());
printf("get_ver_author_contact: %s
",get_ver_author_contact());
printf("get_ver_flag: %s
",get_ver_flag());
printf("get_build_date: %s
",get_build_date());
printf("get_build_time: %s
",get_build_time());
printf("get_ver_major: %d
",get_ver_major());
printf("get_ver_minor: %d
",get_ver_minor());
printf("get_ver_rev: %d
",get_ver_rev());
}
上記versionとmainプログラムのコンパイル、実行
# gcc main.c version.c
# ./a.out
get_version: DEBUG_2016-05-10_18:29:35_v1_2_271
get_ver_author: lida
get_ver_author_contact: [email protected]
get_ver_flag: DEBUG
get_build_date: 2016-05-10
get_build_time: 18:29:35
get_ver_major: 1
get_ver_minor: 2
get_ver_rev: 271