|
1 | 1 | from pythonforandroid.recipe import Recipe
|
2 | 2 | from pythonforandroid.util import current_directory
|
3 |
| -from pythonforandroid.logger import shprint, error |
| 3 | +from pythonforandroid.logger import shprint |
4 | 4 | from multiprocessing import cpu_count
|
5 |
| -from urllib.request import urlopen |
6 |
| -from os import environ |
7 |
| -import json |
8 | 5 | import sh
|
9 |
| - |
10 |
| - |
11 |
| -def get_libsodium_urls(): |
12 |
| - """ |
13 |
| - Retrieves the download url formats for libsodium versions |
14 |
| -
|
15 |
| - Returns dict with version to url format mappings |
16 |
| - """ |
17 |
| - releases_url = 'https://api.github.com/repos/jedisct1/libsodium/releases' |
18 |
| - with urlopen(releases_url) as response: |
19 |
| - response = response.read().decode() |
20 |
| - releases = json.loads(response) |
21 |
| - urls = {} |
22 |
| - for release in releases: |
23 |
| - version = release['name'] |
24 |
| - file_name = 'libsodium-{}.tar.gz'.format(version) |
25 |
| - for asset in release['assets']: |
26 |
| - if asset['name'] == file_name: |
27 |
| - download_url = asset['browser_download_url'] |
28 |
| - urls[version] = download_url.replace(version, '{version}') |
29 |
| - break |
30 |
| - return urls |
31 |
| - |
32 |
| -try: |
33 |
| - URLS = get_libsodium_urls() |
34 |
| -except: |
35 |
| - message = 'failed to get libsodium url formats' |
36 |
| - error(message) |
37 |
| - raise Exception(message) |
| 6 | +from packaging import version as packaging_version |
38 | 7 |
|
39 | 8 |
|
40 | 9 | class LibsodiumRecipe(Recipe):
|
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 version '{}' not found".format(version) |
50 |
| - error(message) |
51 |
| - raise Exception(message) |
| 10 | + version = '1.0.16' |
| 11 | + url = 'https://github.com/jedisct1/libsodium/releases/download/{}/libsodium-{}.tar.gz' |
52 | 12 | depends = []
|
53 | 13 | patches = ['size_max_fix.patch']
|
54 | 14 | built_libraries = {'libsodium.so': 'src/libsodium/.libs'}
|
55 | 15 |
|
| 16 | + @property |
| 17 | + def versioned_url(self): |
| 18 | + asked_version = packaging_version.parse(self.version) |
| 19 | + recipe_version = packaging_version.parse(self._version) |
| 20 | + if asked_version > recipe_version: |
| 21 | + return self._url.format(self.version + '-RELEASE', self.version) |
| 22 | + else: |
| 23 | + return self._url.format(self.version, self.version) |
| 24 | + |
56 | 25 | def build_arch(self, arch):
|
57 | 26 | env = self.get_recipe_env(arch)
|
58 | 27 | with current_directory(self.get_build_dir(arch.arch)):
|
|
0 commit comments