ostbuild: Clean up artifact splitting, put non-symlink .so in runtime

We were breaking nss which just installs libnss3.so as the real
shared library.
This commit is contained in:
Colin Walters 2012-01-15 21:45:12 -05:00
parent e34b90453c
commit d5def94b54
1 changed files with 56 additions and 98 deletions

View File

@ -30,24 +30,15 @@ from .subprocess_helpers import run_sync
PREFIX = '/usr' PREFIX = '/usr'
_BLACKLIST_REGEXPS = map(re.compile, _DOC_DIRS = ['usr/share/doc',
[r'.*\.la$', 'usr/share/gtk-doc',
]) 'usr/share/man',
'usr/share/info']
_RUNTIME_DIRS = ['/etc'] _DEVEL_DIRS = ['usr/include',
'usr/share/aclocal',
_DOC_DIRS = ['/usr/share/doc', 'usr/share/pkgconfig',
'/usr/share/gtk-doc', 'usr/lib/pkgconfig']
'/usr/share/man',
'/usr/share/info']
_DEVEL_DIRS = ['/usr/include',
'/usr/share/aclocal',
'/usr/share/pkgconfig',
'/usr/lib/pkgconfig']
_DEVEL_REGEXPS = map(re.compile,
[r'/(?:usr/)lib/[^/]+\.(?:so|a)$'])
class OstbuildCompileOne(builtins.Builtin): class OstbuildCompileOne(builtins.Builtin):
name = "compile-one" name = "compile-one"
@ -207,66 +198,49 @@ class OstbuildCompileOne(builtins.Builtin):
args = ['make', 'install', 'DESTDIR=' + tempdir] args = ['make', 'install', 'DESTDIR=' + tempdir]
run_sync(args, cwd=builddir) run_sync(args, cwd=builddir)
devel_files = set() runtime_path = os.path.join(self.ostbuild_resultdir, 'runtime')
doc_files = set() devel_path = os.path.join(self.ostbuild_resultdir, 'devel')
runtime_files = set() docs_path = os.path.join(self.ostbuild_resultdir, 'docs')
for artifact_type in ['runtime', 'devel', 'docs']:
resultdir = os.path.join(self.ostbuild_resultdir, artifact_type)
if os.path.isdir(resultdir):
shutil.rmtree(resultdir)
os.makedirs(resultdir)
oldpwd=os.getcwd() # Move symbolic links for shared libraries as well
os.chdir(tempdir) # as static libraries. And delete all .la files.
for root, dirs, files in os.walk('.'): for libdirname in ['lib', 'usr/lib']:
deleted_dirs = set() path = os.path.join(tempdir, libdirname)
for dirname in dirs: if not os.path.isdir(path):
path = os.path.join(root, dirname) continue
subpath = path[1:] for filename in os.listdir(path):
matched = False subpath = os.path.join(path, filename)
for runtime_name in _RUNTIME_DIRS: if filename.endswith('.la'):
if subpath.startswith(runtime_name): os.unlink(subpath)
runtime_files.add(path)
matched = True
break
if not matched:
for devel_name in _DEVEL_DIRS:
if subpath.startswith(devel_name):
devel_files.add(path)
matched = True
break
if not matched:
for doc_name in _DOC_DIRS:
if subpath.startswith(doc_name):
doc_files.add(path)
matched = True
break
if matched:
deleted_dirs.add(dirname)
for dirname in deleted_dirs:
dirs.remove(dirname)
for filename in files:
path = os.path.join(root, filename)
blacklisted = False
for r in _BLACKLIST_REGEXPS:
if r.match(path):
blacklisted = True
break
if blacklisted:
continue continue
if not ((filename.endswith('.so')
and os.path.islink(filename))
or filename.endswith('.a')):
continue
dest = os.path.join(devel_path, libdirname, filename)
self._install_and_unlink(subpath, dest)
matched = False for dirname in _DEVEL_DIRS:
for r in _DEVEL_REGEXPS: dirpath = os.path.join(tempdir, dirname)
if not r.match(path[1:]): if os.path.isdir(dirpath):
continue dest = os.path.join(devel_path, dirname)
devel_files.add(path) self._install_and_unlink(dirpath, dest)
matched = True
break
if not matched:
runtime_files.add(path)
os.chdir(oldpwd)
self.make_artifact('devel', devel_files, tempdir=tempdir) for dirname in _DOC_DIRS:
self.make_artifact('doc', doc_files, tempdir=tempdir) dirpath = os.path.join(tempdir, dirname)
self.make_artifact('runtime', runtime_files, tempdir=tempdir) if os.path.isdir(dirpath):
dest = os.path.join(docs_path, dirname)
self._install_and_unlink(dirpath, dest)
for filename in os.listdir(tempdir):
src_path = os.path.join(tempdir, filename)
dest_path = os.path.join(runtime_path, filename)
self._install_and_unlink(src_path, dest_path)
for tmpname in self.tempfiles: for tmpname in self.tempfiles:
assert os.path.isabs(tmpname) assert os.path.isabs(tmpname)
@ -278,9 +252,11 @@ class OstbuildCompileOne(builtins.Builtin):
except OSError, e: except OSError, e:
pass pass
def _rename_or_copy(self, src, dest): def _install_and_unlink(self, src, dest):
statsrc = os.lstat(src) statsrc = os.lstat(src)
statdest = os.lstat(os.path.dirname(dest)) dirname = os.path.dirname(dest)
if not os.path.isdir(dirname):
os.makedirs(dirname)
if stat.S_ISDIR(statsrc.st_mode): if stat.S_ISDIR(statsrc.st_mode):
if not os.path.isdir(dest): if not os.path.isdir(dest):
@ -289,7 +265,8 @@ class OstbuildCompileOne(builtins.Builtin):
src_child = os.path.join(src, filename) src_child = os.path.join(src, filename)
dest_child = os.path.join(dest, filename) dest_child = os.path.join(dest, filename)
self._rename_or_copy(src_child, dest_child) self._install_and_unlink(src_child, dest_child)
os.rmdir(src)
else: else:
try: try:
os.rename(src, dest) os.rename(src, dest)
@ -299,25 +276,6 @@ class OstbuildCompileOne(builtins.Builtin):
os.symlink(linkto, dest) os.symlink(linkto, dest)
else: else:
shutil.copy2(src, dest) shutil.copy2(src, dest)
os.unlink(src)
def make_artifact(self, dirtype, from_files, tempdir):
resultdir = os.path.join(self.ostbuild_resultdir, dirtype)
if os.path.isdir(resultdir):
shutil.rmtree(resultdir)
os.makedirs(resultdir)
for filename in from_files:
if filename.startswith('./'):
filename = filename[2:]
src_path = os.path.join(tempdir, filename)
dest_path = os.path.join(resultdir, filename)
dest_dir = os.path.dirname(dest_path)
if not os.path.isdir(dest_dir):
os.makedirs(dest_dir)
try:
self._rename_or_copy(src_path, dest_path)
except OSError, e:
fatal("Failed to copy %r to %r: %d %s" % (src_path, dest_path, e.errno, e.strerror))
log("created: %s" % (os.path.abspath (resultdir), ))
builtins.register(OstbuildCompileOne) builtins.register(OstbuildCompileOne)