xref: /aosp_15_r20/external/grpc-grpc-java/core/build.gradle (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1*e07d83d3SAndroid Build Coastguard Workerbuildscript {
2*e07d83d3SAndroid Build Coastguard Worker    dependencies {
3*e07d83d3SAndroid Build Coastguard Worker        classpath 'com.google.guava:guava:30.0-android'
4*e07d83d3SAndroid Build Coastguard Worker    }
5*e07d83d3SAndroid Build Coastguard Worker}
6*e07d83d3SAndroid Build Coastguard Worker
7*e07d83d3SAndroid Build Coastguard Workerplugins {
8*e07d83d3SAndroid Build Coastguard Worker    id "java-library"
9*e07d83d3SAndroid Build Coastguard Worker    id "java-test-fixtures"
10*e07d83d3SAndroid Build Coastguard Worker    id "maven-publish"
11*e07d83d3SAndroid Build Coastguard Worker
12*e07d83d3SAndroid Build Coastguard Worker    id "me.champeau.gradle.japicmp"
13*e07d83d3SAndroid Build Coastguard Worker    id "me.champeau.jmh"
14*e07d83d3SAndroid Build Coastguard Worker    id "ru.vyarus.animalsniffer"
15*e07d83d3SAndroid Build Coastguard Worker}
16*e07d83d3SAndroid Build Coastguard Worker
17*e07d83d3SAndroid Build Coastguard Workerimport static java.nio.charset.StandardCharsets.US_ASCII;
18*e07d83d3SAndroid Build Coastguard Worker
19*e07d83d3SAndroid Build Coastguard Workerimport com.google.common.primitives.Bytes;
20*e07d83d3SAndroid Build Coastguard Worker
21*e07d83d3SAndroid Build Coastguard Workerdescription = 'gRPC: Core'
22*e07d83d3SAndroid Build Coastguard Worker
23*e07d83d3SAndroid Build Coastguard Workerdependencies {
24*e07d83d3SAndroid Build Coastguard Worker    api project(':grpc-api')
25*e07d83d3SAndroid Build Coastguard Worker    implementation libraries.gson,
26*e07d83d3SAndroid Build Coastguard Worker            libraries.android.annotations,
27*e07d83d3SAndroid Build Coastguard Worker            libraries.animalsniffer.annotations,
28*e07d83d3SAndroid Build Coastguard Worker            libraries.errorprone.annotations,
29*e07d83d3SAndroid Build Coastguard Worker            libraries.guava,
30*e07d83d3SAndroid Build Coastguard Worker            libraries.perfmark.api
31*e07d83d3SAndroid Build Coastguard Worker    testFixturesApi libraries.junit
32*e07d83d3SAndroid Build Coastguard Worker    testFixturesImplementation libraries.guava,
33*e07d83d3SAndroid Build Coastguard Worker            libraries.mockito.core,
34*e07d83d3SAndroid Build Coastguard Worker            libraries.truth,
35*e07d83d3SAndroid Build Coastguard Worker            project(':grpc-testing')
36*e07d83d3SAndroid Build Coastguard Worker    testImplementation testFixtures(project(':grpc-context')),
37*e07d83d3SAndroid Build Coastguard Worker            testFixtures(project(':grpc-api')),
38*e07d83d3SAndroid Build Coastguard Worker            project(':grpc-testing'),
39*e07d83d3SAndroid Build Coastguard Worker            project(':grpc-grpclb')
40*e07d83d3SAndroid Build Coastguard Worker    testImplementation (libraries.guava.testlib) {
41*e07d83d3SAndroid Build Coastguard Worker        exclude group: 'junit', module: 'junit'
42*e07d83d3SAndroid Build Coastguard Worker    }
43*e07d83d3SAndroid Build Coastguard Worker
44*e07d83d3SAndroid Build Coastguard Worker    testRuntimeOnly project(':grpc-census')
45*e07d83d3SAndroid Build Coastguard Worker
46*e07d83d3SAndroid Build Coastguard Worker    jmh project(':grpc-testing')
47*e07d83d3SAndroid Build Coastguard Worker
48*e07d83d3SAndroid Build Coastguard Worker    signature libraries.signature.java
49*e07d83d3SAndroid Build Coastguard Worker    signature libraries.signature.android
50*e07d83d3SAndroid Build Coastguard Worker}
51*e07d83d3SAndroid Build Coastguard Worker
52*e07d83d3SAndroid Build Coastguard Workertasks.named("javadoc").configure {
53*e07d83d3SAndroid Build Coastguard Worker    exclude 'io/grpc/internal/**'
54*e07d83d3SAndroid Build Coastguard Worker    exclude 'io/grpc/inprocess/Internal*'
55*e07d83d3SAndroid Build Coastguard Worker    // Disabled until kinda stable.
56*e07d83d3SAndroid Build Coastguard Worker    exclude 'io/grpc/perfmark/**'
57*e07d83d3SAndroid Build Coastguard Worker}
58*e07d83d3SAndroid Build Coastguard Worker
59*e07d83d3SAndroid Build Coastguard Workeranimalsniffer {
60*e07d83d3SAndroid Build Coastguard Worker    // Don't check sourceSets.jmh
61*e07d83d3SAndroid Build Coastguard Worker    sourceSets = [
62*e07d83d3SAndroid Build Coastguard Worker        sourceSets.main,
63*e07d83d3SAndroid Build Coastguard Worker        sourceSets.test
64*e07d83d3SAndroid Build Coastguard Worker    ]
65*e07d83d3SAndroid Build Coastguard Worker}
66*e07d83d3SAndroid Build Coastguard Worker
67*e07d83d3SAndroid Build Coastguard Workercomponents.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
68*e07d83d3SAndroid Build Coastguard Workercomponents.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }
69*e07d83d3SAndroid Build Coastguard Worker
70*e07d83d3SAndroid Build Coastguard Workerimport net.ltgt.gradle.errorprone.CheckSeverity
71*e07d83d3SAndroid Build Coastguard Worker
72*e07d83d3SAndroid Build Coastguard Workerdef replaceBytes(byte[] haystack, byte[] needle, byte[] replacement) {
73*e07d83d3SAndroid Build Coastguard Worker    int i = Bytes.indexOf(haystack, needle);
74*e07d83d3SAndroid Build Coastguard Worker    assert i != -1;
75*e07d83d3SAndroid Build Coastguard Worker    byte[] result = new byte[haystack.length - needle.length + replacement.length];
76*e07d83d3SAndroid Build Coastguard Worker    System.arraycopy(haystack, 0, result, 0, i);
77*e07d83d3SAndroid Build Coastguard Worker    System.arraycopy(replacement, 0, result, i, replacement.length);
78*e07d83d3SAndroid Build Coastguard Worker    System.arraycopy(haystack, i + needle.length, result, i + replacement.length, haystack.length - i - needle.length);
79*e07d83d3SAndroid Build Coastguard Worker    return result;
80*e07d83d3SAndroid Build Coastguard Worker}
81*e07d83d3SAndroid Build Coastguard Worker
82*e07d83d3SAndroid Build Coastguard Workerdef bigEndianShortBytes(int value) {
83*e07d83d3SAndroid Build Coastguard Worker    return [value >> 8, value & 0xFF] as byte[];
84*e07d83d3SAndroid Build Coastguard Worker}
85*e07d83d3SAndroid Build Coastguard Worker
86*e07d83d3SAndroid Build Coastguard Workerdef replaceConstant(File file, String needle, String replacement) {
87*e07d83d3SAndroid Build Coastguard Worker    // CONSTANT_Utf8_info. https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.7
88*e07d83d3SAndroid Build Coastguard Worker    byte[] needleBytes = Bytes.concat(
89*e07d83d3SAndroid Build Coastguard Worker        [1] as byte[], bigEndianShortBytes(needle.length()), needle.getBytes(US_ASCII));
90*e07d83d3SAndroid Build Coastguard Worker    byte[] replacementBytes = Bytes.concat(
91*e07d83d3SAndroid Build Coastguard Worker        [1] as byte[], bigEndianShortBytes(replacement.length()), replacement.getBytes(US_ASCII));
92*e07d83d3SAndroid Build Coastguard Worker    file.setBytes(replaceBytes(file.getBytes(), needleBytes, replacementBytes));
93*e07d83d3SAndroid Build Coastguard Worker}
94*e07d83d3SAndroid Build Coastguard Worker
95*e07d83d3SAndroid Build Coastguard Workerplugins.withId("java") {
96*e07d83d3SAndroid Build Coastguard Worker    tasks.named("compileJava").configure {
97*e07d83d3SAndroid Build Coastguard Worker        doLast {
98*e07d83d3SAndroid Build Coastguard Worker            // Replace value of Signature Attribute.
99*e07d83d3SAndroid Build Coastguard Worker            // https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.9
100*e07d83d3SAndroid Build Coastguard Worker	    //
101*e07d83d3SAndroid Build Coastguard Worker	    // Have new compilations compile against a public class, without breaking the internal
102*e07d83d3SAndroid Build Coastguard Worker	    // ABI for the moment. After giving users some time to recompile, this should be removed
103*e07d83d3SAndroid Build Coastguard Worker	    // and #7211 can continue. When this is removed, at the very least the generics need to
104*e07d83d3SAndroid Build Coastguard Worker	    // be changed to avoid <? extends io.grpc.internal.*>.
105*e07d83d3SAndroid Build Coastguard Worker            project.replaceConstant(
106*e07d83d3SAndroid Build Coastguard Worker                destinationDirectory.file(
107*e07d83d3SAndroid Build Coastguard Worker                    "io/grpc/internal/AbstractManagedChannelImplBuilder.class").get().getAsFile(),
108*e07d83d3SAndroid Build Coastguard Worker                "<T:Lio/grpc/internal/AbstractManagedChannelImplBuilder<TT;>;>Lio/grpc/ManagedChannelBuilder<TT;>;",
109*e07d83d3SAndroid Build Coastguard Worker                "<T:Lio/grpc/ManagedChannelBuilder<TT;>;>Lio/grpc/ManagedChannelBuilder<TT;>;");
110*e07d83d3SAndroid Build Coastguard Worker            project.replaceConstant(
111*e07d83d3SAndroid Build Coastguard Worker                destinationDirectory.file(
112*e07d83d3SAndroid Build Coastguard Worker                    "io/grpc/internal/AbstractServerImplBuilder.class").get().getAsFile(),
113*e07d83d3SAndroid Build Coastguard Worker                "<T:Lio/grpc/internal/AbstractServerImplBuilder<TT;>;>Lio/grpc/ServerBuilder<TT;>;",
114*e07d83d3SAndroid Build Coastguard Worker                "<T:Lio/grpc/ServerBuilder<TT;>;>Lio/grpc/ServerBuilder<TT;>;");
115*e07d83d3SAndroid Build Coastguard Worker        }
116*e07d83d3SAndroid Build Coastguard Worker    }
117*e07d83d3SAndroid Build Coastguard Worker}
118*e07d83d3SAndroid Build Coastguard Worker
119*e07d83d3SAndroid Build Coastguard Workertasks.register("versionFile") {
120*e07d83d3SAndroid Build Coastguard Worker    doLast {
121*e07d83d3SAndroid Build Coastguard Worker        new File(buildDir, "version").write("${project.version}\n")
122*e07d83d3SAndroid Build Coastguard Worker    }
123*e07d83d3SAndroid Build Coastguard Worker}
124