Skip to content

Commit 3848cdf

Browse files
CyanoxygenMingcongBai
authored andcommitted
parser: redo arch-specific variable fetching
A new function is added to simplify the code for reading arch specific bits, such as SRCS__*, CHKSUMS__*, PKGDEP__* and BUILDDEP__*. The following order is used: - PKGDEP__ARCH - PKGDEP__ARCHGROUPS * N - PKGDEP
1 parent c717658 commit 3848cdf

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

acbs/parser.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import os
44
import re
55
from collections import OrderedDict
6-
from typing import Dict, List, Optional
6+
from typing import Dict, List, Optional, Union
77
from urllib.parse import urlparse
88

99
from acbs import bashvar
1010
from acbs.base import ACBSPackageInfo, ACBSSourceInfo
1111
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
1313

1414
generate_mode = False
1515

@@ -88,12 +88,25 @@ def parse_fetch_options(options: str, acbs_source_info: ACBSSourceInfo):
8888
return acbs_source_info
8989

9090

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+
91106
def parse_package_url(var: Dict[str, str], ignore_empty_srcs: bool) -> List[ACBSSourceInfo]:
92107
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')
97110
if var.get('DUMMYSRC') in ['y', 'yes', '1']:
98111
acbs_source_info.append(ACBSSourceInfo('none', '', ''))
99112
return acbs_source_info
@@ -148,23 +161,19 @@ def parse_package(location: str, modifiers: str) -> ACBSPackageInfo:
148161
# source info parser will fail, as there is no SRCS for current
149162
# arch.
150163
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')
153165
# 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
160169
# architecture specific dependencies
161170
acbs_source_info = parse_package_url(spec_var, ignore_empty_srcs)
162-
if not deps:
171+
if not all_deps:
163172
result = ACBSPackageInfo(
164173
name=var['PKGNAME'], deps=[], location=location, source_uri=acbs_source_info)
165174
else:
166175
# 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())
168177
result = ACBSPackageInfo(
169178
name=var['PKGNAME'], deps=list(deps_iter), location=location, source_uri=acbs_source_info)
170179
result.bin_arch = var.get('ABHOST') or arch
@@ -233,3 +242,5 @@ def check_buildability(package: ACBSPackageInfo, required_by: Optional[str]=None
233242
'ARCH') or get_arch_name() or ''
234243
if not arch:
235244
raise ValueError('Unable to determine architecture name')
245+
246+
archgroups = get_archgroups(arch)

0 commit comments

Comments
 (0)