3
3
"""
4
4
from __future__ import absolute_import
5
5
# import compatibility functions and utilities
6
- from ._utils import ConfigParser , StringIO
6
+ from ._utils import ConfigParser , StringIO , shlex
7
7
import io
8
8
import re
9
9
from subprocess import check_call
10
- import shlex
11
-
12
10
13
11
__author__ = {"github.com/" : ["casperdcl" , "lrq3000" ]}
14
12
__all__ = ['PymakeTypeError' , 'PymakeKeyError' ,
15
13
'parse_makefile_aliases' , 'execute_makefile_commands' ]
16
14
17
15
18
- RE_MAKE_CMD = re .compile ('^\t (@\+?)(make)?' , flags = re . M )
19
- RE_MACRO_DEF = re .compile (r"^(\S+)\s*\:?\=\s*(.*?)$" , flags = re . M )
20
- RE_MACRO = re .compile (r"\$\(\s*\S+\s*\)" , flags = re . M )
16
+ RE_MAKE_CMD = re .compile ('^\t (@\+?)(make)?' )
17
+ RE_MACRO_DEF = re .compile (r"^(\S+)\s*\:?\=\s*(.*?)$" )
18
+ RE_MACRO = re .compile (r"\$\(\s*\S+\s*\)" )
21
19
22
20
23
21
class PymakeTypeError (TypeError ):
@@ -42,19 +40,22 @@ def parse_makefile_aliases(filepath):
42
40
43
41
# -- Parsing the Makefile using ConfigParser
44
42
# Adding a fake section to make the Makefile a valid Ini file
45
- ini_str = '[root]\n '
43
+ ini_lines = [ '[root]' ]
46
44
with io .open (filepath , mode = 'r' ) as fd :
47
- ini_str = ini_str + RE_MAKE_CMD .sub ('\t ' , fd .read ())
45
+ ini_lines . extend ( RE_MAKE_CMD .sub ('\t ' , i ) for i in fd .readlines ())
48
46
49
47
# Substitute macros
50
- macros = dict (RE_MACRO_DEF .findall (ini_str ))
48
+ macros = dict (found for l in ini_lines
49
+ for found in RE_MACRO_DEF .findall (l ) if found )
50
+ ini_str = '\n ' .join (ini_lines )
51
51
# allow finite amount of nesting
52
52
for _ in range (99 ):
53
53
for (m , expr ) in getattr (macros , 'iteritems' , macros .items )():
54
- ini_str = re .sub (r"\$\(" + m + "\)" , expr , ini_str , flags = re . M )
55
- if not RE_MACRO .match (ini_str ):
54
+ ini_str = re .sub (r"\$\(" + m + "\)" , expr , ini_str )
55
+ if not RE_MACRO .search (ini_str ):
56
56
# Strip macro definitions for rest of parsing
57
- ini_str = RE_MACRO_DEF .sub ("" , ini_str )
57
+ ini_str = '\n ' .join (l for l in ini_str .splitlines ()
58
+ if not RE_MACRO_DEF .search (l ))
58
59
break
59
60
else :
60
61
raise PymakeKeyError ("No substitution for macros: " +
0 commit comments