[ostree] ostbuild: Run triggers after constructing build root



commit ef7f12f31bcfa1022b49af48473e36fa8b45e928
Author: Colin Walters <walters verbum org>
Date:   Sun Jan 15 17:04:55 2012 -0500

    ostbuild: Run triggers after constructing build root

 Makefile-ostbuild.am                               |    1 +
 src/ostbuild/pyostbuild/buildutil.py               |   26 ++++++++++-
 .../pyostbuild/builtin_chroot_compile_one.py       |   30 ++---------
 .../pyostbuild/builtin_chroot_run_triggers.py      |   51 ++++++++++++++++++++
 src/ostbuild/pyostbuild/main.py                    |    1 +
 5 files changed, 84 insertions(+), 25 deletions(-)
---
diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am
index 7cc2ac8..327d85b 100644
--- a/Makefile-ostbuild.am
+++ b/Makefile-ostbuild.am
@@ -25,6 +25,7 @@ pyostbuild_PYTHON =					\
 	src/ostbuild/pyostbuild/builtin_autodiscover_meta.py	\
 	src/ostbuild/pyostbuild/builtin_build.py	\
 	src/ostbuild/pyostbuild/builtin_chroot_compile_one.py	\
+	src/ostbuild/pyostbuild/builtin_chroot_run_triggers.py	\
 	src/ostbuild/pyostbuild/builtin_commit_artifacts.py	\
 	src/ostbuild/pyostbuild/builtin_compile_one.py	\
 	src/ostbuild/pyostbuild/builtin_resolve.py	\
diff --git a/src/ostbuild/pyostbuild/buildutil.py b/src/ostbuild/pyostbuild/buildutil.py
index b120fd8..3a3716b 100755
--- a/src/ostbuild/pyostbuild/buildutil.py
+++ b/src/ostbuild/pyostbuild/buildutil.py
@@ -15,11 +15,35 @@
 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
+import os
 import re
 
 from .subprocess_helpers import run_sync_get_output
 
-ARTIFACT_RE = re.compile(r'^artifact-([^,]+),([^,]+),([^,]+),([^,]+),(.+)-((?:runtime)|(?:devel))\.tar$')
+BUILD_ENV = {
+    'HOME' : '/', 
+    'HOSTNAME' : 'ostbuild',
+    'LANG': 'C',
+    'PATH' : '/usr/bin:/bin:/usr/sbin:/sbin',
+    'SHELL' : '/bin/bash',
+    'TERM' : 'vt100',
+    'TMPDIR' : '/tmp',
+    'TZ': 'EST5EDT'
+    }
+
+def find_user_chroot_path():
+    # We need to search PATH here manually so we correctly pick up an
+    # ostree install in e.g. ~/bin even though we're going to set PATH
+    # below for our children inside the chroot.
+    ostbuild_user_chroot_path = None
+    for dirname in os.environ['PATH'].split(':'):
+        path = os.path.join(dirname, 'linux-user-chroot')
+        if os.access(path, os.X_OK):
+            ostbuild_user_chroot_path = path
+            break
+    if ostbuild_user_chroot_path is None:
+        ostbuild_user_chroot_path = 'linux-user-chroot'
+    return ostbuild_user_chroot_path
 
 def branch_name_for_artifact(a):
     return 'artifacts/%s/%s/%s' % (a['buildroot'],
diff --git a/src/ostbuild/pyostbuild/builtin_chroot_compile_one.py b/src/ostbuild/pyostbuild/builtin_chroot_compile_one.py
index cdb2e37..50d2d33 100755
--- a/src/ostbuild/pyostbuild/builtin_chroot_compile_one.py
+++ b/src/ostbuild/pyostbuild/builtin_chroot_compile_one.py
@@ -21,20 +21,10 @@ import argparse
 import json
 
 from . import builtins
+from . import buildutil
 from .ostbuildlog import log, fatal
 from .subprocess_helpers import run_sync
 
-BUILD_ENV = {
-    'HOME' : '/', 
-    'HOSTNAME' : 'ostbuild',
-    'LANG': 'C',
-    'PATH' : '/usr/bin:/bin:/usr/sbin:/sbin',
-    'SHELL' : '/bin/bash',
-    'TERM' : 'vt100',
-    'TMPDIR' : '/tmp',
-    'TZ': 'EST5EDT'
-    }
-
 class OstbuildChrootCompileOne(builtins.Builtin):
     name = "chroot-compile-one"
     short_description = "Build artifacts from the current source directory in a chroot"
@@ -95,6 +85,8 @@ class OstbuildChrootCompileOne(builtins.Builtin):
                 shutil.rmtree(rootdir_tmp)
             child_args = ['ostree', '--repo=' + args.repo, 'checkout', '-U', rev, rootdir_tmp]
             run_sync(child_args)
+            child_args = ['ostbuild', 'chroot-run-triggers', rootdir_tmp]
+            run_sync(child_args)
             builddir_tmp = os.path.join(rootdir_tmp, 'ostbuild')
             os.mkdir(builddir_tmp)
             os.mkdir(os.path.join(builddir_tmp, 'source'))
@@ -113,18 +105,8 @@ class OstbuildChrootCompileOne(builtins.Builtin):
         output_metadata.close()
         
         chroot_sourcedir = os.path.join('/ostbuild', 'source', self.metadata['name'])
-        
-        # We need to search PATH here manually so we correctly pick up an
-        # ostree install in e.g. ~/bin even though we're going to set PATH
-        # below for our children inside the chroot.
-        ostbuild_user_chroot_path = None
-        for dirname in os.environ['PATH'].split(':'):
-            path = os.path.join(dirname, 'linux-user-chroot')
-            if os.access(path, os.X_OK):
-                ostbuild_user_chroot_path = path
-                break
-        if ostbuild_user_chroot_path is None:
-            ostbuild_user_chroot_path = 'linux-user-chroot'
+
+        ostbuild_user_chroot_path = buildutil.find_user_chroot_path()
         
         child_args = [ostbuild_user_chroot_path, '--unshare-pid', '--unshare-net', '--unshare-ipc',
                       '--mount-readonly', '/',
@@ -143,7 +125,7 @@ class OstbuildChrootCompileOne(builtins.Builtin):
                                '--ostbuild-resultdir=/ostbuild/results',
                                '--ostbuild-meta=_ostbuild-meta'])
             child_args.extend(rest_args)
