Improved versioning: Added detection remote url repository.

Update PreBuild.bat
This commit is contained in:
s1lentq 2016-03-04 03:43:00 +06:00
parent 6d282d58e4
commit 9fd5eaa043
10 changed files with 126 additions and 34 deletions

View File

@ -7,7 +7,7 @@ Regamedll_CS is a result of reverse engineering of original library mods HLDS (b
At the moment, the work of reverse engineering continues At the moment, the work of reverse engineering continues
## Goals of the project ## Goals of the project
* Provide more stable (than official) version of Half-Life dedicated server with extended API for mods and plugins * Provide more stable (than official) version of Counter-Strike game with extended API for mods and plugins
## How can use it? ## How can use it?
Regamedll_CS is fully compatible with official mod CS 1.6 by Valve. All you have to do is to download binaries and replace original mo.dll/cs.so Regamedll_CS is fully compatible with official mod CS 1.6 by Valve. All you have to do is to download binaries and replace original mo.dll/cs.so

View File

@ -32,7 +32,8 @@ if (gitInfo.tag && gitInfo.tag[0] == 'v') {
countCommit: gitInfo.countCommit, countCommit: gitInfo.countCommit,
lastCommitDate: gitInfo.lastCommitDate, lastCommitDate: gitInfo.lastCommitDate,
commitID: gitInfo.commitID, commitID: gitInfo.commitID,
authorCommit: gitInfo.authorCommit authorCommit: gitInfo.authorCommit,
urlCommits: gitInfo.urlCommits
) )
} else { } else {
versionInfo = new RegamedllVersionInfo( versionInfo = new RegamedllVersionInfo(
@ -42,7 +43,8 @@ if (gitInfo.tag && gitInfo.tag[0] == 'v') {
countCommit: gitInfo.countCommit, countCommit: gitInfo.countCommit,
lastCommitDate: gitInfo.lastCommitDate, lastCommitDate: gitInfo.lastCommitDate,
commitID: gitInfo.commitID, commitID: gitInfo.commitID,
authorCommit: gitInfo.authorCommit authorCommit: gitInfo.authorCommit,
urlCommits: gitInfo.urlCommits
) )
} }

View File

@ -12,4 +12,5 @@ class GitInfo {
Integer countCommit Integer countCommit
String commitID String commitID
String authorCommit String authorCommit
String urlCommits
} }

View File

@ -5,6 +5,7 @@ import groovy.transform.TypeChecked
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
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.revwalk.RevCommit import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.revwalk.RevWalk import org.eclipse.jgit.revwalk.RevWalk
import org.eclipse.jgit.storage.file.FileRepositoryBuilder import org.eclipse.jgit.storage.file.FileRepositoryBuilder
@ -38,6 +39,20 @@ class GitVersioner {
return null; return null;
} }
static String prepareUrlToCommits(String url) {
StringBuilder sb = new StringBuilder();
String childPath;
int pos = url.indexOf('@');
if (pos != -1) {
childPath = url.substring(pos + 1, url.lastIndexOf('.git')).replace(':', '/');
sb.append('https://');
} else {
childPath = url.substring(0, url.lastIndexOf('.git'));
}
sb.append(childPath).append('/commit/');
return sb.toString();
}
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)
@ -49,6 +64,7 @@ class GitVersioner {
return null return null
} }
final StoredConfig cfg = repo.getConfig();
def commit = new RevWalk(repo).parseCommit(head) def commit = new RevWalk(repo).parseCommit(head)
def commitLast = parseCommitLast(repo) def commitLast = parseCommitLast(repo)
int commitCount = getCountCommit(repo) int commitCount = getCountCommit(repo)
@ -56,6 +72,11 @@ class GitVersioner {
def branch = repo.getBranch() def branch = repo.getBranch()
def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC) def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC)
String remote_name = cfg.getString("branch", branch, "remote");
String url = cfg.getString("remote", remote_name, "url");
String urlCommits = prepareUrlToCommits(url);
if (!commit) { if (!commit) {
throw new RuntimeException("Can't find last commit.") throw new RuntimeException("Can't find last commit.")
} }
@ -70,7 +91,8 @@ class GitVersioner {
tag: tag, tag: tag,
countCommit: commitCount, countCommit: commitCount,
commitID: headCommitId, commitID: headCommitId,
authorCommit: authorCommit authorCommit: authorCommit,
urlCommits: urlCommits
) )
} }
} }

View File

@ -16,6 +16,7 @@ class RegamedllVersionInfo {
DateTime lastCommitDate DateTime lastCommitDate
String commitID String commitID
String authorCommit String authorCommit
String urlCommits
String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) { String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) {
StringBuilder sb = new StringBuilder() StringBuilder sb = new StringBuilder()

View File

@ -107,7 +107,7 @@ void GameDLL_Version_f()
// print version // print version
CONSOLE_ECHO("ReGameDLL build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")\n"); CONSOLE_ECHO("ReGameDLL build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")\n");
CONSOLE_ECHO("ReGameDLL API version %i.%i\n", REGAMEDLL_API_VERSION_MAJOR, REGAMEDLL_API_VERSION_MINOR); CONSOLE_ECHO("ReGameDLL API version %i.%i\n", REGAMEDLL_API_VERSION_MAJOR, REGAMEDLL_API_VERSION_MINOR);
CONSOLE_ECHO("Build from: https://github.com/s1lentq/ReGameDLL_CS/commit/" APP_COMMIT_ID " (" APP_COMMIT_AUTHOR ")\n"); CONSOLE_ECHO("Build from: " APP_COMMITS_URL APP_COMMIT_ID " " APP_COMMIT_AUTHOR "\n");
} }
void GameDLL_EndRound_f() void GameDLL_EndRound_f()

View File

