You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
livecd-rootfs/live-build/ubuntu-cpc/hooks.d/base/final.binary

48 lines
1.4 KiB

ubuntu-cpc: Only produce explicitly named artifacts (LP: #1837254) In parallel builds where a list of image targets are provided the build may produce binaries that are not part of the named set of targets but are created by series dependencies. These implicitly created binaries may be generated by multiple builds but are unused as our convention for the ubuntu-cpc project is to only consume binaries from the explicitly named image targets; this avoid overwriting the same object by multiple parallel builds. This patch adds support for a 'provides' keyword for series files. It can be specified multiple times per series file. The field is used by the make-hooks script to generate a list of output files created explicitly by the named image targets. The list is saved to the "explicit_provides" file in the hooks output directory. In the case of the "all" target this list would be empty. This list is consumed by the "final.binary" hook file. This patch adds support for optional final.binary hooks in hooks.d/base and/or hooks.d/extra. These final.binary hooks are always included as the last hook(s) if either exist with the hook in "extra" running last. The base/final.binary hook includes logic to parse the "explicit_provides" file generated by the make-hooks script and remove any binary output not explicitly specified. Some series files named unnecessary dependencies, specifically disk-image, to keep output of implicit artifacts consistent between parallel builds. These unnecessary dependencies are removed in this patch.
6 years ago
#!/usr/bin/env python3
#-*- encoding: utf-8 -*-
"""
The final hook is run after all other binary hooks.
"""
import glob
import os
def remove_implicit_files():
"""
Remove output files not created by explicitly specified image targets
This uses the 'explicit_provides' file generated by the 'make-hooks'
script. If the file is empty, all output will be saved.
"""
explicit = set()
with open('./config/hooks/explicit_provides', 'r', encoding='utf-8') as fp:
for filename in fp:
explicit.add(filename.rstrip())
if not explicit:
print('remove_implicit_files: explicit_provides is empty '
'all binary output will be included')
quit()
all = set(glob.glob('livecd.ubuntu-cpc.*'))
implicit = all - explicit
print('remove_implicit_files: all artifacts considered: {}'.format(all))
print('remove_implicit_files: explict artifacts to keep: '
'{}'.format(explicit))
print('remove_implicit_files: implicit artifacts to remove: '
'{}'.format(implicit))
for file in implicit:
print('remove_implicit_files: removing {} '
'{} bytes'.format(file, os.stat(file).st_size))
if os.path.islink(file):
os.unlink(file)
elif os.path.isfile(file):
os.remove(file)
if __name__ == "__main__":
print('Running {}'.format(__file__))
remove_implicit_files()