github.com/aclements/go-misc@v0.0.0-20240129233631-2f6ede80790c/findflakes/paths.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"bufio"
     9  	"io"
    10  	"os"
    11  	"path/filepath"
    12  )
    13  
    14  func readPaths(r io.Reader) ([]string, error) {
    15  	out := []string{}
    16  	scanner := bufio.NewScanner(os.Stdin)
    17  	for scanner.Scan() {
    18  		out = append(out, filepath.Join(*flagRevDir, scanner.Text()))
    19  	}
    20  	if err := scanner.Err(); err != nil {
    21  		return nil, err
    22  	}
    23  	return out, nil
    24  }
    25  
    26  func pathFailures(revs []*Revision, paths []string) []*failure {
    27  	pathSet := make(map[string]bool, len(paths))
    28  	for _, path := range paths {
    29  		pathSet[path] = true
    30  	}
    31  
    32  	failures := []*failure{}
    33  	for t, rev := range revs {
    34  		for _, build := range rev.Builds {
    35  			path := build.LogPath()
    36  			if pathSet[path] {
    37  				// TODO: Fill OS/Arch.
    38  				failures = append(failures, &failure{
    39  					T:          t,
    40  					CommitsAgo: len(revs) - t - 1,
    41  					Rev:        rev,
    42  					Build:      build,
    43  				})
    44  			}
    45  		}
    46  	}
    47  	return failures
    48  }