Commit a8243345 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e8921f0e
...@@ -375,7 +375,7 @@ func {{.Pkgi.Pkg.Name}}_{{.Name}}_Attach(*tracing.ProbeGroup, func({{.ArgvTypedR ...@@ -375,7 +375,7 @@ func {{.Pkgi.Pkg.Name}}_{{.Name}}_Attach(*tracing.ProbeGroup, func({{.ArgvTypedR
// magic begins all files generated by gotrace // magic begins all files generated by gotrace
const magic = "// Code generated by lab.nexedi.com/kirr/go123/tracing/cmd/gotrace; DO NOT EDIT.\n" const magic = "// Code generated by lab.nexedi.com/kirr/go123/tracing/cmd/gotrace; DO NOT EDIT.\n"
// checkCanWrite check whether it is safe to write at path // checkCanWrite checks whether it is safe to write to file at path
// it is safe to write when either // it is safe to write when either
// - the file does not exist, or // - the file does not exist, or
// - it exits but was previously generated by us // - it exits but was previously generated by us
...@@ -420,6 +420,7 @@ func removeFile(path string) error { ...@@ -420,6 +420,7 @@ func removeFile(path string) error {
return err return err
} }
// Buffer is bytes.Buffer + syntatic sugar
type Buffer struct { type Buffer struct {
bytes.Buffer bytes.Buffer
} }
...@@ -442,7 +443,7 @@ func (s StrSet) Delete(item string) { ...@@ -442,7 +443,7 @@ func (s StrSet) Delete(item string) {
delete(s, item) delete(s, item)
} }
// Itemb returns ordered slice of set items // Itemv returns ordered slice of set items
func (s StrSet) Itemv() []string { func (s StrSet) Itemv() []string {
itemv := make([]string, 0, len(s)) itemv := make([]string, 0, len(s))
for item := range s { for item := range s {
...@@ -453,7 +454,10 @@ func (s StrSet) Itemv() []string { ...@@ -453,7 +454,10 @@ 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) error { //
// buildCtx is build context for discovering packages
// cwd is "current" directory for resolving local imports (e.g. packages like "./some/package")
func tracegen(pkgpath string, buildCtx *build.Context, cwd string) 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?
...@@ -461,6 +465,7 @@ func tracegen(pkgpath string, buildCtx *build.Context) error { ...@@ -461,6 +465,7 @@ func tracegen(pkgpath string, buildCtx *build.Context) error {
ParserMode: parser.ParseComments, ParserMode: parser.ParseComments,
TypeCheckFuncBodies: func(path string) bool { return false }, TypeCheckFuncBodies: func(path string) bool { return false },
Build: buildCtx, Build: buildCtx,
Cwd: cwd,
} }
conf.Import(pkgpath) conf.Import(pkgpath)
...@@ -595,7 +600,12 @@ TODO ... ...@@ -595,7 +600,12 @@ TODO ...
} }
pkgpath := argv[0] pkgpath := argv[0]
err := tracegen(pkgpath, &build.Default) cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
err = tracegen(pkgpath, &build.Default, cwd)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -34,20 +34,17 @@ const ( ...@@ -34,20 +34,17 @@ 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 TreePrepareMode) error { func prepareTestTree(src, dst string, mode TreePrepareMode) error {
println("AAA", dst)
err := os.MkdirAll(dst, 0777) err := os.MkdirAll(dst, 0777)
if err != nil { if err != nil {
return err return err
} }
return 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 {
println("*", srcpath)
if srcpath == src /* skip root */ || err != nil { if srcpath == src /* skip root */ || err != nil {
return err return err
} }
dstpath := dst + strings.TrimPrefix(srcpath, src) dstpath := dst + strings.TrimPrefix(srcpath, src)
//println("·", dstpath)
if info.IsDir() { if info.IsDir() {
err := os.Mkdir(dstpath, 0777) err := os.Mkdir(dstpath, 0777)
return err return err
...@@ -139,7 +136,7 @@ func TestGoTraceGen(t *testing.T) { ...@@ -139,7 +136,7 @@ func TestGoTraceGen(t *testing.T) {
testv := []string{"a/pkg1", "b/pkg2"} testv := []string{"a/pkg1", "b/pkg2"}
for _, tpkg := range testv { for _, tpkg := range testv {
err = tracegen(tpkg, tBuildCtx) err = tracegen(tpkg, tBuildCtx, "" /* = local imorts disabled */)
if err != nil { if err != nil {
t.Errorf("%v: %v", tpkg, err) t.Errorf("%v: %v", tpkg, err)
} }
......
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