feat(go): report project .go sources as project-graph inputs - #189
jonpoole-fluidstack wants to merge 1 commit into
Conversation
Relationship inference derives edges from `go list` reading `.go` imports, but the project graph only invalidated on `go.mod`. A new import with no `go.mod` change left a locally cached graph stale until a config change or `moon clean`. Report each project's own `.go` sources as graph inputs. The walk stops at nested project roots — those files belong to the nested project — so a project's inputs exclude sources it doesn't own and a root-level project doesn't re-walk the whole workspace. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@jonpoole-fluidstack Wait so this adds every |
😢 What I was going for is to invalidate the cache per-project so if you changed a source file under there it would list the deps, but I realise this cached as a single call per workspace. I'm not sure what a good option here is. I think to represent the Go semantics we need to re-run when the imports change, which means busting the cache when go sources change. Shelling out to Go per project is pretty slow though. You can do one list upfront and get the full project graph pretty quickly. In the gRPC go project: So around 200ms - 300ms wall time for a fresh re-run on each moon call. If we don't care about build tags etc. I'm sure doing this in process in with a rust Go parser would be even faster. What do you think? I think where I've left you is not great because it's caching things it shouldn't (sorry D:) so maybe you'd prefer to roll back? |
|
Yeah right now the graph is cached as a whole. I would like to cache it per-node (project) eventually, but that would basically require a rewrite I think.
It's just
It is possible to glob + parse every file. May actually be faster than child process calls. Is an option if the parsing is actually fast and accurate. |
I think We could probably drop the fiddly build tag semantics, but we may end up with edges that aren't technically needed based on the current build tags/platform. I don't think an extra edge once in a while is likely to be a real problem. You can't dynamically change the project graph in .yml anyway. What would be nice down the line would be to infer the project sources as well. We're currently just globbing for
Yeah, ideally, we'd start from the task we're asking of moon, and lazily populate the project edges as we need them. The PDK would need to expose a new function to allow us to finalise a project, and call that when it needs the edge info. Maybe the roadmap for this is:
And then we can figure out if we want to hand roll a parser to pull out the Go imports. If we wanted to get fancy with it, we could look into some wasm/tranpilation here to get access to bits of the Go SDK but this is all private internal code that you're not really meant to access. Even Go tool shell out to |
Apologies, bit of a bug from my last PR that slipped by me. I didn't realise this was being cached based solely on the go.mod. This PR attempts to find all .go files that belong in that project and add these as inputs to the project-graph, as that's what we're basing the project inference on.