From 596b3b221688292414b1632de4763b71dd1ec496 Mon Sep 17 00:00:00 2001 From: davidliu Date: Fri, 14 Jun 2024 15:53:16 +0900 Subject: [PATCH] Fix jni prefix patch (#26) * Fix jni prefix patch * Update VERSION * Fix file path * Handle prefixing imported classes --- build/VERSION | 2 +- build/patches/jni_prefix.patch | 70 +++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/build/VERSION b/build/VERSION index 7b2ac60..907ab8a 100644 --- a/build/VERSION +++ b/build/VERSION @@ -1,4 +1,4 @@ WEBRTC_BUILD_VERSION=125.6422.0.0 WEBRTC_VERSION=125.6422.0 WEBRTC_READABLE_VERSION=M125.6422@{#0} -WEBRTC_COMMIT=9225e0498b0457d74cae2a8bb8aa93fbd0e88552 +WEBRTC_COMMIT=46226b524cf2445bbb34e9c0ccfbcfd3bee7e4a9 \ No newline at end of file diff --git a/build/patches/jni_prefix.patch b/build/patches/jni_prefix.patch index f3660fe..a3fa39a 100644 --- a/build/patches/jni_prefix.patch +++ b/build/patches/jni_prefix.patch @@ -266,15 +266,27 @@ index be0ee6ca43b..8f90d4f6c33 100644 sb.append(f"""\ // This file was generated by diff --git a/third_party/jni_zero/java_types.py b/third_party/jni_zero/java_types.py -index 06708f70ab3..65c1b29ee8d 100644 +index 06708f70ab3..a4df349a492 100644 --- a/third_party/jni_zero/java_types.py +++ b/third_party/jni_zero/java_types.py -@@ -129,7 +129,7 @@ class JavaClass: - return JavaClass(f'{prefix}/{self._fqn}', self) +@@ -62,6 +62,7 @@ class JavaClass: + _fqn: str + # This is only meaningful if make_prefix have been called on the original class. + _class_without_prefix: 'JavaClass' = None ++ _prefix: str = None + + def __post_init__(self): + assert '.' not in self._fqn, f'{self._fqn} should have / and $, but not .' +@@ -126,10 +127,10 @@ class JavaClass: + if not prefix: + return self + prefix = prefix.replace('.', '/') +- return JavaClass(f'{prefix}/{self._fqn}', self) ++ return JavaClass(f'{prefix}/{self._fqn}', self, prefix) def make_nested(self, name): - return JavaClass(f'{self._fqn}${name}') -+ return JavaClass(f'{self.class_without_prefix._fqn}${name}') ++ return JavaClass(f'{self.class_without_prefix._fqn}${name}').make_prefixed(self._prefix) @dataclasses.dataclass(frozen=True) @@ -310,17 +322,49 @@ index 46d9619789e..4b7e721f716 100644 _name = get_path_info(_name, "name") + "_jni.h" outputs += [ "$_jni_output_dir/$_name" ] diff --git a/third_party/jni_zero/parse.py b/third_party/jni_zero/parse.py -index 33203b9848e..f627ed0f8ee 100644 +index 33203b9848e..ffd92a2e135 100644 --- a/third_party/jni_zero/parse.py +++ b/third_party/jni_zero/parse.py -@@ -382,7 +382,10 @@ def _do_parse(filename, *, package_prefix): - - if package_prefix: - outer_class = outer_class.make_prefixed(package_prefix) -+ print("inner classes: ") +@@ -342,13 +342,15 @@ _IMPORT_REGEX = re.compile(r'^import\s+([^\s*]+);', flags=re.MULTILINE) + _IMPORT_CLASS_NAME_REGEX = re.compile(r'^(.*?)\.([A-Z].*)') + + +-def _parse_imports(contents): ++def _parse_imports(contents, package_prefix): + # Regex skips static imports as well as wildcard imports. + names = _IMPORT_REGEX.findall(contents) + for name in names: + m = _IMPORT_CLASS_NAME_REGEX.match(name) + if m: + package, class_name = m.groups() ++ if package.startswith('org.webrtc'): ++ package = package_prefix + '.org.webrtc' + yield java_types.JavaClass( + package.replace('.', '/') + '/' + class_name.replace('.', '$')) + +@@ -385,7 +387,7 @@ def _do_parse(filename, *, package_prefix): nested_classes = [c.make_prefixed(package_prefix) for c in nested_classes] -+ for c in nested_classes: -+ print(c.full_name_with_slashes, c.class_without_prefix.full_name_with_slashes) type_resolver = java_types.TypeResolver(outer_class) - for java_class in _parse_imports(contents): +- for java_class in _parse_imports(contents): ++ for java_class in _parse_imports(contents, package_prefix): + type_resolver.add_import(java_class) + for java_class in nested_classes: + type_resolver.add_nested_class(java_class) +@@ -415,6 +417,7 @@ def _do_parse(filename, *, package_prefix): + + + def parse_java_file(filename, *, package_prefix=None): ++ print("parse_java_file: ", filename) + try: + return _do_parse(filename, package_prefix=package_prefix) + except ParseError as e: +@@ -431,6 +434,7 @@ _JAVAP_METHOD_REGEX = re.compile( + + + def parse_javap(filename, contents): ++ print("parse_javap: ", filename) + contents = _remove_generics(contents) + match = _JAVAP_CLASS_REGEX.search(contents) + if not match: +