Parse a line from a config file containing compile flags. Parameters ---------- line : str A single line containing one or more compile flags. Returns ------- d : dict Dictionary of parsed flags, split into relevant categories. These categories
(line)
| 29 | return self.msg |
| 30 | |
| 31 | def parse_flags(line): |
| 32 | """ |
| 33 | Parse a line from a config file containing compile flags. |
| 34 | |
| 35 | Parameters |
| 36 | ---------- |
| 37 | line : str |
| 38 | A single line containing one or more compile flags. |
| 39 | |
| 40 | Returns |
| 41 | ------- |
| 42 | d : dict |
| 43 | Dictionary of parsed flags, split into relevant categories. |
| 44 | These categories are the keys of `d`: |
| 45 | |
| 46 | * 'include_dirs' |
| 47 | * 'library_dirs' |
| 48 | * 'libraries' |
| 49 | * 'macros' |
| 50 | * 'ignored' |
| 51 | |
| 52 | """ |
| 53 | d = {'include_dirs': [], 'library_dirs': [], 'libraries': [], |
| 54 | 'macros': [], 'ignored': []} |
| 55 | |
| 56 | flags = (' ' + line).split(' -') |
| 57 | for flag in flags: |
| 58 | flag = '-' + flag |
| 59 | if len(flag) > 0: |
| 60 | if flag.startswith('-I'): |
| 61 | d['include_dirs'].append(flag[2:].strip()) |
| 62 | elif flag.startswith('-L'): |
| 63 | d['library_dirs'].append(flag[2:].strip()) |
| 64 | elif flag.startswith('-l'): |
| 65 | d['libraries'].append(flag[2:].strip()) |
| 66 | elif flag.startswith('-D'): |
| 67 | d['macros'].append(flag[2:].strip()) |
| 68 | else: |
| 69 | d['ignored'].append(flag) |
| 70 | |
| 71 | return d |
| 72 | |
| 73 | def _escape_backslash(val): |
| 74 | return val.replace('\\', '\\\\') |