mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-01 08:40:11 +02:00
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:
parent
0c31c4a5ab
commit
48c4354629
@ -1633,6 +1633,10 @@ def parse_androidmanifests(paths, app):
|
|||||||
Extract some information from the AndroidManifest.xml at the given path.
|
Extract some information from the AndroidManifest.xml at the given path.
|
||||||
Returns (version, vercode, package), any or all of which might be None.
|
Returns (version, vercode, package), any or all of which might be None.
|
||||||
All values returned are strings.
|
All values returned are strings.
|
||||||
|
|
||||||
|
Android Studio recommends "you use UTF-8 encoding whenever possible", so
|
||||||
|
this code assumes the files use UTF-8.
|
||||||
|
https://sites.google.com/a/android.com/tools/knownissues/encoding
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ignoreversions = app.UpdateCheckIgnore
|
ignoreversions = app.UpdateCheckIgnore
|
||||||
@ -1663,7 +1667,7 @@ def parse_androidmanifests(paths, app):
|
|||||||
flavour = app['Builds'][-1].gradle[-1]
|
flavour = app['Builds'][-1].gradle[-1]
|
||||||
|
|
||||||
if path.endswith('.gradle') or path.endswith('.gradle.kts'):
|
if path.endswith('.gradle') or path.endswith('.gradle.kts'):
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r', encoding='utf-8') as f:
|
||||||
android_plugin_file = False
|
android_plugin_file = False
|
||||||
inside_flavour_group = 0
|
inside_flavour_group = 0
|
||||||
inside_required_flavour = 0
|
inside_required_flavour = 0
|
||||||
@ -1864,7 +1868,7 @@ def get_gradle_subdir(build_dir, paths):
|
|||||||
if path.exists() and SETTINGS_GRADLE_REGEX.match(str(path.name)):
|
if path.exists() and SETTINGS_GRADLE_REGEX.match(str(path.name)):
|
||||||
for m in GRADLE_SUBPROJECT_REGEX.finditer(path.read_text(encoding='utf-8')):
|
for m in GRADLE_SUBPROJECT_REGEX.finditer(path.read_text(encoding='utf-8')):
|
||||||
for f in (path.parent / m.group(1)).glob('build.gradle*'):
|
for f in (path.parent / m.group(1)).glob('build.gradle*'):
|
||||||
with f.open() as fp:
|
with f.open(encoding='utf-8') as fp:
|
||||||
for line in fp.readlines():
|
for line in fp.readlines():
|
||||||
if ANDROID_PLUGIN_REGEX.match(line):
|
if ANDROID_PLUGIN_REGEX.match(line):
|
||||||
return f.parent.relative_to(build_dir)
|
return f.parent.relative_to(build_dir)
|
||||||
|
@ -1021,7 +1021,7 @@ def copy_triple_t_store_metadata(apps):
|
|||||||
sg_list = glob.glob(os.path.join('build', packageName, 'settings.gradle*'))
|
sg_list = glob.glob(os.path.join('build', packageName, 'settings.gradle*'))
|
||||||
if sg_list:
|
if sg_list:
|
||||||
settings_gradle = sg_list[0]
|
settings_gradle = sg_list[0]
|
||||||
with open(settings_gradle) as fp:
|
with open(settings_gradle, encoding='utf-8') as fp:
|
||||||
data = fp.read()
|
data = fp.read()
|
||||||
for matches in setting_gradle_pattern.findall(data):
|
for matches in setting_gradle_pattern.findall(data):
|
||||||
for m in matches:
|
for m in matches:
|
||||||
|
@ -339,12 +339,12 @@ class BuildTest(unittest.TestCase):
|
|||||||
|
|
||||||
os.mkdir('build')
|
os.mkdir('build')
|
||||||
os.mkdir('build/reports')
|
os.mkdir('build/reports')
|
||||||
with open('build.gradle', 'w') as fp:
|
with open('build.gradle', 'w', encoding='utf-8') as fp:
|
||||||
fp.write('// placeholder')
|
fp.write('// placeholder')
|
||||||
|
|
||||||
os.mkdir('bin')
|
os.mkdir('bin')
|
||||||
os.mkdir('gen')
|
os.mkdir('gen')
|
||||||
with open('build.xml', 'w') as fp:
|
with open('build.xml', 'w', encoding='utf-8') as fp:
|
||||||
fp.write(
|
fp.write(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
@ -315,14 +315,15 @@ class CommonTest(unittest.TestCase):
|
|||||||
fdroidserver.common.prepare_source(FakeVcs(), app, build,
|
fdroidserver.common.prepare_source(FakeVcs(), app, build,
|
||||||
fdroidclient_testdir, fdroidclient_testdir, fdroidclient_testdir)
|
fdroidclient_testdir, fdroidclient_testdir, fdroidclient_testdir)
|
||||||
|
|
||||||
with open(os.path.join(fdroidclient_testdir, 'build.gradle'), 'r') as f:
|
fdroidclient_testdir = Path(fdroidclient_testdir)
|
||||||
filedata = f.read()
|
build_gradle = fdroidclient_testdir / 'build.gradle'
|
||||||
|
filedata = build_gradle.read_text(encoding='utf-8')
|
||||||
self.assertIsNotNone(
|
self.assertIsNotNone(
|
||||||
re.search(r"\s+compileSdkVersion %s\s+" % testint, filedata)
|
re.search(r"\s+compileSdkVersion %s\s+" % testint, filedata)
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(os.path.join(fdroidclient_testdir, 'AndroidManifest.xml')) as f:
|
androidmanifest_xml = fdroidclient_testdir / 'AndroidManifest.xml'
|
||||||
filedata = f.read()
|
filedata = androidmanifest_xml.read_text(encoding='utf-8')
|
||||||
self.assertIsNone(re.search('android:debuggable', filedata))
|
self.assertIsNone(re.search('android:debuggable', filedata))
|
||||||
self.assertIsNotNone(
|
self.assertIsNotNone(
|
||||||
re.search('android:versionName="%s"' % build.versionName, filedata)
|
re.search('android:versionName="%s"' % build.versionName, filedata)
|
||||||
@ -342,10 +343,10 @@ class CommonTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
subdir = 'baz/bar'
|
subdir = 'baz/bar'
|
||||||
subdir_path = os.path.join(app_build_dir, subdir)
|
subdir_path = Path(app_build_dir) / subdir
|
||||||
os.makedirs(subdir_path)
|
subdir_path.mkdir(parents=True, exist_ok=True)
|
||||||
with open(os.path.join(subdir_path, 'build.gradle'), 'w') as fp:
|
build_gradle = subdir_path / 'build.gradle'
|
||||||
fp.write('// just a test placeholder')
|
build_gradle.write_text('// just a test placeholder', encoding='utf-8')
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
@ -921,7 +922,7 @@ class CommonTest(unittest.TestCase):
|
|||||||
self.assertNotEqual(0, len(files))
|
self.assertNotEqual(0, len(files))
|
||||||
for f in files:
|
for f in files:
|
||||||
appid, versionCode = os.path.splitext(os.path.basename(f))[0][12:].split('_')
|
appid, versionCode = os.path.splitext(os.path.basename(f))[0][12:].split('_')
|
||||||
with open(f) as fp:
|
with open(f, encoding='utf-8') as fp:
|
||||||
m = fdroidserver.common.APK_ID_TRIPLET_REGEX.match(fp.read())
|
m = fdroidserver.common.APK_ID_TRIPLET_REGEX.match(fp.read())
|
||||||
if m:
|
if m:
|
||||||
self.assertEqual(appid, m.group(1))
|
self.assertEqual(appid, m.group(1))
|
||||||
@ -962,6 +963,7 @@ class CommonTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_sdkversions_androguard(self):
|
def test_get_sdkversions_androguard(self):
|
||||||
"""This is a sanity test that androguard isn't broken"""
|
"""This is a sanity test that androguard isn't broken"""
|
||||||
|
|
||||||
def get_minSdkVersion(apkfile):
|
def get_minSdkVersion(apkfile):
|
||||||
apk = fdroidserver.common._get_androguard_APK(apkfile)
|
apk = fdroidserver.common._get_androguard_APK(apkfile)
|
||||||
return fdroidserver.common.get_min_sdk_version(apk)
|
return fdroidserver.common.get_min_sdk_version(apk)
|
||||||
@ -1852,9 +1854,9 @@ class CommonTest(unittest.TestCase):
|
|||||||
self.assertEqual([],
|
self.assertEqual([],
|
||||||
data['fdroiddata']['untrackedFiles'])
|
data['fdroiddata']['untrackedFiles'])
|
||||||
dirtyfile = 'dirtyfile'
|
dirtyfile = 'dirtyfile'
|
||||||
with open(dirtyfile, 'w') as fp:
|
with open(dirtyfile, 'w', encoding='utf-8') as fp:
|
||||||
fp.write('this is just a test')
|
fp.write('this is just a test')
|
||||||
with open(file_in_git, 'a') as fp:
|
with open(file_in_git, 'a', encoding='utf-8') as fp:
|
||||||
fp.write('\nappend some stuff')
|
fp.write('\nappend some stuff')
|
||||||
self.assertEqual([],
|
self.assertEqual([],
|
||||||
data['fdroiddata']['modifiedFiles'])
|
data['fdroiddata']['modifiedFiles'])
|
||||||
|
@ -76,7 +76,7 @@ class ScannerTest(unittest.TestCase):
|
|||||||
build = fdroidserver.metadata.Build()
|
build = fdroidserver.metadata.Build()
|
||||||
build.gradle = [flavor]
|
build.gradle = [flavor]
|
||||||
regexs = fdroidserver.scanner.get_gradle_compile_commands(build)
|
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 line in fp.readlines():
|
||||||
for regex in regexs:
|
for regex in regexs:
|
||||||
m = regex.match(line)
|
m = regex.match(line)
|
||||||
@ -93,7 +93,7 @@ class ScannerTest(unittest.TestCase):
|
|||||||
fdroidserver.scanner.config = None
|
fdroidserver.scanner.config = None
|
||||||
fdroidserver.scanner.options = mock.Mock()
|
fdroidserver.scanner.options = mock.Mock()
|
||||||
fdroidserver.scanner.options.json = True
|
fdroidserver.scanner.options.json = True
|
||||||
with open('build.gradle', 'w') as fp:
|
with open('build.gradle', 'w', encoding='utf-8') as fp:
|
||||||
fp.write(
|
fp.write(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
@ -233,7 +233,7 @@ class ScannerTest(unittest.TestCase):
|
|||||||
fp.write('placeholder')
|
fp.write('placeholder')
|
||||||
self.assertTrue(os.path.exists(f))
|
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(
|
fp.write(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
@ -288,7 +288,7 @@ class ScannerTest(unittest.TestCase):
|
|||||||
fdroidserver.scanner.options = mock.Mock()
|
fdroidserver.scanner.options = mock.Mock()
|
||||||
build = fdroidserver.metadata.Build()
|
build = fdroidserver.metadata.Build()
|
||||||
build.scandelete = ['build.gradle']
|
build.scandelete = ['build.gradle']
|
||||||
with open('build.gradle', 'w') as fp:
|
with open('build.gradle', 'w', encoding='utf-8') as fp:
|
||||||
fp.write(
|
fp.write(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user