Skip to content

Commit 435eb15

Browse files
committed
feat: add arg --generate-package-metadata
1 parent 6f6b174 commit 435eb15

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

acbs-build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def main() -> None:
5252
parser.add_argument('-z', '--temp-dir', nargs=1, dest='acbs_temp_dir',
5353
help='Override temp directory')
5454
parser.add_argument('--force-use-apt', help="Only use apt to install dependency", action="store_true", dest="force_use_apt")
55+
parser.add_argument('--generate-package-metadata', help="Generate package metadata", action="store_true", dest="generate_pkg_metadata")
56+
5557

5658
args = parser.parse_args()
5759
if args.acbs_temp_dir:

acbs/main.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def __init__(self, args) -> None:
9999
self.reorder = args.reorder
100100
self.save_list = args.save_list
101101
self.force_use_apt = args.force_use_apt
102+
self.generate_pkg_metadata = args.generate_pkg_metadata
103+
102104
# static vars
103105
self.autobuild_conf_dir = AUTOBUILD_CONF_DIR
104106
self.conf_dir = CONF_DIR
@@ -302,7 +304,7 @@ def build_sequential(self, build_timings, packages: List[ACBSPackageInfo]):
302304
source_name = task.name
303305
if task.base_slug:
304306
source_name = os.path.basename(task.base_slug)
305-
if not has_stamp(task.build_location):
307+
if not has_stamp(task.build_location) and not self.generate_pkg_metadata:
306308
fetch_source(task.source_uri, self.dump_dir, source_name)
307309
if self.dl_only:
308310
if self.generate:
@@ -317,11 +319,13 @@ def build_sequential(self, build_timings, packages: List[ACBSPackageInfo]):
317319
if not task.build_location:
318320
build_dir = make_build_dir(self.tmp_dir)
319321
task.build_location = build_dir
320-
process_source(task, source_name)
322+
if not self.generate_pkg_metadata:
323+
process_source(task, source_name)
321324
else:
322325
# First sub-package in a meta-package
323326
if not has_stamp(task.build_location):
324-
process_source(task, source_name)
327+
if not self.generate_pkg_metadata:
328+
process_source(task, source_name)
325329
Path(os.path.join(task.build_location, '.acbs-stamp')).touch()
326330
build_dir = task.build_location
327331
if task.subdir:
@@ -332,23 +336,25 @@ def build_sequential(self, build_timings, packages: List[ACBSPackageInfo]):
332336
raise RuntimeError(
333337
'Could not determine sub-directory, please specify manually.')
334338
build_dir = os.path.join(build_dir, subdir)
335-
if task.installables:
339+
if task.installables and not self.generate_pkg_metadata:
336340
logging.info('Installing dependencies from repository...')
337341
install_from_repo(task.installables, self.force_use_apt)
338342
start = time.monotonic()
339343
task_name = f'{task.name} ({task.bin_arch} @ {task.epoch + ":" if task.epoch else ""}{task.version}-{task.rel})'
340344
try:
341345
scoped_stage2 = ACBSPackageInfo.is_in_stage2(task.modifiers) | self.stage2
342-
invoke_autobuild(task, build_dir, scoped_stage2)
343-
check_artifact(task.name, build_dir)
346+
invoke_autobuild(task, build_dir, scoped_stage2, self.generate_pkg_metadata)
347+
if not self.generate_pkg_metadata:
348+
check_artifact(task.name, build_dir)
344349
except Exception:
345350
# early printing of build summary before exploding
346351
print_build_timings(build_timings, packages[idx:], time.monotonic() - start)
347352
raise RuntimeError(
348353
f'Build directory of the failed package: {build_dir}')
349-
build_timings.append((task_name, time.monotonic() - start))
350-
ciel_invalidate_cache()
351-
ciel_wait_for_refresh()
354+
if not self.generate_pkg_metadata:
355+
build_timings.append((task_name, time.monotonic() - start))
356+
ciel_invalidate_cache()
357+
ciel_wait_for_refresh()
352358

353359
def acbs_except_hdr(self, type_, value, tb):
354360
logging.debug('Traceback:\n' + ''.join(traceback.format_tb(tb)))

acbs/utils.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,20 @@ def start_build_capture(env: Dict[str, str], build_dir: str):
166166
f.write(footer.encode())
167167
if signal_status or exit_status:
168168
raise RuntimeError('autobuild4 did not exit successfully.')
169+
170+
def start_general_autobuild_metadata(env: Dict[str, str], script_location: str, package_name: str):
171+
process = pexpect.spawn('autobuild', args=["-p"], env=env, encoding='utf-8')
172+
process.expect(pexpect.EOF)
173+
174+
path = ''
175+
if script_location.split('/')[-1] == 'autobuild':
176+
path = os.path.join(script_location, '..', '.srcinfo.json')
177+
else:
178+
path = os.path.join(script_location, '..', f'.srcinfo-{package_name}.json')
169179

180+
with open(path, 'w') as f:
181+
f.write(process.before)
182+
logging.info(f".srcinfo.json is save to: {path}")
170183

171184
def generate_metadata(task: ACBSPackageInfo) -> str:
172185
tree_commit = 'unknown\n'
@@ -228,7 +241,7 @@ def check_artifact(name: str, build_dir: str):
228241
'STOP! Autobuild3 malfunction detected! Returned zero status with no artifact.')
229242

230243

231-
def invoke_autobuild(task: ACBSPackageInfo, build_dir: str, stage2: bool):
244+
def invoke_autobuild(task: ACBSPackageInfo, build_dir: str, stage2: bool, generate_pkg_metadata: bool):
232245
dst_dir = os.path.join(build_dir, 'autobuild')
233246
if os.path.exists(dst_dir) and task.group_seq > 1:
234247
shutil.rmtree(dst_dir)
@@ -254,7 +267,10 @@ def invoke_autobuild(task: ACBSPackageInfo, build_dir: str, stage2: bool):
254267
f.write(generate_metadata(task))
255268
os.chdir(build_dir)
256269
if build_logging:
257-
start_build_capture(env_dict, build_dir)
270+
if not generate_pkg_metadata:
271+
start_build_capture(env_dict, build_dir)
272+
else:
273+
start_general_autobuild_metadata(env_dict, task.script_location, task.name)
258274
return
259275
logging.warning(
260276
'Build logging not available due to pexpect not installed.')

0 commit comments

Comments
 (0)