Skip to content

Commit

Permalink
WORKING Add Cronet to main build
Browse files Browse the repository at this point in the history
TODO: adjust CI
  • Loading branch information
ejona86 committed Sep 7, 2019
1 parent ee79444 commit 20cb69c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 17 deletions.
5 changes: 5 additions & 0 deletions COMPILING.md
Expand Up @@ -11,6 +11,11 @@ developers don't have C compilers installed and don't need to run or modify the
codegen, the build can skip it. To skip, create the file
`<project-root>/gradle.properties` and add `skipCodegen=true`.

Some parts of grpc-java depend on Android. Since many Java developers don't have
the Android SDK installed and don't need to run or modify the Android
components, the build can skip it. To skip, create the file
`<project-root>/gradle.properties` and add `skipAndroid=true`.

Then, to build, run:
```
$ ./gradlew build
Expand Down
1 change: 1 addition & 0 deletions build.gradle
@@ -1,4 +1,5 @@
plugins {
id "com.android.library" apply false // Necessary for Android plugin to find its classes
id "com.google.osdetector" apply false
id "me.champeau.gradle.japicmp" apply false
id "net.ltgt.errorprone" apply false
Expand Down
19 changes: 8 additions & 11 deletions cronet/build.gradle
@@ -1,15 +1,9 @@
apply plugin: 'com.android.library'
plugins {
id "com.android.library"
}

description = "gRPC: Cronet Android"

buildscript {
repositories {
google()
jcenter()
}
dependencies { classpath 'com.android.tools.build:gradle:3.3.0' }
}

allprojects {
repositories {
google()
Expand Down Expand Up @@ -39,8 +33,11 @@ android {
}

dependencies {
implementation 'io.grpc:grpc-core:1.24.0-SNAPSHOT' // CURRENT_GRPC_VERSION
testImplementation 'io.grpc:grpc-testing:1.24.0-SNAPSHOT' // CURRENT_GRPC_VERSION
errorprone 'com.google.errorprone:error_prone_core:2.3.3'
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'

implementation project(':grpc-core')
testImplementation project(':grpc-testing')

implementation "org.chromium.net:cronet-embedded:66.3359.158"

Expand Down
1 change: 0 additions & 1 deletion cronet/settings.gradle

This file was deleted.

Expand Up @@ -119,6 +119,7 @@ public final CronetChannelBuilder alwaysUsePut(boolean enable) {
/**
* Not supported for building cronet channel.
*/
@Deprecated
@Override
public final CronetChannelBuilder usePlaintext(boolean skipNegotiation) {
throw new IllegalArgumentException("Plaintext not currently supported");
Expand Down
4 changes: 1 addition & 3 deletions cronet/src/main/java/io/grpc/cronet/CronetClientStream.java
Expand Up @@ -47,10 +47,8 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
Expand Down Expand Up @@ -256,7 +254,7 @@ public void cancel(Status reason) {
class TransportState extends Http2ClientStreamTransportState {
private final Object lock;
@GuardedBy("lock")
private Queue<PendingData> pendingData = new LinkedList<PendingData>();
private Collection<PendingData> pendingData = new ArrayList<PendingData>();
@GuardedBy("lock")
private boolean streamReady;
@GuardedBy("lock")
Expand Down
Expand Up @@ -254,7 +254,7 @@ public void read() {
callback.onReadCompleted(
cronetStream,
info,
(ByteBuffer) createMessageFrame(new String("response1").getBytes(Charset.forName("UTF-8"))),
createMessageFrame(new String("response1").getBytes(Charset.forName("UTF-8"))),
false);
// Haven't request any message, so no callback is called here.
verify(clientListener, times(0)).messagesAvailable(isA(MessageProducer.class));
Expand Down Expand Up @@ -305,7 +305,7 @@ public void streamSucceeded() {
callback.onReadCompleted(
cronetStream,
info,
(ByteBuffer) createMessageFrame(new String("response").getBytes(Charset.forName("UTF-8"))),
createMessageFrame(new String("response").getBytes(Charset.forName("UTF-8"))),
false);
verify(clientListener, times(1)).messagesAvailable(isA(MessageProducer.class));
verify(cronetStream, times(2)).read(isA(ByteBuffer.class));
Expand Down Expand Up @@ -570,6 +570,7 @@ public void reportTrailersWhenTrailersReceivedAfterReadClosed() {
assertEquals(Status.UNAUTHENTICATED.getCode(), status.getCode());
}

@SuppressWarnings("deprecation")
@Test
public void addCronetRequestAnnotation_deprecated() {
Object annotation = new Object();
Expand Down
20 changes: 20 additions & 0 deletions settings.gradle
@@ -1,5 +1,6 @@
pluginManagement {
plugins {
id "com.android.library" version "3.3.0"
id "com.github.johnrengelman.shadow" version "2.0.4"
id "com.github.kt3k.coveralls" version "2.0.1"
id "com.google.osdetector" version "1.4.0"
Expand All @@ -9,6 +10,17 @@ pluginManagement {
id "net.ltgt.errorprone" version "0.8.1"
id "ru.vyarus.animalsniffer" version "1.5.0"
}
resolutionStrategy {
eachPlugin {
if (target.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:${target.version}")
}
}
}
repositories {
gradlePluginPortal()
google()
}
}

rootProject.name = "grpc"
Expand Down Expand Up @@ -62,3 +74,11 @@ if (settings.hasProperty('skipCodegen') && skipCodegen.toBoolean()) {
include ":grpc-compiler"
project(':grpc-compiler').projectDir = "$rootDir/compiler" as File
}

if (settings.hasProperty('skipAndroid') && skipAndroid.toBoolean()) {
println ' * Skipping the build of Android projects because skipAndroid=true'
} else {
println '*** Android SDK is required. To avoid building Android projects, set -PskipAndroid=true'
include ":grpc-cronet"
project(':grpc-cronet').projectDir = "$rootDir/cronet" as File
}

0 comments on commit 20cb69c

Please sign in to comment.