Skip to content

Commit fc9a824

Browse files
matthijskooijmancmaglie
authored andcommitted
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 36b60f5 commit fc9a824

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

builder_utils/utils.go

+34
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
227227
sourceFile = filepath.Clean(sourceFile)
228228
objectFile = filepath.Clean(objectFile)
229229
dependencyFile = filepath.Clean(dependencyFile)
230+
logger := ctx.GetLogger()
231+
debugLevel := ctx.DebugLevel
232+
233+
if debugLevel >= 20 {
234+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Checking previous results for {0} (result = {1}, dep = {2})", sourceFile, objectFile, dependencyFile)
235+
}
230236

231237
sourceFileStat, err := os.Stat(sourceFile)
232238
if err != nil {
@@ -236,6 +242,9 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
236242
objectFileStat, err := os.Stat(objectFile)
237243
if err != nil {
238244
if os.IsNotExist(err) {
245+
if debugLevel >= 20 {
246+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Not found: {0}", objectFile)
247+
}
239248
return false, nil
240249
} else {
241250
return false, i18n.WrapError(err)
@@ -245,16 +254,25 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
245254
dependencyFileStat, err := os.Stat(dependencyFile)
246255
if err != nil {
247256
if os.IsNotExist(err) {
257+
if debugLevel >= 20 {
258+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Not found: {0}", dependencyFile)
259+
}
248260
return false, nil
249261
} else {
250262
return false, i18n.WrapError(err)
251263
}
252264
}
253265

254266
if sourceFileStat.ModTime().After(objectFileStat.ModTime()) {
267+
if debugLevel >= 20 {
268+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", sourceFile, objectFile)
269+
}
255270
return false, nil
256271
}
257272
if sourceFileStat.ModTime().After(dependencyFileStat.ModTime()) {
273+
if debugLevel >= 20 {
274+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", sourceFile, dependencyFile)
275+
}
258276
return false, nil
259277
}
260278

@@ -274,10 +292,16 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
274292

275293
firstRow := rows[0]
276294
if !strings.HasSuffix(firstRow, ":") {
295+
if debugLevel >= 20 {
296+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "No colon in first line of depfile")
297+
}
277298
return false, nil
278299
}
279300
objFileInDepFile := firstRow[:len(firstRow)-1]
280301
if objFileInDepFile != objectFile {
302+
if debugLevel >= 20 {
303+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Depfile is about different file: {0}", objFileInDepFile)
304+
}
281305
return false, nil
282306
}
283307

@@ -287,12 +311,22 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
287311
if err != nil && !os.IsNotExist(err) {
288312
// There is probably a parsing error of the dep file
289313
// Ignore the error and trigger a full rebuild anyway
314+
if debugLevel >= 20 {
315+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Failed to read: {0}", row)
316+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, i18n.WrapError(err).Error())
317+
}
290318
return false, nil
291319
}
292320
if os.IsNotExist(err) {
321+
if debugLevel >= 20 {
322+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Not found: {0}", row)
323+
}
293324
return false, nil
294325
}
295326
if depStat.ModTime().After(objectFileStat.ModTime()) {
327+
if debugLevel >= 20 {
328+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", row, objectFile)
329+
}
296330
return false, nil
297331
}
298332
}

0 commit comments

Comments
 (0)