|
3 | 3 | import os |
4 | 4 | import re |
5 | 5 | from collections import OrderedDict |
6 | | -from typing import Dict, List, Optional |
| 6 | +from typing import Dict, List, Optional, Union |
7 | 7 | from urllib.parse import urlparse |
8 | 8 |
|
9 | 9 | from acbs import bashvar |
10 | 10 | from acbs.base import ACBSPackageInfo, ACBSSourceInfo |
11 | 11 | from acbs.pm import filter_dependencies |
12 | | -from acbs.utils import fail_arch_regex, get_arch_name, tarball_pattern |
| 12 | +from acbs.utils import fail_arch_regex, get_arch_name, get_archgroups, tarball_pattern |
13 | 13 |
|
14 | 14 | generate_mode = False |
15 | 15 |
|
@@ -88,12 +88,25 @@ def parse_fetch_options(options: str, acbs_source_info: ACBSSourceInfo): |
88 | 88 | return acbs_source_info |
89 | 89 |
|
90 | 90 |
|
| 91 | +def get_var_arch(context: Dict[str, str], varname) -> Union[str, None]: |
| 92 | + try_names = [] |
| 93 | + # Try to expand VARNAME__ARCH first. |
| 94 | + try_names.append('{varname}__{arch}'.format(varname=varname, arch=arch.upper())) |
| 95 | + # Then try expanding VARNAME__ARCHGROUP, e.g. VARNAME__RETRO. |
| 96 | + try_names.extend(['{varname}__{group}'.format(varname=varname, group=g.upper()) for g in archgroups]) |
| 97 | + # Then try the VARNAME itself. |
| 98 | + try_names.append(varname) |
| 99 | + for try_name in try_names: |
| 100 | + if try_name in context.keys(): |
| 101 | + return context[try_name] |
| 102 | + |
| 103 | + return None |
| 104 | + |
| 105 | + |
91 | 106 | def parse_package_url(var: Dict[str, str], ignore_empty_srcs: bool) -> List[ACBSSourceInfo]: |
92 | 107 | acbs_source_info: List[ACBSSourceInfo] = [] |
93 | | - sources = var.get('SRCS__{arch}'.format( |
94 | | - arch=arch.upper())) or var.get('SRCS') |
95 | | - checksums = var.get('CHKSUMS__{arch}'.format( |
96 | | - arch=arch.upper())) or var.get('CHKSUMS') |
| 108 | + sources = get_var_arch(var, 'SRCS') |
| 109 | + checksums = get_var_arch(var, 'CHKSUMS') |
97 | 110 | if var.get('DUMMYSRC') in ['y', 'yes', '1']: |
98 | 111 | acbs_source_info.append(ACBSSourceInfo('none', '', '')) |
99 | 112 | return acbs_source_info |
@@ -148,23 +161,19 @@ def parse_package(location: str, modifiers: str) -> ACBSPackageInfo: |
148 | 161 | # source info parser will fail, as there is no SRCS for current |
149 | 162 | # arch. |
150 | 163 | ignore_empty_srcs = True |
151 | | - deps_arch: Optional[str] = var.get('PKGDEP__{arch}'.format( |
152 | | - arch=arch.upper())) |
| 164 | + deps: Optional[str] = get_var_arch(var, 'PKGDEP') |
153 | 165 | # determine whether this is an undefined value or an empty string |
154 | | - deps: str = (var.get('PKGDEP') or '') if deps_arch is None else deps_arch |
155 | | - builddeps_arch: Optional[str] = var.get('BUILDDEP__{arch}'.format( |
156 | | - arch=arch.upper())) |
157 | | - builddeps = var.get( |
158 | | - 'BUILDDEP') if builddeps_arch is None else builddeps_arch |
159 | | - deps += ' ' + (builddeps or '') # add builddep |
| 166 | + all_deps: str = '' if deps is None else deps |
| 167 | + builddeps: Optional[str] = get_var_arch(var, 'BUILDDEP') |
| 168 | + all_deps += ' ' + (builddeps or '') # add builddep |
160 | 169 | # architecture specific dependencies |
161 | 170 | acbs_source_info = parse_package_url(spec_var, ignore_empty_srcs) |
162 | | - if not deps: |
| 171 | + if not all_deps: |
163 | 172 | result = ACBSPackageInfo( |
164 | 173 | name=var['PKGNAME'], deps=[], location=location, source_uri=acbs_source_info) |
165 | 174 | else: |
166 | 175 | # filter out dependencies that are prefixed with @AB_ (autobuild special placeholders) |
167 | | - deps_iter = filter(lambda d: not d.startswith("@AB_"), deps.split()) |
| 176 | + deps_iter = filter(lambda d: not d.startswith("@AB_"), all_deps.split()) |
168 | 177 | result = ACBSPackageInfo( |
169 | 178 | name=var['PKGNAME'], deps=list(deps_iter), location=location, source_uri=acbs_source_info) |
170 | 179 | result.bin_arch = var.get('ABHOST') or arch |
@@ -233,3 +242,5 @@ def check_buildability(package: ACBSPackageInfo, required_by: Optional[str]=None |
233 | 242 | 'ARCH') or get_arch_name() or '' |
234 | 243 | if not arch: |
235 | 244 | raise ValueError('Unable to determine architecture name') |
| 245 | + |
| 246 | +archgroups = get_archgroups(arch) |
0 commit comments