diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-03-10 12:09:48 -0500 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-03-10 12:57:57 -0500 |
commit | fb299d0fb134c603eafe7737bab8d22ec0b1cd59 (patch) | |
tree | 7f8bfac3259a5c6f55d09c5e041357e98b3c7fe9 /glsl_builders.py | |
parent | 0ace0a129284ffc6646b199699c1607a316fcec0 (diff) | |
download | redot-engine-fb299d0fb134c603eafe7737bab8d22ec0b1cd59.tar.gz |
SCons: Ensure `with` statement where applicable
Diffstat (limited to 'glsl_builders.py')
-rw-r--r-- | glsl_builders.py | 144 |
1 files changed, 70 insertions, 74 deletions
diff --git a/glsl_builders.py b/glsl_builders.py index 406677ac9e..7eb79b8b32 100644 --- a/glsl_builders.py +++ b/glsl_builders.py @@ -44,72 +44,70 @@ class RDHeaderStruct: def include_file_in_rd_header(filename: str, header_data: RDHeaderStruct, depth: int) -> RDHeaderStruct: - fs = open(filename, "r") - line = fs.readline() - - while line: - index = line.find("//") - if index != -1: - line = line[:index] - - if line.find("#[vertex]") != -1: - header_data.reading = "vertex" - line = fs.readline() - header_data.line_offset += 1 - header_data.vertex_offset = header_data.line_offset - continue + with open(filename, "r") as fs: + line = fs.readline() - if line.find("#[fragment]") != -1: - header_data.reading = "fragment" - line = fs.readline() - header_data.line_offset += 1 - header_data.fragment_offset = header_data.line_offset - continue + while line: + index = line.find("//") + if index != -1: + line = line[:index] + + if line.find("#[vertex]") != -1: + header_data.reading = "vertex" + line = fs.readline() + header_data.line_offset += 1 + header_data.vertex_offset = header_data.line_offset + continue + + if line.find("#[fragment]") != -1: + header_data.reading = "fragment" + line = fs.readline() + header_data.line_offset += 1 + header_data.fragment_offset = header_data.line_offset + continue + + if line.find("#[compute]") != -1: + header_data.reading = "compute" + line = fs.readline() + header_data.line_offset += 1 + header_data.compute_offset = header_data.line_offset + continue + + while line.find("#include ") != -1: + includeline = line.replace("#include ", "").strip()[1:-1] + + if includeline.startswith("thirdparty/"): + included_file = os.path.relpath(includeline) + + else: + included_file = os.path.relpath(os.path.dirname(filename) + "/" + includeline) + + if not included_file in header_data.vertex_included_files and header_data.reading == "vertex": + header_data.vertex_included_files += [included_file] + if include_file_in_rd_header(included_file, header_data, depth + 1) is None: + print("Error in file '" + filename + "': #include " + includeline + "could not be found!") + elif not included_file in header_data.fragment_included_files and header_data.reading == "fragment": + header_data.fragment_included_files += [included_file] + if include_file_in_rd_header(included_file, header_data, depth + 1) is None: + print("Error in file '" + filename + "': #include " + includeline + "could not be found!") + elif not included_file in header_data.compute_included_files and header_data.reading == "compute": + header_data.compute_included_files += [included_file] + if include_file_in_rd_header(included_file, header_data, depth + 1) is None: + print("Error in file '" + filename + "': #include " + includeline + "could not be found!") + + line = fs.readline() + + line = line.replace("\r", "").replace("\n", "") + + if header_data.reading == "vertex": + header_data.vertex_lines += [line] + if header_data.reading == "fragment": + header_data.fragment_lines += [line] + if header_data.reading == "compute": + header_data.compute_lines += [line] - if line.find("#[compute]") != -1: - header_data.reading = "compute" line = fs.readline() header_data.line_offset += 1 - header_data.compute_offset = header_data.line_offset - continue - - while line.find("#include ") != -1: - includeline = line.replace("#include ", "").strip()[1:-1] - - if includeline.startswith("thirdparty/"): - included_file = os.path.relpath(includeline) - - else: - included_file = os.path.relpath(os.path.dirname(filename) + "/" + includeline) - - if not included_file in header_data.vertex_included_files and header_data.reading == "vertex": - header_data.vertex_included_files += [included_file] - if include_file_in_rd_header(included_file, header_data, depth + 1) is None: - print("Error in file '" + filename + "': #include " + includeline + "could not be found!") - elif not included_file in header_data.fragment_included_files and header_data.reading == "fragment": - header_data.fragment_included_files += [included_file] - if include_file_in_rd_header(included_file, header_data, depth + 1) is None: - print("Error in file '" + filename + "': #include " + includeline + "could not be found!") - elif not included_file in header_data.compute_included_files and header_data.reading == "compute": - header_data.compute_included_files += [included_file] - if include_file_in_rd_header(included_file, header_data, depth + 1) is None: - print("Error in file '" + filename + "': #include " + includeline + "could not be found!") - - line = fs.readline() - - line = line.replace("\r", "").replace("\n", "") - - if header_data.reading == "vertex": - header_data.vertex_lines += [line] - if header_data.reading == "fragment": - header_data.fragment_lines += [line] - if header_data.reading == "compute": - header_data.compute_lines += [line] - - line = fs.readline() - header_data.line_offset += 1 - - fs.close() return header_data @@ -180,22 +178,20 @@ class RAWHeaderStruct: def include_file_in_raw_header(filename: str, header_data: RAWHeaderStruct, depth: int) -> None: - fs = open(filename, "r") - line = fs.readline() - - while line: - while line.find("#include ") != -1: - includeline = line.replace("#include ", "").strip()[1:-1] + with open(filename, "r") as fs: + line = fs.readline() - included_file = os.path.relpath(os.path.dirname(filename) + "/" + includeline) - include_file_in_raw_header(included_file, header_data, depth + 1) + while line: + while line.find("#include ") != -1: + includeline = line.replace("#include ", "").strip()[1:-1] - line = fs.readline() + included_file = os.path.relpath(os.path.dirname(filename) + "/" + includeline) + include_file_in_raw_header(included_file, header_data, depth + 1) - header_data.code += line - line = fs.readline() + line = fs.readline() - fs.close() + header_data.code += line + line = fs.readline() def build_raw_header( |