From f6ba6a520517f2ee2276411d714116c3588a7514 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 11 Jul 2024 10:10:38 -0700 Subject: [PATCH] util/glsl2spirv: fixup the generated depfile when copying sources So that the depfile contains a reference to the original source rather than the copied one. This is necessary to avoid ninja not finding the copy and causing spurious rebuilds when the copy has been removed, as well as correctly tracking changes to the input files. fixes: 46644ba371e817d8f33ad7b46ce2ba7775e6d2cc Part-of: (cherry picked from commit 36160c967cbafb0e1d24e437cf2daf453778d722) --- .pick_status.json | 2 +- src/util/glsl2spirv.py | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 2f84e7c99d2..0f181ec1ac9 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -254,7 +254,7 @@ "description": "util/glsl2spirv: fixup the generated depfile when copying sources", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "46644ba371e817d8f33ad7b46ce2ba7775e6d2cc", "notes": null diff --git a/src/util/glsl2spirv.py b/src/util/glsl2spirv.py index 7238fb3b649..9c061523ebd 100644 --- a/src/util/glsl2spirv.py +++ b/src/util/glsl2spirv.py @@ -145,7 +145,7 @@ def postprocess_file(args: 'Arguments') -> None: w.writelines(lines) -def preprocess_file(args: 'Arguments', origin_file: T.TextIO, directory: os.PathLike) -> str: +def preprocess_file(args: 'Arguments', origin_file: T.TextIO, directory: os.PathLike, filemap: T.Dict[str, str]) -> str: with open(os.path.join(directory, os.path.basename(origin_file.name)), "w") as copy_file: lines = origin_file.readlines() @@ -157,13 +157,36 @@ def preprocess_file(args: 'Arguments', origin_file: T.TextIO, directory: os.Path copy_file.writelines(lines) + filemap[copy_file.name] = origin_file.name return copy_file.name +def fixup_depfile(depfile: str, filemap: T.Mapping[str, str]) -> None: + """Replace generated file references in the depfile with their source. + """ + depends: T.List[str] = [] + out: T.Optional[str] = None + with open(depfile, 'r') as f: + for line in f.readlines(): + if ':' in line: + out, line = line.split(':', 1) + depends.extend(l.strip() for l in line.split()) + + with open(depfile, 'w') as f: + f.write(out) + f.write(': ') + for dep in depends: + f.write(filemap.get(dep, dep)) + f.write(' ') + f.write('\n') + + def process_file(args: 'Arguments') -> None: + filemap: T.Dict[str, str] = {} + with open(args.input, "r") as infile: - copy_file = preprocess_file(args, infile, - os.path.dirname(args.output)) + copy_file = preprocess_file( + args, infile, os.path.dirname(args.output), filemap) cmd_list = [args.glslang] @@ -184,7 +207,6 @@ def process_file(args: 'Arguments') -> None: for f in args.includes: cmd_list.append('-I' + f) - for d in args.defines: cmd_list.append('-D' + d) @@ -207,6 +229,9 @@ def process_file(args: 'Arguments') -> None: if args.create_entry is not None: os.remove(copy_file) + if args.depfile is not None: + fixup_depfile(args.depfile, filemap) + def main() -> None: args = get_args()