Skip to content

Commit

Permalink
acbs: pass modifiers to autobuild
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuyu committed Mar 16, 2024
1 parent c3521cd commit 6e6074c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion acbs/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def strongly_connected(search_path: str, packages_list: List[str], results: list
print(f'[{len(results) + 1}/{len(pool)}] {vert:30}\r', end='', flush=True)
current_package = packages.get(vert)
if current_package is None:
package = pool.get(vert) or find_package(vert, search_path, stage2)
package = pool.get(vert) or find_package(vert, search_path, '+stage2' if stage2 else '')
if not package:
raise ValueError(
f'Package {vert} not found')
Expand Down
30 changes: 15 additions & 15 deletions acbs/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from acbs.utils import make_build_dir


def check_package_group(name: str, search_path: str, entry_path: str, stage2: bool) -> Optional[List[ACBSPackageInfo]]:
def check_package_group(name: str, search_path: str, entry_path: str, modifiers: str) -> Optional[List[ACBSPackageInfo]]:
# is this a package group?
if os.path.basename(entry_path) == os.path.basename(name) and os.path.isfile(os.path.join(search_path, entry_path, 'spec')):
stub = ACBSPackageInfo(name, [], '', [ACBSSourceInfo('none', '', '')])
stub.base_slug = entry_path
return expand_package_group(stub, search_path, stage2)
return expand_package_group(stub, search_path, modifiers)
with os.scandir(os.path.join(search_path, entry_path)) as group:
# scan potential package groups
for entry_group in group:
Expand All @@ -24,7 +24,7 @@ def check_package_group(name: str, search_path: str, entry_path: str, stage2: bo
continue
# because the package inside the group will have a different name than the folder name
# we will parse the defines file to decide
result = parse_package(full_search_path, stage2)
result = parse_package(full_search_path, modifiers)
if result and result.name == name:
# name of the package inside the group
package_alias = os.path.basename(
Expand All @@ -43,12 +43,12 @@ def check_package_group(name: str, search_path: str, entry_path: str, stage2: bo
group_category), root=os.path.basename(group_root))
result.group_seq = group_seq
group_result = expand_package_group(
result, search_path, stage2)
result, search_path, modifiers)
return group_result
return None


def find_package(name: str, search_path: str, stage2: bool) -> List[ACBSPackageInfo]:
def find_package(name: str, search_path: str, modifiers: str) -> List[ACBSPackageInfo]:
if os.path.isfile(os.path.join(search_path, name)):
with open(os.path.join(search_path, name), 'rt') as f:
content = f.read()
Expand All @@ -60,23 +60,23 @@ def find_package(name: str, search_path: str, stage2: bool) -> List[ACBSPackageI
p = p.strip()
if not p or p.startswith('#'):
continue
found = find_package_inner(p, search_path, stage2=stage2)
found = find_package_inner(p, search_path, modifiers=modifiers)
if not found:
raise RuntimeError(
f'Package {p} requested in {name} was not found.')
results.extend(found)
print()
return results
return find_package_inner(name, search_path, stage2=stage2)
return find_package_inner(name, search_path, modifiers=modifiers)


def find_package_inner(name: str, search_path: str, group=False, stage2: bool=False) -> List[ACBSPackageInfo]:
def find_package_inner(name: str, search_path: str, group=False, modifiers: str='') -> List[ACBSPackageInfo]:
if os.path.isdir(os.path.join(search_path, name)):
flat_path = os.path.join(search_path, name, 'autobuild')
if os.path.isdir(flat_path):
return [parse_package(os.path.join(search_path, name, 'autobuild'), stage2)]
return [parse_package(os.path.join(search_path, name, 'autobuild'), modifiers)]
# is this a package group?
group_result = check_package_group(name, search_path, name, stage2)
group_result = check_package_group(name, search_path, name, modifiers)
if group_result:
return group_result
with os.scandir(search_path) as it:
Expand All @@ -92,20 +92,20 @@ def find_package_inner(name: str, search_path: str, group=False, stage2: bool=Fa
full_search_path = os.path.join(
search_path, entry.name, entry_inner.name, 'autobuild')
if entry_inner.name == name and os.path.isdir(full_search_path):
return [parse_package(full_search_path, stage2)]
return [parse_package(full_search_path, modifiers)]
if not group:
continue
# is this a package group?
group_result = check_package_group(
name, search_path, os.path.join(entry.name, entry_inner.name), stage2)
name, search_path, os.path.join(entry.name, entry_inner.name), modifiers)
if group_result:
return group_result
if group:
return []
else:
# if cannot find a package without considering it as part of a group
# then re-search with group enabled
return find_package_inner(name, search_path, True, stage2)
return find_package_inner(name, search_path, True, modifiers)


def check_package_groups(packages: List[ACBSPackageInfo]):
Expand All @@ -129,7 +129,7 @@ def check_package_groups(packages: List[ACBSPackageInfo]):
groups_seen[base_slug] = pkg.group_seq


def expand_package_group(package: ACBSPackageInfo, search_path: str, stage2: bool) -> List[ACBSPackageInfo]:
def expand_package_group(package: ACBSPackageInfo, search_path: str, modifiers: str) -> List[ACBSPackageInfo]:
group_root = os.path.join(search_path, package.base_slug)
original_base = package.base_slug
actionables: List[ACBSPackageInfo] = []
Expand All @@ -143,7 +143,7 @@ def expand_package_group(package: ACBSPackageInfo, search_path: str, stage2: boo
'Malformed sub-package name: {name}'.format(name=entry.name))
try:
sequence = int(splitted[0])
package = parse_package(entry.path, stage2)
package = parse_package(entry.path, modifiers)
if package:
package.base_slug = original_base
package.group_seq = sequence
Expand Down
3 changes: 1 addition & 2 deletions acbs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def build(self) -> None:
raise ValueError(f'Invalid package name: `{i}`')
logging.debug(f'Finding {i}...')
print(f'[{n + 1}/{len(self.build_queue)}] {i:30}\r', end='', flush=True)
scoped_stage2 = ACBSPackageInfo.is_in_stage2(modifiers) | self.stage2
package = find_package(i, self.tree_dir, stage2=scoped_stage2)
package = find_package(i, self.tree_dir, modifiers)
if not package:
raise RuntimeError(f'Could not find package {i}')
packages.extend(package)
Expand Down
4 changes: 3 additions & 1 deletion acbs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ def parse_package_url_legacy(var: Dict[str, str]) -> ACBSSourceInfo:
return acbs_source_info


def parse_package(location: str, stage2: bool) -> ACBSPackageInfo:
def parse_package(location: str, modifiers: str) -> ACBSPackageInfo:
logging.debug('Parsing {}...'.format(location))
stage2 = ACBSPackageInfo.is_in_stage2(modifiers)
# Call a helper function to check if there's a stage2 defines automatically
defines_location = get_defines_file_path(location, stage2)
spec_location = os.path.join(location, '..', 'spec')
Expand Down Expand Up @@ -184,6 +185,7 @@ def parse_package(location: str, stage2: bool) -> ACBSPackageInfo:
epoch = spec_var.get('EPOCH')
if epoch:
result.epoch = epoch
result.modifiers = modifiers
# collect exported variables (prefixed with `__`)
for k, v in spec_var.items():
if k.startswith('__'):
Expand Down
2 changes: 1 addition & 1 deletion acbs/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def resume_build():
# the spec files changed
if index < new_cursor:
new_cursor = index
resumed_packages.extend(find_package(p.name, builder.tree_dir, stage2))
resumed_packages.extend(find_package(p.name, builder.tree_dir, '+stage2' if stage2 else ''))
# index doesn't matter now, since changes have been detected
if not check_dpkg_state(state, resumed_packages[:new_cursor]):
name = checkpoint_to_group(
Expand Down

0 comments on commit 6e6074c

Please sign in to comment.