Add includes2strings.py: Convenience script to extract required include paths for VS Code from the generated Makefile

pull/1/head
Max Moser 2017-11-06 13:11:07 +01:00
parent 4517f7590f
commit 57217aef8f
1 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,59 @@
#!/bin/env python
import sys
def mkline(path):
return ('"' + path + '",')
def find_paths(line):
ret = []
while line.find("-I") >= 0:
# find the index of the next "-I" if there is one
idx = line.find("-I")
idx += 2
line = line[idx:]
# find the index of the next blank
idx = line.find(" ")
if idx >= 0:
# append to the return-list the string
# delimited by the blank
ret.append(line[:idx])
line = line[idx:]
else:
# if there is no blank until the end of line:
# just use the rest of the line
ret.append(line)
break
return ret
# read from stdin until EOF occurs
lines = sys.stdin.read().split("\n")
# filter empty lines
lines = [line for line in lines if len(line) > 0]
include_paths = []
for read_line in lines:
# convert the read lines to paths and convert them to quoted strings
paths = [mkline(p) for p in find_paths(read_line) if p not in ["", "."]]
for path in paths:
# if we don't have a duplicate... add the path
if path not in include_paths:
include_paths.append(path)
include_paths.sort()
if include_paths:
# if we have at least one element: remove the trailing comma from the last element
tmp = include_paths[:-1]
last = include_paths[-1][:-1]
tmp.append(last)
include_paths = tmp
for path in include_paths:
print(path)