[KeepAnno] Add protobuf compiler and gradle plugin
Bug: b/343389186
Change-Id: Idaf5dd2beda4b740d89ade8a698b32f2c5432704
diff --git a/.gitignore b/.gitignore
index f738441..27d89f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -285,6 +285,8 @@
third_party/proto/test/proto2.tar.gz
third_party/proto/test/proto3
third_party/proto/test/proto3.tar.gz
+third_party/protoc
+third_party/protoc.tar.gz
third_party/r8
third_party/r8.tar.gz
third_party/r8-releases/2.0.74
diff --git a/d8_r8/keepanno/build.gradle.kts b/d8_r8/keepanno/build.gradle.kts
index e58f672..a747444 100644
--- a/d8_r8/keepanno/build.gradle.kts
+++ b/d8_r8/keepanno/build.gradle.kts
@@ -2,14 +2,43 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import com.google.protobuf.gradle.proto
+import com.google.protobuf.gradle.ProtobufExtension
+import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
+
plugins {
`kotlin-dsl`
id("dependencies-plugin")
}
+// It seems like the use of a local maven repo does not allow adding the plugin with the id+version
+// syntax. Also, for some reason the 'protobuf' extension object cannot be directly referenced.
+// This configures the plugin "old style" and pulls out the extension object manually.
+buildscript {
+ dependencies {
+ classpath("com.google.protobuf:protobuf-gradle-plugin:0.9.4")
+ }
+}
+apply(plugin = "com.google.protobuf")
+var os = DefaultNativePlatform.getCurrentOperatingSystem()
+var protobuf = project.extensions.getByName("protobuf") as ProtobufExtension
+protobuf.protoc {
+ if (os.isLinux) {
+ path = getRoot().resolveAll("third_party", "protoc", "linux-x86_64", "bin", "protoc").path
+ } else if (os.isMacOsX) {
+ path = getRoot().resolveAll("third_party", "protoc", "osx-x86_64", "bin", "protoc").path
+ } else {
+ assert(os.isWindows);
+ path = getRoot().resolveAll("third_party", "protoc", "win64", "bin", "protoc.exe").path
+ }
+}
+
java {
sourceSets.main.configure {
java.srcDir(getRoot().resolveAll("src", "keepanno", "java"))
+ proto {
+ srcDir(getRoot().resolveAll("src", "keepanno", "proto"))
+ }
}
sourceCompatibility = JvmCompatibility.sourceCompatibility
targetCompatibility = JvmCompatibility.targetCompatibility
@@ -22,6 +51,7 @@
dependencies {
compileOnly(Deps.asm)
compileOnly(Deps.guava)
+ implementation("com.google.protobuf:protobuf-java:3.19.3")
}
tasks {
diff --git a/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepEdge.java b/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepEdge.java
index e2ce313..607d981 100644
--- a/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepEdge.java
+++ b/src/keepanno/java/com/android/tools/r8/keepanno/ast/KeepEdge.java
@@ -3,6 +3,8 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.keepanno.ast;
+import com.android.tools.r8.keepanno.proto.KeepAnnoProtos;
+
/**
* An edge in the keep graph.
*
@@ -144,6 +146,11 @@
private Builder() {}
+ public Builder applyProto(KeepAnnoProtos.Edge edge) {
+ // TODO(b/343389186): implement this.
+ return this;
+ }
+
public Builder setMetaInfo(KeepEdgeMetaInfo metaInfo) {
this.metaInfo = metaInfo;
return this;
@@ -227,4 +234,8 @@
+ consequences
+ '}';
}
+
+ public void buildProto(KeepAnnoProtos.Edge.Builder builder) {
+ // TODO(b/343389186): implement this.
+ }
}
diff --git a/src/keepanno/proto/keepanno.proto b/src/keepanno/proto/keepanno.proto
new file mode 100644
index 0000000..a4f96d7
--- /dev/null
+++ b/src/keepanno/proto/keepanno.proto
@@ -0,0 +1,56 @@
+// Copyright (c) 2024, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+syntax = "proto3";
+
+package com.android.tools.r8.keepanno.proto;
+
+// All messages are placed under the outer class. This makes it a bit nicer to
+// implement the AST <-> Proto conversions without type conflicts.
+option java_multiple_files = false;
+
+// Descriptive name of the outer class (default would have been `Keepanno`).
+option java_outer_classname = "KeepAnnoProtos";
+
+// Java package consistent with R8 convention.
+option java_package = "com.android.tools.r8.keepanno.proto";
+
+message Version {
+ uint32 major = 1;
+ uint32 minor = 2;
+ uint32 patch = 3;
+}
+
+message Context {
+ oneof context_oneof {
+ string class_descriptor = 1;
+ string method_descriptor = 2;
+ string field_descriptor = 3;
+ }
+}
+
+message MetaInfo {
+ Version version = 1;
+ Context context = 2;
+}
+
+message Declaration {
+ MetaInfo meta_info = 1;
+ oneof decl_oneof {
+ Edge edge = 2;
+ CheckRemoved check_removed = 3;
+ CheckDiscarded check_discarded = 4;
+ }
+}
+
+message CheckRemoved {
+ // TODO(b/343389186): Add content.
+}
+
+message CheckDiscarded {
+ // TODO(b/343389186): Add content.
+}
+
+message Edge {
+ // TODO(b/343389186): Add content.
+}
diff --git a/third_party/dependencies_plugin.tar.gz.sha1 b/third_party/dependencies_plugin.tar.gz.sha1
index d6ec64f..7a7c496 100644
--- a/third_party/dependencies_plugin.tar.gz.sha1
+++ b/third_party/dependencies_plugin.tar.gz.sha1
@@ -1 +1 @@
-ce80383f6ea9554ad1bc99e9be4b5c040a7f7e09
\ No newline at end of file
+a98c3dc84926e632f3c7bd2599bb1c692c26be45
\ No newline at end of file
diff --git a/third_party/protoc.tar.gz.sha1 b/third_party/protoc.tar.gz.sha1
new file mode 100644
index 0000000..dbc9c9e
--- /dev/null
+++ b/third_party/protoc.tar.gz.sha1
@@ -0,0 +1 @@
+aa0e87a89da6cbbe443db5452725dcb643baa5db
\ No newline at end of file
diff --git a/tools/create_local_maven_with_dependencies.py b/tools/create_local_maven_with_dependencies.py
index c3f4819..ca2db6a 100755
--- a/tools/create_local_maven_with_dependencies.py
+++ b/tools/create_local_maven_with_dependencies.py
@@ -35,9 +35,11 @@
ERROR_PRONE_VERSION = '2.18.0'
TESTNG_VERSION = '6.10'
+# keepanno & resource shrinker dependencies
+PROTOBUF_VERSION = '3.19.3'
+
# Resource shrinker dependency versions
AAPT2_PROTO_VERSION = '8.2.0-alpha10-10154469'
-PROTOBUF_VERSION = '3.19.3'
STUDIO_SDK_VERSION = '31.5.0-alpha04'
BUILD_DEPENDENCIES = [
@@ -97,6 +99,7 @@
]
PLUGIN_DEPENDENCIES = [
+ 'com.google.protobuf:protobuf-gradle-plugin:0.9.4',
'org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:pom:4.2.1',
'org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.9.10',
'net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin:pom:3.0.1',