summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauren Perry <lauren.perry@codethink.co.uk>2015-04-29 15:54:43 +0000
committerLauren Perry <lauren.perry@codethink.co.uk>2015-04-30 17:15:40 +0100
commit2985a4683adabe1d36029181dcc97d7974133a06 (patch)
tree4da8924e86ce300782bb9a93b94f7996023c429e
parent9867774b70545831d5b3baca4dc47c17ef890601 (diff)
downloadmorph-2985a4683adabe1d36029181dcc97d7974133a06.tar.gz
morphlib: Add command to get build-log for a given chunk and system file
Change-Id: I09e9b17ef2e0fb94dbf5a96dca91062d64433add
-rw-r--r--morphlib/plugins/show_build_log_plugin.py90
-rw-r--r--without-test-modules1
2 files changed, 91 insertions, 0 deletions
diff --git a/morphlib/plugins/show_build_log_plugin.py b/morphlib/plugins/show_build_log_plugin.py
new file mode 100644
index 00000000..2c80ff50
--- /dev/null
+++ b/morphlib/plugins/show_build_log_plugin.py
@@ -0,0 +1,90 @@
+# Copyright (C) 2015 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import cliapp
+import os
+import urllib
+import urlparse
+
+import morphlib
+
+
+class ShowBuildLog(cliapp.Plugin):
+
+ def enable(self):
+ self.app.add_subcommand('show-build-log', self.show_build_log,
+ arg_synopsis='SYSTEM CHUNK')
+
+ def disable(self):
+ pass
+
+ def show_build_log(self, args):
+ '''Display build logs for a given component in a system.
+
+ Command line arguments:
+
+ * `SYSTEM` is the name of the system we want log data from.
+ * `CHUNK` is the name of the chunk we want log data for.
+
+ Example:
+
+ morph show-build-log devel-system-x86_64-generic.morph pip
+
+ '''
+
+ if len(args) != 2:
+ raise cliapp.AppException('show-build-log expects system filename '
+ 'and chunk as input.')
+
+ artifact_cache_server = (
+ self.app.settings['artifact-cache-server'] or
+ self.app.settings['cache-server'])
+
+ system = args[0]
+ chunk = args[1]
+
+ sb = morphlib.sysbranchdir.open_from_within('.')
+ root_repo_url = sb.get_config('branch.root')
+ ref = sb.get_config('branch.name')
+
+ definitions_repo_path = sb.get_git_directory_name(root_repo_url)
+
+ build_command = morphlib.buildcommand.BuildCommand(self.app, None)
+ srcpool = build_command.create_source_pool(definitions_repo_path, ref,
+ system)
+ root = build_command.resolve_artifacts(srcpool)
+
+ arch = root.source.morphology['arch']
+ build_env = build_command.new_build_env(arch)
+
+ ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
+
+ cache_key = None
+ for source in set(a.source for a in root.walk()):
+ if source.name == chunk:
+ cache_key = ckc.compute_key(source)
+ break
+
+ if cache_key:
+ url = urlparse.urljoin(artifact_cache_server,
+ '/1.0/artifacts?filename=%s.build-log' % source.cache_key)
+ build_log = urllib.urlopen(url)
+ build_output = []
+ for line in build_log:
+ build_output.append(str(line))
+ self.app.output.write(''.join(build_output))
+ else:
+ raise cliapp.AppException('Component not found in the given '
+ 'system.')
diff --git a/without-test-modules b/without-test-modules
index 689fb97f..189f1309 100644
--- a/without-test-modules
+++ b/without-test-modules
@@ -35,6 +35,7 @@ morphlib/plugins/distbuild_plugin.py
morphlib/plugins/certify_plugin.py
morphlib/plugins/get_repo_plugin.py
morphlib/plugins/system_manifests_plugin.py
+morphlib/plugins/show_build_log_plugin.py
distbuild/__init__.py
distbuild/build_controller.py
distbuild/connection_machine.py