Skip to content

Commit

Permalink
Adding in cache testing
Browse files Browse the repository at this point in the history
  • Loading branch information
grantnelson-wf committed Dec 12, 2024
1 parent a3e015c commit c3494fe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,11 +982,13 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
if err := archive.RegisterTypes(s.Types); err != nil {
panic(fmt.Errorf("failed to load type information from %v: %w", archive, err))
}
fmt.Println(`Cached Archive:`, pkg.ImportPath)
s.UpToDateArchives[pkg.ImportPath] = archive
// Existing archive is up to date, no need to build it from scratch.
return archive, nil
}
}
fmt.Println(`Uncached Archive:`, pkg.ImportPath)

// Existing archive is out of date or doesn't exist, let's build the package.
fileSet := token.NewFileSet()
Expand Down
37 changes: 37 additions & 0 deletions tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,35 @@ import (
"golang.org/x/term"
)

type timeKeeper struct {
start time.Time
durNames []string
durations []time.Duration
}

func newTimeKeeper() *timeKeeper {
return &timeKeeper{start: time.Now()}
}

func (s *timeKeeper) Mark(name string) {
s.durNames = append(s.durNames, name)
s.durations = append(s.durations, time.Since(s.start))
}

func (s *timeKeeper) String() string {
width := 0
for _, name := range s.durNames {
if len(name) > width {
width = len(name)
}
}
buf := &bytes.Buffer{}
for i, name := range s.durNames {
buf.WriteString(fmt.Sprintf("timeKeeper: %-*s\t%s\n", width, name, s.durations[i]))
}
return buf.String()
}

var currentDirectory string

func init() {
Expand Down Expand Up @@ -364,12 +393,15 @@ func main() {
fmt.Printf("? \t%s\t[no test files]\n", pkg.ImportPath)
continue
}

tK := newTimeKeeper()
localOpts := options
localOpts.TestedPackage = pkg.ImportPath
s, err := gbuild.NewSession(localOpts)
if err != nil {
return err
}
tK.Mark("session")

_, err = s.BuildPackage(pkg.TestPackage())
if err != nil {
Expand All @@ -379,6 +411,7 @@ func main() {
if err != nil {
return err
}
tK.Mark("build test packages")

fset := token.NewFileSet()
tests := testmain.TestMain{Package: pkg}
Expand All @@ -387,6 +420,7 @@ func main() {
if err != nil {
return fmt.Errorf("failed to generate testmain package for %s: %w", pkg.ImportPath, err)
}
tK.Mark("test synth")
importContext := &compiler.ImportContext{
Packages: s.Types,
Import: s.ImportResolverFor(mainPkg),
Expand All @@ -395,6 +429,7 @@ func main() {
if err != nil {
return fmt.Errorf("failed to compile testmain package for %s: %w", pkg.ImportPath, err)
}
tK.Mark("compile")

if *compileOnly && *outputFilename == "" {
*outputFilename = pkg.Package.Name + "_test.js"
Expand Down Expand Up @@ -424,6 +459,8 @@ func main() {
if err := s.WriteCommandPackage(mainPkgArchive, outfile.Name()); err != nil {
return err
}
tK.Mark("write command")
fmt.Println(tK.String())

if *compileOnly {
continue
Expand Down

0 comments on commit c3494fe

Please sign in to comment.