public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Florian Weimer <fw@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/fw/builtin-syscalls-3] build-many-glibcs.py: Use subclassing to customize Glibc Date: Thu, 12 Dec 2019 08:41:00 -0000 [thread overview] Message-ID: <20191212084100.46188.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=219140e1c15ee8833d18e1dd79c424341cec3eab commit 219140e1c15ee8833d18e1dd79c424341cec3eab Author: Florian Weimer <fweimer@redhat.com> Date: Wed Dec 11 18:53:36 2019 +0100 build-many-glibcs.py: Use subclassing to customize Glibc Introduce GlibcBase as the base class for both Glibc and GlibcForCompiler. Customize the behavior by overriding methods, instead of a flag. Diff: --- scripts/build-many-glibcs.py | 96 ++++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 35 deletions(-) diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py index 0c01c3b..b7edbb6 100755 --- a/scripts/build-many-glibcs.py +++ b/scripts/build-many-glibcs.py @@ -34,6 +34,7 @@ compilers or glibc are to be built. """ +import abc import argparse import datetime import email.mime.text @@ -1177,10 +1178,8 @@ class Config(object): glibcs = [{'variant': variant}] if extra_glibcs is None: extra_glibcs = [] - glibcs = [Glibc(self, **g) for g in glibcs] - extra_glibcs = [Glibc(self, **g) for g in extra_glibcs] - self.all_glibcs = glibcs + extra_glibcs - self.compiler_glibcs = glibcs + self.all_glibcs = [Glibc(self, **g) for g in glibcs + extra_glibcs] + self.compiler_glibcs = [GlibcForCompiler(self, **g) for g in glibcs] self.installdir = ctx.compiler_installdir(self.name) self.bindir = ctx.compiler_bindir(self.name) self.sysroot = ctx.compiler_sysroot(self.name) @@ -1216,7 +1215,7 @@ class Config(object): for g in self.compiler_glibcs: cmdlist.push_subdesc('glibc') cmdlist.push_subdesc(g.name) - g.build_glibc(cmdlist, True) + g.build_glibc(cmdlist) cmdlist.cleanup_dir() cmdlist.pop_subdesc() cmdlist.pop_subdesc() @@ -1381,8 +1380,8 @@ class Config(object): self.build_cross_tool(cmdlist, 'gcc', tool_build, cfg_opts) -class Glibc(object): - """A configuration for building glibc.""" +class GlibcBase(abc.ABC): + """Abstract base class for a configuration for building glibc.""" def __init__(self, compiler, arch=None, os_name=None, variant=None, cfg=None, ccopts=None): @@ -1427,28 +1426,28 @@ class Glibc(object): ['test', '-f', os.path.join(self.compiler.installdir, 'ok')]) cmdlist.use_path(self.compiler.bindir) - self.build_glibc(cmdlist, False) + self.build_glibc(cmdlist) cmdlist.cleanup_dir() self.ctx.add_makefile_cmdlist('glibcs-%s' % self.name, cmdlist, logsdir) - def build_glibc(self, cmdlist, for_compiler): - """Generate commands to build this glibc, either as part of a compiler - build or with the bootstrapped compiler (and in the latter case, run - tests as well).""" + @abc.abstractmethod + def builddir(self): + """Return the build directory (in which glibc is configured).""" + pass + + @abc.abstractmethod + def installdir(self): + """Return the directory into which the built glibc is installed.""" + pass + + def use_usr(self): + """Return True if this configuration uses /usr in the prefix.""" + return self.os != 'gnu' + + def configure_command(self): srcdir = self.ctx.component_srcdir('glibc') - if for_compiler: - builddir = self.ctx.component_builddir('compilers', - self.compiler.name, 'glibc', - self.name) - installdir = self.compiler.sysroot - else: - builddir = self.ctx.component_builddir('glibcs', self.name, - 'glibc') - installdir = self.ctx.glibc_installdir(self.name) - cmdlist.create_use_dir(builddir) - use_usr = self.os != 'gnu' - prefix = '/usr' if use_usr else '' + prefix = '/usr' if self.use_usr() else '' cfg_cmd = [os.path.join(srcdir, 'configure'), '--prefix=%s' % prefix, '--enable-profile', @@ -1468,7 +1467,13 @@ class Glibc(object): if self.os == 'gnu': cfg_cmd += ['MIG=%s' % self.tool_name('mig')] cfg_cmd += self.cfg - cmdlist.add_command('configure', cfg_cmd) + return cfg_cmd + + def build_glibc(self, cmdlist): + """Generate commands to build this glibc.""" + installdir = self.installdir() + cmdlist.create_use_dir(self.builddir()) + cmdlist.add_command('configure', self.configure_command()) cmdlist.add_command('build', ['make']) cmdlist.add_command('install', ['make', 'install', 'install_root=%s' % installdir]) @@ -1476,19 +1481,40 @@ class Glibc(object): # directories always exist. mkdir_cmd = ['mkdir', '-p', os.path.join(installdir, 'lib')] - if use_usr: + if self.use_usr(): mkdir_cmd += [os.path.join(installdir, 'usr', 'lib')] cmdlist.add_command('mkdir-lib', mkdir_cmd) - if not for_compiler: - if self.ctx.strip: - cmdlist.add_command('strip', - ['sh', '-c', - ('%s $(find %s/lib* -name "*.so")' % - (self.tool_name('strip'), installdir))]) - cmdlist.add_command('check', ['make', 'check']) - cmdlist.add_command('save-logs', [self.ctx.save_logs], - always_run=True) +class GlibcForCompiler(GlibcBase): + """Building glibc as part of the compiler builds.""" + + def builddir(self): + return self.ctx.component_builddir('compilers', + self.compiler.name, 'glibc', + self.name) + def installdir(self): + return self.compiler.sysroot + +class Glibc(GlibcBase): + """Building and checking glibc, for installation.""" + + def builddir(self): + return self.ctx.component_builddir('glibcs', self.name, 'glibc') + + def installdir(self): + return self.ctx.glibc_installdir(self.name) + + def build_glibc(self, cmdlist): + super().build_glibc(cmdlist) + if self.ctx.strip: + cmdlist.add_command('strip', + ['sh', '-c', + ('%s $(find %s/lib* -name "*.so")' % + (self.tool_name('strip'), + self.installdir()))]) + cmdlist.add_command('check', ['make', 'check']) + cmdlist.add_command('save-logs', [self.ctx.save_logs], + always_run=True) class Command(object): """A command run in the build process."""
reply other threads:[~2019-12-12 8:41 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191212084100.46188.qmail@sourceware.org \ --to=fw@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).