minor refactor ui/build/ninja.go
1. extract .ninja_log as const
2. log an error during reading .ninja_log
Test: m nothing
Bug: 271527305
Change-Id: I395dd8419620bfa9fad3af23c96e5a22ca44e2fb
diff --git a/ui/build/ninja.go b/ui/build/ninja.go
index a91cc3b..4734494 100644
--- a/ui/build/ninja.go
+++ b/ui/build/ninja.go
@@ -31,10 +31,11 @@
const (
// File containing the environment state when ninja is executed
ninjaEnvFileName = "ninja.environment"
+ ninjaLogFileName = ".ninja_log"
)
func useNinjaBuildLog(ctx Context, config Config, cmd *Cmd) {
- ninjaLogFile := filepath.Join(config.OutDir(), ".ninja_log")
+ ninjaLogFile := filepath.Join(config.OutDir(), ninjaLogFileName)
data, err := os.ReadFile(ninjaLogFile)
var outputBuilder strings.Builder
if err == nil {
@@ -59,9 +60,11 @@
outputBuilder.WriteString(",")
outputBuilder.WriteString(strconv.Itoa(end-start+1) + "\n")
}
+ } else {
+ // If there is no ninja log file, just pass empty ninja weight list.
+ // Because it is still efficient with critical path calculation logic even without weight.
+ ctx.Verbosef("There is an error during reading ninja log, so ninja will use empty weight list: %s", err)
}
- // If there is no ninja log file, just pass empty ninja weight list.
- // Because it is still efficient with critical path calculation logic even without weight.
weightListFile := filepath.Join(config.OutDir(), ".ninja_weight_list")
@@ -263,7 +266,7 @@
ticker := time.NewTicker(ninjaHeartbeatDuration)
defer ticker.Stop()
ninjaChecker := &ninjaStucknessChecker{
- logPath: filepath.Join(config.OutDir(), ".ninja_log"),
+ logPath: filepath.Join(config.OutDir(), ninjaLogFileName),
}
go func() {
for {