Skip to content

Instantly share code, notes, and snippets.

@astellingwerf
Last active January 7, 2016 15:10
Show Gist options
  • Save astellingwerf/8112ad21dfc0dc53ea89 to your computer and use it in GitHub Desktop.
Save astellingwerf/8112ad21dfc0dc53ea89 to your computer and use it in GitHub Desktop.
Gist of our build script in for Gradle support on https://discuss.gradle.org/t/how-to-copy-output-of-binary-task/10846/10
import groovy.transform.Immutable
import groovy.transform.Memoized
import java.security.MessageDigest
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.*
import static groovyx.net.http.ContentType.*
buildscript {
ext.env = System.getenv()
ext.sys = System.properties
ext.osName = sys['os.name']
ext.osArch = sys['os.arch']
ext.dataModel = Boolean.valueOf(sys['is32']) ? '32' : sys['sun.arch.data.model']
ext.is32 = dataModel.equals('32')
ext.isWindows = osName.toLowerCase().contains('windows')
ext.isAMD64 = 'amd64' == osArch
ext.isSun = osName.equals('SunOS')
ext.isAIX = osName.equals('AIX')
ext.isLinux = osName.equals('Linux')
ext.os = isWindows ? 'Windows' : osName
ext.libPathName = isWindows ? 'PATH' : (isAIX ? 'LIBPATH' : 'LD_LIBRARY_PATH')
ext.libPath = 'lib/Release/'
ext.binPath = 'bin/Release/'
ext.libExtension = isWindows ? 'dll' : 'so'
ext.libExtensions = isWindows ? 'dll lib' : 'so' // TODO: AIX '.a' ?
ext.libPrefix = isWindows ? '' : 'lib'
ext.commonScriptsDir = "$projectDir/common-scripts"
ext.cppDir = 'src/cpp/'
repositories {
maven {
// External repo is required to load the dependencies of this build script
name 'read'
url artifactoryReadURL
}
}
dependencies {
classpath ([group: 'org.hidetake', name: 'gradle-ssh-plugin', version: '0.3.10'],
[group: 'org.codehaus.groovy.modules.http-builder', name: 'http-builder' , version: '+'],
[group: 'org.springframework.build.gradle', name: 'propdeps-plugin', version: '0.0.6'])
}
configurations {
distZips
}
}
//This give clean method on root level. Required to cleanup the build folder on root level
apply plugin: 'base'
task wrapper(type: Wrapper) {
gradleVersion = '2.10'
jarFile = 'common-scripts/gradle/wrapper/gradle-wrapper.jar'
}
subprojects {
logger.info("Configuring: ${project}")
repositories {
maven {
url artifactoryReadURL
}
}
// Expose some methods to plugins in buildSrc as Closures on the extra properties of the project
ext.getOSSpecificProperty = this.&getProperty.curry(project)
ext.toCamelCase = this.&changeCamel.rcurry(false)
ext.toPascalCase = this.&changeCamel.rcurry(true)
apply plugin: 'base'
apply plugin: 'java'
apply plugin: 'c'
apply plugin: 'cpp'
apply plugin: 'eclipse'
defaultTasks 'build'
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext.nativeDir = buildDir
ext.libDir = "$nativeDir/$libPath"
ext.binDir = "$nativeDir/$binPath"
// Workaround for http://issues.gradle.org/browse/GRADLE-1205
configurations.compile.transitive = false
// Hundreds more lines...
// Native model
model {
repositories {
libs(PrebuiltLibraries) {
new File("$projectDir/ext/$osIdentifier").eachDir { dir ->
"$dir.name" {
headers.srcDir "$dir.path/include/"
new File(dir ,'lib').listFiles((java.io.FilenameFilter){d,name -> name.endsWith('.a') }).each { staticLib ->
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = staticLib
}
}
new File(dir ,'lib').listFiles((java.io.FilenameFilter){d,name -> name.endsWith('.so') || name.endsWith('.dll')}).each { sharedLib ->
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = sharedLib
}
}
}
}
}
}
buildTypes {
Debug
Release
}
}
getPropertyList(project, 'native.modules').each { moduleName ->
List wrapperClasses = getPropertyList(project, "native.wrappers.$moduleName")
if (!wrapperClasses.isEmpty()) {
task "generateNativeJavaWrapperFor$moduleName"(type: JavaExec) {
// Code to generate some native wrappers around Java code
}
}
model {
components {
"$moduleName"(NativeLibrarySpec) {
sources {
def headers = {
srcDir "src/cpp/$moduleName/" with {
include getPropertyList(project, "native.headers.$moduleName")
}
file("$projectDir/ext/$osIdentifier/")
.listFiles()
.findAll { it.directory }
.each {
srcDir "${it.path}/include/" with { include '**/*.h' }
}
}
cpp {
source {
srcDir "src/cpp/$moduleName/"
include "**/*.cpp"
getPropertyList(project, "native.cpp.excludes.$moduleName").each {
exclude it
}
}
exportedHeaders(headers)
getPropertyList(project, "native.dependency.components.$moduleName").each {
String[] project_lib_linkage = it.split(':')
lib project: ":${project_lib_linkage[0]}",
library: project_lib_linkage[1],
linkage: project_lib_linkage.length == 3 ? project_lib_linkage[2] : 'shared'
}
getPropertyList(project, "native.dependency.libraries.$moduleName").each {
String[] project_lib_linkage = it.split(':')
lib project: ":${project_lib_linkage[0]}",
library: project_lib_linkage[1],
linkage: project_lib_linkage.length == 3 ? project_lib_linkage[2] : 'shared'
}
if (!wrapperClasses.isEmpty()) {
generatedBy tasks."generateNativeJavaWrapperFor$moduleName"
}
}
c {
source {
srcDir "src/cpp/$moduleName/"
include '**/*.c'
}
exportedHeaders(headers)
getPropertyList(project, "native.dependency.components.$moduleName").each {
String[] project_lib_linkage = it.split(':')
lib project: ":${project_lib_linkage[0]}",
library: project_lib_linkage[1],
linkage: project_lib_linkage.length == 3 ? project_lib_linkage[2] : 'shared'
}
}
}
binaries.all {
if (toolChain in Gcc) {
if (buildType == buildTypes.Debug) {
cCompiler.args '-g'
} else if (buildType == buildTypes.Release) {
cCompiler.args '-O3'
}
}
}
}
}
}
}
model {
tasks {
nativeZip(Zip) {
getPropertyList(project, 'native.libextension', libExtensions).each { libExtension ->
from("$projectDir/ext/$osIdentifier") {
include "*/lib/*.$libExtension*"
if (isWindows) include "*/bin/*.$libExtension*"
// XXX eibxml ships an extra lib as 'iconv.dll', but that should be called 'libiconv.dll'
rename '^(iconv.dll)$', 'lib$1'
}
}
from(cppDir) {
include "**/*.manifest"
into("$libPath")
}
switch (getProperty(project, "native.binary.type.$moduleName")) {
case 'executable':
$.binaries.withType(NativeExecutableBinarySpec).each {
println it
// Attach them all
from it.executable.file
dependsOn it.tasks
}
break
case 'static':
$.binaries.withType(StaticLibraryBinarySpec).each {
println it
// Attach them all
from it.staticLibraryFile
dependsOn it.tasks
}
break
case 'shared':
default:
$.binaries.withType(SharedLibraryBinarySpec).each {
println it
// Attach them all
from it.sharedLibraryFile
dependsOn it.tasks
}
break
}
}
}
}
// Hundreds more lines...
} // End of template for subprojects
// Hundreds more lines...
subprojects {
apply from: "$rootProject.projectDir/common-scripts/resolution-strategy.gradle"
}
// Hundreds more lines...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment