mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-18 20:50:10 +01:00
yaml parsing: script build flags can now be lists
This commit is contained in:
parent
c15a7508e7
commit
31ca2092a1
@ -1091,14 +1091,23 @@ 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'])
|
||||
|
||||
post_parse_yaml_metadata(yamldata)
|
||||
app.update(yamldata)
|
||||
return app
|
||||
|
||||
|
||||
def post_parse_yaml_metadata(yamldata):
|
||||
"""transform yaml metadata to our internal data format"""
|
||||
for build in yamldata.get('Builds', []):
|
||||
for flag in build.keys():
|
||||
_flagtype = flagtype(flag)
|
||||
|
||||
# concatenate script flags into a single string if they are stored as list
|
||||
if _flagtype is TYPE_SCRIPT:
|
||||
if isinstance(build[flag], list):
|
||||
build[flag] = ' && '.join(build[flag])
|
||||
|
||||
|
||||
def write_yaml(mf, app):
|
||||
"""Write metadata in yaml format.
|
||||
|
||||
|
@ -216,21 +216,74 @@ class MetadataTest(unittest.TestCase):
|
||||
Builds:
|
||||
- versionCode: 1
|
||||
versionName: v0.1.0
|
||||
sudo:
|
||||
- apt-get update
|
||||
- apt-get install -y whatever
|
||||
- sed -i -e 's/<that attr="bad"/<that attr="good"/' ~/.whatever/config.xml
|
||||
init:
|
||||
- bash generate_some_file.sh
|
||||
- sed -i -e 'g/what/ever/' /some/file
|
||||
prebuild:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
- npm something
|
||||
- echo 'important setting' >> /a/file
|
||||
build:
|
||||
- ./gradlew someSpecialTask
|
||||
- sed -i 'd/that wrong config/' gradle.properties
|
||||
- ./gradlew compile
|
||||
"""))
|
||||
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.maxDiff = None
|
||||
self.assertDictEqual(result, {'AutoName': 'F-Droid',
|
||||
'RepoType': 'git',
|
||||
'Builds': [{'versionCode': 1,
|
||||
'versionName': 'v0.1.0',
|
||||
'prebuild': 'a && b && c'}]})
|
||||
'sudo': "apt-get update && "
|
||||
"apt-get install -y whatever && "
|
||||
"sed -i -e 's/<that attr=\"bad\"/<that attr=\"good\"/' ~/.whatever/config.xml",
|
||||
'init': "bash generate_some_file.sh && "
|
||||
"sed -i -e 'g/what/ever/' /some/file",
|
||||
'prebuild': "npm something && echo 'important setting' >> /a/file",
|
||||
'build': "./gradlew someSpecialTask && "
|
||||
"sed -i 'd/that wrong config/' gradle.properties && "
|
||||
"./gradlew compile"}]})
|
||||
|
||||
def test_parse_yaml_metadata_prebuild_strings(self):
|
||||
mf = io.StringIO(textwrap.dedent("""\
|
||||
AutoName: F-Droid
|
||||
RepoType: git
|
||||
Builds:
|
||||
- versionCode: 1
|
||||
versionName: v0.1.0
|
||||
sudo: |-
|
||||
apt-get update && apt-get install -y whatever && sed -i -e 's/<that attr="bad"/<that attr="good"/' ~/.whatever/config.xml
|
||||
init: bash generate_some_file.sh && sed -i -e 'g/what/ever/' /some/file
|
||||
prebuild: npm something && echo 'important setting' >> /a/file
|
||||
build: |-
|
||||
./gradlew someSpecialTask && sed -i 'd/that wrong config/' gradle.properties && ./gradlew compile
|
||||
"""))
|
||||
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.maxDiff = None
|
||||
self.assertDictEqual(result, {'AutoName': 'F-Droid',
|
||||
'RepoType': 'git',
|
||||
'Builds': [{'versionCode': 1,
|
||||
'versionName': 'v0.1.0',
|
||||
'sudo': "apt-get update && "
|
||||
"apt-get install -y whatever && "
|
||||
"sed -i -e 's/<that attr=\"bad\"/<that attr=\"good\"/' ~/.whatever/config.xml",
|
||||
'init': "bash generate_some_file.sh && "
|
||||
"sed -i -e 'g/what/ever/' /some/file",
|
||||
'prebuild': "npm something && echo 'important setting' >> /a/file",
|
||||
'build': "./gradlew someSpecialTask && "
|
||||
"sed -i 'd/that wrong config/' gradle.properties && "
|
||||
"./gradlew compile"}]})
|
||||
|
||||
def test_parse_yaml_metadata_prebuild_string(self):
|
||||
mf = io.StringIO(textwrap.dedent("""\
|
||||
|
Loading…
Reference in New Issue
Block a user