Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,21 @@ def _parse_makefile(filename, vars=None):
while len(variables) > 0:
for name in tuple(variables):
value = notdone[name]
m1 = _findvar1_rx.search(value)
m2 = _findvar2_rx.search(value)
if m1 and m2:
m = m1 if m1.start() < m2.start() else m2
else:
m = m1 if m1 else m2
m = None
offset = 0
for substr in value.split('$$'):
m1 = _findvar1_rx.search(substr)
m2 = _findvar2_rx.search(substr)
if m1 and m2:
m = m1 if m1.start() < m2.start() else m2
else:
m = m1 if m1 else m2
if m is not None:
break

# Add 2 to account for the $$ which were removed by split('$$')
offset += 2 + len(substr)

if m is not None:
n = m.group(1)
found = True
Expand Down Expand Up @@ -292,11 +301,12 @@ def _parse_makefile(filename, vars=None):
done[n] = item = ""

if found:
after = value[m.end():]
value = value[:m.start()] + item + after
if "$" in after:
after = value[offset + m.end():]
value = value[:offset + m.start()] + item.replace('$', '$$') + after
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please limit lines to 79 characters.

if "$" in after.replace('$$', ''):
notdone[name] = value
else:
value = value.replace('$$', '$')
try:
value = int(value)
except ValueError:
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ def test_parse_makefile(self):
print("var5=dollar$$5", file=makefile)
print("var6=${var3}/lib/python3.5/config-$(VAR2)$(var5)"
"-x86_64-linux-gnu", file=makefile)
print("var7=$${ORIGIN}${var5}", file=makefile)
vars = sysconfig._parse_makefile(TESTFN)
self.assertEqual(vars, {
'var1': 'ab42',
Expand All @@ -412,6 +413,7 @@ def test_parse_makefile(self):
'var4': '$/invalid',
'var5': 'dollar$5',
'var6': '42/lib/python3.5/config-b42dollar$5-x86_64-linux-gnu',
'var7': '${ORIGIN}dollar$5',
})


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Split strings prior to parsing in :func:`sysconfig._parse_makefile` so it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sysconfig._parse_makefile is not a documented function, so I don't think the func role should be used here.

doesn't expand variables formatted as ``$${variable}``.