Skip to content

Commit 6090e53

Browse files
Cyanoxygenliushuyu
andcommitted
stage2: convert stage2 parameter to positional
To avoid logic error. Co-Authored-By: liushuyu <[email protected]>
1 parent 79a3ce2 commit 6090e53

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

acbs/deps.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pool: Dict[str, ACBSPackageInfo] = {}
99

1010

11-
def tarjan_search(packages: 'OrderedDict[str, ACBSPackageInfo]', search_path: str) -> List[List[ACBSPackageInfo]]:
11+
def tarjan_search(packages: 'OrderedDict[str, ACBSPackageInfo]', search_path: str, stage2: bool) -> List[List[ACBSPackageInfo]]:
1212
"""This function describes a Tarjan's strongly connected components algorithm.
1313
The resulting list of ACBSPackageInfo are sorted topologically as a byproduct of the algorithm
1414
"""
@@ -23,7 +23,7 @@ def tarjan_search(packages: 'OrderedDict[str, ACBSPackageInfo]', search_path: st
2323
for i in packages_list:
2424
if index[i] == -1: # recurse on each package that is not yet visited
2525
strongly_connected(search_path, packages_list, results, packages,
26-
i, lowlink, index, stackstate, stack)
26+
i, lowlink, index, stackstate, stack, stage2)
2727
return results
2828

2929

@@ -46,7 +46,7 @@ def prepare_for_reorder(package: ACBSPackageInfo, packages_list: List[str]) -> A
4646
return package
4747

4848

