mirror of https://github.com/grpc/grpc-java.git
188 lines
5.3 KiB
Groovy
188 lines
5.3 KiB
Groovy
apply plugin: "cpp"
|
|
apply plugin: "com.google.protobuf"
|
|
|
|
description = 'The protoc plugin for gRPC Java'
|
|
|
|
buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
mavenLocal()
|
|
}
|
|
dependencies {
|
|
classpath libraries.protobuf_plugin
|
|
}
|
|
}
|
|
|
|
def artifactStagingPath = "$buildDir/artifacts" as File
|
|
// Adds space-delimited arguments from the environment variable env to the
|
|
// argList.
|
|
def addEnvArgs = { env, argList ->
|
|
def value = System.getenv(env)
|
|
if (value != null) {
|
|
value.split(' +').each() { it -> argList.add(it) }
|
|
}
|
|
}
|
|
|
|
// Adds corresponding "-l" option to the argList if libName is not found in
|
|
// LDFLAGS. This is only used for Mac because when building for uploadArchives
|
|
// artifacts, we add the ".a" files directly to LDFLAGS and without "-l" in
|
|
// order to get statically linked, otherwise we add the libraries through "-l"
|
|
// so that they can be searched for in default search paths.
|
|
def addLibraryIfNotLinked = { libName, argList ->
|
|
def ldflags = System.env.LDFLAGS
|
|
if (ldflags == null || !ldflags.contains('lib' + libName + '.a')) {
|
|
argList.add('-l' + libName)
|
|
}
|
|
}
|
|
|
|
def String arch = osdetector.arch
|
|
if (System.getProperty('arch')) {
|
|
arch = System.getProperty('arch')
|
|
}
|
|
|
|
model {
|
|
toolChains {
|
|
// If you have both VC and Gcc installed, VC will be selected, unless you
|
|
// use '-Dvc.disable'
|
|
if (System.getProperty('vc.disable') == null) {
|
|
visualCpp(VisualCpp) {
|
|
}
|
|
}
|
|
gcc(Gcc) {
|
|
}
|
|
clang(Clang) {
|
|
}
|
|
}
|
|
|
|
platforms {
|
|
x86_32 {
|
|
architecture "x86"
|
|
}
|
|
x86_64 {
|
|
architecture "x86_64"
|
|
}
|
|
}
|
|
|
|
components {
|
|
java_plugin(NativeExecutableSpec) {
|
|
if (arch in ['x86_32', 'x86_64']) {
|
|
// If arch is not within the defined platforms, we do not specify the
|
|
// targetPlatform so that Gradle will choose what is appropriate.
|
|
targetPlatform arch
|
|
}
|
|
baseName "$protocPluginBaseName"
|
|
}
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
testCompile project(':grpc-protobuf'),
|
|
project(':grpc-stub')
|
|
}
|
|
|
|
binaries.all {
|
|
if (toolChain in Gcc || toolChain in Clang) {
|
|
cppCompiler.args "--std=c++0x"
|
|
addEnvArgs("CXXFLAGS", cppCompiler.args)
|
|
addEnvArgs("CPPFLAGS", cppCompiler.args)
|
|
if (osdetector.os == "osx") {
|
|
cppCompiler.args "-mmacosx-version-min=10.7", "-stdlib=libc++"
|
|
addLibraryIfNotLinked('protoc', linker.args)
|
|
addLibraryIfNotLinked('protobuf', linker.args)
|
|
} else if (osdetector.os == "windows") {
|
|
linker.args "-static", "-lprotoc", "-lprotobuf", "-static-libgcc", "-static-libstdc++", "-s"
|
|
} else {
|
|
// Link protoc, protobuf, libgcc and libstdc++ statically.
|
|
// Link other (system) libraries dynamically.
|
|
// Clang under OSX doesn't support these options.
|
|
linker.args "-Wl,-Bstatic", "-lprotoc", "-lprotobuf", "-static-libgcc", "-static-libstdc++",
|
|
"-Wl,-Bdynamic", "-lpthread", "-s"
|
|
}
|
|
addEnvArgs("LDFLAGS", linker.args)
|
|
} else if (toolChain in VisualCpp) {
|
|
cppCompiler.args "/EHsc", "/MD"
|
|
if (rootProject.hasProperty('vc.protobuf.include')) {
|
|
cppCompiler.args "/I" + rootProject.properties['vc.protobuf.include']
|
|
}
|
|
linker.args "libprotobuf.lib", "libprotoc.lib"
|
|
if (rootProject.hasProperty('vc.protobuf.libs')) {
|
|
linker.args "/LIBPATH:" + rootProject.properties['vc.protobuf.libs']
|
|
}
|
|
}
|
|
}
|
|
|
|
task buildArtifacts(type: Copy) {
|
|
dependsOn 'java_pluginExecutable'
|
|
from("$buildDir/binaries") {
|
|
if (osdetector.os != 'windows') {
|
|
rename 'protoc-gen-grpc-java', '$0.exe'
|
|
}
|
|
}
|
|
into artifactStagingPath
|
|
}
|
|
|
|
archivesBaseName = "$protocPluginBaseName"
|
|
|
|
artifacts {
|
|
archives("$artifactStagingPath/java_pluginExecutable/${protocPluginBaseName}.exe" as File) {
|
|
classifier osdetector.os + "-" + arch
|
|
type "exe"
|
|
extension "exe"
|
|
builtBy buildArtifacts
|
|
}
|
|
}
|
|
|
|
// Exe files are skipped by Maven by default. Override it.
|
|
// Also skip jar files that is generated by the java plugin.
|
|
[
|
|
install.repositories.mavenInstaller,
|
|
uploadArchives.repositories.mavenDeployer,
|
|
]*.addFilter('all') {artifact, file ->
|
|
! (file.getName().endsWith('jar') || file.getName().endsWith('jar.asc'))
|
|
}
|
|
|
|
[
|
|
uploadArchives.repositories.mavenDeployer,
|
|
]*.beforeDeployment {
|
|
def ret = exec {
|
|
executable 'bash'
|
|
args 'check-artifact.sh', osdetector.os, arch
|
|
}
|
|
if (ret.exitValue != 0) {
|
|
throw new GradleException("check-artifact.sh exited with " + ret.exitValue)
|
|
}
|
|
}
|
|
|
|
protobufCodeGenPlugins = ["java_plugin:$javaPluginPath"]
|
|
|
|
project.afterEvaluate {
|
|
generateTestProto.dependsOn 'java_pluginExecutable'
|
|
}
|
|
|
|
// Ignore test for the moment on Windows. It will be easier to run once the
|
|
// gradle protobuf plugin can support nano.
|
|
if (osdetector.os != 'windows') {
|
|
test.dependsOn('testGolden','testNanoGolden')
|
|
}
|
|
|
|
task testGolden(type: Exec, dependsOn: 'generateTestProto') {
|
|
if (osdetector.os != 'windows') {
|
|
executable "diff"
|
|
} else {
|
|
executable "fc"
|
|
}
|
|
// File isn't found on Windows if last slash is forward-slash
|
|
def slash = System.getProperty("file.separator")
|
|
args "$buildDir/generated-sources/test/io/grpc/testing/integration" + slash + "TestServiceGrpc.java",
|
|
"$projectDir/src/test/golden/TestService.java.txt"
|
|
}
|
|
|
|
task testNanoGolden(type: Exec, dependsOn: 'java_pluginExecutable') {
|
|
doFirst {
|
|
temporaryDir.createNewFile();
|
|
}
|
|
|
|
environment 'TEST_TMP_DIR', temporaryDir
|
|
commandLine './src/test/run_nano_test.sh'
|
|
}
|