mirror of
https://git.launchpad.net/livecd-rootfs
synced 2025-05-05 16:01:34 +00:00
ubuntu-cpc: rework image artifact cleanup
The livecd.ubuntu-cpc.ext4 that is present in each build (plus kernel and initrd) are not renamed from /build/binary/boot/filsystem.ext4 and friends until after the binary hooks are run, so this patch moves from trying to perform this cleanup in a binary hook. Now the cleanup will be run at the end of live-build/binary for the ubuntu-cpc project.
This commit is contained in:
parent
9bea8296ee
commit
8f8ea8922e
@ -892,3 +892,8 @@ if [ -f "config/magic-proxy.pid" ]; then
|
|||||||
iptables -t nat -D OUTPUT -p tcp --dport 80 -m owner ! --uid-owner daemon \
|
iptables -t nat -D OUTPUT -p tcp --dport 80 -m owner ! --uid-owner daemon \
|
||||||
-j REDIRECT --to 8080
|
-j REDIRECT --to 8080
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
case $PROJECT in
|
||||||
|
ubuntu-cpc)
|
||||||
|
config/hooks.d/remove-implicit-artifacts
|
||||||
|
esac
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
#!/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()
|
|
@ -42,11 +42,10 @@ specified multiple times. The field is used by this script to generate a list
|
|||||||
of output files created explicitly by the named image targets. The list is
|
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
|
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
|
the case of the "all" target this list would be empty. This list is
|
||||||
consumed by the "final.binary" hook file.
|
consumed by the "remove-implicit-artifacts" which is run at the end of the build.
|
||||||
|
|
||||||
The final.binary hook is always included as the last hook(s) if it exists,
|
The final.binary hook is always included as the last hook(s) if it exists,
|
||||||
it should not be specified in series files. It can be included from "base"
|
it should not be specified in series files.
|
||||||
and/or "extra" directories with the final hook in "exta" running last.
|
|
||||||
|
|
||||||
ACHTUNG: live build runs scripts with the suffix ".chroot" in a batch separate
|
ACHTUNG: live build runs scripts with the suffix ".chroot" in a batch separate
|
||||||
from scripts ending in ".binary". Even if you arrange them interleaved in your
|
from scripts ending in ".binary". Even if you arrange them interleaved in your
|
||||||
@ -215,11 +214,10 @@ class MakeHooks:
|
|||||||
sys.stderr.write("WARNING: Hooks directory exists and is not empty.\n")
|
sys.stderr.write("WARNING: Hooks directory exists and is not empty.\n")
|
||||||
os.makedirs(self._hooks_dir, exist_ok=True)
|
os.makedirs(self._hooks_dir, exist_ok=True)
|
||||||
|
|
||||||
# Always add final.binary hooks if they exist
|
# Always add final.binary hook if it exists
|
||||||
for subdir in ["base", "extra"]:
|
final_hook = os.path.join(self._script_dir, "base/final.binary")
|
||||||
final_hook = os.path.join(self._script_dir, subdir, "final.binary")
|
if os.path.exists(final_hook) and os.path.isfile(final_hook):
|
||||||
if os.path.exists(final_hook) and os.path.isfile(final_hook):
|
self._hooks_list.append("base/final.binary")
|
||||||
self._hooks_list.append("base/final.binary")
|
|
||||||
|
|
||||||
for counter, hook in enumerate(self._hooks_list, start=1):
|
for counter, hook in enumerate(self._hooks_list, start=1):
|
||||||
hook_basename = os.path.basename(hook)
|
hook_basename = os.path.basename(hook)
|
||||||
@ -239,13 +237,13 @@ class MakeHooks:
|
|||||||
|
|
||||||
def create_explicit_provides(self):
|
def create_explicit_provides(self):
|
||||||
"""
|
"""
|
||||||
Create a file named "explicit_provides" in self._hooks_dir
|
Create a file named "explicit_provides" in self._script_dir
|
||||||
listing all files named on "provides" in the series files of
|
listing all files named on "provides" in the series files of
|
||||||
targets explicitly named by the user. The file is created but
|
targets explicitly named by the user. The file is created but
|
||||||
left empty if there are no explict "provides" keywords in the
|
left empty if there are no explict "provides" keywords in the
|
||||||
targets (this is the case for 'all')
|
targets (this is the case for 'all')
|
||||||
"""
|
"""
|
||||||
with open(os.path.join(self._hooks_dir, "explicit_provides"), "w",
|
with open(os.path.join(self._script_dir, "explicit_provides"), "w",
|
||||||
encoding="utf-8") as fp:
|
encoding="utf-8") as fp:
|
||||||
empty = True
|
empty = True
|
||||||
for provides in self._provides:
|
for provides in self._provides:
|
||||||
|
40
live-build/ubuntu-cpc/hooks.d/remove-implicit-artifacts
Executable file
40
live-build/ubuntu-cpc/hooks.d/remove-implicit-artifacts
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#-*- encoding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print('Running {}'.format(__file__))
|
||||||
|
scriptname = os.path.basename(__file__)
|
||||||
|
explicit = set()
|
||||||
|
with open('./config/hooks.d/explicit_provides', 'r',
|
||||||
|
encoding='utf-8') as fp:
|
||||||
|
for filename in fp:
|
||||||
|
explicit.add(filename.rstrip())
|
||||||
|
|
||||||
|
if not explicit:
|
||||||
|
print('{}: explicit_provides is empty. '
|
||||||
|
'All binary output will be included'.format(scriptname))
|
||||||
|
quit()
|
||||||
|
|
||||||
|
all = set(glob.glob('livecd.ubuntu-cpc.*'))
|
||||||
|
implicit = all - explicit
|
||||||
|
|
||||||
|
print('{}: all artifacts considered: {}'.format(scriptname, all))
|
||||||
|
print('{}: explict artifacts to keep: {}'.format(scriptname, explicit))
|
||||||
|
print('{}: implicit artifacts to remove: {}'.format(scriptname, implicit))
|
||||||
|
|
||||||
|
for file in implicit:
|
||||||
|
if os.path.islink(file):
|
||||||
|
print('{}: unlinking {}'.format(scriptname, file))
|
||||||
|
os.unlink(file)
|
||||||
|
elif os.path.isfile(file):
|
||||||
|
print('{}: removing {} '
|
||||||
|
'{} bytes'.format(scriptname, file, os.stat(file).st_size))
|
||||||
|
os.remove(file)
|
Loading…
x
Reference in New Issue
Block a user