-        env_copy = dict(BUILD_ENV)
+        env_copy = dict(buildutil.BUILD_ENV)
         env_copy['PWD'] = chroot_sourcedir
         run_sync(child_args, env=env_copy, keep_stdin=args.debug_shell)
         
diff --git a/src/ostbuild/pyostbuild/builtin_chroot_run_triggers.py b/src/ostbuild/pyostbuild/builtin_chroot_run_triggers.py
new file mode 100755
index 0000000..bdee64c
--- /dev/null
+++ b/src/ostbuild/pyostbuild/builtin_chroot_run_triggers.py
@@ -0,0 +1,51 @@
+# Copyright (C) 2011,2012 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,re,subprocess,tempfile,shutil
+from StringIO import StringIO
+import argparse
+import json
+
+from . import builtins
+from . import buildutil
+from .ostbuildlog import log, fatal
+from .subprocess_helpers import run_sync
+
+class OstbuildChrootRunTriggers(builtins.Builtin):
+    name = "chroot-run-triggers"
+    short_description = "Run ostree-run-triggers inside a chroot"
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+        parser.add_argument('root')
+        
+        args = parser.parse_args(argv)
+
+        ostbuild_user_chroot_path = buildutil.find_user_chroot_path()
+
+        child_args = [ostbuild_user_chroot_path,
+                      '--unshare-pid', '--unshare-net', '--unshare-ipc',
+                      '--mount-proc', '/proc', 
+                      '--mount-bind', '/dev', '/dev',
+                      args.root,
+                      '/usr/bin/ostree-run-triggers']
+        print "%r" % (child_args,)
+        env_copy = dict(buildutil.BUILD_ENV)
+        env_copy['PWD'] = '/' 
+        run_sync(child_args, env=env_copy)
+                       
+builtins.register(OstbuildChrootRunTriggers)
diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py
index 558957e..4afb450 100755
--- a/src/ostbuild/pyostbuild/main.py
+++ b/src/ostbuild/pyostbuild/main.py
@@ -25,6 +25,7 @@ from . import builtins
 from . import builtin_autodiscover_meta
 from . import builtin_build
 from . import builtin_chroot_compile_one
+from . import builtin_chroot_run_triggers
 from . import builtin_commit_artifacts
 from . import builtin_compile_one
 from . import builtin_resolve



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