fix_python_3.11_ftbfs.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. Description: Fix mozjs/spidermonkey FTBFS with python 3.11
  2. Origin: Fedora, https://src.fedoraproject.org/rpms/0ad/tree/main
  3. Bug-Debian: https://bugs.debian.org/1028179
  4. --- /dev/null
  5. +++ b/libraries/source/spidermonkey/0001-Python-Build-Use-r-instead-of-rU-file-read-modes.patch
  6. @@ -0,0 +1,81 @@
  7. +From 95f1e91ef71d912be5f6dddb6fac68671d850fd6 Mon Sep 17 00:00:00 2001
  8. +From: =?UTF-8?q?Franti=C5=A1ek=20Zatloukal?= <fzatlouk@redhat.com>
  9. +Date: Sun, 24 Jul 2022 11:11:01 +0200
  10. +Subject: [PATCH] Python/Build: Use r instead of rU file read modes
  11. +
  12. +Fixes Python 3.11 build
  13. +---
  14. + python/mozbuild/mozbuild/action/process_define_files.py | 2 +-
  15. + python/mozbuild/mozbuild/preprocessor.py | 6 +++---
  16. + python/mozbuild/mozbuild/util.py | 4 +++-
  17. + 3 files changed, 7 insertions(+), 5 deletions(-)
  18. +
  19. +diff --git a/python/mozbuild/mozbuild/action/process_define_files.py b/python/mozbuild/mozbuild/action/process_define_files.py
  20. +index 6fff0d1..de2bcf4 100644
  21. +--- a/python/mozbuild/mozbuild/action/process_define_files.py
  22. ++++ b/python/mozbuild/mozbuild/action/process_define_files.py
  23. +@@ -36,7 +36,7 @@ def process_define_file(output, input):
  24. + not config.substs.get('JS_STANDALONE'):
  25. + config = PartialConfigEnvironment(mozpath.join(topobjdir, 'js', 'src'))
  26. +
  27. +- with open(path, 'rU') as input:
  28. ++ with open(path, 'r') as input:
  29. + r = re.compile('^\s*#\s*(?P<cmd>[a-z]+)(?:\s+(?P<name>\S+)(?:\s+(?P<value>\S+))?)?', re.U)
  30. + for l in input:
  31. + m = r.match(l)
  32. +diff --git a/python/mozbuild/mozbuild/preprocessor.py b/python/mozbuild/mozbuild/preprocessor.py
  33. +index 0e3a750..66f5cf7 100644
  34. +--- a/python/mozbuild/mozbuild/preprocessor.py
  35. ++++ b/python/mozbuild/mozbuild/preprocessor.py
  36. +@@ -517,7 +517,7 @@ class Preprocessor:
  37. +
  38. + if args:
  39. + for f in args:
  40. +- with io.open(f, 'rU', encoding='utf-8') as input:
  41. ++ with io.open(f, 'r', encoding='utf-8') as input:
  42. + self.processFile(input=input, output=out)
  43. + if depfile:
  44. + mk = Makefile()
  45. +@@ -807,7 +807,7 @@ class Preprocessor:
  46. + args = self.applyFilters(args)
  47. + if not os.path.isabs(args):
  48. + args = os.path.join(self.curdir, args)
  49. +- args = io.open(args, 'rU', encoding='utf-8')
  50. ++ args = io.open(args, 'r', encoding='utf-8')
  51. + except Preprocessor.Error:
  52. + raise
  53. + except Exception:
  54. +@@ -862,7 +862,7 @@ def preprocess(includes=[sys.stdin], defines={},
  55. + pp = Preprocessor(defines=defines,
  56. + marker=marker)
  57. + for f in includes:
  58. +- with io.open(f, 'rU', encoding='utf-8') as input:
  59. ++ with io.open(f, 'r', encoding='utf-8') as input:
  60. + pp.processFile(input=input, output=output)
  61. + return pp.includes
  62. +
  63. +diff --git a/python/mozbuild/mozbuild/util.py b/python/mozbuild/mozbuild/util.py
  64. +index 044cf64..eb992ce 100644
  65. +--- a/python/mozbuild/mozbuild/util.py
  66. ++++ b/python/mozbuild/mozbuild/util.py
  67. +@@ -54,6 +54,8 @@ def exec_(object, globals=None, locals=None):
  68. +
  69. +
  70. + def _open(path, mode):
  71. ++ if mode == "rU":
  72. ++ mode = "r"
  73. + if 'b' in mode:
  74. + return io.open(path, mode)
  75. + return io.open(path, mode, encoding='utf-8', newline='\n')
  76. +@@ -220,7 +222,7 @@ class FileAvoidWrite(BytesIO):
  77. + still occur, as well as diff capture if requested.
  78. + """
  79. +
  80. +- def __init__(self, filename, capture_diff=False, dry_run=False, readmode='rU'):
  81. ++ def __init__(self, filename, capture_diff=False, dry_run=False, readmode='r'):
  82. + BytesIO.__init__(self)
  83. + self.name = filename
  84. + assert type(capture_diff) == bool
  85. +--
  86. +2.37.1
  87. +
  88. --- a/libraries/source/spidermonkey/patch.sh
  89. +++ b/libraries/source/spidermonkey/patch.sh
  90. @@ -2,6 +2,19 @@
  91. # Apply patches if needed
  92. # This script gets called from build.sh.
  93. +# https://bugs.debian.org/1028179
  94. +# The hack below is unfortunately necessary because GNU patch is unable to
  95. +# handle binary patches. Fixing this FTBFS in mozjs requires pulling in a
  96. +# virtualenv upgrade for mozjs.
  97. +# https://src.fedoraproject.org/rpms/0ad/blob/main/f/0ad-python311.patch
  98. +# https://github.com/mozilla/gecko-dev/commit/74641307d32a59806b75cd2b8c7161aca50d5cb7.patch
  99. +git init . -b main
  100. +git config user.name 'Debian Games'
  101. +git config user.email 'pkg-games-devel@lists.alioth.debian.org'
  102. +git add .
  103. +git commit -m 'Initial commit'
  104. +git am --keep-cr ../mozjs_virtualenv.patch
  105. +
  106. # SM78 fails to create virtual envs on macs with python > 3.7
  107. # Unfortunately, 3.7 is mostly unavailable on ARM macs.
  108. # Therefore, replace the custom script with a more up-to-date version from pip
  109. @@ -19,14 +32,6 @@
  110. export PYTHONPATH="$(pwd)/virtualenv:$PYTHONPATH"
  111. patch -p1 < ../FixVirtualEnv.diff
  112. fi
  113. -else
  114. - # In python 3.10 `sysconfig._get_default_scheme()` was renamed to
  115. - # `sysconfig.get_default_scheme()`. This breaks the version of
  116. - # `virtualenv` bundled with the spidermonkey source code.
  117. - #
  118. - # It is assumed that the updated version fetched for macOS systems
  119. - # above does not have this problem.
  120. - patch -p1 < ../FixVirtualenvForPython310.diff
  121. fi
  122. # Mozglue symbols need to be linked against static builds.
  123. @@ -78,6 +83,12 @@
  124. # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1001882
  125. patch -p1 < ../Fix-armhf-build-for-GCC-11-627.patch
  126. +# https://bugs.debian.org/1028179
  127. +# https://src.fedoraproject.org/rpms/0ad/blob/main/f/0001-Python-Build-Use-r-instead-of-rU-file-read-modes.patch
  128. +patch -p1 < ../0001-Python-Build-Use-r-instead-of-rU-file-read-modes.patch
  129. +
  130. +sed -e 's|rest\[1\], 16|0|g' -i python/mozbuild/mozbuild/action/check_binary.py
  131. +
  132. # Patch those separately, as they might interfere with normal behaviour.
  133. if [ "$(uname -s)" = "FreeBSD" ];
  134. then