Skip to content

Commit 596b3b2

Browse files
authored
Fix jni prefix patch (#26)
* Fix jni prefix patch * Update VERSION * Fix file path * Handle prefixing imported classes
1 parent 6902cb3 commit 596b3b2

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed

build/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
WEBRTC_BUILD_VERSION=125.6422.0.0
22
WEBRTC_VERSION=125.6422.0
33
WEBRTC_READABLE_VERSION=M125.6422@{#0}
4-
WEBRTC_COMMIT=9225e0498b0457d74cae2a8bb8aa93fbd0e88552
4+
WEBRTC_COMMIT=46226b524cf2445bbb34e9c0ccfbcfd3bee7e4a9

build/patches/jni_prefix.patch

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,27 @@ index be0ee6ca43b..8f90d4f6c33 100644
266266
sb.append(f"""\
267267
// This file was generated by
268268
diff --git a/third_party/jni_zero/java_types.py b/third_party/jni_zero/java_types.py
269-
index 06708f70ab3..65c1b29ee8d 100644
269+
index 06708f70ab3..a4df349a492 100644
270270
--- a/third_party/jni_zero/java_types.py
271271
+++ b/third_party/jni_zero/java_types.py
272-
@@ -129,7 +129,7 @@ class JavaClass:
273-
return JavaClass(f'{prefix}/{self._fqn}', self)
272+
@@ -62,6 +62,7 @@ class JavaClass:
273+
_fqn: str
274+
# This is only meaningful if make_prefix have been called on the original class.
275+
_class_without_prefix: 'JavaClass' = None
276+
+ _prefix: str = None
277+
278+
def __post_init__(self):
279+
assert '.' not in self._fqn, f'{self._fqn} should have / and $, but not .'
280+
@@ -126,10 +127,10 @@ class JavaClass:
281+
if not prefix:
282+
return self
283+
prefix = prefix.replace('.', '/')
284+
- return JavaClass(f'{prefix}/{self._fqn}', self)
285+
+ return JavaClass(f'{prefix}/{self._fqn}', self, prefix)
274286

275287
def make_nested(self, name):
276288
- return JavaClass(f'{self._fqn}${name}')
277-
+ return JavaClass(f'{self.class_without_prefix._fqn}${name}')
289+
+ return JavaClass(f'{self.class_without_prefix._fqn}${name}').make_prefixed(self._prefix)
278290

279291

280292
@dataclasses.dataclass(frozen=True)
@@ -310,17 +322,49 @@ index 46d9619789e..4b7e721f716 100644
310322
_name = get_path_info(_name, "name") + "_jni.h"
311323
outputs += [ "$_jni_output_dir/$_name" ]
312324
diff --git a/third_party/jni_zero/parse.py b/third_party/jni_zero/parse.py
313-
index 33203b9848e..f627ed0f8ee 100644
325+
index 33203b9848e..ffd92a2e135 100644
314326
--- a/third_party/jni_zero/parse.py
315327
+++ b/third_party/jni_zero/parse.py
316-
@@ -382,7 +382,10 @@ def _do_parse(filename, *, package_prefix):
317-
318-
if package_prefix:
319-
outer_class = outer_class.make_prefixed(package_prefix)
320-
+ print("inner classes: ")
328+
@@ -342,13 +342,15 @@ _IMPORT_REGEX = re.compile(r'^import\s+([^\s*]+);', flags=re.MULTILINE)
329+
_IMPORT_CLASS_NAME_REGEX = re.compile(r'^(.*?)\.([A-Z].*)')
330+
331+
332+
-def _parse_imports(contents):
333+
+def _parse_imports(contents, package_prefix):
334+
# Regex skips static imports as well as wildcard imports.
335+
names = _IMPORT_REGEX.findall(contents)
336+
for name in names:
337+
m = _IMPORT_CLASS_NAME_REGEX.match(name)
338+
if m:
339+
package, class_name = m.groups()
340+
+ if package.startswith('org.webrtc'):
341+
+ package = package_prefix + '.org.webrtc'
342+
yield java_types.JavaClass(
343+
package.replace('.', '/') + '/' + class_name.replace('.', '$'))
344+
345+
@@ -385,7 +387,7 @@ def _do_parse(filename, *, package_prefix):
321346
nested_classes = [c.make_prefixed(package_prefix) for c in nested_classes]
322-
+ for c in nested_classes:
323-
+ print(c.full_name_with_slashes, c.class_without_prefix.full_name_with_slashes)
324347

325348
type_resolver = java_types.TypeResolver(outer_class)
326-
for java_class in _parse_imports(contents):
349+
- for java_class in _parse_imports(contents):
350+
+ for java_class in _parse_imports(contents, package_prefix):
351+
type_resolver.add_import(java_class)
352+
for java_class in nested_classes:
353+
type_resolver.add_nested_class(java_class)
354+
@@ -415,6 +417,7 @@ def _do_parse(filename, *, package_prefix):
355+
356+
357+
def parse_java_file(filename, *, package_prefix=None):
358+
+ print("parse_java_file: ", filename)
359+
try:
360+
return _do_parse(filename, package_prefix=package_prefix)
361+
except ParseError as e:
362+
@@ -431,6 +434,7 @@ _JAVAP_METHOD_REGEX = re.compile(
363+
364+
365+
def parse_javap(filename, contents):
366+
+ print("parse_javap: ", filename)
367+
contents = _remove_generics(contents)
368+
match = _JAVAP_CLASS_REGEX.search(contents)
369+
if not match:
370+

0 commit comments

Comments
 (0)