diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index 832be3e7..c24bb2fe 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -1091,6 +1091,10 @@ def parse_yaml_metadata(mf, app): _("Unrecognised build flag '{build_flag}' " "in '{path}'").format(build_flag=build_flag, path=mf.name)) + + if 'prebuild' in build and type(build['prebuild']) == list: + build['prebuild'] = ' && '.join(build['prebuild']) + app.update(yamldata) return app @@ -1194,6 +1198,8 @@ def write_yaml(mf, app): continue elif value == 'yes': value = 'yes' + if field == 'prebuild': + value = value.split(' && ') b.update({field: _field_to_yaml(flagtype(field), value)}) builds.append(b) diff --git a/tests/metadata.TestCase b/tests/metadata.TestCase index 6b3c66ef..a9be7ec0 100755 --- a/tests/metadata.TestCase +++ b/tests/metadata.TestCase @@ -209,6 +209,58 @@ class MetadataTest(unittest.TestCase): UpdateCheckMode: Tags """)) + def test_parse_yaml_metadata_prebuild(self): + mf = io.StringIO(textwrap.dedent("""\ + AutoName: F-Droid + RepoType: git + Builds: + - versionCode: 1 + versionName: v0.1.0 + prebuild: + - a + - b + - c + """)) + mf.name = 'mock_filename.yaml' + mf.seek(0) + result = {} + with mock.patch('fdroidserver.metadata.warnings_action', 'error'): + fdroidserver.metadata.parse_yaml_metadata(mf, result) + self.assertDictEqual(result, {'AutoName': 'F-Droid', + 'RepoType': 'git', + 'Builds': [{'versionCode': 1, + 'versionName': 'v0.1.0', + 'prebuild': 'a && b && c'}]}) + + def test_write_yaml_prebuild(self): + mf = io.StringIO() + app = fdroidserver.metadata.App() + app.builds = [] + build = fdroidserver.metadata.Build() + build.versionCode = 102030 + build.versionName = 'v1.2.3' + build.prebuild = 'a && b % c && d `echo \'$e\'` && f' + app.builds.append(build) + fdroidserver.metadata.write_yaml(mf, app) + mf.seek(0) + self.assertEqual(mf.read(), textwrap.dedent("""\ + Categories: + - None + License: Unknown + + Builds: + - versionName: v1.2.3 + versionCode: 102030 + prebuild: + - a + - b % c + - d `echo '$e'` + - f + + AutoUpdateMode: None + UpdateCheckMode: None + """)) + if __name__ == "__main__": os.chdir(os.path.dirname(__file__))