Skip to content

Commit

Permalink
[J2KT] Change readable/java/protobuf to use untranspiled Java classes…
Browse files Browse the repository at this point in the history
… for fake protos/fake proto runtime.

Use j2kt_native_import for fake protos/fake proto runtime on J2kt native (matching real protos).

This means we test that message field access (which j2kt rewrites from getter to property read) works with both Kotlin/Native protos (which has only properties) and JavaLite/J2cl protos (which have only getters used via Kotlin/Java interop).

PiperOrigin-RevId: 716621985
  • Loading branch information
Googler authored and copybara-github committed Jan 17, 2025
1 parent e57e3fe commit 4cec33e
Show file tree
Hide file tree
Showing 34 changed files with 372 additions and 1,165 deletions.
65 changes: 47 additions & 18 deletions transpiler/javatests/com/google/j2cl/readable/java/protobuf/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("//build_defs:rules.bzl", "j2kt_jvm_library", "j2kt_native_library")
load("@bazel_tools//tools/build_defs/kotlin/native:rules.bzl", "kt_native_library")
load("//build_defs:rules.bzl", "j2cl_library", "j2kt_native_import")
load("@rules_java//java:defs.bzl", "java_library")
load(
"//transpiler/javatests/com/google/j2cl/readable:readable_example.bzl",
"readable_example",
Expand All @@ -9,34 +11,61 @@ package(
licenses = ["notice"],
)

j2kt_jvm_library(
name = "readable-j2kt-jvm",
srcs = glob([
"*.java",
"*.kt",
]),
# The source files that we want to test. Other files are part of the test fixture.
READABLE_SRCS = [
"Protobuf.java",
]

java_library(
name = "testfixture",
srcs = glob(
["*.java"],
exclude = READABLE_SRCS,
),
deps = [
"//jre/java:javaemul_internal_annotations-j2kt-jvm",
"//third_party:jspecify_annotations-j2kt-jvm",
"//third_party:jspecify_annotations",
],
)

j2kt_native_library(
name = "readable-j2kt-native",
srcs = glob([
"*.java",
"*.kt",
]),
# J2kt-JVM proto dependencies are untranspiled Java libraries
alias(
name = "testfixture-j2kt-jvm",
actual = "testfixture",
)

kt_native_library(
name = "testfixture-kt-native",
srcs = glob(["*.kt"]),
tags = ["manual"],
)

# Kotlin Native proto dependencies are imported Kotlin Native libraries
j2kt_native_import(
name = "testfixture-j2kt-native",
jar = "testfixture",
runtime = "testfixture-kt-native",
tags = ["manual"],
)

# Other transpiled platforms that do not involve Kotlin
j2cl_library(
name = "testfixture-j2cl",
srcs = glob(
["*.java"],
exclude = READABLE_SRCS,
),
experimental_enable_jspecify_support_do_not_enable_without_jspecify_static_checking_or_you_might_cause_an_outage = True,
deps = [
"//jre/java:javaemul_internal_annotations-j2kt-native",
"//third_party:jspecify_annotations-j2kt-native",
"//jre/java:javaemul_internal_annotations-j2cl",
"//third_party:jspecify_annotations-j2cl",
],
)

readable_example(
srcs = glob(["*.java"]),
srcs = READABLE_SRCS,
experimental_enable_jspecify_support_do_not_enable_without_jspecify_static_checking_or_you_might_cause_an_outage = True,
deps = [
":testfixture-j2cl",
"//jre/java:javaemul_internal_annotations-j2cl",
"//third_party:jspecify_annotations-j2cl",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package com.google.protobuf;

import javaemul.internal.annotations.KtNative;

@KtNative
public interface EnumLite {
int getNumber();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package com.google.protobuf;

import javaemul.internal.annotations.KtNative;
import org.jspecify.annotations.NullMarked;

@KtNative
@NullMarked
public class GeneratedMessage {
// Emulates Kotlin property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

import com.google.protobuf.EnumLite;
import com.google.protobuf.Internal.ProtoNonnullApi;
import javaemul.internal.annotations.KtNative;

@KtNative
@ProtoNonnullApi
public enum MyEnum implements EnumLite {
ONE,
TWO;

@Override
public int getNumber() {
throw new RuntimeException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.Internal.ProtoNonnullApi;
import com.google.protobuf.Parser;
import javaemul.internal.annotations.KtNative;
import org.jspecify.annotations.NullMarked;

/**
Expand All @@ -36,7 +35,6 @@
* }</pre>
*/
@ProtoNonnullApi
@KtNative
@NullMarked
public class MyMessage extends GeneratedMessage {
public Parser<MyMessage> getParserForType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
*/
package com.google.protobuf;

import javaemul.internal.annotations.KtNative;
import javaemul.internal.annotations.KtOut;
import org.jspecify.annotations.NullMarked;

@KtNative
@NullMarked
public class Parser<@KtOut T> {}
public class Parser<T> {}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4cec33e

Please sign in to comment.