1From b85ba8c3ff3fb9ae708576ccef03434d2ef73054 Mon Sep 17 00:00:00 2001
2From: Martin Jansa <Martin.Jansa@gmail.com>
3Date: Tue, 14 Jun 2022 09:54:18 +0000
4Subject: [PATCH] waflib: fix compatibility with python-3.11
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9* https://docs.python.org/3.11/whatsnew/3.11.html#changes-in-the-python-api
10
11  open(), io.open(), codecs.open() and fileinput.FileInput no longer
12  accept 'U' (“universal newline”) in the file mode. This flag was
13  deprecated since Python 3.3. In Python 3, the “universal newline” is
14  used by default when a file is open in text mode. The newline parameter
15  of open() controls how universal newlines works. (Contributed by Victor
16  Stinner in bpo-37330.)
17
18* fixes:
19Waf: The wscript in '/OE/build/luneos-langdale/webos-ports/tmp-glibc/work/core2-64-webos-linux/glmark2/2021.12-r0/git' is unreadable
20Traceback (most recent call last):
21  File "/OE/build/luneos-langdale/webos-ports/tmp-glibc/work/core2-64-webos-linux/glmark2/2021.12-r0/git/waflib/Scripting.py", line 104, in waf_entry_point
22    set_main_module(os.path.normpath(os.path.join(Context.run_dir,Context.WSCRIPT_FILE)))
23    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24  File "/OE/build/luneos-langdale/webos-ports/tmp-glibc/work/core2-64-webos-linux/glmark2/2021.12-r0/git/waflib/Scripting.py", line 135, in set_main_module
25    Context.g_module=Context.load_module(file_path)
26                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27  File "/OE/build/luneos-langdale/webos-ports/tmp-glibc/work/core2-64-webos-linux/glmark2/2021.12-r0/git/waflib/Context.py", line 343, in load_module
28    code=Utils.readf(path,m='rU',encoding=encoding)
29         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30  File "/OE/build/luneos-langdale/webos-ports/tmp-glibc/work/core2-64-webos-linux/glmark2/2021.12-r0/git/waflib/Utils.py", line 117, in readf
31    f=open(fname,m)
32      ^^^^^^^^^^^^^
33ValueError: invalid mode: 'rUb'
34
35Upstream-Status: Submitted [https://github.com/glmark2/glmark2/pull/178]
36Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
37---
38 waflib/ConfigSet.py | 2 +-
39 waflib/Context.py   | 4 ++--
40 2 files changed, 3 insertions(+), 3 deletions(-)
41
42diff --git a/waflib/ConfigSet.py b/waflib/ConfigSet.py
43index 16142a2..87de4ad 100644
44--- a/waflib/ConfigSet.py
45+++ b/waflib/ConfigSet.py
46@@ -140,7 +140,7 @@ class ConfigSet(object):
47 		Utils.writef(filename,''.join(buf))
48 	def load(self,filename):
49 		tbl=self.table
50-		code=Utils.readf(filename,m='rU')
51+		code=Utils.readf(filename,m='r')
52 		for m in re_imp.finditer(code):
53 			g=m.group
54 			tbl[g(2)]=eval(g(3))
55diff --git a/waflib/Context.py b/waflib/Context.py
56index 8f2cbfb..f3e35ae 100644
57--- a/waflib/Context.py
58+++ b/waflib/Context.py
59@@ -109,7 +109,7 @@ class Context(ctx):
60 				cache[node]=True
61 				self.pre_recurse(node)
62 				try:
63-					function_code=node.read('rU',encoding)
64+					function_code=node.read('r',encoding)
65 					exec(compile(function_code,node.abspath(),'exec'),self.exec_dict)
66 				finally:
67 					self.post_recurse(node)
68@@ -340,7 +340,7 @@ def load_module(path,encoding=None):
69 		pass
70 	module=imp.new_module(WSCRIPT_FILE)
71 	try:
72-		code=Utils.readf(path,m='rU',encoding=encoding)
73+		code=Utils.readf(path,encoding=encoding)
74 	except EnvironmentError:
75 		raise Errors.WafError('Could not read the file %r'%path)
76 	module_dir=os.path.dirname(path)
77