commit:     d023294af12750f1c9ff4d97b4d449eae6f57dcb
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 17 03:04:51 2021 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Feb 17 03:04:51 2021 +0000
URL:        https://gitweb.gentoo.org/proj/tatt.git/commit/?id=d023294a

tatt/usecombis.py: Give up after too many USE-generation attempts

Closes: #40
Signed-off-by: Sam James <sam <AT> gentoo.org>

 tatt/usecombis.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/tatt/usecombis.py b/tatt/usecombis.py
index fb67be7..c24a82c 100644
--- a/tatt/usecombis.py
+++ b/tatt/usecombis.py
@@ -46,11 +46,31 @@ def findUseFlagCombis (package, config, port):
             swlist.append(2**len(uselist) - 1)
     # Test if we can exhaust all USE-combis by computing the binary logarithm.
     elif len(uselist) > math.log(config['usecombis'],2):
+        
         # Generate a sample of USE combis
         s = 2**(len (uselist))
         rnds = set()
         random.seed()
+        
+        attempts = 0
+        ignore_use_expand = False
+
         while len(swlist) < config['usecombis'] and len(rnds) < s:
+            if attempts >= 10000 and not ignore_use_expand:
+                # After 10000 attempts, let's give up on USE_EXPAND.
+                ignore_use_expand = True
+                attempts = 0
+
+                print("Giving up on USE_EXPAND after {0} tries to find valid 
USE combinations".format(attempts))
+                print("We've found {0} USE combinations so 
far".format(len(swlist)))
+                uselist = [use for use in uselist if not "_" in use]
+                
+            if attempts >= 10000 and ignore_use_expand:
+                # Let's give up entirely and use what we have.
+                print("Giving up on finding more USE combinations after {0} 
further attempts".format(attempts))
+                print("We've found {0} USE combinations".format(len(swlist)))
+                break
+
             r = random.randint(0, s-1)
             if r in rnds:
                 # already checked
@@ -58,6 +78,7 @@ def findUseFlagCombis (package, config, port):
             rnds.add(r)
 
             if not check_uses(ruse, uselist, r, package):
+                attempts += 1
                 # invalid combination
                 continue
 

Reply via email to