Merge changes Ib62b19c1,I80a6ecd8,I37b9aa96,I4de409b3

* changes:
  c2a: Clean-up no-ops with 'pass'
  c2a: Crate: Don't parse -Wclippy, -D, and -W flags
  c2a: Crate: Parse unquoted rustc args
  c2a: Extend unquote() to single quotes
This commit is contained in:
Treehugger Robot
2022-08-25 18:22:08 +00:00
committed by Gerrit Code Review

View File

@@ -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
@@ -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':
@@ -427,14 +428,17 @@ 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'):
# TODO: Consider storing these to include in the Android.bp.
_ = arg # ignored
elif arg.startswith('-Aclippy') or arg.startswith('-Wclippy'):
pass # TODO: Consider storing these to include in the Android.bp.
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