[gnome-ostree] build: Improve internal taskfile API, use more consistently



commit 4b9d6fae61bdaa2ab5068c00776575ffc3fa41cf
Author: Colin Walters <walters verbum org>
Date:   Thu Nov 1 09:12:20 2012 -0400

    build: Improve internal taskfile API, use more consistently
    
    * Tasks are now timestamped
    * Task logs are now consistently named 'log'
    * Make each build a full task (e.g. ostree commit is counted)

 src/ostbuild/pyostbuild/builtin_autobuilder.py |   10 ++++++----
 src/ostbuild/pyostbuild/builtin_build.py       |   22 +++++++++++++---------
 src/ostbuild/pyostbuild/subprocess_helpers.py  |    2 +-
 src/ostbuild/pyostbuild/task.py                |   13 +++++++++++--
 4 files changed, 31 insertions(+), 16 deletions(-)
---
diff --git a/src/ostbuild/pyostbuild/builtin_autobuilder.py b/src/ostbuild/pyostbuild/builtin_autobuilder.py
index 3e8709c..168d423 100755
--- a/src/ostbuild/pyostbuild/builtin_autobuilder.py
+++ b/src/ostbuild/pyostbuild/builtin_autobuilder.py
@@ -104,8 +104,9 @@ class OstbuildAutobuilder(builtins.Builtin):
 
     def _run_resolve(self, fetch=False, components=[]):
         assert self.resolve_proc is None
-        workdir = self._resolve_taskset.start()
-        f = open(os.path.join(workdir, 'log'), 'w')
+        t = self._resolve_taskset.start()
+        workdir = t.path
+        f = t.logfile_stream
         args = ['ostbuild', 'resolve', '--manifest=' + self.manifest]
         if fetch:
             args.append('--fetch')
@@ -137,9 +138,10 @@ class OstbuildAutobuilder(builtins.Builtin):
         assert self.build_proc is None
         assert self.build_needed
         self.build_needed = False
-        workdir = self._build_taskset.start()
+        t = self._build_taskset.start()
+        workdir = t.path
+        f = t.logfile_stream
         statusjson = os.path.join(workdir, 'status.json')
-        f = open(os.path.join(workdir, 'log'), 'w')
         args = ['ostbuild', 'build', '--skip-vcs-matches',
                 '--src-snapshot=' + self.source_snapshot_path,
                 '--status-json-path=' + statusjson]
diff --git a/src/ostbuild/pyostbuild/builtin_build.py b/src/ostbuild/pyostbuild/builtin_build.py
index 121ed91..bcf4062 100755
--- a/src/ostbuild/pyostbuild/builtin_build.py
+++ b/src/ostbuild/pyostbuild/builtin_build.py
@@ -272,7 +272,8 @@ class OstbuildBuild(builtins.Builtin):
 
         taskdir = task.TaskDir(os.path.join(self.workdir, 'tasks'))
         build_taskset = taskdir.get(buildname)
-        workdir = build_taskset.start()
+        t = build_taskset.start()
+        workdir = t.path
 
         temp_metadata_path = os.path.join(workdir, '_ostbuild-meta.json')
         fileutil.write_json_file_atomic(temp_metadata_path, expanded_component)
@@ -294,8 +295,6 @@ class OstbuildBuild(builtins.Builtin):
 
         os.unlink(temp_metadata_path)
 
-        log_path = os.path.join(workdir, 'compile.log')
-
         component_resultdir = os.path.join(workdir, 'results')
         fileutil.ensure_dir(component_resultdir)
 
@@ -333,12 +332,11 @@ class OstbuildBuild(builtins.Builtin):
         env_copy = dict(buildutil.BUILD_ENV)
         env_copy['PWD'] = chroot_sourcedir
 
-        log("Logging to %s" % (log_path, ))
-        f = open(log_path, 'w')
-        
-        success = run_sync_monitor_log_file(child_args, log_path, env=env_copy,
-                                            fatal_on_error=False)
+        success = run_sync(child_args, stdout=t.logfile_stream,
+                           stderr=t.logfile_stream, env=env_copy,
+                           fatal_on_error=False)
         if not success:
+            build_taskset.finish(False)
             self._analyze_build_failure(architecture, component, component_src,
                                         current_vcs_version, previous_vcs_version)
             self._write_status('Failed building ' + build_ref)
@@ -363,7 +361,9 @@ class OstbuildBuild(builtins.Builtin):
             f.close()
             args.append('--statoverride=' + statoverride_path)
 
-        run_sync(args, cwd=component_resultdir)
+        run_sync(args, stdout=t.logfile_stream,
+                 stderr=t.logfile_stream,
+                 cwd=component_resultdir)
         if statoverride_path is not None:
             os.unlink(statoverride_path)
 
@@ -374,6 +374,10 @@ class OstbuildBuild(builtins.Builtin):
                 shutil.rmtree(component_src)
             shutil.rmtree(component_resultdir)
 
+        shutil.rmtree(tmpdir)
+
+        build_taskset.finish(True)
+
         return run_sync_get_output(['ostree', '--repo=' + self.repo,
                                     'rev-parse', build_ref])
 
diff --git a/src/ostbuild/pyostbuild/subprocess_helpers.py b/src/ostbuild/pyostbuild/subprocess_helpers.py
index b05e77e..37ed368 100755
--- a/src/ostbuild/pyostbuild/subprocess_helpers.py
+++ b/src/ostbuild/pyostbuild/subprocess_helpers.py
@@ -111,7 +111,7 @@ def run_sync(args, cwd=None, env=None, fatal_on_error=True, keep_stdin=False,
             logfn("Command %s exited with code %d" % (subprocess.list2cmdline(args), returncode))
         else:
             logfn("pid %d exited with code %d" % (proc.pid, returncode))
-    return returncode
+    return os.WIFEXITED(returncode) and os.WEXITSTATUS(returncode) == 0
 
 def run_sync_monitor_log_file(args, logfile, cwd=None, env=None,
                               fatal_on_error=True, log_initiation=True):
diff --git a/src/ostbuild/pyostbuild/task.py b/src/ostbuild/pyostbuild/task.py
index 8f6dfae..1ba1c20 100644
--- a/src/ostbuild/pyostbuild/task.py
+++ b/src/ostbuild/pyostbuild/task.py
@@ -44,6 +44,9 @@ class TaskHistoryEntry(object):
         self.major = int(match.group(1))
         self.minor = int(match.group(2))
         self.timestamp = None
+        self.logfile_path = None
+        self.logfile_stream = None
+        self.start_timestamp = None
         if state is None:
             statuspath = os.path.join(self.path, 'status')
             if os.path.isfile(statuspath):
@@ -55,6 +58,7 @@ class TaskHistoryEntry(object):
                 self.state = 'interrupted'
         else:
             self.state = state
+            self.start_timestamp = int(time.time())
 
     def finish(self, success):
         statuspath = os.path.join(self.path, 'status')
@@ -65,6 +69,8 @@ class TaskHistoryEntry(object):
             success_str = 'failed'
         self.state = success_str
         self.timestamp = int(time.time())
+        self.logfile_stream.write('Task %s in %d seconds\n' % (success_str, self.timestamp - self.start_timestamp))
+        self.logfile_stream.close()
         f.write(success_str)
         f.close()
 
@@ -109,8 +115,11 @@ class TaskSet(object):
                 lastversion = -1 
         history_path = os.path.join(self.path, '%d.%d' % (yearver, lastversion + 1))
         fileutil.ensure_dir(history_path)
-        self._history.append(TaskHistoryEntry(history_path, state='running'))
-        return history_path
+        entry = TaskHistoryEntry(history_path, state='running')
+        self._history.append(entry)
+        entry.logfile_path = os.path.join(history_path, 'log')
+        entry.logfile_stream = open(entry.logfile_path, 'w')
+        return entry
 
     def finish(self, success):
         assert self._running



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]