def buildShader(shaderXml, root): for shaderInfo in shaderXml: fs = shaderInfo.get('fs') fs_source = shaderInfo.get('fs_source') vs = shaderInfo.get('vs') vs_source = shaderInfo.get('vs_source') define = shaderInfo.get('define') listDefine = None if define != None: listDefine = define.split(',') else: define = "_" if fs_source != None and fs != None: outputFile = root + "/" + fs inputFile = root + "/" + fs_source print(" + %s <- %s : %s" % (fs, fs_source, define)) p = Preprocessor() p.compress = 2 p.line_directive = None if listDefine != None: for d in listDefine: p.define(d.strip()) with open(inputFile, 'rt') as finput: p.parse(finput.read(), inputFile) with open(outputFile, 'w') as foutput: foutput.writelines( "// File Generated by Assets/BuildShader.py - source: [" + os.path.basename(fs_source) + " : " + define + "]\n") p.write(foutput) if vs_source != None and vs != None: outputFile = root + "/" + vs inputFile = root + "/" + vs_source print(" + %s <- %s : %s" % (vs, vs_source, define)) p = Preprocessor() p.compress = 2 p.line_directive = None if listDefine != None: for d in listDefine: p.define(d.strip()) with open(inputFile, 'rt') as finput: p.parse(finput.read(), inputFile) with open(outputFile, 'w') as foutput: foutput.writelines( "// File Generated by Assets/BuildShader.py - source: [" + os.path.basename(vs_source) + " : " + define + "]\n") p.write(foutput) return
def runTest(self): from pcpp import Preprocessor import os start = clock() p = Preprocessor() p.compress = 1 p.line_directive = '#' p.define('__STDC__ 1') p.define('__STDC_VERSION__ 199901L') p.define('__DATE__ "Jan 13 2020"') p.define('__TIME__ "10:47:38"') p.define('NO_SYSTEM_HEADERS') path = 'tests/test-c/n_std.c' with open(path, 'rt') as ih: p.parse(ih.read(), path) with open('tests/n_std.i', 'w') as oh: p.write(oh) end = clock() print("Preprocessed", path, "in", end - start, "seconds") self.assertEqual(p.return_code, 0) with open('tests/n_std.i', 'rt') as ih: written = ih.readlines() with open('tests/n_std-pcpp.i', 'rt') as ih: reference = ih.readlines() if written != reference: print("pcpp is not emitting its reference output! Differences:") for line in difflib.unified_diff(reference, written, fromfile='n_std-pcpp.i', tofile='n_std.i'): print(line, end='') self.assertTrue(False)
def preprocess(source): preprocessor = Preprocessor() preprocessor.line_directive = None preprocessor.parse(source) stream = StringIO() preprocessor.write(stream) return stream.getvalue()
def buildShader(dirName): outputFile = None inputFile = None for root, dirs, files in os.walk(dirName): for file in files: if needBuildShader(file): outputFile = file outputFile = outputFile.replace(".d.hlsl", ".hlsl") outputFile = outputFile.replace(".d.glsl", ".glsl") print("%s <- %s" % (outputFile, file)) outputFile = root + "/" + outputFile inputFile = root + "/" + file p = Preprocessor() p.compress = 2 p.line_directive = None with open(inputFile, 'rt') as finput: p.parse(finput.read(), inputFile) with open(outputFile, 'w') as foutput: p.write(foutput)