From 07f5290ad97affc1b0cb8fc589e06251779585db Mon Sep 17 00:00:00 2001 From: s1lent Date: Fri, 7 Jul 2017 20:01:43 +0700 Subject: [PATCH] Refactoring versioning --- README.md | 2 +- build.gradle | 28 +-- .../groovy/gradlecpp/VelocityUtils.groovy | 21 +- .../src/main/groovy/versioning/GitInfo.groovy | 7 +- .../groovy/versioning/GitVersioner.groovy | 92 +++++++- .../versioning/RevoiceVersionInfo.groovy | 51 +++-- gradle.properties | 2 +- gradlew | 0 msvc/{ReVoice.sln => revoice.sln} | 2 +- publish.gradle | 29 +-- revoice/build.gradle | 32 ++- revoice/msvc/PreBuild.bat | 211 +++++++++++------- revoice/msvc/{ReVoice.def => revoice.def} | 0 revoice/msvc/{ReVoice.rc => revoice.rc} | 17 +- .../msvc/{ReVoice.vcxproj => revoice.vcxproj} | 6 +- ...cxproj.filters => revoice.vcxproj.filters} | 4 +- revoice/src/meta_api.cpp | 4 +- revoice/version/appversion.vm | 22 +- shared.gradle | 27 ++- shared_icc.gradle | 29 ++- shared_msvc.gradle | 10 +- 21 files changed, 368 insertions(+), 228 deletions(-) mode change 100644 => 100755 gradlew rename msvc/{ReVoice.sln => revoice.sln} (93%) rename revoice/msvc/{ReVoice.def => revoice.def} (100%) rename revoice/msvc/{ReVoice.rc => revoice.rc} (89%) rename revoice/msvc/{ReVoice.vcxproj => revoice.vcxproj} (97%) rename revoice/msvc/{ReVoice.vcxproj.filters => revoice.vcxproj.filters} (95%) diff --git a/README.md b/README.md index 32c86f1..294bd62 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# revoice +# Revoice [![Build Status](http://teamcity.rehlds.org/app/rest/builds/buildType:(id:Revoice_Publish)/statusIcon)](http://teamcity.rehlds.org/viewType.html?buildTypeId=Revoice_Publish&guest=1) [![Download](https://camo.githubusercontent.com/089706eb2571f262bb23afc9434d85d52a423cc3/687474703a2f2f7265686c64732e6f72672f76657273696f6e2f7265766f6963652e737667)](http://teamcity.rehlds.org/guestAuth/downloadArtifacts.html?buildTypeId=Revoice_Publish&buildId=lastSuccessful) \ No newline at end of file diff --git a/build.gradle b/build.gradle index 054a872..3ac8596 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,8 @@ import versioning.GitVersioner import versioning.RevoiceVersionInfo +import org.joda.time.DateTime +apply plugin: 'maven-publish' apply from: 'shared.gradle' group = 'revoice' @@ -13,13 +15,8 @@ idea { } def gitInfo = GitVersioner.versionForDir(project.rootDir) -if (!gitInfo) { - throw new RuntimeException('Running outside git repository') -} - RevoiceVersionInfo versionInfo -if (gitInfo.tag && gitInfo.tag[0] == 'v') { - +if (gitInfo && gitInfo.tag && gitInfo.tag[0] == 'v') { def m = gitInfo.tag =~ /^v(\d+)\.(\d+)(\.(\d+))?$/ if (!m.find()) { throw new RuntimeException("Invalid git version tag name ${gitInfo.tag}") @@ -29,22 +26,27 @@ if (gitInfo.tag && gitInfo.tag[0] == 'v') { majorVersion: m.group(1) as int, minorVersion: m.group(2) as int, maintenanceVersion: m.group(4) ? (m.group(4) as int) : null, - countCommit: gitInfo.countCommit, - lastCommitDate: gitInfo.lastCommitDate + localChanges: gitInfo.localChanges, + commitDate: gitInfo.commitDate, + commitSHA: gitInfo.commitSHA, + commitURL: gitInfo.commitURL ) } else { - versionInfo = new RevoiceVersionInfo( majorVersion: project.majorVersion as int, minorVersion: project.minorVersion as int, - specialVersion: project.specialVersion, - countCommit: gitInfo.countCommit, - lastCommitDate: gitInfo.lastCommitDate + maintenanceVersion: project.maintenanceVersion as int, + suffix: '', + localChanges: gitInfo ? gitInfo.localChanges : true, + commitDate: gitInfo ? gitInfo.commitDate : new DateTime(), + commitSHA: gitInfo ? gitInfo.commitSHA : "", + commitURL: gitInfo ? gitInfo.commitURL : "", + commitCount: gitInfo ? (gitInfo.commitCount as int) : null ) } project.ext.revoiceVersionInfo = versionInfo -project.version = versionInfo.asVersion() +project.version = versionInfo.asMavenVersion() apply from: 'publish.gradle' diff --git a/buildSrc/src/main/groovy/gradlecpp/VelocityUtils.groovy b/buildSrc/src/main/groovy/gradlecpp/VelocityUtils.groovy index 34ead60..f1d5f77 100644 --- a/buildSrc/src/main/groovy/gradlecpp/VelocityUtils.groovy +++ b/buildSrc/src/main/groovy/gradlecpp/VelocityUtils.groovy @@ -4,7 +4,6 @@ import org.apache.velocity.Template import org.apache.velocity.VelocityContext import org.apache.velocity.app.Velocity import org.joda.time.format.DateTimeFormat -import versioning.RevoiceVersionInfo class VelocityUtils { @@ -20,29 +19,15 @@ class VelocityUtils { Velocity.init(p); } - static String renderTemplate(File tplFile, RevoiceVersionInfo ctx) { + + static String renderTemplate(File tplFile, Map ctx) { Template tpl = Velocity.getTemplate(tplFile.absolutePath) if (!tpl) { throw new RuntimeException("Failed to load velocity template ${tplFile.absolutePath}: not found") } - def templateCtx = [ - verInfo: ctx - ] - - def velocityContext = new VelocityContext(templateCtx) - - if (ctx.specialVersion.length() > 0) { - velocityContext.put("appFlags", 0x0L) - velocityContext.put("formatSpecialVersion", "-" + ctx.specialVersion) - } else { - - velocityContext.put("appFlags", "VS_FF_SPECIALBUILD") - velocityContext.put("formatSpecialVersion", "") - } - - velocityContext.put("current_version", ctx.asVersion()) + def velocityContext = new VelocityContext(ctx) velocityContext.put("_DateTimeFormat", DateTimeFormat) def sw = new StringWriter() diff --git a/buildSrc/src/main/groovy/versioning/GitInfo.groovy b/buildSrc/src/main/groovy/versioning/GitInfo.groovy index 0158421..e0ad38f 100644 --- a/buildSrc/src/main/groovy/versioning/GitInfo.groovy +++ b/buildSrc/src/main/groovy/versioning/GitInfo.groovy @@ -6,8 +6,11 @@ import org.joda.time.DateTime @CompileStatic @TypeChecked class GitInfo { - DateTime lastCommitDate + boolean localChanges + DateTime commitDate String branch String tag - Integer countCommit + String commitSHA + String commitURL + Integer commitCount } diff --git a/buildSrc/src/main/groovy/versioning/GitVersioner.groovy b/buildSrc/src/main/groovy/versioning/GitVersioner.groovy index ffe3986..88a295c 100644 --- a/buildSrc/src/main/groovy/versioning/GitVersioner.groovy +++ b/buildSrc/src/main/groovy/versioning/GitVersioner.groovy @@ -1,10 +1,14 @@ package versioning +import java.util.Set; + import groovy.transform.CompileStatic import groovy.transform.TypeChecked import org.eclipse.jgit.api.Git +import org.eclipse.jgit.api.Status; import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.lib.Repository +import org.eclipse.jgit.lib.StoredConfig import org.eclipse.jgit.revwalk.RevCommit import org.eclipse.jgit.revwalk.RevWalk import org.eclipse.jgit.storage.file.FileRepositoryBuilder @@ -26,28 +30,96 @@ class GitVersioner { return count; } - static GitInfo versionForDir(File dir) { - FileRepositoryBuilder builder = new FileRepositoryBuilder() - Repository repo = builder.setWorkTree(dir).findGitDir().build() + static String prepareUrlToCommits(String url) { + if (url == null) { + // default remote url + return "https://github.com/s1lentq/Revoice/commit/"; + } - ObjectId head = repo.resolve('HEAD') + 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 { + pos = url.lastIndexOf('.git'); + childPath = (pos == -1) ? url : url.substring(0, pos); + } + + // support for different links to history of commits + if (url.indexOf('bitbucket.org') != -1) { + sb.append(childPath).append('/commits/'); + } else { + sb.append(childPath).append('/commit/'); + } + return sb.toString(); + } + // check uncommited changes + static boolean getUncommittedChanges(Repository repo) { + Git git = new Git(repo); + Status status = git.status().call(); + + Set uncommittedChanges = status.getUncommittedChanges(); + for(String uncommitted : uncommittedChanges) { + return true; + } + + return false; + } + static GitInfo versionForDir(File dir) { + FileRepositoryBuilder builder = new FileRepositoryBuilder(); + Repository repo = builder.setWorkTree(dir) + .findGitDir() + .build() + + ObjectId head = repo.resolve('HEAD'); if (!head) { return null } - def commit = new RevWalk(repo).parseCommit(head) - def branch = repo.getBranch() - def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC) + final StoredConfig cfg = repo.getConfig(); + def commit = new RevWalk(repo).parseCommit(head); + if (!commit) { + throw new RuntimeException("Can't find last commit."); + } - int commitCount = getCountCommit(repo); + def localChanges = getUncommittedChanges(repo); + def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC); + if (localChanges) { + commitDate = new DateTime(); + } + def branch = repo.getBranch(); + + String url = null; + String remote_name = cfg.getString("branch", branch, "remote"); + + if (remote_name == null) { + for (String remotes : cfg.getSubsections("remote")) { + if (url != null) { + println 'Found a second remote: (' + remotes + '), url: (' + cfg.getString("remote", remotes, "url") + ')' + continue; + } + + url = cfg.getString("remote", remotes, "url"); + } + } else { + url = cfg.getString("remote", remote_name, "url"); + } + + String commitURL = prepareUrlToCommits(url); String tag = repo.tags.find { kv -> kv.value.objectId == commit.id }?.key + String commitSHA = commit.getId().abbreviate(7).name(); return new GitInfo( - lastCommitDate: commitDate, + localChanges: localChanges, + commitDate: commitDate, branch: branch, tag: tag, - countCommit: commitCount + commitSHA: commitSHA, + commitURL: commitURL, + commitCount: getCountCommit(repo) ) } } diff --git a/buildSrc/src/main/groovy/versioning/RevoiceVersionInfo.groovy b/buildSrc/src/main/groovy/versioning/RevoiceVersionInfo.groovy index 8ff8d5a..bfdaff3 100644 --- a/buildSrc/src/main/groovy/versioning/RevoiceVersionInfo.groovy +++ b/buildSrc/src/main/groovy/versioning/RevoiceVersionInfo.groovy @@ -3,39 +3,56 @@ package versioning import groovy.transform.CompileStatic import groovy.transform.ToString import groovy.transform.TypeChecked +import org.joda.time.format.DateTimeFormat import org.joda.time.DateTime @CompileStatic @TypeChecked @ToString(includeNames = true) class RevoiceVersionInfo { - int majorVersion - int minorVersion + Integer majorVersion + Integer minorVersion Integer maintenanceVersion - String specialVersion - Integer countCommit - DateTime lastCommitDate + String suffix - String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) { + boolean localChanges + DateTime commitDate + String commitSHA + String commitURL + Integer commitCount + + String asMavenVersion(boolean extra = true, String separator = ".") { StringBuilder sb = new StringBuilder() - sb.append(majorVersion).append(versionSeparator).append(minorVersion) + sb.append(majorVersion).append(separator).append(minorVersion); if (maintenanceVersion != null) { - sb.append(versionSeparator).append(maintenanceVersion) + sb.append(separator).append(maintenanceVersion); } - if (specialVersion && includeSuffix) { - sb.append(suffixSeparator).append(specialVersion) + if (commitCount != null) { + sb.append(separator).append(commitCount) + } + + if (extra && suffix) { + sb.append('-' + suffix) + } + + // do mark for this build like a modified version + if (extra && localChanges) { + sb.append('+m'); } return sb.toString() } - String asVersion() { - if (specialVersion.length() > 0) { - sprintf("%d.%d.%d-%s", majorVersion, minorVersion, countCommit, specialVersion) + String asCommitDate(String pattern = null) { + if (pattern == null) { + pattern = "MMM d yyyy"; + if (commitDate.getDayOfMonth() >= 10) { + pattern = "MMM d yyyy"; + } } - else - sprintf("%d.%d.%d", majorVersion, minorVersion, countCommit) + + return DateTimeFormat.forPattern(pattern).withLocale(Locale.ENGLISH).print(commitDate); } - String asMavenVersion() { - format('.', '-', true) + String asCommitTime() { + return DateTimeFormat.forPattern('HH:mm:ss').withLocale(Locale.ENGLISH).print(commitDate); } } diff --git a/gradle.properties b/gradle.properties index e74de4e..d3247d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ majorVersion=0 minorVersion=1 -specialVersion= +maintenanceVersion=0 diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/msvc/ReVoice.sln b/msvc/revoice.sln similarity index 93% rename from msvc/ReVoice.sln rename to msvc/revoice.sln index 434a4b7..5d66aa2 100644 --- a/msvc/ReVoice.sln +++ b/msvc/revoice.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReVoice", "..\revoice\msvc\ReVoice.vcxproj", "{DAEFE371-7D77-4B72-A8A5-3CD3D1A55786}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "revoice", "..\revoice\msvc\revoice.vcxproj", "{DAEFE371-7D77-4B72-A8A5-3CD3D1A55786}" ProjectSection(ProjectDependencies) = postProject {E1AC990E-C012-4167-80C2-84C98AA7070C} = {E1AC990E-C012-4167-80C2-84C98AA7070C} {966DE7A9-EC15-4C1D-8B46-EA813A845723} = {966DE7A9-EC15-4C1D-8B46-EA813A845723} diff --git a/publish.gradle b/publish.gradle index 8a1c86f..1b4eaba 100644 --- a/publish.gradle +++ b/publish.gradle @@ -10,21 +10,23 @@ void _copyFile(String from, String to) { GradleCppUtils.copyFile(project.file(from), project.file(to), false) } -task publishPrepareFiles << { - def pubRootDir = project.file('publish/publishRoot') - if (pubRootDir.exists()) { - if (!pubRootDir.deleteDir()) { - throw new RuntimeException("Failed to delete ${pubRootDir}") +task publishPrepareFiles { + doLast { + def pubRootDir = project.file('publish/publishRoot') + if (pubRootDir.exists()) { + if (!pubRootDir.deleteDir()) { + throw new RuntimeException("Failed to delete ${pubRootDir}") + } } + + pubRootDir.mkdirs() + + project.file('publish/publishRoot/revoice/bin/win32').mkdirs() + project.file('publish/publishRoot/revoice/bin/linux32').mkdirs() + + _copyFileToDir('publish/revoice_mm.dll', 'publish/publishRoot/revoice/bin/win32/') + _copyFile('publish/librevoice_mm_i386.so', 'publish/publishRoot/revoice/bin/linux32/revoice_mm_i386.so') } - - pubRootDir.mkdirs() - - project.file('publish/publishRoot/revoice/bin/Windows').mkdirs() - project.file('publish/publishRoot/revoice/bin/Linux').mkdirs() - - _copyFileToDir('publish/revoice_mm.dll', 'publish/publishRoot/revoice/bin/Windows/') - _copyFile('publish/librevoice_mm_i386.so', 'publish/publishRoot/revoice/bin/Linux/revoice_mm_i386.so') } task publishPackage(type: Zip, dependsOn: 'publishPrepareFiles') { @@ -35,5 +37,4 @@ task publishPackage(type: Zip, dependsOn: 'publishPrepareFiles') { task doPackage { dependsOn 'publishPackage' - } diff --git a/revoice/build.gradle b/revoice/build.gradle index d489266..a193e3b 100644 --- a/revoice/build.gradle +++ b/revoice/build.gradle @@ -58,7 +58,7 @@ void setupToolchain(NativeBinarySpec b) { enabled: true, pchSourceSet: 'revoice_pch' ) - cfg.compilerOptions.languageStandard = 'c++0x' + cfg.compilerOptions.languageStandard = 'c++11' cfg.defines([ '_stricmp': 'strcasecmp', '_strnicmp': 'strncasecmp', @@ -137,7 +137,7 @@ model { rc { source { srcDir "msvc" - include "ReVoice.rc" + include "revoice.rc" } exportedHeaders { srcDirs "msvc" @@ -158,7 +158,7 @@ afterEvaluate { Tool linker = binary.linker if (GradleCppUtils.windows) { - linker.args "/DEF:${projectDir}\\msvc\\ReVoice.def" + linker.args "/DEF:${projectDir}\\msvc\\revoice.def" } } } @@ -176,17 +176,29 @@ tasks.clean.doLast { task generateAppVersion { RevoiceVersionInfo verInfo = (RevoiceVersionInfo) rootProject.revoiceVersionInfo - def tplversionFile = project.file('version/appversion.vm') - def versionFile = project.file('version/appversion.h') + def tplFile = project.file('version/appversion.vm') + def renderedFile = project.file('version/appversion.h') - inputs.file tplversionFile + // check to up-to-date + inputs.file tplFile inputs.file project.file('gradle.properties') - outputs.file versionFile + outputs.file renderedFile + + // this will ensure that this task is redone when the versions change + inputs.property('version', rootProject.version) + inputs.property('commitDate', verInfo.asCommitDate()) + + println "##teamcity[buildNumber '" + verInfo.asMavenVersion(false) + "']"; doLast { + def templateCtx = [ + verInfo: verInfo + ] - def versionContent = VelocityUtils.renderTemplate(tplversionFile, verInfo) - versionFile.delete() - versionFile.write(versionContent, 'utf-8') + def content = VelocityUtils.renderTemplate(tplFile, templateCtx) + renderedFile.delete() + renderedFile.write(content, 'utf-8') + + println 'The current Revoice maven version is ' + rootProject.version + ', url: (' + verInfo.commitURL + '' + verInfo.commitSHA + ')'; } } diff --git a/revoice/msvc/PreBuild.bat b/revoice/msvc/PreBuild.bat index 34cddef..9342689 100644 --- a/revoice/msvc/PreBuild.bat +++ b/revoice/msvc/PreBuild.bat @@ -1,21 +1,32 @@ -@echo OFF +@setlocal enableextensions enabledelayedexpansion +@echo off :: :: Pre-build auto-versioning script :: -SET srcdir=%~1 -SET repodir=%~2 +set srcdir=%~1 +set repodir=%~2 -SET old_version= -set old_specialbuild="" -SET version_revision=0 -set version_specialbuild= -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_date=%version_pdate_1%__%time:~0,2%-%time:~3,2%-%time:~6,2% -SET version_major=0 -SET version_minor=0 -SET version_specialversion= +set old_version= +set version_major=0 +set version_minor=0 +set version_modifed= +set svn_old_number=664 + +set commitSHA= +set commitURL= +set commitCount=0 +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 @@ -29,8 +40,11 @@ set errlvl="%ERRORLEVEL%" IF EXIST "%srcdir%\appversion.h" ( FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\appversion.h") do ( IF %%i==#define ( - IF %%j==APP_VERSION_C SET old_version=%%k - IF %%j==APP_VERSION_SPECIALBUILD SET old_specialbuild=%%k + IF %%j==APP_VERSION ( + :: Remove quotes + set v=%%k + set old_version=!v:"=! + ) ) ) ) @@ -40,27 +54,25 @@ IF %errlvl% == "1" ( :: if we haven't appversion.h, we need to create it IF NOT "%old_version%" == "" ( - SET version_revision=0 + set commitCount=0 ) ) :: :: 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 ( IF %%i==#define ( - IF %%j==VERSION_MAJOR SET version_major=%%k - IF %%j==VERSION_MINOR SET version_minor=%%k - IF %%j==VERSION_SPECIALVERSION SET version_specialversion=%%k + IF %%j==VERSION_MAJOR set version_major=%%k + IF %%j==VERSION_MINOR set version_minor=%%k ) ) ) ELSE ( FOR /F "usebackq tokens=1,2,3,* delims==" %%i in ("%repodir%..\gradle.properties") do ( IF NOT [%%j] == [] ( - IF %%i==majorVersion SET version_major=%%j - IF %%i==minorVersion SET version_minor=%%j - IF %%i==specialVersion SET version_specialversion=%%j + IF %%i==majorVersion set version_major=%%j + IF %%i==minorVersion set version_minor=%%j ) ) ) @@ -69,49 +81,108 @@ IF EXIST "%srcdir%\version.h" ( :: Read revision and release date from it :: IF NOT %errlvl% == "1" ( - FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-list --all | wc -l"') DO ( + :: Get current branch + FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --abbrev-ref HEAD"') DO ( + set branch_name=%%i + ) + + FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-list --count !branch_name!"') DO ( IF NOT [%%i] == [] ( - set version_revision=%%i + set /a commitCount=%%i+%svn_old_number% ) ) ) +:: +:: Get remote url repository +:: +IF NOT %errlvl% == "1" ( + + set branch_remote=origin + :: 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 commitURL=%%i + ) + :: Get commit id + FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --verify HEAD"') DO ( + set shafull=%%i + set commitSHA=!shafull:~0,+7! + ) + + IF [!commitURL!] == [] ( + + FOR /F "tokens=1" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO ( + set commitURL=%%i + ) + + :: strip .git + if "x!commitURL:~-4!"=="x.git" ( + set commitURL=!commitURL:~0,-4! + ) + + :: append extra string + If NOT "!commitURL!"=="!commitURL:bitbucket.org=!" ( + set commitURL=!commitURL!/commits/ + ) ELSE ( + set commitURL=!commitURL!/commit/ + ) + + ) ELSE ( + :: strip .git + if "x!commitURL:~-4!"=="x.git" ( + set commitURL=!commitURL:~0,-4! + ) + :: replace : to / + set commitURL=!commitURL::=/! + + :: append extra string + If NOT "!commitURL!"=="!commitURL:bitbucket.org=!" ( + set commitURL=https://!commitURL!/commits/ + ) ELSE ( + set commitURL=https://!commitURL!/commit/ + ) + ) +) + +:: +:: Detect local modifications +:: +set localChanged=0 +IF NOT %errlvl% == "1" ( + FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." ls-files -m"') DO ( + set localChanged=1 + ) +) + +IF [%localChanged%]==[1] ( + set version_modifed=+m +) + :: :: Now form full version string like 1.0.0.1 :: -set new_version=%version_major%,%version_minor%,0,%version_revision% - -:: -:: Detect local modifications -:: -SET localChanged=0 -IF NOT %errlvl% == "1" ( - FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." ls-files -m"') DO ( - SET localChanged=1 - ) -) - -IF [%localChanged%]==[1] ( - IF NOT [%version_specialversion%] == [] ( - set version_specialbuild=%version_specialversion% - ) ELSE ( - set version_specialbuild=m - ) -) ELSE ( - set version_specialbuild= -) +set new_version=%version_major%.%version_minor%.%commitCount%%version_modifed% :: :: Update appversion.h if version has changed or modifications/mixed revisions detected :: -IF NOT "%new_version%"=="%old_version%" goto _update -IF NOT "%version_specialbuild%"==%old_specialbuild% goto _update +IF NOT "%new_version%"=="%old_version%" ( + goto _update +) + goto _exit :_update -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% + +:: +:: Write appversion.h +:: +echo Updating appversion.h, new version is "%new_version%", the old one was %old_version% echo #ifndef __APPVERSION_H__>"%srcdir%\appversion.h" echo #define __APPVERSION_H__>>"%srcdir%\appversion.h" @@ -122,38 +193,19 @@ echo // Don't edit it.>>"%srcdir%\appversion.h" echo // >>"%srcdir%\appversion.h" echo.>>"%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" -) +>>"%srcdir%\appversion.h" echo #define APP_VERSION_C %version_major%,%version_minor%,%commitCount% +echo #define APP_VERSION_STRD "%version_major%.%version_minor%.%commitCount%">>"%srcdir%\appversion.h" +echo #define APP_VERSION_FLAGS 0x0L>>"%srcdir%\appversion.h" echo.>>"%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.>>"%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.>>"%srcdir%\appversion.h" +echo #define APP_COMMIT_DATE "%YYYY%-%DD%-%MM%">>"%srcdir%\appversion.h" +echo #define APP_COMMIT_TIME "%hour%:%min%:%sec%">>"%srcdir%\appversion.h" -IF NOT "%version_specialbuild%" == "" ( - echo #define APP_VERSION_FLAGS VS_FF_SPECIALBUILD>>"%srcdir%\appversion.h" - echo #define APP_VERSION_SPECIALBUILD "%version_specialbuild%">>"%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 #define APP_COMMIT_SHA "%commitSHA%">>"%srcdir%\appversion.h" +echo #define APP_COMMIT_URL "%commitURL%">>"%srcdir%\appversion.h" echo.>>"%srcdir%\appversion.h" echo #endif //__APPVERSION_H__>>"%srcdir%\appversion.h" @@ -163,6 +215,7 @@ echo.>>"%srcdir%\appversion.h" :: Do update of version.cpp file last modify time to force it recompile :: copy /b "%srcdir%\version.cpp"+,, "%srcdir%\version.cpp" +endlocal :_exit -exit /B 0 \ No newline at end of file +exit /B 0 diff --git a/revoice/msvc/ReVoice.def b/revoice/msvc/revoice.def similarity index 100% rename from revoice/msvc/ReVoice.def rename to revoice/msvc/revoice.def diff --git a/revoice/msvc/ReVoice.rc b/revoice/msvc/revoice.rc similarity index 89% rename from revoice/msvc/ReVoice.rc rename to revoice/msvc/revoice.rc index 461778c..4534022 100644 --- a/revoice/msvc/ReVoice.rc +++ b/revoice/msvc/revoice.rc @@ -28,18 +28,18 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL // TEXTINCLUDE // -1 TEXTINCLUDE +1 TEXTINCLUDE BEGIN "resource.h\0" END -2 TEXTINCLUDE +2 TEXTINCLUDE BEGIN "#include ""winres.h""\r\n" "\0" END -3 TEXTINCLUDE +3 TEXTINCLUDE BEGIN "\r\n" "\0" @@ -72,14 +72,14 @@ BEGIN BEGIN BLOCK "041904b0" BEGIN - VALUE "CompanyName", "" + VALUE "CompanyName", "ReHLDS Team" VALUE "FileDescription", "Voice transcoding module for ReHLDS" - VALUE "FileVersion", APP_VERSION_STRD_RC + VALUE "FileVersion", APP_VERSION_STRD VALUE "InternalName", "Revoice" - VALUE "LegalCopyright", "" + VALUE "LegalCopyright", "Copyright (c) 2015" VALUE "OriginalFilename", "revoice_mm.dll" VALUE "ProductName", "Revoice" - VALUE "ProductVersion", APP_VERSION_STRD_RC + VALUE "ProductVersion", APP_VERSION_STRD #if APP_VERSION_FLAGS != 0x0L VALUE "SpecialBuild", APP_VERSION_SPECIALBUILD #endif @@ -87,7 +87,7 @@ BEGIN END BLOCK "VarFileInfo" BEGIN - VALUE "Translation", 0x419, 1200 + VALUE "Translation", 0x0, 1200 END END @@ -105,4 +105,3 @@ END ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED - diff --git a/revoice/msvc/ReVoice.vcxproj b/revoice/msvc/revoice.vcxproj similarity index 97% rename from revoice/msvc/ReVoice.vcxproj rename to revoice/msvc/revoice.vcxproj index abd26c1..a11d68a 100644 --- a/revoice/msvc/ReVoice.vcxproj +++ b/revoice/msvc/revoice.vcxproj @@ -96,15 +96,15 @@ true true - + - + {DAEFE371-7D77-4B72-A8A5-3CD3D1A55786} Win32Proj - ReVoice + revoice 8.1 diff --git a/revoice/msvc/ReVoice.vcxproj.filters b/revoice/msvc/revoice.vcxproj.filters similarity index 95% rename from revoice/msvc/ReVoice.vcxproj.filters rename to revoice/msvc/revoice.vcxproj.filters index 44f58ee..51b6791 100644 --- a/revoice/msvc/ReVoice.vcxproj.filters +++ b/revoice/msvc/revoice.vcxproj.filters @@ -179,7 +179,7 @@ - + version @@ -188,6 +188,6 @@ - + \ No newline at end of file diff --git a/revoice/src/meta_api.cpp b/revoice/src/meta_api.cpp index dc5e1f6..12bc7d0 100644 --- a/revoice/src/meta_api.cpp +++ b/revoice/src/meta_api.cpp @@ -53,8 +53,8 @@ static META_FUNCTIONS gMetaFunctionTable = { plugin_info_t Plugin_info = { META_INTERFACE_VERSION, // ifvers "Revoice", // name - APP_VERSION_STRD, // version - APP_VERSION_YMD_STR, // date + APP_VERSION, // version + APP_COMMIT_DATE, // date "The Legion", // author "", // url "REVOICE", // logtag, all caps please diff --git a/revoice/version/appversion.vm b/revoice/version/appversion.vm index ca01468..d17386a 100644 --- a/revoice/version/appversion.vm +++ b/revoice/version/appversion.vm @@ -7,21 +7,15 @@ // // Version defines -\#define VERSION_MAJOR ${verInfo.majorVersion} -\#define VERSION_MINOR ${verInfo.minorVersion} +\#define APP_VERSION "$verInfo.asMavenVersion()" +\#define APP_VERSION_C $verInfo.asMavenVersion(false, ",") +\#define APP_VERSION_STRD "$verInfo.asMavenVersion(false)" +\#define APP_VERSION_FLAGS 0x0L -\#define APP_VERSION_D ${verInfo.format('.', '-', true)} -\#define APP_VERSION_C ${verInfo.majorVersion},${verInfo.minorVersion},0,${verInfo.countCommit} +\#define APP_COMMIT_DATE "$verInfo.asCommitDate("yyyy-MM-dd")" +\#define APP_COMMIT_TIME "$verInfo.asCommitTime()" -\#define APP_VERSION_STRD "${verInfo.majorVersion}.${verInfo.minorVersion}.${verInfo.countCommit}${formatSpecialVersion}" -\#define APP_VERSION_STRD_RC "${verInfo.majorVersion}.${verInfo.minorVersion}.${verInfo.countCommit}${formatSpecialVersion}" - -\#define APP_VERSION_FLAGS ${appFlags} -\#define APP_VERSION_SPECIALBUILD "${verInfo.specialVersion}" - -#set ( $commitYMD = $_DateTimeFormat.forPattern('yyyy-MM-dd').print($verInfo.lastCommitDate) ) - -\#define APP_VERSION_YMD_STR "${commitYMD}" -\#define APP_VERSION APP_VERSION_STRD +\#define APP_COMMIT_SHA "$verInfo.commitSHA" +\#define APP_COMMIT_URL "$verInfo.commitURL" #endif //__APPVERSION_H__ diff --git a/shared.gradle b/shared.gradle index cc61691..107161f 100644 --- a/shared.gradle +++ b/shared.gradle @@ -11,23 +11,34 @@ apply from: 'shared_icc.gradle' rootProject.ext.createToolchainConfig = { NativeBinarySpec bin -> BinaryKind binaryKind - if (bin instanceof NativeExecutableBinarySpec) { + if (bin instanceof NativeExecutableBinarySpec) + { binaryKind = BinaryKind.EXECUTABLE - } else if (bin instanceof SharedLibraryBinarySpec) { + } + else if (bin instanceof SharedLibraryBinarySpec) + { binaryKind = BinaryKind.SHARED_LIBRARY - } else if (bin instanceof StaticLibraryBinarySpec) { + } + else if (bin instanceof StaticLibraryBinarySpec) + { binaryKind = BinaryKind.STATIC_LIBRARY - } else { + } + else + { throw new RuntimeException("Unknown executable kind ${bin.class.name}") } boolean releaseBuild = bin.buildType.name.toLowerCase() == 'release' - - if (bin.toolChain instanceof VisualCpp) { + if (bin.toolChain instanceof VisualCpp) + { return rootProject.createMsvcConfig(releaseBuild, binaryKind) - } else if (bin.toolChain instanceof Icc) { + } + else if (bin.toolChain instanceof Icc) + { return rootProject.createIccConfig(releaseBuild, binaryKind) - } else { + } + else + { throw new RuntimeException("Unknown native toolchain: ${bin.toolChain.class.name}") } } diff --git a/shared_icc.gradle b/shared_icc.gradle index 9fb7e9d..6244385 100644 --- a/shared_icc.gradle +++ b/shared_icc.gradle @@ -9,26 +9,26 @@ rootProject.ext.createIccConfig = { boolean release, BinaryKind binKind -> compilerOptions: new GccToolchainConfig.CompilerOptions( optimizationLevel: OptimizationLevel.LEVEL_3, stackProtector: false, - interProceduralOptimizations: true, + interProceduralOptimizations: true, // -ipo + noBuiltIn: true, + intelExtensions: false, asmBlocks: true, + positionIndependentCode: false, extraDefines: [ - 'linux': null, - '__linux__': null, - 'NDEBUG': null + '_GLIBCXX_USE_CXX11_ABI': 0, // don't use specific c++11 features from GCC 5.X for backward compatibility to earlier version ABI libstdc++.so.6 ] ), - linkerOptions: new GccToolchainConfig.LinkerOptions( - interProceduralOptimizations: true, + interProceduralOptimizations: true, // -ipo stripSymbolTable: true, - staticLibGcc: true, + staticLibStdCpp: false, + staticLibGcc: false, staticIntel: true, ), - librarianOptions: new GccToolchainConfig.LibrarianOptions( ) ) @@ -39,28 +39,27 @@ rootProject.ext.createIccConfig = { boolean release, BinaryKind binKind -> optimizationLevel: OptimizationLevel.DISABLE, stackProtector: true, interProceduralOptimizations: false, + noBuiltIn: true, intelExtensions: false, asmBlocks: true, extraDefines: [ - 'linux': null, - '__linux__': null, - 'NDEBUG': null + '_ITERATOR_DEBUG_LEVEL': 0, // for std::list, disable debug iterator in debug mode + '_GLIBCXX_USE_CXX11_ABI': 0, // don't use specific c++11 features from GCC 5.X for backward compatibility to earlier version ABI libstdc++.so.6 ] ), - linkerOptions: new GccToolchainConfig.LinkerOptions( interProceduralOptimizations: false, stripSymbolTable: false, - staticLibGcc: true, + staticLibStdCpp: false, + staticLibGcc: false, staticIntel: true, ), - librarianOptions: new GccToolchainConfig.LibrarianOptions( ) ) } - return cfg; + return cfg } diff --git a/shared_msvc.gradle b/shared_msvc.gradle index 3d04183..dc0125a 100644 --- a/shared_msvc.gradle +++ b/shared_msvc.gradle @@ -42,10 +42,8 @@ rootProject.ext.createMsvcConfig = { boolean release, BinaryKind binKind -> 'WIN32': null, '_MBCS': null, 'NDEBUG': null, - 'NOMINMAX': null ] ), - linkerOptions: new MsvcToolchainConfig.LinkerOptions( linkTimeCodeGenKind: LinkTimeCodeGenKind.USE_LTCG, errorReportingMode: ErrorReporting.NO_ERROR_REPORT, @@ -55,13 +53,11 @@ rootProject.ext.createMsvcConfig = { boolean release, BinaryKind binKind -> enableCOMDATFolding: true, generateDebugInfo: true, dataExecutionPrevention: true, - randomizedBaseAddress: true + randomizedBaseAddress: true, ), - librarianOptions: new MsvcToolchainConfig.LibrarianOptions( linkTimeCodeGenKind: LinkTimeCodeGenKind.USE_LTCG ), - generatePdb: true ) } else { @@ -93,10 +89,8 @@ rootProject.ext.createMsvcConfig = { boolean release, BinaryKind binKind -> 'WIN32': null, '_MBCS': null, '_DEBUG': null, - 'NOMINMAX': null, ] ), - linkerOptions: new MsvcToolchainConfig.LinkerOptions( linkTimeCodeGenKind: LinkTimeCodeGenKind.DEFAULT, errorReportingMode: ErrorReporting.NO_ERROR_REPORT, @@ -108,11 +102,9 @@ rootProject.ext.createMsvcConfig = { boolean release, BinaryKind binKind -> dataExecutionPrevention: true, randomizedBaseAddress: true ), - librarianOptions: new MsvcToolchainConfig.LibrarianOptions( linkTimeCodeGenKind: LinkTimeCodeGenKind.USE_LTCG ), - generatePdb: true )