blob: 85840d491fec6bd26694cd2025523ef1e5d94ccc [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package codifier
import "log"
// PickUnskiplisted picks the first item in the given list that is not present
// in the skiplist file. The picked item is stored under the given key name.
func (p *Proc) PickUnskiplisted(listName, skiplistfileName, key string) *Proc {
if p == nil {
log.Println(" PickUnskiplisted() error: nil receiver")
return nil
}
list, ok := p.Store[listName].([]string)
if !ok {
log.Printf(" PickUnskiplisted(): key %q not present in store", listName)
return nil
}
// Read skiplist and pick one.
index, picked, ok, err := findMissing(list, skiplistfileName)
if err != nil {
log.Printf(" PickUnskiplisted() error: %v", err)
return nil
}
if !ok {
log.Printf(" PickUnskiplisted(): all values are skipped in %s", skiplistfileName)
return nil
}
log.Printf("PickUnskiplisted(): picked (%d/%d) %q ", index, len(list), picked)
p.Store[key] = picked
return p
}
// AddToSkiplist adds the value in the store for the given key to the skiplist
// file, including a comment whether the build succeeded or failed. This
// operator allows Codifier code to use a skiplist to record build and test
// failures, then avoid those files on later runs.
func (p *Proc) AddToSkiplist(key, skiplistfileName string) *Proc {
if p == nil {
log.Println(" AddToSkiplist() error: nil receiver")
return nil
}
value, ok := p.Store[key].(string)
if !ok {
log.Printf(" AddToSkiplist(): key %q not present in store", key)
return nil
}
var comment string
switch {
case !p.buildSuccess && !p.testSuccess:
comment = "Build failed, no test."
case p.buildSuccess && !p.testSuccess:
comment = "Build succeeded, test failed."
case !p.buildSuccess && p.testSuccess:
log.Print(" AddToSkiplist() error: inconsistent build/test result")
return nil
case p.buildSuccess && p.testSuccess:
comment = "Build succeeded, test succeeded."
}
if err := skiplistAdd(skiplistfileName, comment, value); err != nil {
log.Printf(" AddToSkiplist() error: %v", err)
return nil
}
log.Printf("Added to skiplist: %q = %q", key, value)
return p
}