always open Android source files as UTF-8

Android Studio recommends "you use UTF-8 encoding whenever possible",
so this code assumes the files use UTF-8.  UTF-8 is also the default
encoding on GNU/Linux and macOS.
https://sites.google.com/a/android.com/tools/knownissues/encoding

Windows will probably default to UTF16, since that's the native
encoding for files.  So forcing things to use UTF-8 should help
compatibility.
This commit is contained in:
Hans-Christoph Steiner 2021-06-14 15:38:37 +02:00
parent 0c31c4a5ab
commit 48c4354629
No known key found for this signature in database
GPG key ID: 3E177817BA1B9BFA
5 changed files with 26 additions and 20 deletions

View file

@ -76,7 +76,7 @@ class ScannerTest(unittest.TestCase):
build = fdroidserver.metadata.Build()
build.gradle = [flavor]
regexs = fdroidserver.scanner.get_gradle_compile_commands(build)
with open(f) as fp:
with open(f, encoding='utf-8') as fp:
for line in fp.readlines():
for regex in regexs:
m = regex.match(line)
@ -93,7 +93,7 @@ class ScannerTest(unittest.TestCase):
fdroidserver.scanner.config = None
fdroidserver.scanner.options = mock.Mock()
fdroidserver.scanner.options.json = True
with open('build.gradle', 'w') as fp:
with open('build.gradle', 'w', encoding='utf-8') as fp:
fp.write(
textwrap.dedent(
"""
@ -233,7 +233,7 @@ class ScannerTest(unittest.TestCase):
fp.write('placeholder')
self.assertTrue(os.path.exists(f))
with open('build.xml', 'w') as fp:
with open('build.xml', 'w', encoding='utf-8') as fp:
fp.write(
textwrap.dedent(
"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
@ -288,7 +288,7 @@ class ScannerTest(unittest.TestCase):
fdroidserver.scanner.options = mock.Mock()
build = fdroidserver.metadata.Build()
build.scandelete = ['build.gradle']
with open('build.gradle', 'w') as fp:
with open('build.gradle', 'w', encoding='utf-8') as fp:
fp.write(
textwrap.dedent(
"""