xref: /aosp_15_r20/external/grpc-grpc-java/compiler/build.gradle (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1*e07d83d3SAndroid Build Coastguard Workerplugins {
2*e07d83d3SAndroid Build Coastguard Worker    id "cpp"
3*e07d83d3SAndroid Build Coastguard Worker    id "java"
4*e07d83d3SAndroid Build Coastguard Worker    id "maven-publish"
5*e07d83d3SAndroid Build Coastguard Worker
6*e07d83d3SAndroid Build Coastguard Worker    id "com.google.protobuf"
7*e07d83d3SAndroid Build Coastguard Worker}
8*e07d83d3SAndroid Build Coastguard Worker
9*e07d83d3SAndroid Build Coastguard Workerdescription = 'The protoc plugin for gRPC Java'
10*e07d83d3SAndroid Build Coastguard Worker
11*e07d83d3SAndroid Build Coastguard Workerdef artifactStagingPath = "$buildDir/artifacts" as File
12*e07d83d3SAndroid Build Coastguard Worker// Adds space-delimited arguments from the environment variable env to the
13*e07d83d3SAndroid Build Coastguard Worker// argList.
14*e07d83d3SAndroid Build Coastguard Workerdef addEnvArgs = { env, argList ->
15*e07d83d3SAndroid Build Coastguard Worker    def value = System.getenv(env)
16*e07d83d3SAndroid Build Coastguard Worker    if (value != null) {
17*e07d83d3SAndroid Build Coastguard Worker        value.split(' +').each() { it -> argList.add(it) }
18*e07d83d3SAndroid Build Coastguard Worker    }
19*e07d83d3SAndroid Build Coastguard Worker}
20*e07d83d3SAndroid Build Coastguard Worker
21*e07d83d3SAndroid Build Coastguard Worker// Adds corresponding "-l" option to the argList if libName is not found in
22*e07d83d3SAndroid Build Coastguard Worker// LDFLAGS. This is only used for Mac because when building for uploadArchives
23*e07d83d3SAndroid Build Coastguard Worker// artifacts, we add the ".a" files directly to LDFLAGS and without "-l" in
24*e07d83d3SAndroid Build Coastguard Worker// order to get statically linked, otherwise we add the libraries through "-l"
25*e07d83d3SAndroid Build Coastguard Worker// so that they can be searched for in default search paths.
26*e07d83d3SAndroid Build Coastguard Workerdef addLibraryIfNotLinked = { libName, argList ->
27*e07d83d3SAndroid Build Coastguard Worker    def ldflags = System.env.LDFLAGS
28*e07d83d3SAndroid Build Coastguard Worker    if (ldflags == null || !ldflags.contains('lib' + libName + '.a')) {
29*e07d83d3SAndroid Build Coastguard Worker        argList.add('-l' + libName)
30*e07d83d3SAndroid Build Coastguard Worker    }
31*e07d83d3SAndroid Build Coastguard Worker}
32*e07d83d3SAndroid Build Coastguard Worker
33*e07d83d3SAndroid Build Coastguard Workerdef String arch = rootProject.hasProperty('targetArch') ? rootProject.targetArch : osdetector.arch
34*e07d83d3SAndroid Build Coastguard Workerdef boolean vcDisable = rootProject.hasProperty('vcDisable') ? rootProject.vcDisable : false
35*e07d83d3SAndroid Build Coastguard Workerdef boolean usingVisualCpp // Whether VisualCpp is actually available and selected
36*e07d83d3SAndroid Build Coastguard Worker
37*e07d83d3SAndroid Build Coastguard Workermodel {
38*e07d83d3SAndroid Build Coastguard Worker    toolChains {
39*e07d83d3SAndroid Build Coastguard Worker        // If you have both VC and Gcc installed, VC will be selected, unless you
40*e07d83d3SAndroid Build Coastguard Worker        // set 'vcDisable=true'
41*e07d83d3SAndroid Build Coastguard Worker        if (!vcDisable) {
42*e07d83d3SAndroid Build Coastguard Worker            visualCpp(VisualCpp) {
43*e07d83d3SAndroid Build Coastguard Worker                // Prefer vcvars-provided environment over registry-discovered environment
44*e07d83d3SAndroid Build Coastguard Worker                def String vsDir = System.getenv("VSINSTALLDIR")
45*e07d83d3SAndroid Build Coastguard Worker                def String winDir = System.getenv("WindowsSdkDir")
46*e07d83d3SAndroid Build Coastguard Worker                if (vsDir != null && winDir != null) {
47*e07d83d3SAndroid Build Coastguard Worker                    installDir = vsDir
48*e07d83d3SAndroid Build Coastguard Worker                    windowsSdkDir = winDir
49*e07d83d3SAndroid Build Coastguard Worker                }
50*e07d83d3SAndroid Build Coastguard Worker            }
51*e07d83d3SAndroid Build Coastguard Worker        }
52*e07d83d3SAndroid Build Coastguard Worker        gcc(Gcc) {
53*e07d83d3SAndroid Build Coastguard Worker            target("ppcle_64") {
54*e07d83d3SAndroid Build Coastguard Worker                cppCompiler.executable = 'powerpc64le-linux-gnu-g++'
55*e07d83d3SAndroid Build Coastguard Worker                linker.executable = 'powerpc64le-linux-gnu-g++'
56*e07d83d3SAndroid Build Coastguard Worker            }
57*e07d83d3SAndroid Build Coastguard Worker            target("aarch_64") {
58*e07d83d3SAndroid Build Coastguard Worker                cppCompiler.executable = 'aarch64-linux-gnu-g++'
59*e07d83d3SAndroid Build Coastguard Worker                linker.executable = 'aarch64-linux-gnu-g++'
60*e07d83d3SAndroid Build Coastguard Worker            }
61*e07d83d3SAndroid Build Coastguard Worker            target("s390_64") {
62*e07d83d3SAndroid Build Coastguard Worker                cppCompiler.executable = 's390x-linux-gnu-g++'
63*e07d83d3SAndroid Build Coastguard Worker                linker.executable = 's390x-linux-gnu-g++'
64*e07d83d3SAndroid Build Coastguard Worker            }
65*e07d83d3SAndroid Build Coastguard Worker            target("loongarch_64")
66*e07d83d3SAndroid Build Coastguard Worker        }
67*e07d83d3SAndroid Build Coastguard Worker        clang(Clang) {
68*e07d83d3SAndroid Build Coastguard Worker        }
69*e07d83d3SAndroid Build Coastguard Worker    }
70*e07d83d3SAndroid Build Coastguard Worker
71*e07d83d3SAndroid Build Coastguard Worker    platforms {
72*e07d83d3SAndroid Build Coastguard Worker        x86_32 { architecture "x86" }
73*e07d83d3SAndroid Build Coastguard Worker        x86_64 { architecture "x86_64" }
74*e07d83d3SAndroid Build Coastguard Worker        ppcle_64 { architecture "ppcle_64" }
75*e07d83d3SAndroid Build Coastguard Worker        aarch_64 { architecture "aarch_64" }
76*e07d83d3SAndroid Build Coastguard Worker        s390_64 { architecture "s390_64" }
77*e07d83d3SAndroid Build Coastguard Worker        loongarch_64 { architecture "loongarch_64" }
78*e07d83d3SAndroid Build Coastguard Worker    }
79*e07d83d3SAndroid Build Coastguard Worker
80*e07d83d3SAndroid Build Coastguard Worker    components {
81*e07d83d3SAndroid Build Coastguard Worker        java_plugin(NativeExecutableSpec) {
82*e07d83d3SAndroid Build Coastguard Worker            if (arch in [
83*e07d83d3SAndroid Build Coastguard Worker                'x86_32',
84*e07d83d3SAndroid Build Coastguard Worker                'x86_64',
85*e07d83d3SAndroid Build Coastguard Worker                'ppcle_64',
86*e07d83d3SAndroid Build Coastguard Worker                'aarch_64',
87*e07d83d3SAndroid Build Coastguard Worker                's390_64',
88*e07d83d3SAndroid Build Coastguard Worker                'loongarch_64'
89*e07d83d3SAndroid Build Coastguard Worker            ]) {
90*e07d83d3SAndroid Build Coastguard Worker                // If arch is not within the defined platforms, we do not specify the
91*e07d83d3SAndroid Build Coastguard Worker                // targetPlatform so that Gradle will choose what is appropriate.
92*e07d83d3SAndroid Build Coastguard Worker                targetPlatform arch
93*e07d83d3SAndroid Build Coastguard Worker            }
94*e07d83d3SAndroid Build Coastguard Worker            baseName "$protocPluginBaseName"
95*e07d83d3SAndroid Build Coastguard Worker        }
96*e07d83d3SAndroid Build Coastguard Worker    }
97*e07d83d3SAndroid Build Coastguard Worker
98*e07d83d3SAndroid Build Coastguard Worker    binaries {
99*e07d83d3SAndroid Build Coastguard Worker        all {
100*e07d83d3SAndroid Build Coastguard Worker            if (toolChain in Gcc || toolChain in Clang) {
101*e07d83d3SAndroid Build Coastguard Worker                cppCompiler.define("GRPC_VERSION", version)
102*e07d83d3SAndroid Build Coastguard Worker                cppCompiler.args "--std=c++0x"
103*e07d83d3SAndroid Build Coastguard Worker                addEnvArgs("CXXFLAGS", cppCompiler.args)
104*e07d83d3SAndroid Build Coastguard Worker                addEnvArgs("CPPFLAGS", cppCompiler.args)
105*e07d83d3SAndroid Build Coastguard Worker                if (osdetector.os == "osx") {
106*e07d83d3SAndroid Build Coastguard Worker                    cppCompiler.args "-mmacosx-version-min=10.7", "-stdlib=libc++"
107*e07d83d3SAndroid Build Coastguard Worker                    addLibraryIfNotLinked('protoc', linker.args)
108*e07d83d3SAndroid Build Coastguard Worker                    addLibraryIfNotLinked('protobuf', linker.args)
109*e07d83d3SAndroid Build Coastguard Worker                } else if (osdetector.os == "windows") {
110*e07d83d3SAndroid Build Coastguard Worker                    linker.args "-static", "-lprotoc", "-lprotobuf", "-static-libgcc", "-static-libstdc++",
111*e07d83d3SAndroid Build Coastguard Worker                            "-s"
112*e07d83d3SAndroid Build Coastguard Worker		  } else if (osdetector.arch == "ppcle_64") {
113*e07d83d3SAndroid Build Coastguard Worker		      linker.args "-Wl,-Bstatic", "-lprotoc", "-lprotobuf", "-Wl,-Bdynamic", "-lpthread", "-s"
114*e07d83d3SAndroid Build Coastguard Worker		  } else {
115*e07d83d3SAndroid Build Coastguard Worker                    // Link protoc, protobuf, libgcc and libstdc++ statically.
116*e07d83d3SAndroid Build Coastguard Worker                    // Link other (system) libraries dynamically.
117*e07d83d3SAndroid Build Coastguard Worker                    // Clang under OSX doesn't support these options.
118*e07d83d3SAndroid Build Coastguard Worker                    linker.args "-Wl,-Bstatic", "-lprotoc", "-lprotobuf", "-static-libgcc",
119*e07d83d3SAndroid Build Coastguard Worker                            "-static-libstdc++",
120*e07d83d3SAndroid Build Coastguard Worker                            "-Wl,-Bdynamic", "-lpthread", "-s"
121*e07d83d3SAndroid Build Coastguard Worker                }
122*e07d83d3SAndroid Build Coastguard Worker                addEnvArgs("LDFLAGS", linker.args)
123*e07d83d3SAndroid Build Coastguard Worker            } else if (toolChain in VisualCpp) {
124*e07d83d3SAndroid Build Coastguard Worker                usingVisualCpp = true
125*e07d83d3SAndroid Build Coastguard Worker                cppCompiler.define("GRPC_VERSION", version)
126*e07d83d3SAndroid Build Coastguard Worker                cppCompiler.args "/EHsc", "/MT"
127*e07d83d3SAndroid Build Coastguard Worker                if (rootProject.hasProperty('vcProtobufInclude')) {
128*e07d83d3SAndroid Build Coastguard Worker                    cppCompiler.args "/I${rootProject.vcProtobufInclude}"
129*e07d83d3SAndroid Build Coastguard Worker                }
130*e07d83d3SAndroid Build Coastguard Worker                linker.args "libprotobuf.lib", "libprotoc.lib"
131*e07d83d3SAndroid Build Coastguard Worker                if (rootProject.hasProperty('vcProtobufLibs')) {
132*e07d83d3SAndroid Build Coastguard Worker                    linker.args "/LIBPATH:${rootProject.vcProtobufLibs}"
133*e07d83d3SAndroid Build Coastguard Worker                }
134*e07d83d3SAndroid Build Coastguard Worker            }
135*e07d83d3SAndroid Build Coastguard Worker        }
136*e07d83d3SAndroid Build Coastguard Worker    }
137*e07d83d3SAndroid Build Coastguard Worker}
138*e07d83d3SAndroid Build Coastguard Worker
139*e07d83d3SAndroid Build Coastguard Workerconfigurations {
140*e07d83d3SAndroid Build Coastguard Worker    testLiteImplementation
141*e07d83d3SAndroid Build Coastguard Worker}
142*e07d83d3SAndroid Build Coastguard Worker
143*e07d83d3SAndroid Build Coastguard Workerdependencies {
144*e07d83d3SAndroid Build Coastguard Worker    testImplementation project(':grpc-protobuf'),
145*e07d83d3SAndroid Build Coastguard Worker            project(':grpc-stub'),
146*e07d83d3SAndroid Build Coastguard Worker            libraries.javax.annotation
147*e07d83d3SAndroid Build Coastguard Worker    testLiteImplementation project(':grpc-protobuf-lite'),
148*e07d83d3SAndroid Build Coastguard Worker            project(':grpc-stub'),
149*e07d83d3SAndroid Build Coastguard Worker            libraries.javax.annotation
150*e07d83d3SAndroid Build Coastguard Worker}
151*e07d83d3SAndroid Build Coastguard Worker
152*e07d83d3SAndroid Build Coastguard WorkersourceSets {
153*e07d83d3SAndroid Build Coastguard Worker    testLite {
154*e07d83d3SAndroid Build Coastguard Worker        proto { setSrcDirs(['src/test/proto']) }
155*e07d83d3SAndroid Build Coastguard Worker    }
156*e07d83d3SAndroid Build Coastguard Worker}
157*e07d83d3SAndroid Build Coastguard Worker
158*e07d83d3SAndroid Build Coastguard Workertasks.named("compileTestJava").configure {
159*e07d83d3SAndroid Build Coastguard Worker    options.errorprone.excludedPaths = ".*/build/generated/source/proto/.*"
160*e07d83d3SAndroid Build Coastguard Worker}
161*e07d83d3SAndroid Build Coastguard Worker
162*e07d83d3SAndroid Build Coastguard Workertasks.named("compileTestLiteJava").configure {
163*e07d83d3SAndroid Build Coastguard Worker    options.compilerArgs = compileTestJava.options.compilerArgs
164*e07d83d3SAndroid Build Coastguard Worker    options.compilerArgs += [
165*e07d83d3SAndroid Build Coastguard Worker        "-Xlint:-cast"
166*e07d83d3SAndroid Build Coastguard Worker    ]
167*e07d83d3SAndroid Build Coastguard Worker    options.errorprone.excludedPaths = ".*/build/generated/source/proto/.*"
168*e07d83d3SAndroid Build Coastguard Worker}
169*e07d83d3SAndroid Build Coastguard Worker
170*e07d83d3SAndroid Build Coastguard Workertasks.named("checkstyleTestLite").configure {
171*e07d83d3SAndroid Build Coastguard Worker    enabled = false
172*e07d83d3SAndroid Build Coastguard Worker}
173*e07d83d3SAndroid Build Coastguard Worker
174*e07d83d3SAndroid Build Coastguard Workerprotobuf {
175*e07d83d3SAndroid Build Coastguard Worker    protoc {
176*e07d83d3SAndroid Build Coastguard Worker        if (project.hasProperty('protoc')) {
177*e07d83d3SAndroid Build Coastguard Worker            path = project.protoc
178*e07d83d3SAndroid Build Coastguard Worker        } else {
179*e07d83d3SAndroid Build Coastguard Worker            artifact = libs.protobuf.protoc.get()
180*e07d83d3SAndroid Build Coastguard Worker        }
181*e07d83d3SAndroid Build Coastguard Worker    }
182*e07d83d3SAndroid Build Coastguard Worker    plugins {
183*e07d83d3SAndroid Build Coastguard Worker        grpc { path = javaPluginPath }
184*e07d83d3SAndroid Build Coastguard Worker    }
185*e07d83d3SAndroid Build Coastguard Worker    generateProtoTasks {
186*e07d83d3SAndroid Build Coastguard Worker        all().configureEach {
187*e07d83d3SAndroid Build Coastguard Worker            dependsOn 'java_pluginExecutable'
188*e07d83d3SAndroid Build Coastguard Worker            inputs.file javaPluginPath
189*e07d83d3SAndroid Build Coastguard Worker        }
190*e07d83d3SAndroid Build Coastguard Worker        ofSourceSet('test').configureEach {
191*e07d83d3SAndroid Build Coastguard Worker            plugins { grpc {} }
192*e07d83d3SAndroid Build Coastguard Worker        }
193*e07d83d3SAndroid Build Coastguard Worker        ofSourceSet('testLite').configureEach {
194*e07d83d3SAndroid Build Coastguard Worker            builtins {
195*e07d83d3SAndroid Build Coastguard Worker                java { option 'lite' }
196*e07d83d3SAndroid Build Coastguard Worker            }
197*e07d83d3SAndroid Build Coastguard Worker            plugins {
198*e07d83d3SAndroid Build Coastguard Worker                grpc { option 'lite' }
199*e07d83d3SAndroid Build Coastguard Worker            }
200*e07d83d3SAndroid Build Coastguard Worker        }
201*e07d83d3SAndroid Build Coastguard Worker    }
202*e07d83d3SAndroid Build Coastguard Worker}
203*e07d83d3SAndroid Build Coastguard Worker
204*e07d83d3SAndroid Build Coastguard Workerprintln "*** Building codegen requires Protobuf version ${libs.versions.protobuf.get()}"
205*e07d83d3SAndroid Build Coastguard Workerprintln "*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin"
206*e07d83d3SAndroid Build Coastguard Worker
207*e07d83d3SAndroid Build Coastguard Workertasks.register("buildArtifacts", Copy) {
208*e07d83d3SAndroid Build Coastguard Worker    dependsOn 'java_pluginExecutable'
209*e07d83d3SAndroid Build Coastguard Worker    from("$buildDir/exe") {
210*e07d83d3SAndroid Build Coastguard Worker        if (osdetector.os != 'windows') {
211*e07d83d3SAndroid Build Coastguard Worker            rename 'protoc-gen-grpc-java', '$0.exe'
212*e07d83d3SAndroid Build Coastguard Worker        }
213*e07d83d3SAndroid Build Coastguard Worker    }
214*e07d83d3SAndroid Build Coastguard Worker    into artifactStagingPath
215*e07d83d3SAndroid Build Coastguard Worker}
216*e07d83d3SAndroid Build Coastguard Worker
217*e07d83d3SAndroid Build Coastguard WorkerarchivesBaseName = "$protocPluginBaseName"
218*e07d83d3SAndroid Build Coastguard Worker
219*e07d83d3SAndroid Build Coastguard Workerdef checkArtifacts = tasks.register("checkArtifacts") {
220*e07d83d3SAndroid Build Coastguard Worker    dependsOn buildArtifacts
221*e07d83d3SAndroid Build Coastguard Worker    doLast {
222*e07d83d3SAndroid Build Coastguard Worker        if (!usingVisualCpp) {
223*e07d83d3SAndroid Build Coastguard Worker            def ret = exec {
224*e07d83d3SAndroid Build Coastguard Worker                executable 'bash'
225*e07d83d3SAndroid Build Coastguard Worker                args 'check-artifact.sh', osdetector.os, arch
226*e07d83d3SAndroid Build Coastguard Worker            }
227*e07d83d3SAndroid Build Coastguard Worker            if (ret.exitValue != 0) {
228*e07d83d3SAndroid Build Coastguard Worker                throw new GradleException("check-artifact.sh exited with " + ret.exitValue)
229*e07d83d3SAndroid Build Coastguard Worker            }
230*e07d83d3SAndroid Build Coastguard Worker        } else {
231*e07d83d3SAndroid Build Coastguard Worker            def exeName = "$artifactStagingPath/java_plugin/${protocPluginBaseName}.exe"
232*e07d83d3SAndroid Build Coastguard Worker            def os = new ByteArrayOutputStream()
233*e07d83d3SAndroid Build Coastguard Worker            def ret = exec {
234*e07d83d3SAndroid Build Coastguard Worker                executable 'dumpbin'
235*e07d83d3SAndroid Build Coastguard Worker                args '/nologo', '/dependents', exeName
236*e07d83d3SAndroid Build Coastguard Worker                standardOutput = os
237*e07d83d3SAndroid Build Coastguard Worker            }
238*e07d83d3SAndroid Build Coastguard Worker            if (ret.exitValue != 0) {
239*e07d83d3SAndroid Build Coastguard Worker                throw new GradleException("dumpbin exited with " + ret.exitValue)
240*e07d83d3SAndroid Build Coastguard Worker            }
241*e07d83d3SAndroid Build Coastguard Worker            def dlls = os.toString() =~ /Image has the following dependencies:\s+(.*)\s+Summary/
242*e07d83d3SAndroid Build Coastguard Worker            if (dlls[0][1] != "KERNEL32.dll") {
243*e07d83d3SAndroid Build Coastguard Worker                throw new Exception("unexpected dll deps: " + dlls[0][1]);
244*e07d83d3SAndroid Build Coastguard Worker            }
245*e07d83d3SAndroid Build Coastguard Worker            os.reset()
246*e07d83d3SAndroid Build Coastguard Worker            ret = exec {
247*e07d83d3SAndroid Build Coastguard Worker                executable 'dumpbin'
248*e07d83d3SAndroid Build Coastguard Worker                args '/nologo', '/headers', exeName
249*e07d83d3SAndroid Build Coastguard Worker                standardOutput = os
250*e07d83d3SAndroid Build Coastguard Worker            }
251*e07d83d3SAndroid Build Coastguard Worker            if (ret.exitValue != 0) {
252*e07d83d3SAndroid Build Coastguard Worker                throw new GradleException("dumpbin exited with " + ret.exitValue)
253*e07d83d3SAndroid Build Coastguard Worker            }
254*e07d83d3SAndroid Build Coastguard Worker            def machine = os.toString() =~ / machine \(([^)]+)\)/
255*e07d83d3SAndroid Build Coastguard Worker            def expectedArch = [x86_32: "x86", x86_64: "x64"][arch]
256*e07d83d3SAndroid Build Coastguard Worker            if (machine[0][1] != expectedArch) {
257*e07d83d3SAndroid Build Coastguard Worker                throw new Exception("unexpected architecture: " + machine[0][1]);
258*e07d83d3SAndroid Build Coastguard Worker            }
259*e07d83d3SAndroid Build Coastguard Worker        }
260*e07d83d3SAndroid Build Coastguard Worker    }
261*e07d83d3SAndroid Build Coastguard Worker}
262*e07d83d3SAndroid Build Coastguard Worker
263*e07d83d3SAndroid Build Coastguard Worker// Exe files are skipped by Maven by default. Override it.
264*e07d83d3SAndroid Build Coastguard Worker// Also skip jar files that is generated by the java plugin.
265*e07d83d3SAndroid Build Coastguard Workerpublishing {
266*e07d83d3SAndroid Build Coastguard Worker    publications {
267*e07d83d3SAndroid Build Coastguard Worker        maven(MavenPublication) {
268*e07d83d3SAndroid Build Coastguard Worker            // Removes all artifacts since grpc-compiler doesn't generates any Jar
269*e07d83d3SAndroid Build Coastguard Worker            artifacts = []
270*e07d83d3SAndroid Build Coastguard Worker            artifactId 'protoc-gen-grpc-java'
271*e07d83d3SAndroid Build Coastguard Worker            artifact("$artifactStagingPath/java_plugin/${protocPluginBaseName}.exe" as File) {
272*e07d83d3SAndroid Build Coastguard Worker                classifier osdetector.os + "-" + arch
273*e07d83d3SAndroid Build Coastguard Worker                extension "exe"
274*e07d83d3SAndroid Build Coastguard Worker                builtBy checkArtifacts
275*e07d83d3SAndroid Build Coastguard Worker            }
276*e07d83d3SAndroid Build Coastguard Worker            pom.withXml {
277*e07d83d3SAndroid Build Coastguard Worker                // This isn't any sort of Java archive artifact, and OSSRH doesn't enforce
278*e07d83d3SAndroid Build Coastguard Worker                // javadoc for 'pom' packages. 'exe' would be a more appropriate packaging
279*e07d83d3SAndroid Build Coastguard Worker                // value, but it isn't clear how that will be interpreted. In addition,
280*e07d83d3SAndroid Build Coastguard Worker                // 'pom' is typically the value used when building an exe with Maven.
281*e07d83d3SAndroid Build Coastguard Worker                asNode().project.packaging*.value = 'pom'
282*e07d83d3SAndroid Build Coastguard Worker            }
283*e07d83d3SAndroid Build Coastguard Worker        }
284*e07d83d3SAndroid Build Coastguard Worker    }
285*e07d83d3SAndroid Build Coastguard Worker}
286*e07d83d3SAndroid Build Coastguard Worker
287*e07d83d3SAndroid Build Coastguard Workerdef configureTestTask(Task task, String dep, String extraPackage, String serviceName) {
288*e07d83d3SAndroid Build Coastguard Worker    test.dependsOn task
289*e07d83d3SAndroid Build Coastguard Worker    task.dependsOn "generateTest${dep}Proto"
290*e07d83d3SAndroid Build Coastguard Worker    if (osdetector.os != 'windows') {
291*e07d83d3SAndroid Build Coastguard Worker        task.executable "diff"
292*e07d83d3SAndroid Build Coastguard Worker        task.args "-u"
293*e07d83d3SAndroid Build Coastguard Worker    } else {
294*e07d83d3SAndroid Build Coastguard Worker        task.executable "fc"
295*e07d83d3SAndroid Build Coastguard Worker    }
296*e07d83d3SAndroid Build Coastguard Worker    // File isn't found on Windows if last slash is forward-slash
297*e07d83d3SAndroid Build Coastguard Worker    def slash = System.getProperty("file.separator")
298*e07d83d3SAndroid Build Coastguard Worker    task.args "$buildDir/generated/source/proto/test${dep}/grpc/io/grpc/testing/compiler${extraPackage}${slash}${serviceName}Grpc.java",
299*e07d83d3SAndroid Build Coastguard Worker            "$projectDir/src/test${dep}/golden/${serviceName}.java.txt"
300*e07d83d3SAndroid Build Coastguard Worker}
301*e07d83d3SAndroid Build Coastguard Worker
302*e07d83d3SAndroid Build Coastguard Workertasks.register("testGolden", Exec) {
303*e07d83d3SAndroid Build Coastguard Worker    configureTestTask(it, '', '', 'TestService')
304*e07d83d3SAndroid Build Coastguard Worker}
305*e07d83d3SAndroid Build Coastguard Workertasks.register("testLiteGolden", Exec) {
306*e07d83d3SAndroid Build Coastguard Worker    configureTestTask(it, 'Lite', '', 'TestService')
307*e07d83d3SAndroid Build Coastguard Worker}
308*e07d83d3SAndroid Build Coastguard Workertasks.register("testDeprecatedGolden", Exec) {
309*e07d83d3SAndroid Build Coastguard Worker    configureTestTask(it, '', '', 'TestDeprecatedService')
310*e07d83d3SAndroid Build Coastguard Worker}
311*e07d83d3SAndroid Build Coastguard Workertasks.register("testDeprecatedLiteGolden", Exec) {
312*e07d83d3SAndroid Build Coastguard Worker    configureTestTask(it, 'Lite', '', 'TestDeprecatedService')
313*e07d83d3SAndroid Build Coastguard Worker}
314