return 0;
}
+static PyObject* Pakfire_bind(PakfireObject* self, PyObject* args) {
+ const char* src = NULL;
+ const char* dst = NULL;
+
+ if (!PyArg_ParseTuple(args, "s|z", &src, &dst))
+ return NULL;
+
+ int r = pakfire_bind(self->pakfire, src, dst, 0);
+ if (r) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
static struct PyMethodDef Pakfire_methods[] = {
+ {
+ "bind",
+ (PyCFunction)Pakfire_bind,
+ METH_VARARGS,
+ NULL,
+ },
{
"dist",
(PyCFunction)Pakfire_dist,
return pakfire_path_join(pakfire->path, path);
}
+PAKFIRE_EXPORT int pakfire_bind(Pakfire pakfire, const char* src, const char* dst, int flags) {
+ if (!dst)
+ dst = src;
+
+ char* mountpoint = pakfire_make_path(pakfire, dst);
+ if (!mountpoint)
+ return 1;
+
+ DEBUG(pakfire, "Mounting %s to %s\n", src, mountpoint);
+
+ // Make sure the directory exists
+ int r = pakfire_mkdir(pakfire, mountpoint, 0);
+ if (r)
+ goto ERROR;
+
+ // Perform mount
+ r = mount(src, mountpoint, NULL, flags|MS_BIND, NULL);
+
+ERROR:
+ free(mountpoint);
+ return r;
+}
+
static const struct pakfire_mountpoint {
const char* source;
const char* target;
class Pakfire(_pakfire.Pakfire):
__version__ = PAKFIRE_VERSION
- def __init__(self, path="/", config=None, arch=None, distro=None, offline=False):
+ def __init__(self, path=None, config=None, arch=None, distro=None, offline=False):
_pakfire.Pakfire.__init__(self, path, arch, offline=offline)
# Initialise logging system
# Setup logging
self.log = self.setup_logging(logfile)
- # Path
- self.path = os.path.join(BUILD_ROOT, self.build_id)
-
# Architecture to build for
self.arch = arch or _pakfire.native_arch()
self.cgroup = self._make_cgroup()
def __enter__(self):
- self.log.debug("Entering %s" % self.path)
-
- # Mount the build environment
- self._mount()
+ self.log.debug("Entering %s" % self)
# Setup domain name resolution in chroot
- self.setup_dns()
+ #self.setup_dns()
return BuilderContext(self)
def __exit__(self, type, value, traceback):
- self.log.debug("Leaving %s" % self.path)
+ self.log.debug("Leaving %s" % self)
# Kill all remaining processes in the build environment
self.cgroup.killall()
self.cgroup.destroy()
self.cgroup = None
- # Umount the build environment
- self._umount()
-
- # Delete everything
- self._destroy()
-
def setup_logging(self, logfile):
l = log.getChild(self.build_id)
l.setLevel(logging.DEBUG)
return cgroup
- def _destroy(self):
- self.log.debug("Destroying environment %s" % self.path)
-
- if os.path.exists(self.path):
- util.rm(self.path)
-
- def _mount(self):
- """
- Mounts the build environment
- """
- os.makedirs(self.path)
-
- # Bind-mount the ccache if enabled
- if self.settings.get("enable_ccache"):
- if not os.path.exists(CCACHE_CACHE_DIR):
- os.makedirs(CCACHE_CACHE_DIR)
-
- os.makedirs("%s/var/cache/ccache" % self.path)
-
- _pakfire.mount(CCACHE_CACHE_DIR, "%s/var/cache/ccache" % self.path,
- flags=_pakfire.MS_BIND)
-
- def _umount(self):
- """
- Umounts the build environment
- """
- mountpoints = (
- "%s/var/cache/ccache" % self.path,
- )
-
- for mp in mountpoints:
- _pakfire.umount(mp)
-
def copyin(self, file_out, file_in):
if file_in.startswith("/"):
file_in = file_in[1:]
# Initialise Pakfire instance
self.pakfire = base.Pakfire(
- path=self.builder.path,
config=self.builder.config,
distro=self.builder.config.distro,
arch=self.builder.arch,
)
+ # Mount ccache
+ self.pakfire.bind(CCACHE_CACHE_DIR, "/var/cache/ccache")
+
@property
def environ(self):
# Build a minimal environment for executing, but try to inherit TERM and LANG