-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented gradle build
- Loading branch information
Showing
28 changed files
with
1,465 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
**/msvc/*.suo | ||
**/msvc/*.aps | ||
**/msvc/ipch | ||
**/PublishPath*.txt | ||
**/*.log | ||
|
||
publish | ||
**/appversion.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import versioning.GitVersioner | ||
import versioning.RevoiceVersionInfo | ||
|
||
apply from: 'shared.gradle' | ||
group = 'revoice' | ||
|
||
apply plugin: 'idea' | ||
|
||
idea { | ||
project { | ||
languageLevel = 'JDK_1_7' | ||
} | ||
} | ||
|
||
def gitInfo = GitVersioner.versionForDir(project.rootDir) | ||
if (!gitInfo) { | ||
throw new RuntimeException('Running outside git repository') | ||
} | ||
|
||
RevoiceVersionInfo versionInfo | ||
if (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}") | ||
} | ||
|
||
versionInfo = new RevoiceVersionInfo( | ||
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 | ||
) | ||
} else { | ||
|
||
versionInfo = new RevoiceVersionInfo( | ||
majorVersion: project.majorVersion as int, | ||
minorVersion: project.minorVersion as int, | ||
specialVersion: project.specialVersion, | ||
countCommit: gitInfo.countCommit, | ||
lastCommitDate: gitInfo.lastCommitDate | ||
) | ||
} | ||
|
||
project.ext.revoiceVersionInfo = versionInfo | ||
project.version = versionInfo.asVersion() | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '2.4' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apply plugin: 'groovy' | ||
|
||
repositories { | ||
//mavenLocal() | ||
mavenCentral() | ||
maven { | ||
url 'http://nexus.rehlds.org/nexus/content/repositories/rehlds-releases/' | ||
} | ||
maven { | ||
url 'http://nexus.rehlds.org/nexus/content/repositories/rehlds-snapshots/' | ||
} | ||
} | ||
|
||
dependencies { | ||
compile gradleApi() | ||
compile localGroovy() | ||
compile 'commons-io:commons-io:2.4' | ||
compile 'commons-lang:commons-lang:2.6' | ||
compile 'joda-time:joda-time:2.7' | ||
compile 'org.doomedsociety.gradlecpp:gradle-cpp-plugin:1.2' | ||
compile 'org.eclipse.jgit:org.eclipse.jgit:3.7.0.201502260915-r' | ||
compile 'org.apache.velocity:velocity:1.7' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package gradlecpp | ||
|
||
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 { | ||
|
||
static { | ||
Properties p = new Properties(); | ||
|
||
p.setProperty("resource.loader", "class"); | ||
p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); | ||
p.setProperty("class.resource.loader.path", ""); | ||
|
||
p.setProperty("input.encoding", "UTF-8"); | ||
p.setProperty("output.encoding", "UTF-8"); | ||
|
||
Velocity.init(p); | ||
} | ||
static String renderTemplate(File tplFile, RevoiceVersionInfo 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()) | ||
|
||
velocityContext.put("_DateTimeFormat", DateTimeFormat) | ||
|
||
def sw = new StringWriter() | ||
tpl.merge(velocityContext, sw) | ||
|
||
return sw.toString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package versioning | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.transform.TypeChecked | ||
import org.joda.time.DateTime | ||
|
||
@CompileStatic @TypeChecked | ||
class GitInfo { | ||
DateTime lastCommitDate | ||
String branch | ||
String tag | ||
Integer countCommit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package versioning | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.transform.TypeChecked | ||
import org.eclipse.jgit.api.Git | ||
import org.eclipse.jgit.lib.ObjectId | ||
import org.eclipse.jgit.lib.Repository | ||
import org.eclipse.jgit.revwalk.RevCommit | ||
import org.eclipse.jgit.revwalk.RevWalk | ||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder | ||
import org.joda.time.DateTime | ||
import org.joda.time.DateTimeZone | ||
|
||
@CompileStatic @TypeChecked | ||
class GitVersioner { | ||
|
||
static GitInfo versionForDir(String dir) { | ||
versionForDir(new File(dir)) | ||
} | ||
static int getCountCommit(Repository repo) { | ||
Iterable<RevCommit> commits = Git.wrap(repo).log().call() | ||
int count = 0; | ||
commits.each { | ||
count++; | ||
} | ||
|
||
return count; | ||
} | ||
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) | ||
|
||
int commitCount = getCountCommit(repo); | ||
|
||
String tag = repo.tags.find { kv -> kv.value.objectId == commit.id }?.key | ||
|
||
return new GitInfo( | ||
lastCommitDate: commitDate, | ||
branch: branch, | ||
tag: tag, | ||
countCommit: commitCount | ||
) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
buildSrc/src/main/groovy/versioning/RevoiceVersionInfo.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package versioning | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.transform.ToString | ||
import groovy.transform.TypeChecked | ||
import org.joda.time.DateTime | ||
|
||
@CompileStatic @TypeChecked | ||
@ToString(includeNames = true) | ||
class RevoiceVersionInfo { | ||
int majorVersion | ||
int minorVersion | ||
Integer maintenanceVersion | ||
String specialVersion | ||
Integer countCommit | ||
DateTime lastCommitDate | ||
|
||
String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) { | ||
StringBuilder sb = new StringBuilder() | ||
sb.append(majorVersion).append(versionSeparator).append(minorVersion) | ||
if (maintenanceVersion != null) { | ||
sb.append(versionSeparator).append(maintenanceVersion) | ||
} | ||
|
||
if (specialVersion && includeSuffix) { | ||
sb.append(suffixSeparator).append(specialVersion) | ||
} | ||
|
||
return sb.toString() | ||
} | ||
String asVersion() { | ||
if (specialVersion.length() > 0) { | ||
sprintf("%d.%d.%d-%s", majorVersion, minorVersion, countCommit, specialVersion) | ||
} | ||
else | ||
sprintf("%d.%d.%d", majorVersion, minorVersion, countCommit) | ||
} | ||
String asMavenVersion() { | ||
format('.', '-', true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import org.doomedsociety.gradlecpp.cfg.ToolchainConfig | ||
import org.doomedsociety.gradlecpp.cfg.ToolchainConfigUtils | ||
import org.doomedsociety.gradlecpp.msvc.MsvcToolchainConfig | ||
import org.doomedsociety.gradlecpp.gcc.GccToolchainConfig | ||
import org.doomedsociety.gradlecpp.toolchain.icc.Icc | ||
import org.doomedsociety.gradlecpp.toolchain.icc.IccCompilerPlugin | ||
import org.gradle.nativeplatform.NativeBinarySpec | ||
import org.gradle.nativeplatform.NativeLibrarySpec | ||
import org.gradle.nativeplatform.toolchain.VisualCpp | ||
|
||
apply plugin: 'cpp' | ||
apply plugin: IccCompilerPlugin | ||
|
||
void setupToolchain(NativeBinarySpec b) { | ||
ToolchainConfig cfg = rootProject.createToolchainConfig(b) | ||
|
||
if (cfg instanceof MsvcToolchainConfig) { | ||
cfg.compilerOptions.args '/Ob2', '/Oi', '/GF', '/GR-' | ||
} else if (cfg instanceof GccToolchainConfig) { | ||
cfg.compilerOptions.languageStandard = 'c++0x' | ||
cfg.compilerOptions.args '-msse2', '-fp-model fast=2', '-fomit-frame-pointer', '-fvisibility=hidden', '-fvisibility-inlines-hidden', '-fno-rtti', '-g0', '-s' | ||
} | ||
|
||
ToolchainConfigUtils.apply(project, cfg, b) | ||
} | ||
|
||
model { | ||
buildTypes { | ||
debug | ||
release | ||
} | ||
|
||
platforms { | ||
x86 { | ||
architecture "x86" | ||
} | ||
} | ||
|
||
toolChains { | ||
visualCpp(VisualCpp) { | ||
} | ||
icc(Icc) { | ||
} | ||
} | ||
|
||
components { | ||
silk(NativeLibrarySpec) { | ||
targetPlatform 'x86' | ||
|
||
sources { | ||
silk_src(CppSourceSet) { | ||
source { | ||
srcDir "src" | ||
include "**/*.c" | ||
} | ||
|
||
exportedHeaders { | ||
srcDir "include" | ||
} | ||
} | ||
} | ||
|
||
binaries.all { NativeBinarySpec b -> | ||
project.setupToolchain(b) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import org.doomedsociety.gradlecpp.cfg.ToolchainConfig | ||
import org.doomedsociety.gradlecpp.cfg.ToolchainConfigUtils | ||
import org.doomedsociety.gradlecpp.msvc.MsvcToolchainConfig | ||
import org.doomedsociety.gradlecpp.gcc.GccToolchainConfig | ||
import org.doomedsociety.gradlecpp.toolchain.icc.Icc | ||
import org.doomedsociety.gradlecpp.toolchain.icc.IccCompilerPlugin | ||
import org.gradle.nativeplatform.NativeBinarySpec | ||
import org.gradle.nativeplatform.NativeLibrarySpec | ||
import org.gradle.nativeplatform.toolchain.VisualCpp | ||
|
||
apply plugin: 'cpp' | ||
apply plugin: IccCompilerPlugin | ||
|
||
void setupToolchain(NativeBinarySpec b) { | ||
ToolchainConfig cfg = rootProject.createToolchainConfig(b) | ||
|
||
if (cfg instanceof MsvcToolchainConfig) { | ||
cfg.compilerOptions.args '/Ob2', '/Oi', '/GF', '/GR-' | ||
} else if (cfg instanceof GccToolchainConfig) { | ||
cfg.compilerOptions.languageStandard = 'c++0x' | ||
cfg.compilerOptions.args '-msse2', '-fp-model fast=2', '-fomit-frame-pointer', '-fvisibility=hidden', '-fvisibility-inlines-hidden', '-fno-rtti', '-g0', '-s' | ||
} | ||
|
||
ToolchainConfigUtils.apply(project, cfg, b) | ||
} | ||
|
||
model { | ||
buildTypes { | ||
debug | ||
release | ||
} | ||
|
||
platforms { | ||
x86 { | ||
architecture "x86" | ||
} | ||
} | ||
|
||
toolChains { | ||
visualCpp(VisualCpp) { | ||
} | ||
icc(Icc) { | ||
} | ||
} | ||
|
||
components { | ||
speex(NativeLibrarySpec) { | ||
targetPlatform 'x86' | ||
|
||
sources { | ||
speex_src(CppSourceSet) { | ||
source { | ||
srcDir "src" | ||
include "**/*.c" | ||
} | ||
|
||
exportedHeaders { | ||
srcDir "include" | ||
} | ||
} | ||
} | ||
|
||
binaries.all { NativeBinarySpec b -> | ||
project.setupToolchain(b) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.