Refactoring versioned

This commit is contained in:
s1lentq 2016-12-09 21:07:34 +07:00
parent dd3e68fb69
commit 54739c62ab
11 changed files with 180 additions and 203 deletions

View File

@ -1,5 +1,6 @@
import versioning.GitVersioner import versioning.GitVersioner
import versioning.RegamedllVersionInfo import versioning.RegamedllVersionInfo
import org.joda.time.DateTime
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
apply from: 'shared.gradle' apply from: 'shared.gradle'
@ -14,10 +15,6 @@ idea {
} }
def gitInfo = GitVersioner.versionForDir(project.rootDir) def gitInfo = GitVersioner.versionForDir(project.rootDir)
if (!gitInfo) {
throw new RuntimeException('Running outside git repository')
}
RegamedllVersionInfo versionInfo RegamedllVersionInfo versionInfo
if (gitInfo.tag && gitInfo.tag[0] == 'v') { if (gitInfo.tag && gitInfo.tag[0] == 'v') {
def m = gitInfo.tag =~ /^v(\d+)\.(\d+)(\.(\d+))?$/ def m = gitInfo.tag =~ /^v(\d+)\.(\d+)(\.(\d+))?$/
@ -29,22 +26,22 @@ if (gitInfo.tag && gitInfo.tag[0] == 'v') {
majorVersion: m.group(1) as int, majorVersion: m.group(1) as int,
minorVersion: m.group(2) as int, minorVersion: m.group(2) as int,
maintenanceVersion: m.group(4) ? (m.group(4) as int) : null, maintenanceVersion: m.group(4) ? (m.group(4) as int) : null,
countCommit: gitInfo.countCommit, localChanges: gitInfo.localChanges,
lastCommitDate: gitInfo.lastCommitDate, commitDate: gitInfo.commitDate,
commitID: gitInfo.commitID, commitSHA: gitInfo.commitSHA,
authorCommit: gitInfo.authorCommit, commitURL: gitInfo.commitURL
urlCommits: gitInfo.urlCommits
) )
} else { } else {
versionInfo = new RegamedllVersionInfo( versionInfo = new RegamedllVersionInfo(
majorVersion: project.majorVersion as int, majorVersion: project.majorVersion as int,
minorVersion: project.minorVersion as int, minorVersion: project.minorVersion as int,
suffix: 'SNAPSHOT', maintenanceVersion: project.maintenanceVersion as int,
countCommit: gitInfo.countCommit, suffix: 'dev',
lastCommitDate: gitInfo.lastCommitDate, localChanges: gitInfo ? gitInfo.localChanges : true,
commitID: gitInfo.commitID, commitDate: gitInfo ? gitInfo.commitDate : new DateTime(),
authorCommit: gitInfo.authorCommit, commitSHA: gitInfo ? gitInfo.commitSHA : "",
urlCommits: gitInfo.urlCommits commitURL: gitInfo ? gitInfo.commitURL : "",
commitCount: gitInfo ? (gitInfo.commitCount as int) : null
) )
} }

View File

@ -9,6 +9,9 @@ repositories {
maven { maven {
url 'http://nexus.rehlds.org/nexus/content/repositories/regamedll-snapshots/' url 'http://nexus.rehlds.org/nexus/content/repositories/regamedll-snapshots/'
} }
maven {
url 'http://nexus.rehlds.org/nexus/content/repositories/regamedll-dev/'
}
} }

View File

@ -6,11 +6,11 @@ import org.joda.time.DateTime
@CompileStatic @TypeChecked @CompileStatic @TypeChecked
class GitInfo { class GitInfo {
DateTime lastCommitDate boolean localChanges
DateTime commitDate
String branch String branch
String tag String tag
Integer countCommit String commitSHA
String commitID String commitURL
String authorCommit Integer commitCount
String urlCommits
} }

View File

