Skip to content

Commit f6ba6a5

Browse files
dcbaker-intel1ace
authored andcommitted
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: 46644ba Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30132> (cherry picked from commit 36160c9)
1 parent 3b61e8f commit f6ba6a5

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

.pick_status.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
"description": "util/glsl2spirv: fixup the generated depfile when copying sources",
255255
"nominated": true,
256256
"nomination_type": 1,
257-
"resolution": 0,
257+
"resolution": 1,
258258
"main_sha": null,
259259
"because_sha": "46644ba371e817d8f33ad7b46ce2ba7775e6d2cc",
260260
"notes": null

src/util/glsl2spirv.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def postprocess_file(args: 'Arguments') -> None:
145145
w.writelines(lines)
146146

147147

148-
def preprocess_file(args: 'Arguments', origin_file: T.TextIO, directory: os.PathLike) -> str:
148+
def preprocess_file(args: 'Arguments', origin_file: T.TextIO, directory: os.PathLike, filemap: T.Dict[str, str]) -> str:
149149
with open(os.path.join(directory, os.path.basename(origin_file.name)), "w") as copy_file:
150150
lines = origin_file.readlines()
151151

@@ -157,13 +157,36 @@ def preprocess_file(args: 'Arguments', origin_file: T.TextIO, directory: os.Path
157157

158158
copy_file.writelines(lines)
159159

160+
filemap[copy_file.name] = origin_file.name
160161
return copy_file.name
161162

162163

164+
def fixup_depfile(depfile: str, filemap: T.Mapping[str, str]) -> None:
165+
"""Replace generated file references in the depfile with their source.
166+
"""
167+
depends: T.List[str] = []
168+
out: T.Optional[str] = None
169+
with open(depfile, 'r') as f:
170+
for line in f.readlines():
171+
if ':' in line:
172+
out, line = line.split(':', 1)
173+
depends.extend(l.strip() for l in line.split())
174+
175+
with open(depfile, 'w') as f:
176+
f.write(out)
177+
f.write(': ')
178+
for dep in depends:
179+
f.write(filemap.get(dep, dep))
180+
f.write(' ')
181+
f.write('\n')
182+
183+
163184
def process_file(args: 'Arguments') -> None:
185+
filemap: T.Dict[str, str] = {}
186+
164187
with open(args.input, "r") as infile:
165-
copy_file = preprocess_file(args, infile,
166-
os.path.dirname(args.output))
188+
copy_file = preprocess_file(
189+
args, infile, os.path.dirname(args.output), filemap)
167190

168191
cmd_list = [args.glslang]
169192

@@ -184,7 +207,6 @@ def process_file(args: 'Arguments') -> None:
184207

185208
for f in args.includes:
186209
cmd_list.append('-I' + f)
187-
188210
for d in args.defines:
189211
cmd_list.append('-D' + d)
190212

@@ -207,6 +229,9 @@ def process_file(args: 'Arguments') -> None:
207229
if args.create_entry is not None:
208230
os.remove(copy_file)
209231

232+
if args.depfile is not None:
233+
fixup_depfile(args.depfile, filemap)
234+
210235

211236
def main() -> None:
212237
args = get_args()

0 commit comments

Comments
 (0)