From dde806f72d96562888865317619a3984a4d64472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Wed, 24 Aug 2022 15:46:54 +0100 Subject: [PATCH 1/4] c2a: Extend unquote() to single quotes Bug: 243662244 Test: - Change-Id: I4de409b3135369425f8fa934f490e701505cd55d --- scripts/cargo2android.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cargo2android.py b/scripts/cargo2android.py index 77ddee4ad..8f2ccc638 100755 --- a/scripts/cargo2android.py +++ b/scripts/cargo2android.py @@ -182,7 +182,7 @@ def test_base_name(path): def unquote(s): # remove quotes around str - if s and len(s) > 1 and s[0] == '"' and s[-1] == '"': + if s and len(s) > 1 and s[0] == s[-1] and s[0] in ('"', "'"): return s[1:-1] return s From 435dfe58d18fa344ac1a6df406ee51b906168101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Wed, 24 Aug 2022 15:48:25 +0100 Subject: [PATCH 2/4] c2a: Crate: Parse unquoted rustc args Prevent the script from missing flags (minus-prefixed arguments) due to the CLI argument being quoted (making the "-" its second character). This removes the need to manually unquote the args in the few cases where the code already handles them being in quotes. Bug: 243662244 Test: - Change-Id: I37b9aa96dcbbeb04616bddfca657d066b998d7c7 --- scripts/cargo2android.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/cargo2android.py b/scripts/cargo2android.py index 8f2ccc638..bd412e6cd 100755 --- a/scripts/cargo2android.py +++ b/scripts/cargo2android.py @@ -367,8 +367,9 @@ class Crate(object): """Find important rustc arguments to convert to Android.bp properties.""" self.line_num = line_num self.line = line - args = line.split() # Loop through every argument of rustc. + args = list(map(unquote, line.split())) i = 0 + # Loop through every argument of rustc. while i < len(args): arg = args[i] if arg == '--crate-name': @@ -387,8 +388,8 @@ class Crate(object): self.target = args[i] elif arg == '--cfg': i += 1 - if args[i].startswith('\'feature='): - self.features.append(unquote(args[i].replace('\'feature=', '')[:-1])) + if args[i].startswith('feature='): + self.features.append(unquote(args[i].replace('feature=', ''))) else: self.cfgs.append(args[i]) elif arg == '--extern': @@ -432,7 +433,7 @@ class Crate(object): self.emit_list = arg.replace('--emit=', '') elif arg.startswith('--edition='): self.edition = arg.replace('--edition=', '') - elif arg.startswith('\'-Aclippy'): + elif arg.startswith('-Aclippy'): # TODO: Consider storing these to include in the Android.bp. _ = arg # ignored elif not arg.startswith('-'): From e5342d134ad27e5fc6a30f3351ea7fc8b501edf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Wed, 24 Aug 2022 16:15:16 +0100 Subject: [PATCH 3/4] c2a: Crate: Don't parse -Wclippy, -D, and -W flags Don't fail the generation of the Android.bp file when those flags are encountered. Bug: 243662244 Test: Used on gdbstub, which fixed issues seen in aosp/2191020 Change-Id: I80a6ecd8df7980234552a98ddb1149dc29542ac7 --- scripts/cargo2android.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/cargo2android.py b/scripts/cargo2android.py index bd412e6cd..f8eaeeb4d 100755 --- a/scripts/cargo2android.py +++ b/scripts/cargo2android.py @@ -433,9 +433,13 @@ class Crate(object): self.emit_list = arg.replace('--emit=', '') elif arg.startswith('--edition='): self.edition = arg.replace('--edition=', '') - elif arg.startswith('-Aclippy'): + elif arg.startswith('-Aclippy') or arg.startswith('-Wclippy'): # TODO: Consider storing these to include in the Android.bp. _ = arg # ignored + elif arg.startswith('-W'): + pass # ignored + elif arg.startswith('-D'): + pass # TODO: Consider storing these to include in the Android.bp. elif not arg.startswith('-'): # shorten imported crate main source paths like $HOME/.cargo/ # registry/src/github.com-1ecc6299db9ec823/memchr-2.3.3/src/lib.rs From fd12b5feed7e9c7dd4edf20385a01524088f5b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Wed, 24 Aug 2022 16:19:02 +0100 Subject: [PATCH 4/4] c2a: Clean-up no-ops with 'pass' Bug: 243662244 Test: - Change-Id: Ib62b19c18da7e3a44c74303a72a9c27f9d8b3315 --- scripts/cargo2android.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/cargo2android.py b/scripts/cargo2android.py index f8eaeeb4d..48158fd1e 100755 --- a/scripts/cargo2android.py +++ b/scripts/cargo2android.py @@ -428,14 +428,13 @@ class Crate(object): elif arg == '--out-dir' or arg == '--color': # ignored i += 1 elif arg.startswith('--error-format=') or arg.startswith('--json='): - _ = arg # ignored + pass # ignored elif arg.startswith('--emit='): self.emit_list = arg.replace('--emit=', '') elif arg.startswith('--edition='): self.edition = arg.replace('--edition=', '') elif arg.startswith('-Aclippy') or arg.startswith('-Wclippy'): - # TODO: Consider storing these to include in the Android.bp. - _ = arg # ignored + pass # TODO: Consider storing these to include in the Android.bp. elif arg.startswith('-W'): pass # ignored elif arg.startswith('-D'):