49-
def strongly_connected(search_path: str, packages_list: List[str], results: list, packages: 'OrderedDict[str, ACBSPackageInfo]', vert: str, lowlink: Dict[str, int], index: Dict[str, int], stackstate: Dict[str, bool], stack: Deque[str], depth=0):
49+
def strongly_connected(search_path: str, packages_list: List[str], results: list, packages: 'OrderedDict[str, ACBSPackageInfo]', vert: str, lowlink: Dict[str, int], index: Dict[str, int], stackstate: Dict[str, bool], stack: Deque[str], stage2: bool, depth=0):
5050
# update depth indices
5151
index[vert] = depth
5252
lowlink[vert] = depth
@@ -58,7 +58,7 @@ def strongly_connected(search_path: str, packages_list: List[str], results: list
5858
print(f'[{len(results) + 1}/{len(pool)}] {vert}\t\t\r', end='', flush=True)
5959
current_package = packages.get(vert)
6060
if current_package is None:
61-
package = pool.get(vert) or find_package(vert, search_path)
61+
package = pool.get(vert) or find_package(vert, search_path, stage2)
6262
if not package:
6363
raise ValueError(
6464
f'Package {vert} not found')

acbs/find.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from acbs.utils import make_build_dir
77

88

9-
def check_package_group(name: str, search_path: str, entry_path: str, stage2=False) -> Optional[List[ACBSPackageInfo]]:
9+
def check_package_group(name: str, search_path: str, entry_path: str, stage2: bool) -> Optional[List[ACBSPackageInfo]]:
1010
# is this a package group?
1111
if os.path.basename(entry_path) == os.path.basename(name) and os.path.isfile(os.path.join(search_path, entry_path, 'spec')):
1212
stub = ACBSPackageInfo(name, [], '', [ACBSSourceInfo('none', '', '')])
1313
stub.base_slug = entry_path
14-
return expand_package_group(stub, search_path, stage2=stage2)
14+
return expand_package_group(stub, search_path, stage2)
1515
with os.scandir(os.path.join(search_path, entry_path)) as group:
1616
# scan potential package groups
1717
for entry_group in group:
@@ -23,7 +23,7 @@ def check_package_group(name: str, search_path: str, entry_path: str, stage2=Fal
2323
continue
2424
# because the package inside the group will have a different name than the folder name
2525
# we will parse the defines file to decide
26-
result = parse_package(full_search_path, stage2=stage2)
26+
result = parse_package(full_search_path, stage2)
2727
if result and result.name == name:
2828
# name of the package inside the group
2929
package_alias = os.path.basename(
@@ -42,12 +42,12 @@ def check_package_group(name: str, search_path: str, entry_path: str, stage2=Fal
4242
group_category), root=os.path.basename(group_root))
4343
result.group_seq = group_seq
4444
group_result = expand_package_group(
45-
result, search_path, stage2=stage2)
45+
result, search_path, stage2)
4646
return group_result
4747
return None
4848

4949

50-
def find_package(name: str, search_path: str, stage2=False) -> List[ACBSPackageInfo]:
50+
def find_package(name: str, search_path: str, stage2: bool) -> List[ACBSPackageInfo]:
5151
if os.path.isfile(os.path.join(search_path, name)):
5252
with open(os.path.join(search_path, name), 'rt') as f:
5353
content = f.read()
@@ -59,23 +59,23 @@ def find_package(name: str, search_path: str, stage2=False) -> List[ACBSPackageI
5959
p = p.strip()
6060
if not p or p.startswith('#'):
6161
continue
62-
found = find_package_inner(p, search_path, stage2=stage2)
62+
found = find_package_inner(p, search_path, stage2)
6363
if not found:
6464
raise RuntimeError(
6565
f'Package {p} requested in {name} was not found.')
6666
results.extend(found)
6767
print()
6868
return results
69-
return find_package_inner(name, search_path, stage2=stage2)
69+
return find_package_inner(name, search_path, stage2)
7070

7171

72-
def find_package_inner(name: str, search_path: str, group=False, stage2=False) -> List[ACBSPackageInfo]:
72+
def find_package_inner(name: str, search_path: str, stage2: bool, group=False) -> List[ACBSPackageInfo]:
7373
if os.path.isdir(os.path.join(search_path, name)):
7474
flat_path = os.path.join(search_path, name, 'autobuild')
7575
if os.path.isdir(flat_path):
76-
return [parse_package(os.path.join(search_path, name, 'autobuild'), stage2=stage2)]
76+
return [parse_package(os.path.join(search_path, name, 'autobuild'), stage2)]
7777
# is this a package group?
78-
group_result = check_package_group(name, search_path, name, stage2=stage2)
78+
group_result = check_package_group(name, search_path, name, stage2)
7979
if group_result:
8080
return group_result
8181
with os.scandir(search_path) as it:
@@ -91,12 +91,12 @@ def find_package_inner(name: str, search_path: str, group=False, stage2=False) -
9191
full_search_path = os.path.join(
9292
search_path, entry.name, entry_inner.name, 'autobuild')
9393
if entry_inner.name == name and os.path.isdir(full_search_path):
94-
return [parse_package(full_search_path, stage2=stage2)]
94+
return [parse_package(full_search_path, stage2)]
9595
if not group:
9696
continue
9797
# is this a package group?
9898
group_result = check_package_group(
99-
name, search_path, os.path.join(entry.name, entry_inner.name), stage2=stage2)
99+
name, search_path, os.path.join(entry.name, entry_inner.name), stage2)
100100
if group_result:
101101
return group_result
102102
if group:
@@ -124,7 +124,7 @@ def check_package_groups(packages: List[ACBSPackageInfo]):
124124
groups_seen[base_slug] = pkg.group_seq
125125

126126

127-
def expand_package_group(package: ACBSPackageInfo, search_path: str, stage2=False) -> List[ACBSPackageInfo]:
127+
def expand_package_group(package: ACBSPackageInfo, search_path: str, stage2: bool) -> List[ACBSPackageInfo]:
128128
group_root = os.path.join(search_path, package.base_slug)
129129
original_base = package.base_slug
130130
actionables: List[ACBSPackageInfo] = []
@@ -138,7 +138,7 @@ def expand_package_group(package: ACBSPackageInfo, search_path: str, stage2=Fals
138138
'Malformed sub-package name: {name}'.format(name=entry.name))
139139
try:
140140
sequence = int(splitted[0])
141-
package = parse_package(entry.path, stage2=stage2)
141+
package = parse_package(entry.path, stage2)
142142
if package:
143143
package.base_slug = original_base
144144
package.group_seq = sequence

acbs/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def build(self) -> None:
104104
if not package:
105105
raise RuntimeError(f'Could not find package {i}')
106106
packages.extend(package)
107-
resolved = self.resolve_deps(packages)
107+
resolved = self.resolve_deps(packages, self.stage2)
108108
if not packages:
109109
logging.info('Nothing to do after dependency resolution')
110110
return
@@ -134,7 +134,7 @@ def save_checkpoint(self, build_timings, packages):
134134
raise RuntimeError(
135135
f'Build error.\nUse `acbs-build --resume {filename}` to resume after you sorted out the situation.')
136136

137-
def reorder_deps(self, packages):
137+
def reorder_deps(self, packages, stage2: bool):
138138
logging.info('Re-ordering packages...')
139139
new_packages = []
140140
package_names = [p.name for p in packages]
@@ -143,7 +143,7 @@ def reorder_deps(self, packages):
143143
logging.debug(f'Prepare for re-ordering: {pkg.name}')
144144
new_packages.append(prepare_for_reorder(pkg, package_names))
145145
graph = get_deps_graph(new_packages)
146-
return tarjan_search(graph, self.tree_dir)
146+
return tarjan_search(graph, self.tree_dir, stage2)
147147

148148
def filter_unbuildable(self, packages: List[ACBSPackageInfo]) -> List[ACBSPackageInfo]:
149149
unbuildable = []
@@ -157,7 +157,7 @@ def filter_unbuildable(self, packages: List[ACBSPackageInfo]) -> List[ACBSPackag
157157
logging.warning(f'The following packages will be skipped as they are not buildable:\n\t{(" ".join(unbuildable))}')
158158
return buildable
159159

160-
def resolve_deps(self, packages):
160+
def resolve_deps(self, packages, stage2: bool):
161161
error = False
162162
if not self.no_deps:
163163
logging.debug('Filtering packages...')
@@ -167,7 +167,7 @@ def resolve_deps(self, packages):
167167
logging.debug('Converting queue into adjacency graph...')
168168
graph = get_deps_graph(packages)
169169
logging.debug('Running Tarjan search...')
170-
resolved = tarjan_search(graph, self.tree_dir)
170+
resolved = tarjan_search(graph, self.tree_dir, stage2)
171171
# re-order the packages
172172
if self.reorder:
173173
print()

acbs/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
generate_mode = False
1414

1515

16-
def get_defines_file_path(location: str, stage2: bool=False) -> str:
16+
def get_defines_file_path(location: str, stage2: bool) -> str:
1717
'''
1818
Return ${location}/defines or ${location}/defines.stage2 depending on the value of stage2 and whether the .stage2 file exists.
1919
'''
@@ -135,7 +135,7 @@ def parse_package_url_legacy(var: Dict[str, str]) -> ACBSSourceInfo:
135135
return acbs_source_info
136136

137137

138-
def parse_package(location: str, stage2=False) -> ACBSPackageInfo:
138+
def parse_package(location: str, stage2: bool) -> ACBSPackageInfo:
139139
logging.debug('Parsing {}...'.format(location))
140140
# Call a helper function to check if there's a stage2 defines automatically
141141
defines_location = get_defines_file_path(location, stage2)

acbs/resume.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def resume_build():
5757

5858
state = do_load_checkpoint(filename)
5959
builder = BuildCore(args)
60+
stage2 = builder.stage2
6061
logging.info('Resuming from {}'.format(filename))
6162
if state.version != __version__:
6263
logging.warning(
@@ -83,7 +84,7 @@ def resume_build():
8384
# the spec files changed
8485
if index < new_cursor:
8586
new_cursor = index
86-
resumed_packages.extend(find_package(p.name, builder.tree_dir))
87+
resumed_packages.extend(find_package(p.name, builder.tree_dir, stage2))
8788
# index doesn't matter now, since changes have been detected
8889
if not check_dpkg_state(state, resumed_packages[:new_cursor]):
8990
name = checkpoint_to_group(

0 commit comments

Comments
 (0)