blob: 85af5470933a88c65f5cc5eb72a16eea285787d3 [file] [log] [blame]
Andrew Geissler517393d2023-01-13 08:55:19 -06001From 1479dd9c75917d2be70ee840c9db141e59987e44 Mon Sep 17 00:00:00 2001
2From: Alexander Kanavin <alex@linutronix.de>
3Date: Wed, 14 Sep 2022 14:03:10 +0200
4Subject: [PATCH] mozjs-91: backport a python 3.11 compatibility patch
5
6# HG changeset patch
7# User ahochheiden <ahochheiden@mozilla.com>
8# Date 1654151264 0
9# Node ID f54162b2c1f2fe52c6137ab2c3469a1944f58b27
10# Parent 6e7776492240c27732840d65a33dcc440fa1aba0
11Bug 1769631 - Remove 'U' from 'mode' parameters for various 'open' calls to ensure Python3.11 compatibility r=firefox-build-system-reviewers,glandium
12
13The 'U' flag represents "universal newline". It has been deprecated
14since Python3.3. Since then "universal newline" is the default when a
15file is opened in text mode (not bytes). In Python3.11 using the 'U'
16flag throws errors. There should be no harm in removing 'U' from 'open'
17everywhere it is used, and doing allows the use of Python3.11.
18
19For more reading see: https://docs.python.org/3.11/whatsnew/3.11.html#changes-in-the-python-api
20
21Differential Revision: https://phabricator.services.mozilla.com/D147721
22
23Upstream-Status: Backport [https://hg.mozilla.org/mozilla-central/rev/f54162b2c1f2fe52c6137ab2c3469a1944f58b27]
24Signed-off-by: Alexander Kanavin <alex@linutronix.de>
25
26---
27 dom/base/usecounters.py | 2 +-
28 python/mozbuild/mozbuild/action/process_define_files.py | 2 +-
29 python/mozbuild/mozbuild/backend/base.py | 2 +-
30 python/mozbuild/mozbuild/preprocessor.py | 6 +++---
31 python/mozbuild/mozbuild/util.py | 2 +-
32 python/mozbuild/mozpack/files.py | 4 ++--
33 6 files changed, 9 insertions(+), 9 deletions(-)
34
35diff --git a/dom/base/usecounters.py b/dom/base/usecounters.py
36index 780e3b32b2..7e2c7148ec 100644
37--- a/dom/base/usecounters.py
38+++ b/dom/base/usecounters.py
39@@ -8,7 +8,7 @@ import re
40
41 def read_conf(conf_filename):
42 # Can't read/write from a single StringIO, so make a new one for reading.
43- stream = open(conf_filename, "rU")
44+ stream = open(conf_filename, "r")
45
46 def parse_counters(stream):
47 for line_num, line in enumerate(stream):
48diff --git a/python/mozbuild/mozbuild/action/process_define_files.py b/python/mozbuild/mozbuild/action/process_define_files.py
49index f1d401ac26..aca59d0f05 100644
50--- a/python/mozbuild/mozbuild/action/process_define_files.py
51+++ b/python/mozbuild/mozbuild/action/process_define_files.py
52@@ -36,7 +36,7 @@ def process_define_file(output, input):
53 ) and not config.substs.get("JS_STANDALONE"):
54 config = PartialConfigEnvironment(mozpath.join(topobjdir, "js", "src"))
55
56- with open(path, "rU") as input:
57+ with open(path, "r") as input:
58 r = re.compile(
59 "^\s*#\s*(?P<cmd>[a-z]+)(?:\s+(?P<name>\S+)(?:\s+(?P<value>\S+))?)?", re.U
60 )
61diff --git a/python/mozbuild/mozbuild/backend/base.py b/python/mozbuild/mozbuild/backend/base.py
62index 7bc1986d86..b64a709468 100644
63--- a/python/mozbuild/mozbuild/backend/base.py
64+++ b/python/mozbuild/mozbuild/backend/base.py
65@@ -272,7 +272,7 @@ class BuildBackend(LoggingMixin):
66 return status
67
68 @contextmanager
69- def _write_file(self, path=None, fh=None, readmode="rU"):
70+ def _write_file(self, path=None, fh=None, readmode="r"):
71 """Context manager to write a file.
72
73 This is a glorified wrapper around FileAvoidWrite with integration to
74diff --git a/python/mozbuild/mozbuild/preprocessor.py b/python/mozbuild/mozbuild/preprocessor.py
75index f7820b9c91..857f1a6c9b 100644
76--- a/python/mozbuild/mozbuild/preprocessor.py
77+++ b/python/mozbuild/mozbuild/preprocessor.py
78@@ -531,7 +531,7 @@ class Preprocessor:
79
80 if args:
81 for f in args:
82- with io.open(f, "rU", encoding="utf-8") as input:
83+ with io.open(f, "r", encoding="utf-8") as input:
84 self.processFile(input=input, output=out)
85 if depfile:
86 mk = Makefile()
87@@ -860,7 +860,7 @@ class Preprocessor:
88 args = self.applyFilters(args)
89 if not os.path.isabs(args):
90 args = os.path.join(self.curdir, args)
91- args = io.open(args, "rU", encoding="utf-8")
92+ args = io.open(args, "r", encoding="utf-8")
93 except Preprocessor.Error:
94 raise
95 except Exception:
96@@ -914,7 +914,7 @@ class Preprocessor:
97 def preprocess(includes=[sys.stdin], defines={}, output=sys.stdout, marker="#"):
98 pp = Preprocessor(defines=defines, marker=marker)
99 for f in includes:
100- with io.open(f, "rU", encoding="utf-8") as input:
101+ with io.open(f, "r", encoding="utf-8") as input:
102 pp.processFile(input=input, output=output)
103 return pp.includes
104
105diff --git a/python/mozbuild/mozbuild/util.py b/python/mozbuild/mozbuild/util.py
106index b09f164698..4f1e0cdc5f 100644
107--- a/python/mozbuild/mozbuild/util.py
108+++ b/python/mozbuild/mozbuild/util.py
109@@ -236,7 +236,7 @@ class FileAvoidWrite(BytesIO):
110 still occur, as well as diff capture if requested.
111 """
112
113- def __init__(self, filename, capture_diff=False, dry_run=False, readmode="rU"):
114+ def __init__(self, filename, capture_diff=False, dry_run=False, readmode="r"):
115 BytesIO.__init__(self)
116 self.name = filename
117 assert type(capture_diff) == bool
118diff --git a/python/mozbuild/mozpack/files.py b/python/mozbuild/mozpack/files.py
119index 1d8a1ed2d8..a295a67b5a 100644
120--- a/python/mozbuild/mozpack/files.py
121+++ b/python/mozbuild/mozpack/files.py
122@@ -554,7 +554,7 @@ class PreprocessedFile(BaseFile):
123 pp = Preprocessor(defines=self.defines, marker=self.marker)
124 pp.setSilenceDirectiveWarnings(self.silence_missing_directive_warnings)
125
126- with _open(self.path, "rU") as input:
127+ with _open(self.path, "r") as input:
128 with _open(os.devnull, "w") as output:
129 pp.processFile(input=input, output=output)
130
131@@ -611,7 +611,7 @@ class PreprocessedFile(BaseFile):
132 pp = Preprocessor(defines=self.defines, marker=self.marker)
133 pp.setSilenceDirectiveWarnings(self.silence_missing_directive_warnings)
134
135- with _open(self.path, "rU") as input:
136+ with _open(self.path, "r") as input:
137 pp.processFile(input=input, output=dest, depfile=deps_out)
138
139 dest.close()