@ -1,8 +1,11 @@
package versioning package versioning
import java.util.Set;
import groovy.transform.CompileStatic import groovy.transform.CompileStatic
import groovy.transform.TypeChecked import groovy.transform.TypeChecked
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.lib.ObjectId
import org.eclipse.jgit.lib.Repository import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.StoredConfig import org.eclipse.jgit.lib.StoredConfig
@ -27,18 +30,6 @@ class GitVersioner {
return count; return count;
} }
// return last commit excluding merge commit
static RevCommit parseCommitLast(Repository repo) {
Iterable<RevCommit> commits = Git.wrap(repo).log().call()
for (RevCommit b : commits) {
if (b.getParents().length > 1) { // it's merge commit ignore it
continue;
}
return b;
}
return null;
}
static String prepareUrlToCommits(String url) { static String prepareUrlToCommits(String url) {
if (url == null) { if (url == null) {
// default remote url // default remote url
@ -64,24 +55,42 @@ class GitVersioner {
} }
return sb.toString(); return sb.toString();
} }
// check uncommited changes
static boolean getUncommittedChanges(Repository repo) {
Git git = new Git(repo);
Status status = git.status().call();
Set<String> uncommittedChanges = status.getUncommittedChanges();
for(String uncommitted : uncommittedChanges) {
return true;
}
return false;
}
static GitInfo versionForDir(File dir) { static GitInfo versionForDir(File dir) {
FileRepositoryBuilder builder = new FileRepositoryBuilder() FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setWorkTree(dir) Repository repo = builder.setWorkTree(dir)
.findGitDir() .findGitDir()
.build() .build()
ObjectId head = repo.resolve('HEAD') ObjectId head = repo.resolve('HEAD');
if (!head) { if (!head) {
return null return null
} }
final StoredConfig cfg = repo.getConfig(); final StoredConfig cfg = repo.getConfig();
def commit = new RevWalk(repo).parseCommit(head) def commit = new RevWalk(repo).parseCommit(head);
def commitLast = parseCommitLast(repo) if (!commit) {
int commitCount = getCountCommit(repo) throw new RuntimeException("Can't find last commit.");
}
def branch = repo.getBranch() def localChanges = getUncommittedChanges(repo);
def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC) def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC);
if (localChanges) {
commitDate = new DateTime();
}
def branch = repo.getBranch();
String url = null; String url = null;
String remote_name = cfg.getString("branch", branch, "remote"); String remote_name = cfg.getString("branch", branch, "remote");
@ -99,31 +108,18 @@ class GitVersioner {
url = cfg.getString("remote", remote_name, "url"); url = cfg.getString("remote", remote_name, "url");
} }
println 'Debug: Start'; String commitURL = prepareUrlToCommits(url);
println ' cfg: (' + cfg + ')';
println ' branch: (' + branch + ')';
println ' remote_name: (' + remote_name + ')';
println ' url: (' + url + ')';
println 'Debug: End';
String urlCommits = prepareUrlToCommits(url);
if (!commit) {
throw new RuntimeException("Can't find last commit.")
}
String tag = repo.tags.find { kv -> kv.value.objectId == commit.id }?.key String tag = repo.tags.find { kv -> kv.value.objectId == commit.id }?.key
String headCommitId = commit.getId().abbreviate(7).name(); String commitSHA = commit.getId().abbreviate(7).name();
String authorCommit = commitLast.getAuthorIdent().getName();
return new GitInfo( return new GitInfo(
lastCommitDate: commitDate, localChanges: localChanges,
commitDate: commitDate,
branch: branch, branch: branch,
tag: tag, tag: tag,
countCommit: commitCount, commitSHA: commitSHA,
commitID: headCommitId, commitURL: commitURL,
authorCommit: authorCommit, commitCount: getCountCommit(repo)
urlCommits: urlCommits
) )
} }
} }

View File

