Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
eea958fd
Commit
eea958fd
authored
Jul 03, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
248d426b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
48 deletions
+39
-48
go/xcommon/tracing/cmd/gotrace/gotrace.go
go/xcommon/tracing/cmd/gotrace/gotrace.go
+35
-47
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
+1
-1
go/xcommon/tracing/cmd/gotrace/testdata/src/a/pkg1/ztrace.go
go/xcommon/tracing/cmd/gotrace/testdata/src/a/pkg1/ztrace.go
+3
-0
No files found.
go/xcommon/tracing/cmd/gotrace/gotrace.go
View file @
eea958fd
...
...
@@ -484,70 +484,58 @@ func (s StrSet) Itemv() []string {
return
itemv
}
//
tracegen generates code according to tracing directives in a package @ pkgpath
//
findPackageNoZTrace is (*build.Context).Import but filters-out ztrace* files from found package
//
// 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 ignore build tags?
bpkg
,
err
:=
buildCtx
.
Import
(
pkgpath
,
cwd
,
0
)
if
err
!=
nil
{
return
err
}
// canonical package path e.g. "." -> "path/to/package"
pkgpath
=
bpkg
.
ImportPath
// XXX reject on .InvalidGoFiles ?
fset
:=
token
.
NewFileSet
()
// XXX -> Package?
filev
:=
[]
*
ast
.
File
{}
// parse go and cgo sources
for
_
,
fgo
:=
range
append
(
bpkg
.
GoFiles
,
bpkg
.
CgoFiles
...
)
{
fpath
:=
bpkg
.
Dir
+
"/"
+
fgo
// don't load what should be generated by us. reasons:
// - code generated could be wrong with older version of the
// tool - it should not prevent from regenerating.
// - generated code imports packages which might be not there
// yet in gopath (lab.nexedi.com/kirr/go123/tracing)
if
strings
.
HasPrefix
(
fgo
,
"ztrace"
)
{
// if it is there but not created by us - complain
err
=
checkCanWrite
(
fpath
)
if
err
!=
nil
{
return
err
// we don't load what should be generated by us for 2 reasons:
// - code generated could be wrong with older version of the
// tool - it should not prevent from regenerating.
// - generated code imports packages which might be not there
// yet in gopath (lab.nexedi.com/kirr/go123/tracing)
func
findPackageNoZTrace
(
ctxt
*
build
.
Context
,
fromDir
,
importPath
string
,
mode
build
.
ImportMode
)
(
*
build
.
Package
,
error
)
{
bp
,
err
:=
ctxt
.
Import
(
importPath
,
fromDir
,
mode
)
filter
:=
func
(
filev
*
[]
string
)
{
okv
:=
[]
string
{}
for
_
,
f
:=
range
*
filev
{
if
strings
.
HasPrefix
(
f
,
"ztrace"
)
{
bp
.
IgnoredGoFiles
=
append
(
bp
.
IgnoredGoFiles
,
f
)
}
else
{
okv
=
append
(
okv
,
f
)
}
continue
}
*
filev
=
okv
}
f
,
err
:=
parser
.
ParseFile
(
fset
,
fpath
,
nil
,
parser
.
ParseComments
)
if
err
!=
nil
{
return
err
}
if
bp
!=
nil
{
filter
(
&
bp
.
GoFiles
)
filter
(
&
bp
.
CgoFiles
)
filter
(
&
bp
.
TestGoFiles
)
filter
(
&
bp
.
XTestGoFiles
)
filter
(
&
bp
.
SFiles
)
filev
=
append
(
filev
,
f
)
// XXX also adjust .Import{s,Pos}, .TestImport{s,Pos}, .XTestImport{s,Pos} ?
}
return
nil
// XXX test-only with .TestGoFiles .XTestGoFiles
return
bp
,
err
}
// tracegen generates code according to tracing directives in a package @ pkgpath
//
// ctxt is build context for discovering packages
// cwd is "current" directory for resolving local imports (e.g. packages like "./some/package")
func
tracegen
(
pkgpath
string
,
ctxt
*
build
.
Context
,
cwd
string
)
error
{
// TODO test-only with .TestGoFiles .XTestGoFiles
// 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?
conf
:=
loader
.
Config
{
ParserMode
:
parser
.
ParseComments
,
TypeCheckFuncBodies
:
func
(
path
string
)
bool
{
return
false
},
Build
:
buildCtx
,
Build
:
ctxt
,
Cwd
:
cwd
,
FindPackage
:
findPackageNoZTrace
,
}
conf
.
Import
(
pkgpath
)
// load package + all its imports
// XXX ignore trace.go & trace.s on load here? -> TODO remove the first
lprog
,
err
:=
conf
.
Load
()
if
err
!=
nil
{
return
err
...
...
go/xcommon/tracing/cmd/gotrace/gotrace_test.go
View file @
eea958fd
...
...
@@ -133,7 +133,7 @@ func TestGoTraceGen(t *testing.T) {
}
// XXX autodetect (go list ?)
testv
:=
[]
string
{
"a/pkg1"
,
"b/pkg2"
}
testv
:=
[]
string
{
"a/pkg1"
,
"b/pkg2"
,
"c/pkg3"
}
for
_
,
tpkg
:=
range
testv
{
err
=
tracegen
(
tpkg
,
tBuildCtx
,
""
/* = local imorts disabled */
)
...
...
go/xcommon/tracing/cmd/gotrace/testdata/src/a/pkg1/ztrace.go
0 → 100644
View file @
eea958fd
// Code generated by lab.nexedi.com/kirr/go123/tracing/cmd/gotrace; DO NOT EDIT.
Bad
bad
bad
-
I
'
m
invalid
go
file
.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment