2019-04-23 12:21:21 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-09-24 10:52:05 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
2019-04-23 12:21:21 +00:00
|
|
|
import json
|
|
|
|
import subprocess
|
|
|
|
|
2019-09-24 10:52:05 +00:00
|
|
|
from taskgraph.util.memoize import memoize
|
2019-04-23 12:21:21 +00:00
|
|
|
|
2019-05-27 13:00:44 +00:00
|
|
|
|
2019-09-24 10:52:05 +00:00
|
|
|
@memoize
|
2019-08-21 15:32:01 +00:00
|
|
|
def get_variant(build_type, engine):
|
|
|
|
output = _run_gradle_process('printVariant', variantBuildType=build_type, variantEngine=engine)
|
|
|
|
content = _extract_content_from_command_output(output, prefix='variant: ')
|
2019-09-24 10:52:05 +00:00
|
|
|
return json.loads(content)
|
2019-04-23 12:21:21 +00:00
|
|
|
|
|
|
|
|
2019-08-21 15:32:01 +00:00
|
|
|
def _run_gradle_process(gradle_command, **kwargs):
|
|
|
|
gradle_properties = [
|
|
|
|
'-P{property_name}={value}'.format(property_name=property_name, value=value)
|
|
|
|
for property_name, value in kwargs.iteritems()
|
|
|
|
]
|
2019-04-23 12:21:21 +00:00
|
|
|
|
2019-08-21 15:32:01 +00:00
|
|
|
process = subprocess.Popen(["./gradlew", "--no-daemon", "--quiet", gradle_command] + gradle_properties, stdout=subprocess.PIPE)
|
2019-04-23 12:21:21 +00:00
|
|
|
output, err = process.communicate()
|
|
|
|
exit_code = process.wait()
|
|
|
|
|
|
|
|
if exit_code is not 0:
|
2019-09-24 10:52:05 +00:00
|
|
|
raise RuntimeError("Gradle command returned error: {}".format(exit_code))
|
2019-04-23 12:21:21 +00:00
|
|
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
|
|
|
def _extract_content_from_command_output(output, prefix):
|
|
|
|
variants_line = [line for line in output.split('\n') if line.startswith(prefix)][0]
|
|
|
|
return variants_line.split(' ', 1)[1]
|