| 1 |
From: Mike Hommey <[email protected]> |
| 2 |
Date: Tue, 19 Aug 2025 05:09:09 +0000 |
| 3 |
Subject: Bug 1969769 - Change uses of ast.Str with ast.Constant. |
| 4 |
r=firefox-build-system-reviewers,ahochheiden |
| 5 |
|
| 6 |
ast.Str was deprecated in python 3.12 and removed in 3.14. It inherited |
| 7 |
from ast.Constant, `Str.s` was equivalent to `Constant.value`, so we can |
| 8 |
use the latter on both old and newer python versions. |
| 9 |
|
| 10 |
Differential Revision: https://phabricator.services.mozilla.com/D261512 |
| 11 |
|
| 12 |
(cherry picked from commit d497aa4f770ca02f6083e93b94996a8fe32c2ff4) |
| 13 |
|
| 14 |
Origin: upstream, 144.0 |
| 15 |
--- |
| 16 |
python/mozbuild/mozbuild/frontend/reader.py | 14 +++++++------- |
| 17 |
python/mozbuild/mozbuild/vendor/rewrite_mozbuild.py | 6 ++---- |
| 18 |
2 files changed, 9 insertions(+), 11 deletions(-) |
| 19 |
|
| 20 |
diff --git a/python/mozbuild/mozbuild/frontend/reader.py b/python/mozbuild/mozbuild/frontend/reader.py |
| 21 |
index 9f6292c..89bf999 100644 |
| 22 |
--- a/python/mozbuild/mozbuild/frontend/reader.py |
| 23 |
+++ b/python/mozbuild/mozbuild/frontend/reader.py |
| 24 |
@@ -470,7 +470,7 @@ class TemplateFunction: |
| 25 |
return c( |
| 26 |
ast.Subscript( |
| 27 |
value=c(ast.Name(id=self._global_name, ctx=ast.Load())), |
| 28 |
- slice=c(ast.Index(value=c(ast.Str(s=node.id)))), |
| 29 |
+ slice=c(ast.Index(value=c(ast.Constant(value=node.id)))), |
| 30 |
ctx=node.ctx, |
| 31 |
) |
| 32 |
) |
| 33 |
@@ -1039,8 +1039,8 @@ class BuildReader: |
| 34 |
else: |
| 35 |
# Others |
| 36 |
assert isinstance(target.slice, ast.Index) |
| 37 |
- assert isinstance(target.slice.value, ast.Str) |
| 38 |
- key = target.slice.value.s |
| 39 |
+ assert isinstance(target.slice.value, ast.Constant) |
| 40 |
+ key = target.slice.value.value |
| 41 |
elif isinstance(target, ast.Attribute): |
| 42 |
assert isinstance(target.attr, str) |
| 43 |
key = target.attr |
| 44 |
@@ -1051,11 +1051,11 @@ class BuildReader: |
| 45 |
value = node.value |
| 46 |
if isinstance(value, ast.List): |
| 47 |
for v in value.elts: |
| 48 |
- assert isinstance(v, ast.Str) |
| 49 |
- yield v.s |
| 50 |
+ assert isinstance(v, ast.Constant) |
| 51 |
+ yield v.value |
| 52 |
else: |
| 53 |
- assert isinstance(value, ast.Str) |
| 54 |
- yield value.s |
| 55 |
+ assert isinstance(value, ast.Constant) |
| 56 |
+ yield value.value |
| 57 |
|
| 58 |
assignments = [] |
| 59 |
|
| 60 |
diff --git a/python/mozbuild/mozbuild/vendor/rewrite_mozbuild.py b/python/mozbuild/mozbuild/vendor/rewrite_mozbuild.py |
| 61 |
index cfcc0f1..de06b58 100644 |
| 62 |
--- a/python/mozbuild/mozbuild/vendor/rewrite_mozbuild.py |
| 63 |
+++ b/python/mozbuild/mozbuild/vendor/rewrite_mozbuild.py |
| 64 |
@@ -327,15 +327,13 @@ def assignment_node_to_source_filename_list(code, node): |
| 65 |
""" |
| 66 |
if isinstance(node.value, ast.List) and "elts" in node.value._fields: |
| 67 |
for f in node.value.elts: |
| 68 |
- if not isinstance(f, ast.Constant) and not isinstance(f, ast.Str): |
| 69 |
+ if not isinstance(f, ast.Constant): |
| 70 |
log( |
| 71 |
"Found non-constant source file name in list: ", |
| 72 |
ast_get_source_segment(code, f), |
| 73 |
) |
| 74 |
return [] |
| 75 |
- return [ |
| 76 |
- f.value if isinstance(f, ast.Constant) else f.s for f in node.value.elts |
| 77 |
- ] |
| 78 |
+ return [f.value for f in node.value.elts] |
| 79 |
elif isinstance(node.value, ast.ListComp): |
| 80 |
# SOURCES += [f for f in foo if blah] |
| 81 |
log("Could not find the files for " + ast_get_source_segment(code, node.value)) |