Skip to content

Commit e92bf65

Browse files
Let ObjFileIsUpToDate output verbose debug output
If -debug-level=20 is passed, whenever the cached file is not usable for whatever reason, a message is displayed. This should help debug caching problems. The messages are hardcoded in the source and not put into `constants`, since they are only debug messages. Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent cc978ec commit e92bf65

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Diff for: builder_utils/utils.go

+34
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
194194
sourceFile = filepath.Clean(sourceFile)
195195
objectFile = filepath.Clean(objectFile)
196196
dependencyFile = filepath.Clean(dependencyFile)
197+
logger := ctx.GetLogger()
198+
debugLevel := ctx.DebugLevel
199+
200+
if debugLevel >= 20 {
201+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Checking previous results for {0} (result = {1}, dep = {2})", sourceFile, objectFile, dependencyFile)
202+
}
197203

198204
sourceFileStat, err := os.Stat(sourceFile)
199205
if err != nil {
@@ -203,6 +209,9 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
203209
objectFileStat, err := os.Stat(objectFile)
204210
if err != nil {
205211
if os.IsNotExist(err) {
212+
if debugLevel >= 20 {
213+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Not found: {0}", objectFile)
214+
}
206215
return false, nil
207216
} else {
208217
return false, i18n.WrapError(err)
@@ -212,16 +221,25 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
212221
dependencyFileStat, err := os.Stat(dependencyFile)
213222
if err != nil {
214223
if os.IsNotExist(err) {
224+
if debugLevel >= 20 {
225+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Not found: {0}", dependencyFile)
226+
}
215227
return false, nil
216228
} else {
217229
return false, i18n.WrapError(err)
218230
}
219231
}
220232

221233
if sourceFileStat.ModTime().After(objectFileStat.ModTime()) {
234+
if debugLevel >= 20 {
235+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", sourceFile, objectFile)
236+
}
222237
return false, nil
223238
}
224239
if sourceFileStat.ModTime().After(dependencyFileStat.ModTime()) {
240+
if debugLevel >= 20 {
241+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", sourceFile, dependencyFile)
242+
}
225243
return false, nil
226244
}
227245

@@ -241,10 +259,16 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
241259

242260
firstRow := rows[0]
243261
if !strings.HasSuffix(firstRow, ":") {
262+
if debugLevel >= 20 {
263+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "No colon in first line of depfile")
264+
}
244265
return false, nil
245266
}
246267
objFileInDepFile := firstRow[:len(firstRow)-1]
247268
if objFileInDepFile != objectFile {
269+
if debugLevel >= 20 {
270+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Depfile is about different file: {0}", objFileInDepFile)
271+
}
248272
return false, nil
249273
}
250274

@@ -254,12 +278,22 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
254278
if err != nil && !os.IsNotExist(err) {
255279
// There is probably a parsing error of the dep file
256280
// Ignore the error and trigger a full rebuild anyway
281+
if debugLevel >= 20 {
282+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Failed to read: {0}", row)
283+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, i18n.WrapError(err).Error())
284+
}
257285
return false, nil
258286
}
259287
if os.IsNotExist(err) {
288+
if debugLevel >= 20 {
289+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Not found: {0}", row)
290+
}
260291
return false, nil
261292
}
262293
if depStat.ModTime().After(objectFileStat.ModTime()) {
294+
if debugLevel >= 20 {
295+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", row, objectFile)
296+
}
263297
return false, nil
264298
}
265299
}

0 commit comments

Comments
 (0)