Last active
January 14, 2024 23:38
-
-
Save patriciogonzalezvivo/9a50569c2ef9b08058706443a39d838e to your computer and use it in GitHub Desktop.
Resolve includes for GLSL, HLSL and metal on Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from os.path import join, abspath, dirname, basename | |
def load_source( folder: str, filename: str, dependencies = []): | |
path = abspath( join(folder, filename) ) | |
if path in dependencies: | |
return "" | |
else: | |
dependencies.append( path ) | |
source = "" | |
lines = open( path ).readlines() | |
for line in lines: | |
if match := re.search(r'#include\s*["|<](.*.[glsl|hlsl|metal])["|>]' ,line, re.IGNORECASE): | |
new_folder = join(folder, dirname( match.group(1) )) | |
new_dep = basename( match.group(1) ) | |
source += load_source(new_folder, new_dep, dependencies) | |
else: | |
source += line | |
return source |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment