Skip to content
Snippets Groups Projects
run.py 73.5 KiB
Newer Older
                )
                output = os.path.join(self.build_area, bundle)

                with open(output + '.new', 'wb') as writer:
                    self.worker.check_call([
                        'cat',
                        '{}/bundle'.format(self.worker.scratch),
                    ], stdout=writer)

                os.rename(output + '.new', output)
Simon McVittie's avatar
Simon McVittie committed

    def usrmerge(self, chroot):
        self.root_worker.check_call([
            'time',
            'chroot', chroot,
            'sh',
            '-euc',

            'usrmerge () {\n'
            '    local f="$1"\n'
            '\n'
            '    ls -dl "$f" "/usr$f" >&2 || true\n'
            '    if [ "$(readlink "$f")" = "/usr$f" ]; then\n'
            '        echo "Removing $f in favour of /usr$f" >&2\n'
            '        rm -v -f "$f"\n'
            '    elif [ "$(readlink "/usr$f")" = "$f" ]; then\n'
            '        echo "Removing /usr$f in favour of $f" >&2\n'
            '        rm -v -f "/usr$f"\n'
            '    elif [ "$(readlink -f "/usr$f")" = \\\n'
            '           "$(readlink -f "$f")" ]; then\n'
            '        echo "/usr$f and $f are functionally identical" >&2\n'
            '        rm -v -f "$f"\n'
            '    else\n'
            '        echo "Cannot merge $f with /usr$f" >&2\n'
            '        exit 1\n'
            '    fi\n'
            '}\n'
            '\n'
            'find /bin /sbin /lib* -not -xtype d |\n'
            'while read f; do\n'
            '    if [ -e "/usr$f" ]; then\n'
            '        usrmerge "$f"\n'
            '    fi\n'
            'done\n'
            '',

            'sh',   # argv[0]
            chroot,
        ])
        self.root_worker.check_call([
            'time',
            'sh', '-euc',
            'cd "$1"; tar -cf- bin sbin lib* | tar -C usr -xf-',
            'sh', chroot,
        ])
        self.root_worker.check_call([
            'time',
            'sh', '-euc', 'cd "$1"; rm -fr bin sbin lib*',
            'sh', chroot,
        ])
        self.root_worker.check_call([
            'time',
            'sh', '-euc', 'cd "$1"; ln -vs usr/bin usr/sbin usr/lib* .',
            'sh', chroot,
        ])

Simon McVittie's avatar
Simon McVittie committed
if __name__ == '__main__':
Simon McVittie's avatar
Simon McVittie committed
    if sys.stderr.isatty():
        try:
            import colorlog
        except ImportError:
            pass
        else:
            formatter = colorlog.ColoredFormatter(
                '%(log_color)s%(levelname)s:%(name)s:%(reset)s %(message)s')
            handler = logging.StreamHandler()
            handler.setFormatter(formatter)
            logging.getLogger().addHandler(handler)
    else:
        logging.basicConfig()

    logging.getLogger().setLevel(logging.DEBUG)
Simon McVittie's avatar
Simon McVittie committed

    try:
        Builder().run_command_line()
    except KeyboardInterrupt:
        raise SystemExit(130)
    except subprocess.CalledProcessError as e:
        logger.error('%s', e)
        raise SystemExit(1)