@ -3,40 +3,54 @@ package versioning
import groovy.transform.CompileStatic import groovy.transform.CompileStatic
import groovy.transform.ToString import groovy.transform.ToString
import groovy.transform.TypeChecked import groovy.transform.TypeChecked
import org.joda.time.format.DateTimeFormat
import org.joda.time.DateTime import org.joda.time.DateTime
@CompileStatic @TypeChecked @CompileStatic @TypeChecked
@ToString(includeNames = true) @ToString(includeNames = true)
class RegamedllVersionInfo { class RegamedllVersionInfo {
int majorVersion Integer majorVersion
int minorVersion Integer minorVersion
Integer maintenanceVersion Integer maintenanceVersion
String suffix String suffix
Integer countCommit
DateTime lastCommitDate
String commitID
String authorCommit
String urlCommits
String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) { boolean localChanges
DateTime commitDate
String commitSHA
String commitURL
Integer commitCount
String asMavenVersion() {
StringBuilder sb = new StringBuilder() StringBuilder sb = new StringBuilder()
sb.append(majorVersion).append(versionSeparator).append(minorVersion) sb.append(majorVersion).append('.' + minorVersion);
if (maintenanceVersion != null) { if (maintenanceVersion != null) {
sb.append(versionSeparator).append(maintenanceVersion) sb.append('.' + maintenanceVersion);
} }
if (suffix && includeSuffix) { if (commitCount != null) {
sb.append(suffixSeparator).append(suffix) sb.append('.' + commitCount)
}
if (suffix) {
sb.append('-' + suffix)
}
// do mark for this build like a modified version
if (localChanges) {
sb.append('+m');
} }
return sb.toString() return sb.toString()
} }
String asVersion() { String asCommitDate() {
StringBuilder sb = new StringBuilder() String pattern = "MMM d yyyy";
sb.append(majorVersion).append('.' + minorVersion).append('.' + countCommit); if (commitDate.getDayOfMonth() >= 10) {
return sb; pattern = "MMM d yyyy";
}
return DateTimeFormat.forPattern(pattern).withLocale(Locale.ENGLISH).print(commitDate);
} }
String asMavenVersion() { String asCommitTime() {
format('.', '-', true) return DateTimeFormat.forPattern('HH:mm:ss').withLocale(Locale.ENGLISH).print(commitDate);
} }
} }

View File

@ -1,2 +1,3 @@
majorVersion=0 majorVersion=5
minorVersion=2 minorVersion=0
maintenanceVersion=0

View File

