def _setup_distfiles(self): if not self.verified_files and self.allow_fetching: ops = self.domain.pkg_operations(self.pkg, observer=self.observer) if not ops.fetch(): raise format.GenericBuildError("failed fetching required distfiles") self.verified_files = ops._fetch_op.verified_files if self.verified_files: try: if os.path.exists(self.env["DISTDIR"]): if (os.path.isdir(self.env["DISTDIR"]) and not os.path.islink(self.env["DISTDIR"])): shutil.rmtree(self.env["DISTDIR"]) else: os.unlink(self.env["DISTDIR"]) except EnvironmentError as e: raise format.FailedDirectory( self.env["DISTDIR"], f"failed removing existing file/dir/link: {e}") from e if not ensure_dirs(self.env["DISTDIR"], mode=0o770, gid=portage_gid): raise format.FailedDirectory( self.env["DISTDIR"], "failed creating distdir symlink directory") try: for src, dest in [ (k, pjoin(self.env["DISTDIR"], v.filename)) for (k, v) in self.verified_files.items()]: os.symlink(src, dest) except EnvironmentError as e: raise format.GenericBuildError( f"Failed symlinking in distfiles for src {src} -> {dest}: {e}") from e
def setup_distfiles(self): if not self.verified_files and self.allow_fetching: ops = self.domain.pkg_operations(self.pkg, observer=self.observer) if not ops.fetch(): raise format.BuildError("failed fetching required distfiles") self.verified_files = ops._fetch_op.verified_files if self.verified_files: try: if os.path.exists(self.env["DISTDIR"]): if (os.path.isdir(self.env["DISTDIR"]) and not os.path.islink(self.env["DISTDIR"])): shutil.rmtree(self.env["DISTDIR"]) else: os.unlink(self.env["DISTDIR"]) except EnvironmentError as oe: raise_from( format.FailedDirectory( self.env["DISTDIR"], "failed removing existing file/dir/link at: exception %s" % oe)) if not ensure_dirs(self.env["DISTDIR"], mode=0770, gid=portage_gid): raise format.FailedDirectory(
def setup_workdir(self): # ensure dirs. for k in ("HOME", "T", "WORKDIR", "D"): if not ensure_dirs(self.env[k], mode=0o4770, gid=portage_gid, minimal=True): raise format.FailedDirectory( self.env[k], "%s doesn't fulfill minimum mode %o and gid %i" % (k, 0o770, portage_gid)) # XXX hack, just 'til pkgcore controls these directories if (os.stat(self.env[k]).st_mode & 0o2000): logger.warning(f"{self.env[k]} ( {k} ) is setgid")
def setup(self): """ execute the setup phase, mapping out to pkg_setup in the ebuild necessarily dirs are created as required, and build env is initialized at this point """ if self.distcc: for p in ("", "/lock", "/state"): if not ensure_dirs(pjoin(self.env["DISTCC_DIR"], p), mode=02775, gid=portage_gid): raise format.FailedDirectory( pjoin(self.env["DISTCC_DIR"], p), "failed creating needed distcc directory")
def _setup_env_data_source(self): if not ensure_dirs(self.env["T"], mode=0o770, gid=portage_gid, minimal=True): raise format.FailedDirectory( self.env['T'], "%s doesn't fulfill minimum mode %o and gid %i" % ( self.env['T'], 0o770, portage_gid)) if self.env_data_source is not None: fp = pjoin(self.env["T"], "environment") # load data first (might be a local_source), *then* write # if it's a src_ebuild being installed, trying to do two steps # stomps the local_sources data. data = self.env_data_source.bytes_fileobj().read() with open(fp, "wb") as f: f.write(data) del data
class buildable(ebd, setup_mixin, format.build): """build operation""" _built_class = ebuild_built.fresh_built_package # XXX this is unclean- should be handing in strictly what is build # env, rather then dumping domain settings as env. def __init__(self, domain, pkg, verified_files, eclass_cache, observer=None, **kwargs): """ :param pkg: :obj:`pkgcore.ebuild.ebuild_src.package` instance we'll be building :param domain_settings: dict bled down from the domain configuration; basically initial env :param eclass_cache: the :class:`pkgcore.ebuild.eclass_cache` we'll be using :param files: mapping of fetchables mapped to their disk location """ use = kwargs.get("use_override", pkg.use) domain_settings = domain.settings format.build.__init__(self, domain, pkg, verified_files, observer) ebd.__init__(self, pkg, initial_env=domain_settings, features=domain_settings["FEATURES"], **kwargs) self.env["FILESDIR"] = pjoin(os.path.dirname(pkg.ebuild.path), "files") self.eclass_cache = eclass_cache self.env["ECLASSDIR"] = eclass_cache.eclassdir portdir = self.env["PORTDIR"] = eclass_cache.portdir if portdir is None: del self.env["PORTDIR"] self.run_test = self.feat_or_bool("test", domain_settings) self.allow_failed_test = self.feat_or_bool("test-fail-continue", domain_settings) if "test" in self.restrict: self.run_test = False elif "test" not in use: if self.run_test: logger.warning( "disabling test for %s due to test use flag being disabled" % pkg) self.run_test = False # XXX minor hack path = self.env["PATH"].split(":") for s, default in (("DISTCC", ".distcc"), ("CCACHE", "ccache")): b = (self.feat_or_bool(s, domain_settings) and not s in self.restrict) setattr(self, s.lower(), b) if b: # looks weird I realize, but # pjoin("/foor/bar", "/barr/foo") == "/barr/foo" # and pjoin("/foo/bar", ".asdf") == "/foo/bar/.asdf" self.env.setdefault(s + "_DIR", pjoin(self.tmpdir, default)) # gentoo bug 355283 libdir = self.env.get("ABI") if libdir is not None: libdir = self.env.get("LIBDIR_%s" % (libdir, )) if libdir is not None: libdir = self.env.get(libdir) if libdir is None: libdir = "lib" path.insert(0, "/usr/%s/%s/bin" % (libdir, s.lower())) else: for y in ("_PATH", "_DIR"): if s + y in self.env: del self.env[s + y] path = [piece for piece in path if piece] self.env["PATH"] = ":".join(path) self.env["A"] = ' '.join(set(x.filename for x in pkg.fetchables)) if self.eapi_obj.options.has_AA: pkg = getattr(self.pkg, '_raw_pkg', self.pkg) self.env["AA"] = ' '.join( set(x.filename for x in iflatten_instance( pkg.fetchables, fetch.fetchable))) if self.eapi_obj.options.has_KV: ret = spawn_get_output(['uname', '-r']) if ret[0] == 0: self.env["KV"] = ret[1][0].strip() if self.eapi_obj.options.has_merge_type: self.env["MERGE_TYPE"] = "source" if self.setup_is_for_src: self.init_distfiles_env() def init_distfiles_env(self): # cvs/svn ebuilds need to die. distdir_write = self.domain.fetcher.get_storage_path() if distdir_write is None: raise format.GenericBuildError( "no usable distdir was found " "for PORTAGE_ACTUAL_DISTDIR from fetcher %s" % self.domain.fetcher) self.env["PORTAGE_ACTUAL_DISTDIR"] = distdir_write self.env["DISTDIR"] = normpath(pjoin(self.builddir, "distdir")) for x in ("PORTAGE_ACTUAL_DISTDIR", "DISTDIR"): self.env[x] = os.path.realpath(self.env[x]).rstrip("/") + "/" def setup_distfiles(self): if not self.verified_files and self.allow_fetching: ops = self.domain.pkg_operations(self.pkg, observer=self.observer) if not ops.fetch(): raise format.BuildError("failed fetching required distfiles") self.verified_files = ops._fetch_op.verified_files if self.verified_files: try: if os.path.exists(self.env["DISTDIR"]): if (os.path.isdir(self.env["DISTDIR"]) and not os.path.islink(self.env["DISTDIR"])): shutil.rmtree(self.env["DISTDIR"]) else: os.unlink(self.env["DISTDIR"]) except EnvironmentError as oe: raise_from( format.FailedDirectory( self.env["DISTDIR"], "failed removing existing file/dir/link at: exception %s" % oe)) if not ensure_dirs(self.env["DISTDIR"], mode=0770, gid=portage_gid): raise format.FailedDirectory( self.env["DISTDIR"], "failed creating distdir symlink directory")
# note all pkgs have this attribute is_source = getattr(self.pkg, '_is_from_source', True) if self.eapi_obj.options.has_merge_type: env["MERGE_TYPE"] = (is_source and "source") or "binary" else: # we still must export this, just via the portage var name w/ # different values. if we didn't, spec or not, kernel binpkg # merging would be broke. env["EMERGE_FROM"] = (is_source and "ebuild") or "binary" def setup_logging(self): if self.logging and not ensure_dirs( os.path.dirname(self.logging), mode=02770, gid=portage_gid): raise format.FailedDirectory( os.path.dirname(self.logging), "PORT_LOGDIR, desired mode 02770 and gid %i" % portage_gid) def setup_workdir(self): # ensure dirs. for k in ("HOME", "T", "WORKDIR", "D"): if not ensure_dirs( self.env[k], mode=04770, gid=portage_gid, minimal=True): raise format.FailedDirectory( self.env[k], "%s doesn't fulfill minimum mode %o and gid %i" % (k, 0770, portage_gid)) # XXX hack, just 'til pkgcore controls these directories if (os.stat(self.env[k]).st_mode & 02000): logger.warning("%s ( %s ) is setgid" % (self.env[k], k))
def setup(self): """Execute the setup phase, mapping out to pkg_setup in the ebuild. Necessarily dirs are created as required, and build env is initialized at this point. """ if self.distcc: for p in ("", "/lock", "/state"): if not ensure_dirs(pjoin(self.env["DISTCC_DIR"], p), mode=0o2775, gid=portage_gid): raise format.FailedDirectory( pjoin(self.env["DISTCC_DIR"], p), "failed creating needed distcc directory") if self.ccache: # yuck. st = None try: st = os.stat(self.env["CCACHE_DIR"]) except OSError as e: st = None if not ensure_dirs(self.env["CCACHE_DIR"], mode=0o2775, gid=portage_gid): raise format.FailedDirectory( self.env["CCACHE_DIR"], "failed creation of ccache dir") from e # XXX this is more then mildly stupid. st = os.stat(self.env["CCACHE_DIR"]) try: if st.st_gid != portage_gid or (st.st_mode & 0o2775) != 0o2775: try: cwd = os.getcwd() except OSError: cwd = "/" with chdir(cwd): # crap. os.chmod(self.env["CCACHE_DIR"], 0o2775) os.chown(self.env["CCACHE_DIR"], -1, portage_gid) if 0 != spawn( ["chgrp", "-R", str(portage_gid), self.env["CCACHE_DIR"]]): raise format.FailedDirectory( self.env["CCACHE_DIR"], "failed changing ownership for CCACHE_DIR") if 0 != spawn_bash( "find '%s' -type d -print0 | %s --null chmod 02775" % (self.env["CCACHE_DIR"], xargs)): raise format.FailedDirectory( self.env["CCACHE_DIR"], "failed correcting perms for CCACHE_DIR") if 0 != spawn_bash( "find '%s' -type f -print0 | %s --null chmod 0775" % (self.env["CCACHE_DIR"], xargs)): raise format.FailedDirectory( self.env["CCACHE_DIR"], "failed correcting perms for CCACHE_DIR") except OSError as e: raise format.FailedDirectory( self.env["CCACHE_DIR"], "failed ensuring perms/group owner for CCACHE_DIR") from e return setup_mixin.setup(self)
def setup_logging(self): if self.logging and not ensure_dirs(os.path.dirname(self.logging), mode=0o2770, gid=portage_gid): raise format.FailedDirectory( os.path.dirname(self.logging), "PORT_LOGDIR, desired mode 02770 and gid %i" % portage_gid)