Skip to content

Commit

Permalink
front: skip non-existant paths in gcc depfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberTailor committed Jul 17, 2023
1 parent c0ba526 commit 7cd19ae
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions compiler/front/depfiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Functions for writing target's dependencies in various formats.

import
std/[strutils, tables]
std/[os, strutils, tables]

import
compiler/utils/[pathutils],
Expand All @@ -25,13 +25,14 @@ proc writeDepsFile*(g: ModuleGraph) =
f.writeLine(toFullPath(g.config, k))
f.close()

func makefileQuoted(path: string): string =
return path.multiReplace((" ", "\\ "), ("#", "\\#"))

proc writeGccDepfile*(depfile: File, target: string, paths: openArray[string]) =
## Outputs one `make` rule containing target's file name, a colon, and the
## names of all specified paths. Spaces and hashes are escaped.
let target = target.multiReplace((" ", "\\ "), ("#", "\\#"))
depfile.write(target & ": \\" & '\n')
for it in paths:
let path = it.multiReplace((" ", "\\ "), ("#", "\\#"))
if path.len == 0:
depfile.write(target.makefileQuoted & ": \\" & '\n')
for path in paths:
if path.len == 0 or not fileExists(path):
continue
depfile.write('\t' & path & " \\" & '\n')
depfile.write('\t' & path.makefileQuoted & " \\" & '\n')

0 comments on commit 7cd19ae

Please sign in to comment.