sort-makefile-lines.py: Allow '_' in name and "^# name"

'_' is used in Makefile variable names and many variables end with
"^# name".  Relax sort-makefile-lines.py to allow '_' in name and
"^# name" as variable end.  This fixes BZ #31385.
This commit is contained in:
H.J. Lu 2024-02-15 03:22:55 -08:00
parent dbae3a3940
commit 6a2512bf16

View File

@ -129,7 +129,7 @@ def sort_makefile_lines():
for i in range(len(lines)): for i in range(len(lines)):
# Look for things like "var = \", "var := \" or "var += \" # Look for things like "var = \", "var := \" or "var += \"
# to start the sorted list. # to start the sorted list.
var = re.search(r'^([a-zA-Z0-9-]*) [\+:]?\= \\$', lines[i]) var = re.search(r'^([-_a-zA-Z0-9]*) [\+:]?\= \\$', lines[i])
if var: if var:
# Remember the index and the name. # Remember the index and the name.
startmarks.append((i, var.group(1))) startmarks.append((i, var.group(1)))
@ -140,7 +140,7 @@ def sort_makefile_lines():
rangemarks = [] rangemarks = []
for sm in startmarks: for sm in startmarks:
# Look for things like " # var" to end the sorted list. # Look for things like " # var" to end the sorted list.
reg = r'^ # ' + sm[1] + r'$' reg = r'^ *# ' + sm[1] + r'$'
for j in range(sm[0] + 1, len(lines)): for j in range(sm[0] + 1, len(lines)):
if re.search(reg, lines[j]): if re.search(reg, lines[j]):
# Remember the block to sort (inclusive). # Remember the block to sort (inclusive).