diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2014-09-22 09:22:56 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-09-22 09:22:56 +0000 |
commit | cb7eed0a589c7b2ea62ca6df789422d09b9dcb43 (patch) | |
tree | e6bb5d5c4e06f14de98569298cc00e3fcbbf829f /morphlib/plugins | |
parent | e62eced3044c2383de3029e9d7ae2b2649704e80 (diff) | |
parent | 945c60a1aa0b48f49c08e70206a5ca24f1c710bb (diff) | |
download | morph-cb7eed0a589c7b2ea62ca6df789422d09b9dcb43.tar.gz |
Merge branch 'baserock/richardmaw-os/tidy-build-logic-v7'
Reviewed-by: Lars Wirzenius (+2 to misc fixups)
Reviewed-by: Sam Thursfield (+1 to per-source building)
Reviewed-by: Paul Sherwood (+1 to per-source building)
Diffstat (limited to 'morphlib/plugins')
-rw-r--r-- | morphlib/plugins/cross-bootstrap_plugin.py | 125 | ||||
-rw-r--r-- | morphlib/plugins/show_dependencies_plugin.py | 4 |
2 files changed, 57 insertions, 72 deletions
diff --git a/morphlib/plugins/cross-bootstrap_plugin.py b/morphlib/plugins/cross-bootstrap_plugin.py index 0c3e3a4a..7b53a4a5 100644 --- a/morphlib/plugins/cross-bootstrap_plugin.py +++ b/morphlib/plugins/cross-bootstrap_plugin.py @@ -58,38 +58,39 @@ class BootstrapSystemBuilder(morphlib.builder2.BuilderBase): def build_and_cache(self): with self.build_watch('overall-build'): - handle = self.local_artifact_cache.put(self.artifact) - fs_root = self.staging_area.destdir(self.artifact.source) - try: - self.unpack_binary_chunks(fs_root) - self.unpack_sources(fs_root) - self.write_build_script(fs_root) - system_name = self.artifact.source.morphology['name'] - self.create_tarball(handle, fs_root, system_name) - except BaseException, e: - logging.error(traceback.format_exc()) - self.app.status(msg='Error while building bootstrap image', - error=True) - handle.abort() - raise - - handle.close() + for system_name, artifact in self.source.artifacts.iteritems(): + handle = self.local_artifact_cache.put(artifact) + fs_root = self.staging_area.destdir(self.source) + try: + self.unpack_binary_chunks(fs_root) + self.unpack_sources(fs_root) + self.write_build_script(fs_root) + self.create_tarball(handle, fs_root, system_name) + except BaseException, e: + logging.error(traceback.format_exc()) + self.app.status(msg='Error while building bootstrap image', + error=True) + handle.abort() + raise + + handle.close() self.save_build_times() - return [self.artifact] + return self.source.artifacts.items() def unpack_binary_chunks(self, dest): cache = self.local_artifact_cache - for chunk_artifact in self.artifact.source.cross_chunks: - with cache.get(chunk_artifact) as chunk_file: - try: - morphlib.bins.unpack_binary_from_file(chunk_file, dest) - except BaseException, e: - self.app.status( - msg='Error unpacking binary chunk %(name)s', - name=chunk_artifact.name, - error=True) - raise + for chunk_source in self.source.cross_sources: + for chunk_artifact in chunk_source.artifacts.itervalues(): + with cache.get(chunk_artifact) as chunk_file: + try: + morphlib.bins.unpack_binary_from_file(chunk_file, dest) + except BaseException, e: + self.app.status( + msg='Error unpacking binary chunk %(name)s', + name=chunk_artifact.name, + error=True) + raise def unpack_sources(self, path): # Multiple chunks sources may be built from the same repo ('linux' @@ -98,24 +99,18 @@ class BootstrapSystemBuilder(morphlib.builder2.BuilderBase): # # It might be neater to build these as "source artifacts" individually, # but that would waste huge amounts of space in the artifact cache. - for a in self.artifact.walk(): - if a in self.artifact.source.cross_chunks: - continue - if a.source.morphology['kind'] != 'chunk': - continue - - escaped_source = escape_source_name(a.source) + for s in self.source.native_sources: + escaped_source = escape_source_name(s) source_dir = os.path.join(path, 'src', escaped_source) if not os.path.exists(source_dir): os.makedirs(source_dir) morphlib.builder2.extract_sources( - self.app, self.repo_cache, a.source.repo, a.source.sha1, - source_dir) + self.app, self.repo_cache, s.repo, s.sha1, source_dir) - name = a.source.morphology['name'] + name = s.name chunk_script = os.path.join(path, 'src', 'build-%s' % name) with morphlib.savefile.SaveFile(chunk_script, 'w') as f: - self.write_chunk_build_script(a, f) + self.write_chunk_build_script(s, f) os.chmod(chunk_script, 0777) def write_build_script(self, path): @@ -130,15 +125,8 @@ class BootstrapSystemBuilder(morphlib.builder2.BuilderBase): if k != 'PATH': f.write('export %s="%s"\n' % (k, v)) - # FIXME: really, of course, we need to iterate the sources not the - # artifacts ... this will break when we have chunk splitting! - for a in self.artifact.walk(): - if a in self.artifact.source.cross_chunks: - continue - if a.source.morphology['kind'] != 'chunk': - continue - - name = a.source.morphology['name'] + for s in self.source.native_sources: + name = s.name f.write('\necho Building %s\n' % name) f.write('mkdir /%s.inst\n' % name) f.write('env DESTDIR=/%s.inst $SRCDIR/build-%s\n' @@ -150,17 +138,17 @@ class BootstrapSystemBuilder(morphlib.builder2.BuilderBase): f.write(driver_footer) os.chmod(driver_script, 0777) - def write_chunk_build_script(self, chunk, f): - m = chunk.source.morphology + def write_chunk_build_script(self, source, f): + m = source.morphology f.write('#!/bin/sh\n') f.write('# Build script generated by morph\n') f.write('set -e\n') f.write('chunk_name=%s\n' % m['name']) - repo = escape_source_name(chunk.source) + repo = escape_source_name(source) f.write('cp -a $SRCDIR/%s $DESTDIR/$chunk_name.build\n' % repo) f.write('cd $DESTDIR/$chunk_name.build\n') - f.write('export PREFIX=%s\n' % chunk.source.prefix) + f.write('export PREFIX=%s\n' % source.prefix) bs = morphlib.buildsystem.lookup_build_system(m['build-system']) @@ -261,12 +249,8 @@ class CrossBootstrapPlugin(cliapp.Plugin): build_command = morphlib.buildcommand.BuildCommand(self.app, build_env) morph_name = morphlib.util.sanitise_morphology_path(system_name) - builds_artifacts = [system_name + '-bootstrap-rootfs'] srcpool = build_command.create_source_pool(root_repo, ref, morph_name) - system_source = srcpool.lookup(root_repo, ref, morph_name) - system_source.morphology.builds_artifacts = builds_artifacts - # FIXME: this is a quick fix in order to get it working for # Baserock 13 release, it is not a reasonable fix def validate(self, root_artifact): @@ -284,35 +268,36 @@ class CrossBootstrapPlugin(cliapp.Plugin): # Calculate build order # This is basically a hacked version of BuildCommand.build_in_order() - artifacts = system_artifact.walk() - cross_chunks = [] - native_chunks = [] - for a in artifacts: - if a.source.morphology['kind'] == 'chunk': - if a.source.build_mode == 'bootstrap': - cross_chunks.append(a) + sources = build_command.get_ordered_sources(system_artifact.walk()) + cross_sources = [] + native_sources = [] + for s in sources: + if s.morphology['kind'] == 'chunk': + if s.build_mode == 'bootstrap': + cross_sources.append(s) else: - native_chunks.append(a) + native_sources.append(s) - if len(cross_chunks) == 0: + if len(cross_sources) == 0: raise morphlib.Error( 'Nothing to cross-compile. Only chunks built in \'bootstrap\' ' 'mode can be cross-compiled.') - for i, a in enumerate(cross_chunks): - build_command.cache_or_build_artifact(a, build_env) + for s in cross_sources: + build_command.cache_or_build_source(s, build_env) - for i, a in enumerate(native_chunks): - build_command.get_sources(a) + for s in native_sources: + build_command.fetch_sources(s) # Install those to the output tarball ... self.app.status(msg='Building final bootstrap system image') - system_artifact.source.cross_chunks = cross_chunks + system_artifact.source.cross_sources = cross_sources + system_artifact.source.native_sources = native_sources staging_area = build_command.create_staging_area( build_env, use_chroot=False) builder = BootstrapSystemBuilder( self.app, staging_area, build_command.lac, build_command.rac, - system_artifact, build_command.lrc, 1, False) + system_artifact.source, build_command.lrc, 1, False) builder.build_and_cache() self.app.status( diff --git a/morphlib/plugins/show_dependencies_plugin.py b/morphlib/plugins/show_dependencies_plugin.py index 3a1cb7ad..e70f6bfb 100644 --- a/morphlib/plugins/show_dependencies_plugin.py +++ b/morphlib/plugins/show_dependencies_plugin.py @@ -74,6 +74,6 @@ class ShowDependenciesPlugin(cliapp.Plugin): for artifact in reversed(root_artifact.walk()): self.app.output.write(' %s\n' % artifact) - for dependency in sorted(artifact.dependencies, key=str): - self.app.output.write(' -> %s\n' % dependency) + for dep in sorted(artifact.source.dependencies, key=str): + self.app.output.write(' -> %s\n' % dep) |