@ -11,7 +11,6 @@ void _copyFile(String from, String to) {
} }
task publishPrepareFiles { task publishPrepareFiles {
//dependsOn ':flightrec/decoder:uberjar'
doLast { doLast {
def pubRootDir = project.file('publish/publishRoot') def pubRootDir = project.file('publish/publishRoot')
if (pubRootDir.exists()) { if (pubRootDir.exists()) {
@ -72,6 +71,11 @@ publishing {
resolveStrategy = DELEGATE_FIRST resolveStrategy = DELEGATE_FIRST
name project.name name project.name
description project.description description project.description
properties {
commitDate project.ext.regamedllVersionInfo.commitDate
commitSHA project.ext.regamedllVersionInfo.commitSHA
}
//url github //url github
//scm { //scm {
// url "${github}.git" // url "${github}.git"
@ -79,17 +83,17 @@ publishing {
//} //}
/* /*
licenses { licenses {
license { license {
name 'The Apache Software License, Version 2.0' name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt' url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo' distribution 'repo'
} }
} }
developers { developers {
developer { developer {
id 'dreamstalker' id 'dreamstalker'
name 'dreamstalker' name 'dreamstalker'
} }
} }
*/ */
} }
@ -110,8 +114,8 @@ if (file('repo_creds.properties').exists()) {
publishing { publishing {
repositories { repositories {
maven { maven {
if (project.version.contains('SNAPSHOT')) { if (project.version.contains('dev')) {
url "http://nexus.rehlds.org/nexus/content/repositories/regamedll-snapshots/" url "http://nexus.rehlds.org/nexus/content/repositories/regamedll-dev/"
} else { } else {
url "http://nexus.rehlds.org/nexus/content/repositories/regamedll-releases/" url "http://nexus.rehlds.org/nexus/content/repositories/regamedll-releases/"
} }
@ -127,6 +131,5 @@ task doPublish {
dependsOn 'publishPackage' dependsOn 'publishPackage'
if (repoCreds.getProperty('username') && repoCreds.getProperty('password')) { if (repoCreds.getProperty('username') && repoCreds.getProperty('password')) {
dependsOn 'publish' dependsOn 'publish'
//dependsOn ':flightrec/decoder_api:publish'
} }
} }

View File

@ -1,6 +1,7 @@
import gradlecpp.RegamedllPlayTestPlugin import gradlecpp.RegamedllPlayTestPlugin
import gradlecpp.RegamedllPlayTestTask import gradlecpp.RegamedllPlayTestTask
import gradlecpp.VelocityUtils import gradlecpp.VelocityUtils
import org.doomedsociety.gradlecpp.GradleCppUtils import org.doomedsociety.gradlecpp.GradleCppUtils
import org.doomedsociety.gradlecpp.LazyNativeDepSet import org.doomedsociety.gradlecpp.LazyNativeDepSet
import org.doomedsociety.gradlecpp.cfg.ToolchainConfig import org.doomedsociety.gradlecpp.cfg.ToolchainConfig
@ -377,11 +378,14 @@ task generateAppVersion {
def tplFile = project.file('version/appversion.vm') def tplFile = project.file('version/appversion.vm')
def renderedFile = project.file('version/appversion.h') def renderedFile = project.file('version/appversion.h')
// check to up-to-date
inputs.file tplFile inputs.file tplFile
inputs.file project.file('gradle.properties') inputs.file project.file('gradle.properties')
outputs.file renderedFile outputs.file renderedFile
inputs.property('version', verInfo.asMavenVersion())
inputs.property('lastCommitDate', verInfo.lastCommitDate.toString()) // this will ensure that this task is redone when the versions change
inputs.property('version', rootProject.version)
inputs.property('commitDate', verInfo.asCommitDate())
doLast { doLast {
def templateCtx = [ def templateCtx = [
@ -389,10 +393,9 @@ task generateAppVersion {
] ]
def content = VelocityUtils.renderTemplate(tplFile, templateCtx) def content = VelocityUtils.renderTemplate(tplFile, templateCtx)
renderedFile.delete() renderedFile.delete()
renderedFile.write(content, 'utf-8') renderedFile.write(content, 'utf-8')
println 'The current ReGameDLL version is ' + verInfo.asVersion().toString() + ', maven version is ' + verInfo.asMavenVersion().toString() + ', commit id: ' + verInfo.commitID.toString() + ', commit author: ' + verInfo.authorCommit.toString() + ', url: (' + verInfo.urlCommits.toString() + ')'; println 'The current ReGameDLL maven version is ' + rootProject.version + ', url: (' + verInfo.commitURL + '' + verInfo.commitSHA + ')';
} }
} }

View File

@ -97,7 +97,7 @@ cvar_t sk_scientist_heal3 = { "sk_scientist_heal3", "0", 0, 0.0f, NULL };
#ifdef REGAMEDLL_ADD #ifdef REGAMEDLL_ADD
cvar_t game_version = { "game_version", APP_VERSION_STRD, FCVAR_SERVER, 0.0f, nullptr }; cvar_t game_version = { "game_version", APP_VERSION, FCVAR_SERVER, 0.0f, nullptr };
cvar_t maxmoney = { "mp_maxmoney", "16000", FCVAR_SERVER, 0.0f, nullptr }; cvar_t maxmoney = { "mp_maxmoney", "16000", FCVAR_SERVER, 0.0f, nullptr };
cvar_t round_infinite = { "mp_round_infinite", "0", FCVAR_SERVER, 0.0f, nullptr }; cvar_t round_infinite = { "mp_round_infinite", "0", FCVAR_SERVER, 0.0f, nullptr };
cvar_t hegrenade_penetration = { "mp_hegrenade_penetration", "0", 0, 0.0f, nullptr }; cvar_t hegrenade_penetration = { "mp_hegrenade_penetration", "0", 0, 0.0f, nullptr };
@ -114,7 +114,7 @@ cvar_t showtriggers = { "showtriggers", "0", 0, 0.0f, nullptr }; // debug cva
// TODO: Maybe it's better to register in the engine? // TODO: Maybe it's better to register in the engine?
cvar_t hostagehurtable = { "mp_hostage_hurtable", "1", FCVAR_SERVER, 0.0f, nullptr }; cvar_t hostagehurtable = { "mp_hostage_hurtable", "1", FCVAR_SERVER, 0.0f, nullptr };
cvar_t roundover = { "mp_roundover", "0", FCVAR_SERVER, 0.0f, nullptr }; cvar_t roundover = { "mp_roundover", "0", FCVAR_SERVER, 0.0f, nullptr };
cvar_t forcerespawn = { "mp_forcerespawn", "0", FCVAR_SERVER, 0.0f, nullptr }; cvar_t forcerespawn = { "mp_forcerespawn", "0", FCVAR_SERVER, 0.0f, nullptr };
void GameDLL_Version_f() void GameDLL_Version_f()
@ -123,9 +123,9 @@ void GameDLL_Version_f()
return; return;
// print version // print version
CONSOLE_ECHO("ReGameDLL build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")\n"); CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");
CONSOLE_ECHO("ReGameDLL API version %i.%i\n", REGAMEDLL_API_VERSION_MAJOR, REGAMEDLL_API_VERSION_MINOR); CONSOLE_ECHO("Build date: " APP_COMMIT_TIME " " APP_COMMIT_DATE "\n");
CONSOLE_ECHO("Build from: " APP_COMMITS_URL APP_COMMIT_ID " " APP_COMMIT_AUTHOR "\n"); CONSOLE_ECHO("Build from: " APP_COMMIT_URL APP_COMMIT_SHA "\n");
} }
void GameDLL_EndRound_f() void GameDLL_EndRound_f()
@ -264,8 +264,7 @@ void EXT_FUNC GameDLLInit()
CVAR_REGISTER(&forcerespawn); CVAR_REGISTER(&forcerespawn);
// print version // print version
CONSOLE_ECHO("ReGameDLL build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")\n"); CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");
CONSOLE_ECHO("ReGameDLL API version %i.%i\n", REGAMEDLL_API_VERSION_MAJOR, REGAMEDLL_API_VERSION_MINOR);
#endif // REGAMEDLL_ADD #endif // REGAMEDLL_ADD

View File

@ -8,22 +8,26 @@ set srcdir=%~1
set repodir=%~2 set repodir=%~2
set old_version= set old_version=
set old_specialbuild=""
set version_revision=0
set version_specialbuild=
set version_id_commit=
set version_author_commit=
set version_pdate_1=%date:~-4%-%date:~3,2%-%date:~0,2%
set version_pdate=%version_pdate_1%%time:~0,2%:%time:~3,2%:%time:~6,2%
set version_pdate_2=%time:~0,2%-%time:~3,2%-%time:~6,2%
set version_pdate_2=%version_pdate_2: =%
set version_date=%version_pdate_1%__%version_pdate_2%
set version_major=0 set version_major=0
set version_minor=0 set version_minor=0
set version_specialversion= set version_maintenance=0
set url_commit= set version_modifed=
set commitSHA=
set commitURL=
set commitCount=0
set branch_name=master set branch_name=master
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "hour=%dt:~8,2%"
set "min=%dt:~10,2%"
set "sec=%dt:~12,2%"
for /f "tokens=%MM%" %%I in ("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") do set "month=%%I"
:: ::
:: Check for git.exe presence :: Check for git.exe presence
:: ::
@ -36,8 +40,11 @@ set errlvl="%ERRORLEVEL%"
IF EXIST "%srcdir%\appversion.h" ( IF EXIST "%srcdir%\appversion.h" (
FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\appversion.h") do ( FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\appversion.h") do (
IF %%i==#define ( IF %%i==#define (
IF %%j==APP_VERSION_C set old_version=%%k IF %%j==APP_VERSION (
IF %%j==APP_VERSION_SPECIALBUILD set old_specialbuild=%%k :: Remove quotes
set v=%%k
set old_version=!v:"=!
)
) )
) )
) )
@ -47,7 +54,7 @@ IF %errlvl% == "1" (
:: if we haven't appversion.h, we need to create it :: if we haven't appversion.h, we need to create it
IF NOT "%old_version%" == "" ( IF NOT "%old_version%" == "" (
set version_revision=0 set commitCount=0
) )
) )
@ -59,7 +66,7 @@ IF EXIST "%srcdir%\version.h" (
IF %%i==#define ( IF %%i==#define (
IF %%j==VERSION_MAJOR set version_major=%%k IF %%j==VERSION_MAJOR set version_major=%%k
IF %%j==VERSION_MINOR set version_minor=%%k IF %%j==VERSION_MINOR set version_minor=%%k
IF %%j==VERSION_SPECIALVERSION set version_specialversion=%%k IF %%j==VERSION_MAINTENANCE set version_maintenance=%%k
) )
) )
) ELSE ( ) ELSE (
@ -67,7 +74,7 @@ IF EXIST "%srcdir%\version.h" (
IF NOT [%%j] == [] ( IF NOT [%%j] == [] (
IF %%i==majorVersion set version_major=%%j IF %%i==majorVersion set version_major=%%j
IF %%i==minorVersion set version_minor=%%j IF %%i==minorVersion set version_minor=%%j
IF %%i==specialVersion set version_specialversion=%%j IF %%i==maintenanceVersion set version_maintenance=%%j
) )
) )
) )
@ -83,17 +90,11 @@ IF NOT %errlvl% == "1" (
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-list --count !branch_name!"') DO ( FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-list --count !branch_name!"') DO (
IF NOT [%%i] == [] ( IF NOT [%%i] == [] (
set version_revision=%%i set commitCount=%%i
) )
) )
) )
::
:: Now form full version string like 1.0.0.1
::
set new_version=%version_major%,%version_minor%,0,%version_revision%
:: ::
:: Get remote url repository :: Get remote url repository
:: ::
@ -106,49 +107,45 @@ IF NOT %errlvl% == "1" (
) )
:: Get remote url :: Get remote url
FOR /F "tokens=2 delims=@" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO ( FOR /F "tokens=2 delims=@" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
set url_commit=%%i set commitURL=%%i
)
:: Get author last no-merge commit
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." log -1 --no-merges --pretty=format:%%an"') DO (
set version_author_commit=%%i
) )
:: Get commit id :: Get commit id
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --verify HEAD"') DO ( FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --verify HEAD"') DO (
set var=%%i set shafull=%%i
set version_id_commit=!var:~0,+7! set commitSHA=!shafull:~0,+7!
) )
IF [!url_commit!] == [] ( IF [!commitURL!] == [] (
FOR /F "tokens=1" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO ( FOR /F "tokens=1" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
set url_commit=%%i set commitURL=%%i
) )
:: strip .git :: strip .git
if "x!url_commit:~-4!"=="x.git" ( if "x!commitURL:~-4!"=="x.git" (
set url_commit=!url_commit:~0,-4! set commitURL=!commitURL:~0,-4!
) )
:: append extra string :: append extra string
If NOT "%url_commit%"=="%url_commit:bitbucket.org=%" ( If NOT "%commitURL%"=="%commitURL:bitbucket.org=%" (
set url_commit=!url_commit!/commit/ set commitURL=!commitURL!/commit/
) ELSE ( ) ELSE (
set url_commit=!url_commit!/commits/ set commitURL=!commitURL!/commits/
) )
) ELSE ( ) ELSE (
:: strip .git :: strip .git
if "x!url_commit:~-4!"=="x.git" ( if "x!commitURL:~-4!"=="x.git" (
set url_commit=!url_commit:~0,-4! set commitURL=!commitURL:~0,-4!
) )
:: replace : to / :: replace : to /
set url_commit=!url_commit::=/! set commitURL=!commitURL::=/!
:: append extra string :: append extra string
If NOT "%url_commit%"=="%url_commit:bitbucket.org=%" ( If NOT "%commitURL%"=="%commitURL:bitbucket.org=%" (
set url_commit=https://!url_commit!/commit/ set commitURL=https://!commitURL!/commit/
) ELSE ( ) ELSE (
set url_commit=https://!url_commit!/commits/ set commitURL=https://!commitURL!/commits/
) )
) )
) )
@ -164,25 +161,23 @@ IF NOT %errlvl% == "1" (
) )
IF [%localChanged%]==[1] ( IF [%localChanged%]==[1] (
IF NOT [%version_specialversion%] == [] ( set version_modifed=+m
set version_specialbuild=%version_specialversion%
) ELSE (
set version_specialbuild=m
)
) ELSE (
set version_specialbuild=
) )
::
:: Now form full version string like 1.0.0.1
::
set new_version=%version_major%.%version_minor%.%version_maintenance%.%commitCount%-dev%version_modifed%
:: ::
:: Update appversion.h if version has changed or modifications/mixed revisions detected :: Update appversion.h if version has changed or modifications/mixed revisions detected
:: ::
IF NOT "%new_version%"=="%old_version%" goto _update IF NOT "%new_version%"=="%old_version%" goto _update
IF NOT "%version_specialbuild%"==%old_specialbuild% goto _update
goto _exit goto _exit
:_update :_update
echo Updating appversion.h, new version is "%new_version%", the old one was "%old_version%" echo Updating appversion.h, new version is "%new_version%", the old one was %old_version%
echo new special build is "%version_specialbuild%", the old one was %old_specialbuild%
echo #ifndef __APPVERSION_H__>"%srcdir%\appversion.h" echo #ifndef __APPVERSION_H__>"%srcdir%\appversion.h"
echo #define __APPVERSION_H__>>"%srcdir%\appversion.h" echo #define __APPVERSION_H__>>"%srcdir%\appversion.h"
@ -193,40 +188,15 @@ echo // Don't edit it.>>"%srcdir%\appversion.h"
echo // >>"%srcdir%\appversion.h" echo // >>"%srcdir%\appversion.h"
echo.>>"%srcdir%\appversion.h" echo.>>"%srcdir%\appversion.h"
echo // Version defines>>"%srcdir%\appversion.h" echo // Version defines>>"%srcdir%\appversion.h"
echo #define APP_VERSION "%new_version%">>"%srcdir%\appversion.h"
IF "%version_specialversion%" == "" (
echo #define APP_VERSION_D %version_major%.%version_minor%.%version_revision% >>"%srcdir%\appversion.h"
echo #define APP_VERSION_STRD "%version_major%.%version_minor%.%version_revision%">>"%srcdir%\appversion.h"
echo #define APP_VERSION_STRD_RC "%version_major%.%version_minor%.%version_revision%">>"%srcdir%\appversion.h"
echo #define APP_VERSION_C %version_major%,%version_minor%,0,%version_revision% >>"%srcdir%\appversion.h"
echo #define APP_VERSION_STRCS "%version_major%,%version_minor%,0,%version_revision%">>"%srcdir%\appversion.h"
) ELSE (
echo #define APP_VERSION_D %version_major%.%version_minor%.%version_maintenance%.%version_revision% >>"%srcdir%\appversion.h"
echo #define APP_VERSION_STRD "%version_major%.%version_minor%.%version_maintenance%.%version_revision%">>"%srcdir%\appversion.h"
echo #define APP_VERSION_STRD_RC "%version_major%.%version_minor%.%version_maintenance%.%version_revision%">>"%srcdir%\appversion.h"
echo #define APP_VERSION_C %version_major%,%version_minor%,%version_maintenance%,%version_revision% >>"%srcdir%\appversion.h"
echo #define APP_VERSION_STRCS "%version_major%,%version_minor%,%version_maintenance%,%version_revision%">>"%srcdir%\appversion.h"
)
echo.>>"%srcdir%\appversion.h" echo.>>"%srcdir%\appversion.h"
echo #define APP_VERSION_DATE %version_date%>>"%srcdir%\appversion.h" echo #define APP_COMMIT_DATE "%month% %DD% %YYYY%">>"%srcdir%\appversion.h"
echo #define APP_VERSION_DATE_STR "%version_date%">>"%srcdir%\appversion.h" echo #define APP_COMMIT_TIME "%hour%:%min%:%sec%">>"%srcdir%\appversion.h"
echo #define APP_VERSION_PDATE_STR "%version_pdate%">>"%srcdir%\appversion.h"
echo #define APP_VERSION_YMD_STR "%version_pdate_1%">>"%srcdir%\appversion.h"
echo.>>"%srcdir%\appversion.h"
echo #define APP_COMMIT_AUTHOR "(%version_author_commit%)">>"%srcdir%\appversion.h"
echo #define APP_COMMIT_ID "%version_id_commit%">>"%srcdir%\appversion.h"
echo #define APP_COMMITS_URL "%url_commit%">>"%srcdir%\appversion.h"
echo.>>"%srcdir%\appversion.h"
IF NOT "%version_specialbuild%" == "" ( echo.>>"%srcdir%\appversion.h"
echo #define APP_VERSION_FLAGS VS_FF_SPECIALBUILD>>"%srcdir%\appversion.h" echo #define APP_COMMIT_SHA "%commitSHA%">>"%srcdir%\appversion.h"
echo #define APP_VERSION_SPECIALBUILD "%version_specialbuild%">>"%srcdir%\appversion.h" echo #define APP_COMMIT_URL "%commitURL%">>"%srcdir%\appversion.h"
echo #define APP_VERSION APP_VERSION_STRD "" APP_VERSION_SPECIALBUILD>>"%srcdir%\appversion.h"
) ELSE (
echo #define APP_VERSION_FLAGS 0x0L>>"%srcdir%\appversion.h"
echo #define APP_VERSION APP_VERSION_STRD>>"%srcdir%\appversion.h"
)
echo.>>"%srcdir%\appversion.h" echo.>>"%srcdir%\appversion.h"
echo #endif //__APPVERSION_H__>>"%srcdir%\appversion.h" echo #endif //__APPVERSION_H__>>"%srcdir%\appversion.h"
@ -239,4 +209,4 @@ copy /b "%srcdir%\version.cpp"+,, "%srcdir%\version.cpp"
endlocal endlocal
:_exit :_exit
exit /B 0 exit /B 0

View File

@ -7,21 +7,12 @@
// //
// Version defines // Version defines
\#define VERSION_MAJOR ${verInfo.majorVersion} \#define APP_VERSION "$verInfo.asMavenVersion()"
\#define VERSION_MINOR ${verInfo.minorVersion}
\#define APP_COMMIT_AUTHOR "(${verInfo.authorCommit})" \#define APP_COMMIT_DATE "$verInfo.asCommitDate()"
\#define APP_COMMIT_ID "${verInfo.commitID}" \#define APP_COMMIT_TIME "$verInfo.asCommitTime()"
\#define APP_COMMITS_URL "${verInfo.urlCommits}"
\#define APP_VERSION_D ${verInfo.format('.', '-', true)} \#define APP_COMMIT_SHA "$verInfo.commitSHA"
\#define APP_VERSION_C ${verInfo.majorVersion},${verInfo.minorVersion},0,${verInfo.countCommit} \#define APP_COMMIT_URL "$verInfo.commitURL"
\#define APP_VERSION_STRD "${verInfo.majorVersion}.${verInfo.minorVersion}.${verInfo.countCommit}"
\#define APP_VERSION_STRD_RC "${verInfo.majorVersion}.${verInfo.minorVersion}.${verInfo.countCommit}"
#set ( $commitYMD = $_DateTimeFormat.forPattern('yyyy-MM-dd').print($verInfo.lastCommitDate) )
\#define APP_VERSION_YMD_STR "${commitYMD}"
\#define APP_VERSION APP_VERSION_STRD
#endif //__APPVERSION_H__ #endif //__APPVERSION_H__