|
4 | 4 | from multiprocessing import cpu_count
|
5 | 5 | import sh
|
6 | 6 |
|
| 7 | +from urllib.request import urlopen |
| 8 | +import json |
| 9 | +from pythonforandroid.logger import error |
| 10 | +from os import environ |
| 11 | + |
| 12 | +def get_libsodium_urls(): |
| 13 | + """ |
| 14 | + Retrieves the download url formats for libsodium versions |
| 15 | +
|
| 16 | + Returns dict with version to url format mappings |
| 17 | + """ |
| 18 | + releases_url = 'https://api.github.com/repos/jedisct1/libsodium/releases' |
| 19 | + with urlopen(releases_url) as response: |
| 20 | + response = response.read().decode() |
| 21 | + releases = json.loads(response) |
| 22 | + urls = {} |
| 23 | + for release in releases: |
| 24 | + version = release['name'] |
| 25 | + for asset in release['assets']: |
| 26 | + file_name = 'libsodium-{}.tar.gz'.format(version) |
| 27 | + if asset['name'] == file_name: |
| 28 | + download_url = asset['browser_download_url'] |
| 29 | + urls[version] = download_url.replace(version, '{version}') |
| 30 | + break |
| 31 | + return urls |
| 32 | + |
| 33 | +try: |
| 34 | + URLS = get_libsodium_urls() |
| 35 | +except: |
| 36 | + message = 'failed to get libsodium repo assets' |
| 37 | + error(message) |
| 38 | + raise Exception(message) |
7 | 39 |
|
8 | 40 | class LibsodiumRecipe(Recipe):
|
9 |
| - version = '1.0.18' |
10 |
| - url = 'https://github.com/jedisct1/libsodium/releases/download/{version}-RELEASE/libsodium-{version}.tar.gz' |
| 41 | + env_version = environ.get('VERSION_libsodium') |
| 42 | + if not env_version: |
| 43 | + version = '1.0.16' |
| 44 | + else: |
| 45 | + version = env_version |
| 46 | + try: |
| 47 | + url = URLS[version] |
| 48 | + except KeyError: |
| 49 | + message = 'libsodium {} not found in repo assets'.format(version) |
| 50 | + error(message) |
| 51 | + raise Exception(message) |
11 | 52 | depends = []
|
12 | 53 | patches = ['size_max_fix.patch']
|
13 | 54 | built_libraries = {'libsodium.so': 'src/libsodium/.libs'}
|
|
0 commit comments