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 {
|
2018-06-12 09:35:18 +08:00
|
|
|
maven { // The google mirror is less flaky than mavenCentral()
|
|
|
|
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
|
2015-03-12 09:03:31 +08:00
|
|
|
mavenLocal()
|
2015-01-30 07:00:58 +08:00
|
|
|
}
|
2018-06-12 09:35:18 +08:00
|
|
|
dependencies { 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 ->
|
2018-06-12 09:35:18 +08:00
|
|
|
def value = System.getenv(env)
|
|
|
|
if (value != null) {
|
|
|
|
value.split(' +').each() { it -> argList.add(it) }
|
|
|
|
}
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
|
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 ->
|
2018-06-12 09:35:18 +08:00
|
|
|
def ldflags = System.env.LDFLAGS
|
|
|
|
if (ldflags == null || !ldflags.contains('lib' + libName + '.a')) {
|
|
|
|
argList.add('-l' + libName)
|
|
|
|
}
|
2015-04-18 03:40:42 +08:00
|
|
|
}
|
|
|
|
|
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
|
2017-12-09 04:36:36 +08:00
|
|
|
def boolean usingVisualCpp // Whether VisualCpp is actually available and selected
|
2015-04-30 09:16:15 +08:00
|
|
|
|
2015-03-12 09:03:31 +08:00
|
|
|
model {
|
2018-06-12 09:35:18 +08:00
|
|
|
toolChains {
|
|
|
|
// If you have both VC and Gcc installed, VC will be selected, unless you
|
|
|
|
// set 'vcDisable=true'
|
|
|
|
if (!vcDisable) {
|
|
|
|
visualCpp(VisualCpp) {
|
|
|
|
// Prefer vcvars-provided environment over registry-discovered environment
|
|
|
|
def String vsDir = System.getenv("VSINSTALLDIR")
|
|
|
|
def String winDir = System.getenv("WindowsSdkDir")
|
|
|
|
if (vsDir != null && winDir != null) {
|
|
|
|
installDir = vsDir
|
|
|
|
windowsSdkDir = winDir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gcc(Gcc) {
|
|
|
|
target("ppcle_64")
|
|
|
|
target("aarch_64")
|
|
|
|
}
|
|
|
|
clang(Clang) {
|
2018-05-17 06:37:24 +08:00
|
|
|
}
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
2015-04-30 09:16:15 +08:00
|
|
|
|
2018-06-12 09:35:18 +08:00
|
|
|
platforms {
|
|
|
|
x86_32 { architecture "x86" }
|
|
|
|
x86_64 { architecture "x86_64" }
|
|
|
|
ppcle_64 { architecture "ppcle_64" }
|
|
|
|
aarch_64 { architecture "aarch_64" }
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
|
2018-06-12 09:35:18 +08:00
|
|
|
components {
|
|
|
|
java_plugin(NativeExecutableSpec) {
|
|
|
|
if (arch in [
|
|
|
|
'x86_32',
|
|
|
|
'x86_64',
|
|
|
|
'ppcle_64',
|
|
|
|
'aarch_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"
|
|
|
|
}
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
2016-01-27 04:13:06 +08:00
|
|
|
|
2018-06-12 09:35:18 +08:00
|
|
|
binaries {
|
|
|
|
all {
|
|
|
|
if (toolChain in Gcc || toolChain in Clang) {
|
|
|
|
cppCompiler.define("GRPC_VERSION", version)
|
|
|
|
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) {
|
|
|
|
usingVisualCpp = true
|
|
|
|
cppCompiler.define("GRPC_VERSION", version)
|
|
|
|
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}"
|
|
|
|
}
|
|
|
|
}
|
2016-01-27 04:13:06 +08:00
|
|
|
}
|
|
|
|
}
|
2015-01-16 02:29:05 +08:00
|
|
|
}
|
|
|
|
|
2015-05-08 08:32:31 +08:00
|
|
|
configurations {
|
2018-06-12 09:35:18 +08:00
|
|
|
testLiteCompile
|
|
|
|
testNanoCompile
|
2015-05-08 08:32:31 +08:00
|
|
|
}
|
|
|
|
|
2015-01-30 07:00:58 +08:00
|
|
|
dependencies {
|
2018-06-12 09:35:18 +08:00
|
|
|
testCompile project(':grpc-protobuf'),
|
2018-10-18 02:49:30 +08:00
|
|
|
project(':grpc-stub'),
|
|
|
|
libraries.javax_annotation
|
2018-06-12 09:35:18 +08:00
|
|
|
testLiteCompile project(':grpc-protobuf-lite'),
|
2018-10-18 02:49:30 +08:00
|
|
|
project(':grpc-stub'),
|
|
|
|
libraries.javax_annotation
|
2018-06-12 09:35:18 +08:00
|
|
|
testNanoCompile project(':grpc-protobuf-nano'),
|
2018-10-18 02:49:30 +08:00
|
|
|
project(':grpc-stub'),
|
|
|
|
libraries.javax_annotation
|
2015-05-08 08:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sourceSets {
|
2018-06-12 09:35:18 +08:00
|
|
|
testLite {
|
|
|
|
proto { setSrcDirs(['src/test/proto']) }
|
2016-05-24 03:05:41 +08:00
|
|
|
}
|
2018-06-12 09:35:18 +08:00
|
|
|
testNano {
|
|
|
|
proto { setSrcDirs(['src/test/proto']) }
|
2015-06-23 07:29:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-26 03:42:59 +08:00
|
|
|
compileTestJava {
|
2018-06-12 09:35:18 +08:00
|
|
|
options.compilerArgs += [
|
2018-12-14 02:17:06 +08:00
|
|
|
"-Xlint:-cast"
|
2018-06-12 09:35:18 +08:00
|
|
|
]
|
2018-12-14 02:17:06 +08:00
|
|
|
options.errorprone.excludedPaths = ".*/build/generated/source/proto/.*"
|
2016-07-26 03:42:59 +08:00
|
|
|
}
|
|
|
|
|
2016-03-30 05:13:28 +08:00
|
|
|
compileTestLiteJava {
|
2018-06-12 09:35:18 +08:00
|
|
|
options.compilerArgs = compileTestJava.options.compilerArgs
|
|
|
|
// Protobuf-generated Lite produces quite a few warnings.
|
|
|
|
options.compilerArgs += [
|
|
|
|
"-Xlint:-rawtypes",
|
|
|
|
"-Xlint:-unchecked",
|
|
|
|
"-Xlint:-fallthrough"
|
|
|
|
]
|
2018-12-14 02:17:06 +08:00
|
|
|
options.errorprone.excludedPaths = ".*/build/generated/source/proto/.*"
|
2016-05-25 05:29:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
compileTestNanoJava {
|
2018-06-12 09:35:18 +08:00
|
|
|
options.compilerArgs = compileTestJava.options.compilerArgs
|
2018-12-14 02:17:06 +08:00
|
|
|
options.errorprone.excludedPaths = ".*/build/generated/source/proto/.*"
|
2016-03-23 02:31:36 +08:00
|
|
|
}
|
|
|
|
|
2015-06-23 07:29:30 +08:00
|
|
|
protobuf {
|
2018-06-12 09:35:18 +08:00
|
|
|
protoc {
|
|
|
|
if (project.hasProperty('protoc')) {
|
|
|
|
path = project.protoc
|
|
|
|
} else {
|
|
|
|
artifact = "com.google.protobuf:protoc:${protocVersion}"
|
|
|
|
}
|
2015-06-23 07:29:30 +08:00
|
|
|
}
|
2018-06-12 09:35:18 +08:00
|
|
|
plugins {
|
|
|
|
javalite {
|
|
|
|
if (project.hasProperty('protoc-gen-javalite')) {
|
|
|
|
path = project['protoc-gen-javalite']
|
|
|
|
} else {
|
|
|
|
artifact = libraries.protoc_lite
|
|
|
|
}
|
2016-07-26 03:42:59 +08:00
|
|
|
}
|
2018-06-12 09:35:18 +08:00
|
|
|
grpc { path = javaPluginPath }
|
2016-03-30 05:13:28 +08:00
|
|
|
}
|
2018-06-12 09:35:18 +08:00
|
|
|
generateProtoTasks {
|
|
|
|
all().each { task ->
|
|
|
|
task.dependsOn 'java_pluginExecutable'
|
|
|
|
task.inputs.file javaPluginPath
|
|
|
|
}
|
|
|
|
ofSourceSet('test')*.plugins { grpc {} }
|
|
|
|
ofSourceSet('testLite')*.each { task ->
|
|
|
|
task.builtins { remove java }
|
|
|
|
task.plugins {
|
|
|
|
javalite {}
|
|
|
|
grpc { option 'lite' }
|
|
|
|
}
|
2015-05-08 08:32:31 +08:00
|
|
|
}
|
2018-06-12 09:35:18 +08:00
|
|
|
ofSourceSet('testNano').each { task ->
|
|
|
|
task.builtins {
|
|
|
|
remove java
|
|
|
|
javanano { option 'ignore_services=true' }
|
|
|
|
}
|
|
|
|
task.plugins { grpc { option 'nano' } }
|
2015-05-08 08:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkstyleTestNano {
|
2018-06-12 09:35:18 +08:00
|
|
|
source = fileTree(dir: "src/testNano", include: "**/*.java")
|
2015-01-30 07:00:58 +08:00
|
|
|
}
|
|
|
|
|
2017-05-24 08:04:51 +08:00
|
|
|
println "*** Building codegen requires Protobuf version ${protocVersion}"
|
2015-09-02 06:26:48 +08:00
|
|
|
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) {
|
2018-06-12 09:35:18 +08:00
|
|
|
dependsOn 'java_pluginExecutable'
|
|
|
|
from("$buildDir/exe") {
|
|
|
|
if (osdetector.os != 'windows') {
|
|
|
|
rename 'protoc-gen-grpc-java', '$0.exe'
|
|
|
|
}
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
2018-06-12 09:35:18 +08:00
|
|
|
into artifactStagingPath
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
archivesBaseName = "$protocPluginBaseName"
|
|
|
|
|
|
|
|
artifacts {
|
2018-06-12 09:35:18 +08:00
|
|
|
archives("$artifactStagingPath/java_plugin/${protocPluginBaseName}.exe" as File) {
|
|
|
|
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.
|
|
|
|
[
|
2018-06-12 09:35:18 +08:00
|
|
|
install.repositories.mavenInstaller,
|
|
|
|
uploadArchives.repositories.mavenDeployer,
|
2016-01-30 09:01:33 +08:00
|
|
|
]*.setFilter {artifact, file ->
|
2018-06-12 09:35:18 +08:00
|
|
|
! (file.getName().endsWith('jar') || file.getName().endsWith('jar.asc'))
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[
|
2018-06-12 09:35:18 +08:00
|
|
|
uploadArchives.repositories.mavenDeployer,
|
2017-12-09 04:36:36 +08:00
|
|
|
]*.beforeDeployment { it ->
|
2018-06-12 09:35:18 +08:00
|
|
|
if (!usingVisualCpp) {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
def exeName = "$artifactStagingPath/java_plugin/${protocPluginBaseName}.exe"
|
|
|
|
def os = new ByteArrayOutputStream()
|
|
|
|
def ret = exec {
|
|
|
|
executable 'dumpbin'
|
|
|
|
args '/nologo', '/dependents', exeName
|
|
|
|
standardOutput = os
|
|
|
|
}
|
|
|
|
if (ret.exitValue != 0) {
|
|
|
|
throw new GradleException("dumpbin exited with " + ret.exitValue)
|
|
|
|
}
|
|
|
|
def dlls = os.toString() =~ /Image has the following dependencies:\s+(.*)\s+Summary/
|
|
|
|
if (dlls[0][1] != "KERNEL32.dll") {
|
|
|
|
throw new Exception("unexpected dll deps: " + dlls[0][1]);
|
|
|
|
}
|
|
|
|
os.reset()
|
|
|
|
ret = exec {
|
|
|
|
executable 'dumpbin'
|
|
|
|
args '/nologo', '/headers', exeName
|
|
|
|
standardOutput = os
|
|
|
|
}
|
|
|
|
if (ret.exitValue != 0) {
|
|
|
|
throw new GradleException("dumpbin exited with " + ret.exitValue)
|
|
|
|
}
|
|
|
|
def machine = os.toString() =~ / machine \(([^)]+)\)/
|
|
|
|
def expectedArch = [x86_32: "x86", x86_64: "x64"][arch]
|
|
|
|
if (machine[0][1] != expectedArch) {
|
|
|
|
throw new Exception("unexpected architecture: " + machine[0][1]);
|
|
|
|
}
|
2017-12-09 04:36:36 +08:00
|
|
|
}
|
2015-03-12 09:03:31 +08:00
|
|
|
}
|
|
|
|
|
2016-01-30 09:01:33 +08:00
|
|
|
[
|
2018-06-12 09:35:18 +08:00
|
|
|
install.repositories.mavenInstaller,
|
|
|
|
uploadArchives.repositories.mavenDeployer,
|
2016-01-30 09:01:33 +08:00
|
|
|
]*.pom*.whenConfigured { pom ->
|
2018-06-12 09:35:18 +08:00
|
|
|
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-01-30 09:01:33 +08:00
|
|
|
}
|
|
|
|
|
2018-08-08 05:24:33 +08:00
|
|
|
def configureTestTask(Task task, String dep, String extraPackage, String serviceName) {
|
2018-06-12 09:35:18 +08:00
|
|
|
test.dependsOn task
|
|
|
|
task.dependsOn "generateTest${dep}Proto"
|
|
|
|
if (osdetector.os != 'windows') {
|
|
|
|
task.executable "diff"
|
|
|
|
task.args "-u"
|
|
|
|
} else {
|
|
|
|
task.executable "fc"
|
|
|
|
}
|
|
|
|
// File isn't found on Windows if last slash is forward-slash
|
|
|
|
def slash = System.getProperty("file.separator")
|
2018-08-08 05:24:33 +08:00
|
|
|
task.args "$buildDir/generated/source/proto/test${dep}/grpc/io/grpc/testing/compiler${extraPackage}${slash}${serviceName}Grpc.java",
|
|
|
|
"$projectDir/src/test${dep}/golden/${serviceName}.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)
|
2018-08-08 05:24:33 +08:00
|
|
|
task testDeprecatedGolden(type: Exec)
|
|
|
|
task testDeprecatedLiteGolden(type: Exec)
|
|
|
|
task testDeprecatedNanoGolden(type: Exec)
|
|
|
|
configureTestTask(testGolden, '', '', 'TestService')
|
|
|
|
configureTestTask(testLiteGolden, 'Lite', '', 'TestService')
|
|
|
|
configureTestTask(testNanoGolden, 'Nano', '/nano', 'TestService')
|
|
|
|
configureTestTask(testDeprecatedGolden, '', '', 'TestDeprecatedService')
|
|
|
|
configureTestTask(testDeprecatedLiteGolden, 'Lite', '', 'TestDeprecatedService')
|
|
|
|
configureTestTask(testDeprecatedNanoGolden, 'Nano', '/nano', 'TestDeprecatedService')
|