diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py --- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -281,6 +281,8 @@ def parse_makefile(fn, g=None): # do variable interpolation here while notdone: + last_notdone = notdone.copy() + for name in notdone.keys(): value = notdone[name] m = _findvar1_rx.search(value) or _findvar2_rx.search(value) @@ -312,6 +314,11 @@ def parse_makefile(fn, g=None): else: # bogus variable reference; just drop it since we can't deal del notdone[name] + + # if we did not change a thing in notdone, we won't do it in the next round + if last_notdone==notdone: + print "sysconfig.py: warning: could not resolve names from makefile (recursive definition?):", notdone + break fp.close() diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py --- a/Lib/distutils/tests/test_sysconfig.py +++ b/Lib/distutils/tests/test_sysconfig.py @@ -30,8 +30,35 @@ class SysconfigTestCase(unittest.TestCas self.assert_(isinstance(cvars, dict)) self.assert_(cvars) + def test_parse_makefile(self): + # see http://bugs.python.org/issue1299. this will hang forever + # if you're version is affected by the above bug + import tempfile + fd, makefile = tempfile.mkstemp() + os.write(fd, """ +SELF1=$(SELF2) +SELF2=$(SELF1) +FOO=5 +BAR=$(FOO) +""") + os.close(fd) + del fd + + res=sysconfig.parse_makefile(makefile) + os.unlink(makefile) + + self.assertEqual(res, {'FOO': 5, 'BAR': 5}) + + + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(SysconfigTestCase)) return suite + +def test_main(): + test_suite().debug() + +if __name__ == '__main__': + test_main()