commit:     9538fb410afca98bf5f69b8767b96dbfc8fc296d
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 18 02:13:54 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Dec 18 02:16:03 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=9538fb41

Guard package.license use in profiles with new 'profile-license' format 
extension

In a6ba2a33ca28b801661e6d783bb6662f16d132cc, we added support for reading
package.license from profiles. Guard it with a new 'profile-license'
format extension as we're less inconsistent with this than I previously
thought.

Bug: https://bugs.gentoo.org/686888
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../package/ebuild/_config/LicenseManager.py       |  5 +++--
 lib/portage/repository/config.py                   |  1 +
 lib/portage/tests/ebuild/test_config.py            | 24 +++++++++++++++++-----
 man/portage.5                                      |  5 ++++-
 4 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/lib/portage/package/ebuild/_config/LicenseManager.py 
b/lib/portage/package/ebuild/_config/LicenseManager.py
index f515740071..1b9bf665dd 100644
--- a/lib/portage/package/ebuild/_config/LicenseManager.py
+++ b/lib/portage/package/ebuild/_config/LicenseManager.py
@@ -28,8 +28,9 @@ class LicenseManager:
         self._read_license_groups(license_group_locations)
 
         if user_config:
-            for profile in locations_manager.profiles:
-                self._read_user_config(profile)
+            for profile in locations_manager.profiles_complex:
+                if "profile-license" in profile.profile_formats:
+                    self._read_user_config(profile.location)
             self._read_user_config(locations_manager.abs_user_config)
 
     def _read_user_config(self, abs_user_config):

diff --git a/lib/portage/repository/config.py b/lib/portage/repository/config.py
index e3f0c6bf5a..f3331db7f9 100644
--- a/lib/portage/repository/config.py
+++ b/lib/portage/repository/config.py
@@ -64,6 +64,7 @@ _valid_profile_formats = frozenset(
         "profile-default-eapi",
         "build-id",
         "profile-repo-deps",
+        "profile-license",
     ]
 )
 

diff --git a/lib/portage/tests/ebuild/test_config.py 
b/lib/portage/tests/ebuild/test_config.py
index 4394098725..1b436c2dfe 100644
--- a/lib/portage/tests/ebuild/test_config.py
+++ b/lib/portage/tests/ebuild/test_config.py
@@ -186,11 +186,18 @@ class ConfigTestCase(TestCase):
             playground.cleanup()
 
     def testLicenseManagerProfile(self):
-        profile_config = {
+        repo_configs = {
+            "test_repo": {
+                "layout.conf": ("profile-formats = profile-license",),
+            }
+        }
+        profile_configs = {
             "package.license": self._testLicenseManagerPackageLicense,
         }
 
-        playground = ResolverPlayground(profile=profile_config)
+        playground = ResolverPlayground(
+            repo_configs=repo_configs, profile=profile_configs
+        )
         settings = config(clone=playground.settings)
         try:
             portage.util.noiselimit = -2
@@ -203,14 +210,21 @@ class ConfigTestCase(TestCase):
             playground.cleanup()
 
     def testLicenseManagerMixed(self):
-        profile_config = {
+        profile_configs = {
             "package.license": self._testLicenseManagerPackageLicense[:4],
         }
-        user_config = {
+        user_configs = {
             "package.license": self._testLicenseManagerPackageLicense[4:],
         }
+        repo_configs = {
+            "test_repo": {
+                "layout.conf": ("profile-formats = profile-license",),
+            }
+        }
 
-        playground = ResolverPlayground(user_config=user_config, 
profile=profile_config)
+        playground = ResolverPlayground(
+            user_config=user_configs, repo_configs=repo_configs, 
profile=profile_configs
+        )
         settings = config(clone=playground.settings)
         try:
             portage.util.noiselimit = -2

diff --git a/man/portage.5 b/man/portage.5
index 787fc18e1a..17423b30bc 100644
--- a/man/portage.5
+++ b/man/portage.5
@@ -1558,7 +1558,8 @@ The EAPI to use for profiles when unspecified. This 
attribute is
 supported only if profile-default-eapi is included in profile-formats.
 .TP
 .BR profile\-formats " = [pms] [portage-1] [portage-2] [profile-bashrcs] \
-[profile-set] [profile-default-eapi] [build-id] [profile-repo-deps]"
+[profile-set] [profile-default-eapi] [build-id] [profile-repo-deps] \
+[profile-license]"
 Control functionality available to profiles in this repo such as which files
 may be dirs, or the syntax available in parent files.  Use "portage-2" if 
you're
 unsure.  The default is "portage-1-compat" mode which is meant to be compatible
@@ -1575,6 +1576,8 @@ build\-id atom is identical to a version-specific atom, 
except that the
 version is followed by a hyphen and an integer build\-id.
 Setting profile\-repo\-deps allows dependency atoms in the profile to
 refer to specific repositories.
+Setting profile\-license allows \fBpackage.license\fR to be used in
+profiles.
 .RE
 .RE
 

Reply via email to