diff mbox

make build-many-glibcs.py work on python3.2

Message ID 58344D35.7080506@arm.com
State New
Headers show

Commit Message

Szabolcs Nagy Nov. 22, 2016, 1:50 p.m. UTC
I used this patch to run the new build script with python3.2, it may be worth
adding this hack if python3.5 is not widespread (might work with older python,
i haven't tested that).

2016-11-22  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* scripts/build-many-glibcs.py (os.cpu_count): Add compatibility definition.
	(re.fullmatch, subprocess.run): Likewise.

Comments

Joseph Myers Nov. 22, 2016, 5:24 p.m. UTC | #1
On Tue, 22 Nov 2016, Szabolcs Nagy wrote:

> +try:

> +    os.cpu_count

> +except:

> +    os.cpu_count = lambda: 1


multiprocessing.cpu_count may be a better fallback.

> +try:

> +    re.fullmatch

> +except:

> +    re.fullmatch = lambda p,s,f=0: re.match("^"+p+"$",s,f)


You don't need the ^ since match means match at the start of the string.  
And \Z corresponds more accurately to fullmatch semantics than $.

(I think the principle of including such compatibility code is fine if 
people want to use the script with older Python 3.x.  I don't have 
anything older than 3.4 (the version on Ubuntu 14.04) to hand for testing 
such compatibility code myself.)

-- 
Joseph S. Myers
joseph@codesourcery.com
diff mbox

Patch

diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
index 517dec4..b928dee 100755
--- a/scripts/build-many-glibcs.py
+++ b/scripts/build-many-glibcs.py
@@ -40,6 +40,42 @@  import subprocess
 import sys
 import urllib.request
 
+try:
+    os.cpu_count
+except:
+    os.cpu_count = lambda: 1
+
+try:
+    re.fullmatch
+except:
+    re.fullmatch = lambda p,s,f=0: re.match("^"+p+"$",s,f)
+
+try:
+    subprocess.run
+except:
+    class _CompletedProcess:
+        def __init__(self, args, returncode, stdout=None, stderr=None):
+            self.args = args
+            self.returncode = returncode
+            self.stdout = stdout
+            self.stderr = stderr
+
+    def _run(*popenargs, input=None, timeout=None, check=False, **kwargs):
+        assert(timeout is None)
+        with subprocess.Popen(*popenargs, **kwargs) as process:
+            try:
+                stdout, stderr = process.communicate(input)
+            except:
+                process.kill()
+                process.wait()
+                raise
+            returncode = process.poll()
+            if check and returncode:
+                raise subprocess.CalledProcessError(returncode, popenargs)
+        return _CompletedProcess(popenargs, returncode, stdout, stderr)
+
+    subprocess.run = _run
+
 
 class Context(object):
     """The global state associated with builds in a given directory."""