@ -586,7 +586,7 @@ void CBasePlayer::Radio(const char *msg_id, const char *msg_verbose, short pitch
{ {
// search the place name where is located the player // search the place name where is located the player
const char *placeName = NULL; const char *placeName = NULL;
if (TheBotPhrases != NULL) if (g_bIsCzeroGame && TheBotPhrases != NULL)
{ {
Place playerPlace = TheNavAreaGrid.GetPlace(&pev->origin); Place playerPlace = TheNavAreaGrid.GetPlace(&pev->origin);
const BotPhraseList *placeList = TheBotPhrases->GetPlaceList(); const BotPhraseList *placeList = TheBotPhrases->GetPlaceList();

View File

@ -2337,6 +2337,9 @@ int UTIL_ReadFlags(const char *c)
// Determine whether bots can be used or not // Determine whether bots can be used or not
bool UTIL_AreBotsAllowed() bool UTIL_AreBotsAllowed()
{ {
if (g_engfuncs.pfnEngCheckParm == NULL)
return false;
if (g_bIsCzeroGame) if (g_bIsCzeroGame)
{ {
// If they pass in -nobots, don't allow bots. This is for people who host servers, to // If they pass in -nobots, don't allow bots. This is for people who host servers, to

View File

@ -1,21 +1,27 @@
@echo OFF @setlocal enableextensions enabledelayedexpansion
@echo off
:: ::
:: Pre-build auto-versioning script :: Pre-build auto-versioning script
:: ::
SET srcdir=%~1 set srcdir=%~1
SET repodir=%~2 set repodir=%~2
SET old_version= set old_version=
set old_specialbuild="" set old_specialbuild=""
SET version_revision=0 set version_revision=0
set version_specialbuild= set version_specialbuild=
SET version_pdate_1=%date:~-4%-%date:~3,2%-%date:~0,2% set version_id_commit=
SET version_pdate=%version_pdate_1% %time:~0,2%:%time:~3,2%:%time:~6,2% set version_author_commit=
SET version_date=%version_pdate_1%__%time:~0,2%-%time:~3,2%-%time:~6,2% set version_pdate_1=%date:~-4%-%date:~3,2%-%date:~0,2%
SET version_major=0 set version_pdate=%version_pdate_1%%time:~0,2%:%time:~3,2%:%time:~6,2%
SET version_minor=0 set version_pdate_2=%time:~0,2%-%time:~3,2%-%time:~6,2%
SET version_specialversion= set version_pdate_2=%version_pdate_2: =%
set version_date=%version_pdate_1%__%version_pdate_2%
set version_major=0
set version_minor=0
set version_specialversion=
set url_commit=
:: ::
:: Check for git.exe presence :: Check for git.exe presence
@ -29,8 +35,8 @@ 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_C set old_version=%%k
IF %%j==APP_VERSION_SPECIALBUILD SET old_specialbuild=%%k IF %%j==APP_VERSION_SPECIALBUILD set old_specialbuild=%%k
) )
) )
) )
@ -40,27 +46,27 @@ 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 version_revision=0
) )
) )
:: ::
:: Read major, minor and maintenance version components from Version.h :: Read major, minor and maintenance version components from Version.h
:: ::
IF EXIST "%srcdir%\version.h" ( IF EXIST "%srcdir%\version.h" (
FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\version.h") do ( FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\version.h") do (
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_SPECIALVERSION set version_specialversion=%%k
) )
) )
) ELSE ( ) ELSE (
FOR /F "usebackq tokens=1,2,3,* delims==" %%i in ("%repodir%..\gradle.properties") do ( FOR /F "usebackq tokens=1,2,3,* delims==" %%i in ("%repodir%..\gradle.properties") do (
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==specialVersion set version_specialversion=%%j
) )
) )
) )
@ -82,13 +88,66 @@ IF NOT %errlvl% == "1" (
set new_version=%version_major%,%version_minor%,0,%version_revision% set new_version=%version_major%,%version_minor%,0,%version_revision%
::
:: Get remote url repository
::
IF NOT %errlvl% == "1" (
set branch_name=master
set branch_remote=origin
:: Get current branch
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --abbrev-ref HEAD"') DO (
set branch_name=%%i
)
:: Get remote name by current branch
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." config branch.!branch_name!.remote"') DO (
set branch_remote=%%i
)
:: Get remote url
FOR /F "tokens=2 delims=@" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
set url_commit=%%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
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --verify HEAD"') DO (
set var=%%i
set version_id_commit=!var:~0,+7!
)
IF [!url_commit!] == [] (
FOR /F "tokens=1" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
set url_commit=%%i
)
:: strip .git
if "x!url_commit:~-4!"=="x.git" (
set url_commit=!url_commit:~0,-4!
)
:: append extra string
set url_commit=!url_commit!/commit/
) ELSE (
:: strip .git
if "x!url_commit:~-4!"=="x.git" (
set url_commit=!url_commit:~0,-4!
)
:: replace : to /
set url_commit=!url_commit::=/!
:: append extra string
set url_commit=https://!url_commit!/commit/
)
)
:: ::
:: Detect local modifications :: Detect local modifications
:: ::
SET localChanged=0 set localChanged=0
IF NOT %errlvl% == "1" ( IF NOT %errlvl% == "1" (
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." ls-files -m"') DO ( FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." ls-files -m"') DO (
SET localChanged=1 set localChanged=1
) )
) )
@ -128,23 +187,25 @@ IF "%version_specialversion%" == "" (
echo #define APP_VERSION_STRD "%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_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_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" echo #define APP_VERSION_STRCS "%version_major%,%version_minor%,0,%version_revision%">>"%srcdir%\appversion.h"
) ELSE ( ) ELSE (
echo #define APP_VERSION_D %version_major%.%version_minor%.%version_maintenance%.%version_revision% >>"%srcdir%\appversion.h" 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 "%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_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_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 #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_VERSION_DATE %version_date%>>"%srcdir%\appversion.h"
echo #define APP_VERSION_DATE_STR "%version_date%">>"%srcdir%\appversion.h" echo #define APP_VERSION_DATE_STR "%version_date%">>"%srcdir%\appversion.h"
echo.>>"%srcdir%\appversion.h"
echo #define APP_VERSION_PDATE_STR "%version_pdate%">>"%srcdir%\appversion.h" echo #define APP_VERSION_PDATE_STR "%version_pdate%">>"%srcdir%\appversion.h"
echo.>>"%srcdir%\appversion.h"
echo #define APP_VERSION_YMD_STR "%version_pdate_1%">>"%srcdir%\appversion.h" echo #define APP_VERSION_YMD_STR "%version_pdate_1%">>"%srcdir%\appversion.h"
echo.>>"%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%" == "" ( IF NOT "%version_specialbuild%" == "" (
echo #define APP_VERSION_FLAGS VS_FF_SPECIALBUILD>>"%srcdir%\appversion.h" echo #define APP_VERSION_FLAGS VS_FF_SPECIALBUILD>>"%srcdir%\appversion.h"
@ -163,6 +224,7 @@ echo.>>"%srcdir%\appversion.h"
:: Do update of version.cpp file last modify time to force it recompile :: Do update of version.cpp file last modify time to force it recompile
:: ::
copy /b "%srcdir%\version.cpp"+,, "%srcdir%\version.cpp" copy /b "%srcdir%\version.cpp"+,, "%srcdir%\version.cpp"
endlocal
:_exit :_exit
exit /B 0 exit /B 0

View File

@ -10,8 +10,9 @@
\#define VERSION_MAJOR ${verInfo.majorVersion} \#define VERSION_MAJOR ${verInfo.majorVersion}
\#define VERSION_MINOR ${verInfo.minorVersion} \#define VERSION_MINOR ${verInfo.minorVersion}
\#define APP_COMMIT_AUTHOR "${verInfo.authorCommit}" \#define APP_COMMIT_AUTHOR "(${verInfo.authorCommit})"
\#define APP_COMMIT_ID "${verInfo.commitID}" \#define APP_COMMIT_ID "${verInfo.commitID}"
\#define APP_COMMITS_URL "${verInfo.urlCommits}"
\#define APP_VERSION_D ${verInfo.format('.', '-', true)} \#define APP_VERSION_D ${verInfo.format('.', '-', true)}
\#define APP_VERSION_C ${verInfo.majorVersion},${verInfo.minorVersion},0,${verInfo.countCommit} \#define APP_VERSION_C ${verInfo.majorVersion},${verInfo.minorVersion},0,${verInfo.countCommit}