Commit f67bb046 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c9762c3f
...@@ -416,25 +416,6 @@ func removeFile(path string) error { ...@@ -416,25 +416,6 @@ func removeFile(path string) error {
return os.Remove(path) return os.Remove(path)
} }
/*
// writer is interface for gotrace output operations
// made for testing
type writer interface {
writeFile(path string, data []byte) error
removeFile(path string) error
}
type fsWriter struct{}
func (fsWriter) writeFile(path string, data []byte) error {
return writeFile(path, data)
}
func (fsWriter) removeFile(path string) error {
return removeFile(path)
}
*/
type Buffer struct { type Buffer struct {
bytes.Buffer bytes.Buffer
} }
...@@ -468,7 +449,7 @@ func (s StrSet) Itemv() []string { ...@@ -468,7 +449,7 @@ func (s StrSet) Itemv() []string {
} }
// tracegen generates code according to tracing directives in a package @ pkgpath // tracegen generates code according to tracing directives in a package @ pkgpath
func tracegen(pkgpath string, buildCtx *build.Context, w writer) error { func tracegen(pkgpath string, buildCtx *build.Context) error {
// XXX typechecking is much slower than parsing + we don't need to // XXX typechecking is much slower than parsing + we don't need to
// load anything except the package in question // load anything except the package in question
// TODO -> use just AST parsing for loading? // TODO -> use just AST parsing for loading?
...@@ -566,7 +547,7 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error { ...@@ -566,7 +547,7 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
// write output to ztrace.go // write output to ztrace.go
fulltext := append(prologue.Bytes(), text.Bytes()...) fulltext := append(prologue.Bytes(), text.Bytes()...)
err = w.writeFile(filepath.Join(pkgdir, "ztrace.go"), fulltext) err = writeFile(filepath.Join(pkgdir, "ztrace.go"), fulltext)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
...@@ -574,13 +555,13 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error { ...@@ -574,13 +555,13 @@ func tracegen(pkgpath string, buildCtx *build.Context, w writer) error {
// write empty ztrace.s so go:linkname works, if there are trace imports // write empty ztrace.s so go:linkname works, if there are trace imports
ztrace_s := filepath.Join(pkgdir, "ztrace.s") ztrace_s := filepath.Join(pkgdir, "ztrace.s")
if len(pkg.Importv) == 0 { if len(pkg.Importv) == 0 {
err = w.removeFile(ztrace_s) err = removeFile(ztrace_s)
} else { } else {
text.Reset() text.Reset()
text.WriteString(magic) text.WriteString(magic)
text.emit("// empty .s so `go build` does not use -complete for go:linkname to work") text.emit("// empty .s so `go build` does not use -complete for go:linkname to work")
err = w.writeFile(ztrace_s, text.Bytes()) err = writeFile(ztrace_s, text.Bytes())
} }
if err != nil { if err != nil {
...@@ -610,7 +591,7 @@ TODO ... ...@@ -610,7 +591,7 @@ TODO ...
} }
pkgpath := argv[0] pkgpath := argv[0]
err := tracegen(pkgpath, build.Default) err := tracegen(pkgpath, &build.Default)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -2,26 +2,15 @@ package main ...@@ -2,26 +2,15 @@ package main
import ( import (
"go/build" "go/build"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing" "testing"
)
/*
// memWriter saves in memory filesystem modifications gotrace wanted to made
type memWriter struct {
wrote map[string]string // path -> data
removed StrSet
}
func (mw *memWriter) writeFile(path string, data []byte) error { "lab.nexedi.com/kirr/go123/exc"
mw.wrote[path] = string(data) )
return nil
}
func (mw *memWriter) removeFile(path) error {
mw.removed.Add(path)
return nil
}
*/
func xglob(t *testing.T, pattern string) []string { func xglob(t *testing.T, pattern string) []string {
t.Helper() t.Helper()
...@@ -41,20 +30,20 @@ const ( ...@@ -41,20 +30,20 @@ const (
// prepareTestTree copies files from src to dst recursively processing *.ok and *.rm depending on mode // prepareTestTree copies files from src to dst recursively processing *.ok and *.rm depending on mode
// dst should not initially exist // dst should not initially exist
func prepareTestTree(src, dst string, mode prepareMode) error { func prepareTestTree(src, dst string, mode TreePrepareMode) error {
err := os.MkdirAll(dst, 0777) err := os.MkdirAll(dst, 0777)
if err != nil { if err != nil {
return err return err
} }
filepath.Walk(src, func(srcpath string, info os.FileInfo, err error) error { return filepath.Walk(src, func(srcpath string, info os.FileInfo, err error) error {
dstpath := dst + "/" + strings.TrimPrefix(srcpath, src) dstpath := dst + "/" + strings.TrimPrefix(srcpath, src)
if info.IsDir() { if info.IsDir() {
err := os.Mkdir(dstpath, 0777) err := os.Mkdir(dstpath, 0777)
if err != nil { if err != nil {
return err return err
} }
return cpR(srcpath, dstpath) return prepareTestTree(srcpath, dstpath, mode)
} }
var isOk, isRm bool var isOk, isRm bool
...@@ -62,7 +51,7 @@ func prepareTestTree(src, dst string, mode prepareMode) error { ...@@ -62,7 +51,7 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
isOk = true isOk = true
dstpath = strings.TrimSuffix(dstpath, ".ok") dstpath = strings.TrimSuffix(dstpath, ".ok")
} }
if strings.hasSuffix(srcpath, ".rm") { if strings.HasSuffix(srcpath, ".rm") {
isRm = true isRm = true
dstpath = strings.TrimSuffix(dstpath, ".rm") dstpath = strings.TrimSuffix(dstpath, ".rm")
} }
...@@ -73,13 +62,13 @@ func prepareTestTree(src, dst string, mode prepareMode) error { ...@@ -73,13 +62,13 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
} }
switch mode { switch mode {
case prepareGolden: case TreePrepareGolden:
// no removed files in golden tree // no removed files in golden tree
if isRm { if isRm {
return nil return nil
} }
case prepareWork: case TreePrepareWork:
// no ok files initially in work tree // no ok files initially in work tree
if isOk { if isOk {
return nil return nil
...@@ -99,8 +88,8 @@ func prepareTestTree(src, dst string, mode prepareMode) error { ...@@ -99,8 +88,8 @@ func prepareTestTree(src, dst string, mode prepareMode) error {
}) })
} }
xprepareTree(t *testing.T, src, dst string, mode prepareMode) { func xprepareTree(src, dst string, mode TreePrepareMode) {
err := prepareTestTree(src, dst) err := prepareTestTree(src, dst, mode)
exc.Raiseif(err) exc.Raiseif(err)
} }
...@@ -118,12 +107,12 @@ func TestGoTraceGen(t *testing.T) { ...@@ -118,12 +107,12 @@ func TestGoTraceGen(t *testing.T) {
xprepareTree("testdata", work, TreePrepareWork) xprepareTree("testdata", work, TreePrepareWork)
// test build context with GOPATH set to work tree // test build context with GOPATH set to work tree
var tBuildCtx = build.Context{ var tBuildCtx = &build.Context{
GOARCH: "amd64", GOARCH: "amd64",
GOOS: "linux", GOOS: "linux",
GOROOT: runtime.GOROOT(), GOROOT: runtime.GOROOT(),
GOPATH: work, GOPATH: work,
Compiler: runtime.Compiler(), Compiler: runtime.Compiler,
} }
// XXX autodetect (go list ?) // XXX autodetect (go list ?)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment