14 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
15 stdout, stderr = p.communicate()
17 p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
18 stdout, stderr = p.communicate(input=data)
20 return stdout.decode(
'utf-8'), stderr.decode(
'utf-8'), p.returncode
100 parser = argparse.ArgumentParser(description=
'Description of your program')
101 parser.add_argument(
'--insights', help=
'C++ Insights binary', required=
True)
102 parser.add_argument(
'--cxx', help=
'C++ compiler to used', default=
'/usr/local/clang-current/bin/clang++')
103 parser.add_argument(
'--std', help=
'C++ Standard to used', default=
'c++17')
104 parser.add_argument(
'args', nargs=argparse.REMAINDER)
105 args = vars(parser.parse_args())
107 insightsPath = args[
'insights']
108 remainingArgs = args[
'args']
109 defaultCppStd =
'-std=%s'% (args[
'std'])
114 for f
in os.listdir(
'.'):
115 if not f.startswith(
'opt-')
or not f.endswith(
'.md'):
118 optionName = os.path.splitext(f)[0][4:].strip()
120 data = open(f,
'r').read()
122 cppFileName =
'cmdl-examples/%s.cpp' %(optionName)
124 cpp = open(cppFileName,
'r').read().strip()
126 data = data.replace(
'%s-source' %(optionName), cpp)
128 cmd = [insightsPath, cppFileName,
'--%s' %(optionName),
'--', defaultCppStd,
'-m64']
129 stdout, stderr, retCode =
runCmd(cmd)
131 data = data.replace(
'%s-transformed' %(optionName), stdout)
133 open(f,
'w').write(data)
135 regEx = re.compile(
'(<!-- source:(.*?).cpp -->(.*?)<!-- source-end:(.*?) -->)', re.DOTALL)
136 regExIns = re.compile(
'(<!-- transformed:(.*?).cpp -->(.*?)<!-- transformed-end:(.*?) -->)', re.DOTALL)
138 for f
in os.listdir(
'examples'):
139 if not f.endswith(
'.md'):
142 exampleName = os.path.splitext(f)[0].strip()
144 mdFileName = os.path.join(
'examples',
'%s.md' %(exampleName))
146 mdData = open(mdFileName,
'r').read()
148 mdData = regEx.sub(replaceSource, mdData)
151 mdData = regExIns.sub(rpl, mdData)
153 open(mdFileName,
'w').write(mdData)