* [gentoo-commits] proj/portage:master commit in: lib/portage/util/, /
@ 2021-02-28 10:10 Zac Medico
0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2021-02-28 10:10 UTC (permalink / raw
To: gentoo-commits
commit: 695be424d3ef3bba6cf26f6ff70df066e1cd248c
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 28 07:34:13 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Feb 28 09:49:05 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=695be424
setup.py: add entry_points when installed with pip
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/util/bin_entry_point.py | 24 ++++++++++++++++++++++++
setup.py | 27 +++++++++++++++++++++------
2 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/lib/portage/util/bin_entry_point.py b/lib/portage/util/bin_entry_point.py
new file mode 100644
index 000000000..7f2ee3849
--- /dev/null
+++ b/lib/portage/util/bin_entry_point.py
@@ -0,0 +1,24 @@
+# Copyright 2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+__all__ = ["bin_entry_point"]
+
+import sys
+
+from portage.const import PORTAGE_BIN_PATH
+from portage import os
+
+
+def bin_entry_point():
+ """
+ Adjust sys.argv[0] to point to a script in PORTAGE_BIN_PATH, and
+ then execute the script, in order to implement entry_points when
+ portage has been installed by pip.
+ """
+ script_path = os.path.join(PORTAGE_BIN_PATH, os.path.basename(sys.argv[0]))
+ if os.access(script_path, os.X_OK):
+ sys.argv[0] = script_path
+ os.execvp(sys.argv[0], sys.argv)
+ else:
+ print("File not found:", script_path, file=sys.stderr)
+ return 127
diff --git a/setup.py b/setup.py
index 96d9932e0..7d6fb6609 100755
--- a/setup.py
+++ b/setup.py
@@ -2,6 +2,7 @@
# Copyright 1998-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
+from distutils import sysconfig
from distutils.core import setup, Command, Extension
from distutils.command.build import build
from distutils.command.build_ext import build_ext as _build_ext
@@ -19,6 +20,7 @@ from distutils.util import change_root, subst_vars
import codecs
import collections
import glob
+import itertools
import os
import os.path
import platform
@@ -26,6 +28,12 @@ import re
import subprocess
import sys
+autodetect_pip = os.path.basename(os.environ.get("_", "")) == "pip" or os.path.basename(
+ os.path.dirname(__file__)
+).startswith("pip-")
+venv_prefix = "" if sys.prefix == sys.base_prefix else sys.prefix
+create_entry_points = bool(autodetect_pip or venv_prefix)
+eprefix = sysconfig.get_python_lib() if venv_prefix else ""
# TODO:
# - smarter rebuilds of docs w/ 'install_docbook' and 'install_apidoc'.
@@ -220,8 +228,9 @@ class x_build_scripts_custom(build_scripts):
self.scripts = x_scripts[self.dir_name]
else:
self.scripts = set(self.scripts)
- for other_files in x_scripts.values():
- self.scripts.difference_update(other_files)
+ if not (create_entry_points and self.dir_name == "portage"):
+ for other_files in x_scripts.values():
+ self.scripts.difference_update(other_files)
def run(self):
# group scripts by subdirectory
@@ -471,9 +480,10 @@ class x_install_lib(install_lib):
'VERSION': self.distribution.get_version(),
})
rewrite_file('portage/const.py', {
- 'PORTAGE_BASE_PATH': self.portage_base,
- 'PORTAGE_BIN_PATH': self.portage_bindir,
- 'PORTAGE_CONFIG_PATH': self.portage_confdir,
+ 'EPREFIX': eprefix,
+ 'GLOBAL_CONFIG_PATH': self.portage_confdir,
+ 'PORTAGE_BASE_PATH': eprefix + self.portage_base,
+ 'PORTAGE_BIN_PATH': eprefix + self.portage_bindir,
})
return ret
@@ -675,7 +685,12 @@ setup(
['$portage_base/bin', ['bin/deprecated-path']],
['$sysconfdir/portage/repo.postsync.d', ['cnf/repo.postsync.d/example']],
],
-
+ entry_points={
+ "console_scripts": [
+ "{}=portage.util.bin_entry_point:bin_entry_point".format(os.path.basename(path))
+ for path in itertools.chain.from_iterable(x_scripts.values())
+ ],
+ } if create_entry_points else {},
ext_modules = [Extension(name=n, sources=m,
extra_compile_args=['-D_FILE_OFFSET_BITS=64',
'-D_LARGEFILE_SOURCE', '-D_LARGEFILE64_SOURCE'])
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/util/, /
@ 2022-11-30 22:29 Sam James
0 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2022-11-30 22:29 UTC (permalink / raw
To: gentoo-commits
commit: f99ddf5659d143dd876ab05c5ff2ce425ffde672
Author: Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Sun Nov 27 19:12:53 2022 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Nov 30 22:28:58 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=f99ddf56
Revert "env-update: skip PATH in systemd user environment definition"
This reverts commit 21739ea1e0a793e207b7ae28d524e45582d9b2ca, as it
was appearantly not necessary. Not sure what drove me into believing
that this was needed…
Thanks to Arsen for pointing this out.
Closes: https://bugs.gentoo.org/883307
Reported-by: Arsen Arsenović <arsen <AT> aarsen.me>
Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>
Closes: https://github.com/gentoo/portage/pull/949
Signed-off-by: Sam James <sam <AT> gentoo.org>
NEWS | 3 +++
lib/portage/util/env_update.py | 5 -----
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index 6fd185fcb..57d9c92ee 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,9 @@ Bug fixes:
in different ways, but one example was a rebuild in / causing the same package
to be added to ROOT, even when it had no other reason to be.
+* env-update: Also generate PATH definition in systemd user environment file
+ /etc/environment.d/10-gentoo-env.conf
+
portage-3.0.39 (2022-11-20)
--------------
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
index bb0ebf84c..bac5b6e7a 100644
--- a/lib/portage/util/env_update.py
+++ b/lib/portage/util/env_update.py
@@ -417,11 +417,6 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, writemsg_lev
systemd_gentoo_env.write(senvnotice)
for env_key in env_keys:
- # Skip PATH since this makes it impossible to use
- # "systemctl --user import-environment PATH".
- if env_key == "PATH":
- continue
-
env_key_value = env[env_key]
# Skip variables with the empty string
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/util/, /
@ 2023-07-26 7:58 Sam James
0 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2023-07-26 7:58 UTC (permalink / raw
To: gentoo-commits
commit: 3da0ff3d2dd47469becd80e744c0c3ced448a516
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 08:16:45 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Jul 26 07:58:30 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3da0ff3d
lib: env_update: check ldconfig exit code
Bug: https://bugs.gentoo.org/910376
Signed-off-by: Sam James <sam <AT> gentoo.org>
NEWS | 2 ++
lib/portage/util/env_update.py | 13 ++++++++++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index fcbbdb2a5..4c54ba382 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@ Bug fixes:
* install-qa-check.d/05prefix: Fix prefixifying shebang for >= EAPI 7 ebuilds
(bug #909147).
+* env-update: Check exit code from ldconfig (bug #910376).
+
* emerge: Fix 'no ebuilds available' message always mentioning binpkgs
(bug #909853).
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
index d76042a6b..5c2b2fdd5 100644
--- a/lib/portage/util/env_update.py
+++ b/lib/portage/util/env_update.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2020 Gentoo Authors
+# Copyright 2010-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
__all__ = ["env_update"]
@@ -6,6 +6,7 @@ __all__ = ["env_update"]
import errno
import glob
import stat
+import sys
import time
import portage
@@ -363,12 +364,12 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, writemsg_lev
writemsg_level(
_(">>> Regenerating %setc/ld.so.cache...\n") % (target_root,)
)
- os.system(f"cd / ; {ldconfig} -X -r '{target_root}'")
+ ret = os.system(f"cd / ; {ldconfig} -X -r '{target_root}'")
elif ostype in ("FreeBSD", "DragonFly"):
writemsg_level(
_(">>> Regenerating %svar/run/ld-elf.so.hints...\n") % target_root
)
- os.system(
+ ret = os.system(
(
"cd / ; %s -elf -i "
+ "-f '%svar/run/ld-elf.so.hints' '%setc/ld.so.conf'"
@@ -376,6 +377,12 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, writemsg_lev
% (ldconfig, target_root, target_root)
)
+ ret = os.waitstatus_to_exitcode(ret)
+ if ret > 0:
+ writemsg(f"!!! ldconfig failed with exit status {ret}\n", noiselevel=-1)
+ if ret < 0:
+ writemsg(f"!!! ldconfig was killed with signal {-ret}\n", noiselevel=-1)
+
del specials["LDPATH"]
notice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/util/, /
@ 2023-08-02 6:31 Sam James
0 siblings, 0 replies; 5+ messages in thread
From: Sam James @ 2023-08-02 6:31 UTC (permalink / raw
To: gentoo-commits
commit: 19c27a2471c78d5e17b14325477fee60ead791e5
Author: James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 30 13:19:10 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 2 06:31:20 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=19c27a24
Use the correct library path when launching scripts directly from a venv
It's not clear what bin_entry_point.sh was trying to do before. The
regular expression didn't appear to match any likely shebang. The
wrapper already runs under the desired Python, so we only need to use
sys.executable, which points to the venv's python symlink.
We don't need to worry about handling non-Python scripts any more either
as the new Meson-based build system just installs these directly to bin
rather than creating an entrypoint for them. Any Python-based Portage
scripts they execute are now tried from the same directory first and
will therefore use the correct environment, as above.
Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>
Signed-off-by: Sam James <sam <AT> gentoo.org>
NEWS | 3 +++
lib/portage/util/bin_entry_point.py | 18 +++++-------------
2 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/NEWS b/NEWS
index 0e3541af4..53db165e8 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,9 @@ Bug fixes:
* Ensure non-Python (s)bin scripts launch other Python-based Portage scripts
using the same environment.
+* Use the correct Python library path when launching scripts directly from a
+ virtual environment.
+
portage-3.0.49 (2023-06-21)
--------------
diff --git a/lib/portage/util/bin_entry_point.py b/lib/portage/util/bin_entry_point.py
index bb012b6b7..efa8b17b7 100644
--- a/lib/portage/util/bin_entry_point.py
+++ b/lib/portage/util/bin_entry_point.py
@@ -1,9 +1,8 @@
-# Copyright 2021 Gentoo Authors
+# Copyright 2021-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
__all__ = ["bin_entry_point"]
-import re
import sys
from portage.const import PORTAGE_BIN_PATH
@@ -18,17 +17,10 @@ def bin_entry_point():
"""
script_path = os.path.join(PORTAGE_BIN_PATH, os.path.basename(sys.argv[0]))
if os.access(script_path, os.X_OK):
- with open(script_path) as f:
- shebang = f.readline()
- python_match = re.search(r"/python[\d\.]*\s+([^/]*)\s+$", shebang)
- if python_match:
- sys.argv = [
- os.path.join(os.path.dirname(sys.argv[0]), "python"),
- python_match.group(1),
- script_path,
- ] + sys.argv[1:]
- os.execvp(sys.argv[0], sys.argv)
- sys.argv[0] = script_path
+ sys.argv = [
+ sys.executable,
+ script_path,
+ ] + sys.argv[1:]
os.execvp(sys.argv[0], sys.argv)
else:
print("File not found:", script_path, file=sys.stderr)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/util/, /
@ 2023-10-02 21:40 James Le Cuirot
0 siblings, 0 replies; 5+ messages in thread
From: James Le Cuirot @ 2023-10-02 21:40 UTC (permalink / raw
To: gentoo-commits
commit: 8008e209d900dc988217ce3721292ba895cd0494
Author: James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 1 09:32:33 2023 +0000
Commit: James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Mon Oct 2 21:38:18 2023 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=8008e209
env-update: Write /usr/etc/ld.so.conf to fix bfd in some obscure cases
This is only needed on prefixed systems. bfd currently reads
${EPREFIX}/etc/ld.so.conf and adds the prefix to these paths, but these
paths are already prefixed. We need them to stay prefixed for ldconfig
and the runtime linker. bfd will use ${EPREFIX}/usr/etc/ld.so.conf
instead if that is present, so we can write the unprefixed paths there.
Other linkers do not use these files at all. We tried to patch bfd to
not use them either, as it shouldn't really be necessary, but that
broke some cases, so we are trying this safer approach instead.
env-update does not write the files under /etc/ld.so.conf.d, but we
shouldn't need to handle these in any case, as all known instances are
not affected by this issue.
Bug: https://bugs.gentoo.org/892549
Closes: https://github.com/gentoo/portage/pull/1105
Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>
NEWS | 3 +++
lib/portage/util/env_update.py | 19 +++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/NEWS b/NEWS
index 75680fce18..c6d0247691 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,9 @@ Bug fixes:
* emerge: fix application count when listing search results for ambiguous
packages (bug #915054).
+* env-update: Write ${EPREFIX}/usr/etc/ld.so.conf with unprefixed paths on
+ prefixed systems to fix the bfd linker in some obscure cases (bug #892549).
+
Cleanups:
* vartree: Remove unused variables and parameters
diff --git a/lib/portage/util/env_update.py b/lib/portage/util/env_update.py
index 04fde5a52c..b19a853251 100644
--- a/lib/portage/util/env_update.py
+++ b/lib/portage/util/env_update.py
@@ -221,6 +221,25 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, writemsg_lev
myfd.write(x + "\n")
myfd.close()
+ if eprefix:
+ # ldconfig needs ld.so.conf paths to be prefixed, but the bfd linker
+ # needs them unprefixed, so write an alternative ld.so.conf file for
+ # the latter. Other linkers do not use these files. See ldelf.c in
+ # binutils for precise bfd behavior, as well as bug #892549.
+ ldsoconf_path = os.path.join(eroot, "usr", "etc", "ld.so.conf")
+ ensure_dirs(os.path.dirname(ldsoconf_path), mode=0o755)
+ myfd = atomic_ofstream(ldsoconf_path)
+ myfd.write(
+ "# ld.so.conf autogenerated by env-update; make all changes to\n"
+ f"# contents of {eprefix}/etc/env.d directory.\n"
+ "# This file is only used by the bfd linker. The paths are not\n"
+ "# prefixed as this is automatically added by the linker.\n"
+ )
+ for x in specials["LDPATH"]:
+ if x.startswith(eprefix + os.path.sep):
+ myfd.write(x[len(eprefix) :] + "\n")
+ myfd.close()
+
potential_lib_dirs = set()
for lib_dir_glob in ("usr/lib*", "lib*"):
x = os.path.join(eroot, lib_dir_glob)
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-02 21:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-28 10:10 [gentoo-commits] proj/portage:master commit in: lib/portage/util/, / Zac Medico
-- strict thread matches above, loose matches on Subject: below --
2022-11-30 22:29 Sam James
2023-07-26 7:58 Sam James
2023-08-02 6:31 Sam James
2023-10-02 21:40 James Le Cuirot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox