2015-01-16 02:29:05 +08:00
|
|
|
apply plugin: "cpp"
|
2015-04-29 09:14:34 +08:00
|
|
|
apply plugin: "com.google.protobuf"
|
2015-01-16 02:29:05 +08:00
|
|
|
|
2015-01-23 04:31:56 +08:00
|
|
|
description = 'The protoc plugin for gRPC Java'
|
|
|
|
|
2015-01-30 07:00:58 +08:00
|
|
|
buildscript {
|
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
2015-03-12 09:03:31 +08:00
|
|
|
mavenLocal()
|
2015-01-30 07:00:58 +08:00
|
|
|
}
|
|
|
|
dependencies {
|
2015-04-18 01:49:11 +08:00
|
|
|
classpath libraries.protobuf_plugin
|
2015-01-30 07:00:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 09:03:31 +08:00
|
|
|
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) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 03:40:42 +08:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 04:10:28 +08:00
|
|
|
def String arch = rootProject.hasProperty('targetArch') ? rootProject.targetArch : osdetector.arch
|
|
|
|
def boolean vcDisable = rootProject.hasProperty('vcDisable') ? rootProject.vcDisable : false
|
2015-04-30 09:16:15 +08:00
|
|
|
|
2015-03-12 09:03:31 +08:00
|
|
|
model {
|
|
|
|
toolChains {
|
2015-04-30 09:16:15 +08:00
|
|
|
// If you have both VC and Gcc installed, VC will be selected, unless you
|
2015-05-07 04:10:28 +08:00
|
|
|
// set 'vcDisable=true'
|
|
|
|
if (!vcDisable) {
|
2015-04-30 09:16:15 +08:00
|
|
|
visualCpp(VisualCpp) {
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
2015-04-30 09:16:15 +08:00
|
|
|
}
|
|
|
|
gcc(Gcc) {
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
clang(Clang) {
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 09:16:15 +08:00
|
|
|
|
2015-03-12 09:03:31 +08:00
|
|
|
platforms {
|
|
|
|
x86_32 {
|
2015-04-30 09:16:15 +08:00
|
|
|
architecture "x86"
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
x86_64 {
|
|
|
|
architecture "x86_64"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
components {
|
|
|
|
java_plugin(NativeExecutableSpec) {
|
2015-04-30 09:16:15 +08:00
|
|
|
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
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
baseName "$protocPluginBaseName"
|
|
|
|
}
|
2015-04-10 04:11:31 +08:00
|
|
|
}
|
2016-01-27 04:13:06 +08:00
|
|
|
|
|
|
|
binaries {
|
|
|
|
all {
|
|
|
|
if (toolChain in Gcc || toolChain in Clang) {
|
2016-04-12 01:34:15 +08:00
|
|
|
cppCompiler.define("GRPC_VERSION", version)
|
2016-01-27 04:13:06 +08:00
|
|
|
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) {
|
2016-04-12 01:34:15 +08:00
|
|
|
cppCompiler.define("GRPC_VERSION", version)
|
2016-01-27 04:13:06 +08:00
|
|
|
cppCompiler.args "/EHsc", "/MT"
|
|
|
|
if (rootProject.hasProperty('vcProtobufInclude')) {
|
|
|
|
cppCompiler.args "/I${rootProject.vcProtobufInclude}"
|
|
|
|
}
|
|
|
|
linker.args "libprotobuf.lib", "libprotoc.lib"
|
|
|
|
if (rootProject.hasProperty('vcProtobufLibs')) {
|
|
|
|
linker.args "/LIBPATH:${rootProject.vcProtobufLibs}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-16 02:29:05 +08:00
|
|
|
}
|
|
|
|
|
2015-05-08 08:32:31 +08:00
|
|
|
configurations {
|
2016-03-30 05:13:28 +08:00
|
|
|
testLiteCompile
|
2015-05-08 08:32:31 +08:00
|
|
|
testNanoCompile
|
|
|
|
}
|
|
|
|
|
2015-01-30 07:00:58 +08:00
|
|
|
dependencies {
|
2015-04-11 06:40:44 +08:00
|
|
|
testCompile project(':grpc-protobuf'),
|
|
|
|
project(':grpc-stub')
|
2016-03-30 05:13:28 +08:00
|
|
|
testLiteCompile project(':grpc-protobuf-lite'),
|
|
|
|
project(':grpc-stub')
|
2015-05-08 08:32:31 +08:00
|
|
|
testNanoCompile project(':grpc-protobuf-nano'),
|
|
|
|
project(':grpc-stub')
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceSets {
|
2016-03-30 05:13:28 +08:00
|
|
|
testLite {}
|
2015-05-08 08:32:31 +08:00
|
|
|
testNano {
|
|
|
|
proto {
|
|
|
|
setSrcDirs(['src/test/proto'])
|
2015-06-23 07:29:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 05:13:28 +08:00
|
|
|
compileTestLiteJava {
|
2016-03-23 02:31:36 +08:00
|
|
|
// Protobuf-generated Lite produces quite a few warnings.
|
2016-05-25 05:29:52 +08:00
|
|
|
options.compilerArgs = compileTestJava.options.compilerArgs +
|
|
|
|
["-Xlint:-unchecked", "-Xlint:-rawtypes"]
|
|
|
|
}
|
|
|
|
|
|
|
|
compileTestNanoJava {
|
|
|
|
options.compilerArgs = compileTestJava.options.compilerArgs
|
2016-03-23 02:31:36 +08:00
|
|
|
}
|
|
|
|
|
2015-06-23 07:29:30 +08:00
|
|
|
protobuf {
|
|
|
|
protoc {
|
|
|
|
if (project.hasProperty('protoc')) {
|
|
|
|
path = project.protoc
|
|
|
|
} else {
|
|
|
|
artifact = "com.google.protobuf:protoc:${protobufVersion}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
plugins {
|
|
|
|
grpc {
|
|
|
|
path = javaPluginPath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
generateProtoTasks {
|
2016-04-20 00:33:23 +08:00
|
|
|
all().each { task ->
|
|
|
|
task.dependsOn 'java_pluginExecutable'
|
|
|
|
task.inputs.file javaPluginPath
|
|
|
|
}
|
2015-06-23 07:29:30 +08:00
|
|
|
ofSourceSet('test')*.plugins {
|
|
|
|
grpc {}
|
|
|
|
}
|
2016-03-30 05:13:28 +08:00
|
|
|
ofSourceSet('testLite')*.plugins {
|
|
|
|
grpc {
|
|
|
|
option 'lite'
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 07:29:30 +08:00
|
|
|
ofSourceSet('testNano').each { task ->
|
|
|
|
task.builtins {
|
2015-05-08 08:32:31 +08:00
|
|
|
remove java
|
|
|
|
javanano {
|
|
|
|
option 'ignore_services=true'
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 07:29:30 +08:00
|
|
|
task.plugins {
|
2015-05-08 08:32:31 +08:00
|
|
|
grpc {
|
2016-03-30 07:16:21 +08:00
|
|
|
option 'nano'
|
2015-05-08 08:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkstyleTestNano {
|
|
|
|
source = fileTree(dir: "src/testNano", include: "**/*.java")
|
2015-01-30 07:00:58 +08:00
|
|
|
}
|
|
|
|
|
2015-09-02 06:26:48 +08:00
|
|
|
println "*** Building codegen requires Protobuf version ${protobufVersion}"
|
|
|
|
println "*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin"
|
|
|
|
|
2015-03-12 09:03:31 +08:00
|
|
|
task buildArtifacts(type: Copy) {
|
2015-04-30 09:16:15 +08:00
|
|
|
dependsOn 'java_pluginExecutable'
|
2016-01-27 07:30:35 +08:00
|
|
|
from("$buildDir/exe") {
|
2015-03-12 09:03:31 +08:00
|
|
|
if (osdetector.os != 'windows') {
|
|
|
|
rename 'protoc-gen-grpc-java', '$0.exe'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
into artifactStagingPath
|
|
|
|
}
|
|
|
|
|
|
|
|
archivesBaseName = "$protocPluginBaseName"
|
|
|
|
|
|
|
|
artifacts {
|
2016-01-27 07:30:35 +08:00
|
|
|
archives("$artifactStagingPath/java_plugin/${protocPluginBaseName}.exe" as File) {
|
2015-04-30 09:16:15 +08:00
|
|
|
classifier osdetector.os + "-" + arch
|
|
|
|
type "exe"
|
|
|
|
extension "exe"
|
|
|
|
builtBy buildArtifacts
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2016-01-30 09:01:33 +08:00
|
|
|
]*.setFilter {artifact, file ->
|
2015-03-12 09:03:31 +08:00
|
|
|
! (file.getName().endsWith('jar') || file.getName().endsWith('jar.asc'))
|
|
|
|
}
|
|
|
|
|
|
|
|
[
|
|
|
|
uploadArchives.repositories.mavenDeployer,
|
|
|
|
]*.beforeDeployment {
|
2015-04-30 09:16:15 +08:00
|
|
|
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)
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-30 09:01:33 +08:00
|
|
|
[
|
|
|
|
install.repositories.mavenInstaller,
|
|
|
|
uploadArchives.repositories.mavenDeployer,
|
|
|
|
]*.pom*.whenConfigured { pom ->
|
|
|
|
pom.project {
|
|
|
|
// This isn't any sort of Java archive artifact, and OSSRH doesn't enforce
|
|
|
|
// javadoc for 'pom' packages. 'exe' would be a more appropriate packaging
|
|
|
|
// value, but it isn't clear how that will be interpreted. In addition,
|
|
|
|
// 'pom' is typically the value used when building an exe with Maven.
|
|
|
|
packaging = "pom"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 05:13:28 +08:00
|
|
|
def configureTestTask(Task task, String dep, String extraPackage) {
|
|
|
|
test.dependsOn task
|
2016-03-23 02:31:36 +08:00
|
|
|
task.dependsOn "generateTest${dep}Proto"
|
2015-04-18 01:49:11 +08:00
|
|
|
if (osdetector.os != 'windows') {
|
2015-05-08 08:32:31 +08:00
|
|
|
task.executable "diff"
|
2015-03-01 01:59:25 +08:00
|
|
|
} else {
|
2015-05-08 08:32:31 +08:00
|
|
|
task.executable "fc"
|
2015-03-01 01:59:25 +08:00
|
|
|
}
|
|
|
|
// File isn't found on Windows if last slash is forward-slash
|
|
|
|
def slash = System.getProperty("file.separator")
|
2016-03-23 02:31:36 +08:00
|
|
|
task.args "$buildDir/generated/source/proto/test${dep}/grpc/io/grpc/testing/integration${extraPackage}${slash}TestServiceGrpc.java",
|
2016-03-30 05:13:28 +08:00
|
|
|
"$projectDir/src/test${dep}/golden/TestService.java.txt"
|
2015-01-23 04:31:56 +08:00
|
|
|
}
|
2015-02-21 07:03:06 +08:00
|
|
|
|
2015-05-08 08:32:31 +08:00
|
|
|
task testGolden(type: Exec)
|
2016-03-23 02:31:36 +08:00
|
|
|
task testLiteGolden(type: Exec)
|
2015-05-08 08:32:31 +08:00
|
|
|
task testNanoGolden(type: Exec)
|
2016-03-30 05:13:28 +08:00
|
|
|
configureTestTask(testGolden, '', '')
|
|
|
|
configureTestTask(testLiteGolden, 'Lite', '')
|
|
|
|
configureTestTask(testNanoGolden, 'Nano', '/nano')
|