mirror of
https://github.com/truenas/core-build.git
synced 2026-02-20 18:08:03 +00:00
123 lines
4.2 KiB
Python
Executable File
123 lines
4.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
#+
|
|
# Copyright 2015 iXsystems, Inc.
|
|
# All rights reserved
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# modification, are permitted providing that the following conditions
|
|
# are met:
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer.
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
#
|
|
#####################################################################
|
|
|
|
import os
|
|
import errno
|
|
import shutil
|
|
from utils import sh, e, info, objdir, sha256, is_elf
|
|
|
|
|
|
output = objdir('${NAME}.debug.txz')
|
|
|
|
|
|
def main():
|
|
sh('rm -rf ${DEBUG_ROOT}')
|
|
sh('mkdir -p ${DEBUG_ROOT}')
|
|
|
|
info('Saving debug information in ${{DEBUG_ROOT}}')
|
|
|
|
destpath = os.path.join(e('${DEBUG_ROOT}'), "usr/lib");
|
|
os.makedirs(destpath)
|
|
shutil.move(os.path.join(e('${WORLD_DESTDIR}'), "usr/lib/debug"),
|
|
destpath)
|
|
|
|
for root, dirs, files in os.walk(e('${WORLD_DESTDIR}/')):
|
|
for name in files:
|
|
filename = os.path.join(root, name)
|
|
relpath = os.path.relpath(filename, e('${WORLD_DESTDIR}'))
|
|
destpath = os.path.join(e('${DEBUG_ROOT}'), relpath)
|
|
|
|
ext = os.path.splitext(name)[1]
|
|
|
|
if ext == '.ko':
|
|
continue
|
|
|
|
if relpath.startswith('boot'):
|
|
continue
|
|
|
|
if ext == '.c':
|
|
make_dir(destpath)
|
|
shutil.move(filename, destpath)
|
|
for f in os.listdir(root):
|
|
if f.endswith('.html'):
|
|
html_path = os.path.join(root, f)
|
|
if 'Generated by Cython' in open(html_path).read():
|
|
relpath = os.path.relpath(html_path, e('${WORLD_DESTDIR}'))
|
|
destpath = os.path.join(e('${DEBUG_ROOT}'), relpath)
|
|
shutil.move(html_path, destpath)
|
|
continue
|
|
|
|
if ext == '.html':
|
|
continue
|
|
|
|
if not is_elf(filename):
|
|
continue
|
|
|
|
if sh("readelf -S %s | grep -q '.debug_info'" % (filename), nofail=True) != 0:
|
|
continue
|
|
|
|
make_dir(destpath)
|
|
|
|
# We need to remove any flags on protected files and restore
|
|
# them after stripping
|
|
flags = os.stat(filename).st_flags
|
|
os.chflags(filename, 0)
|
|
|
|
if not relpath.startswith('rescue'):
|
|
sh('objcopy --only-keep-debug ${filename} ${destpath}.debug')
|
|
sh('objcopy --strip-unneeded ${filename}', nofail=True)
|
|
sh('objcopy --add-gnu-debuglink="${destpath}.debug" ${filename}', log='/dev/null', nofail=True)
|
|
else:
|
|
sh('strip ${filename}')
|
|
|
|
os.chflags(filename, flags)
|
|
|
|
|
|
def create_package():
|
|
info('Creating debug package')
|
|
if os.path.exists('/usr/local/bin/pigz'):
|
|
sh('tar -C ${DEBUG_ROOT} -cvf - . | /usr/local/bin/pigz -c > ${output}', log='/dev/null')
|
|
else:
|
|
sh('tar -C ${DEBUG_ROOT} -cvJf ${output} .', log='/dev/null')
|
|
|
|
sha256(output)
|
|
|
|
|
|
def make_dir(path):
|
|
try:
|
|
os.makedirs(os.path.dirname(path))
|
|
except OSError as err:
|
|
if err.errno != errno.EEXIST:
|
|
raise
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if e("${BUILD_DEBUG_PACKAGE}") not in ("no", "NO"):
|
|
main()
|
|
create_package()
|