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
// magic begins all files generated by gotrace
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
// - the file does not exist, or
// - it exits but was previously generated by us
......@@ -420,6 +420,7 @@ func removeFile(path string) error {
return err
}
// Buffer is bytes.Buffer + syntatic sugar
type Buffer struct {
bytes.Buffer
}
......@@ -442,7 +443,7 @@ func (s StrSet) Delete(item string) {
delete(s, item)
}
// Itemb returns ordered slice of set items
// Itemv returns ordered slice of set items
func (s StrSet) Itemv() []string {
itemv := make([]string, 0, len(s))
for item := range s {
......@@ -453,7 +454,10 @@ func (s StrSet) Itemv() []string {
}
// 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
// load anything except the package in question
// TODO -> use just AST parsing for loading?
......@@ -461,6 +465,7 @@ func tracegen(pkgpath string, buildCtx *build.Context) error {
ParserMode: parser.ParseComments,
TypeCheckFuncBodies: func(path string) bool { return false },
Build: buildCtx,
Cwd: cwd,
}
conf.Import(pkgpath)
......@@ -595,7 +600,12 @@ TODO ...
}
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 {
log.Fatal(err)
}
......
......@@ -34,20 +34,17 @@ const (
// prepareTestTree copies files from src to dst recursively processing *.ok and *.rm depending on mode
// dst should not initially exist
func prepareTestTree(src, dst string, mode TreePrepareMode) error {
println("AAA", dst)
err := os.MkdirAll(dst, 0777)
if err != nil {
return err
}
return filepath.Walk(src, func(srcpath string, info os.FileInfo, err error) error {
println("*", srcpath)
if srcpath == src /* skip root */ || err != nil {
return err
}
dstpath := dst + strings.TrimPrefix(srcpath, src)
//println("·", dstpath)
if info.IsDir() {
err := os.Mkdir(dstpath, 0777)
return err
......@@ -139,7 +136,7 @@ func TestGoTraceGen(t *testing.T) {
testv := []string{"a/pkg1", "b/pkg2"}
for _, tpkg := range testv {
err = tracegen(tpkg, tBuildCtx)
err = tracegen(tpkg, tBuildCtx, "" /* = local imorts disabled */)
if err != nil {
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