Faster tool to extract package name, imports for build systems

2 views
Skip to first unread message

Albert Strasheim

unread,
Sep 6, 2010, 6:15:19 AM9/6/10
to golang-dev
Hello all

I've been doing some work on building Go code with SCons (release
coming soon), with some inspiration from Ross Light's sconsgo work:

https://code.launchpad.net/sconsgo

I've added support for cgo and a few methods to make build scripts for
projects that follow the src/{pkg,cmd} convention as simple as:

env = Environment(tools=['default','golang'])
env.GoPackages('src/pkg')
env.GoCommands('src/cmd')

One issue I had to deal with is that one needs to obtain package names
and imports from .go files to calculate dependencies.

I started by parsing the output from gofmt -ast=true, but this is too
slow. Running gofmt with -ast=true takes about 6 seconds for our
project, where the entire build with make takes less than 2 seconds.

Ross's solution for this problem in sconsgo was to include a small
helper application (written in Go) to just print out package names and
imports. Using this helper instead of gofmt allows our SCons build to
run as fast as make.

Given that many build tools (SCons, waf, etc.) need these two bits of
information, perhaps support for this special case can be rolled into
gofmt? Alternatively, maybe a more flexible goast tool could be
created?

I think it would be worthwhile to have a tool like this included in
the Go distribution so that any build system can use it.

Thoughts on how to approach this greatly appreciated.

Regards

Albert

Andrew Gerrand

unread,
Sep 6, 2010, 6:41:19 AM9/6/10
to Albert Strasheim, golang-dev
goinstall (specifically cmd/goinstall/parse.go) has this
functionality, so maybe it would be worth adding a flag to that. Or to
generalise the code somehow and put it into godoc, which might seem a
more natural place for it.

Andrew

Reply all
Reply to author
Forward
0 new messages