> I just can't figure out how to do this.  Maybe it can't be done in `go
> list` ?  Or maybe we're just missing some detail of go modules..

go list operates in the context of a single module (in the mode you
are interested in), so you cannot do this with a single command across
multiple modules.

> First I do a `find` for any file that has a specific comment tag,
> indicating that the package needs codegen.  The results span several
> of the in-repo submodules.

Just to check, I'm assuming the results of this find command are being
translated to a list of packages? Because the transitive dependencies
of a list of packages within a module can be done via a single go list
command.

> For each target package, I want to get the list of all deps and
> extract the GoFiles.  Then I can use that to determine if the codegen
> needs to run.

FWIW I wrote a tool to do just this:
https://pkg.go.dev/myitcv.io@v0.0.0-20201125173645-a7167afc9e13/cmd/gogenerate
which might work in your situation.

> Where it breaks down is that I can't seem to `go list` all at once:
>
> ```
> # This works within the "root" module
> $ go list -f '{{.GoFiles}}' ./subdir
> [file.go]

This will work.

> # This does not work across modules
> $ go list -f '{{.GoFiles}}' ./submod/used ./submod/unused
> main module (example.com/m) does not contain package example.com/m/submod/used
> main module (example.com/m) does not contain package 
> example.com/m/submod/unused

Per above, this will not work across module boundaries.

> # Nor does this work, even with module replacements
> $ go list -f '{{.GoFiles}}' ./staging/src/example.com/other1/used
> ./staging/src/example.com/other1/unused
> main module (example.com/m) does not contain package
> example.com/m/staging/src/example.com/other1/used
> main module (example.com/m) does not contain package
> example.com/m/staging/src/example.com/other1/unused
> ```

With replace directives in place this should work, but you won't be
able to use the relative path to the modules (which is in fact
interpreted as a directory): it will need to be the full
module/package path.

> I can run `go list` multiple times, but that's INCREDIBLY slow - most
> of these submodules have common deps that are large.  This re-parses
> everything over and over.  It takes almost 60 seconds just to do `cd
> $dir; go list` (on the real kubernetes repo).

Do you have a repro of this taking 60 seconds? Because that really
shouldn't be the case with a populated local module cache.


Paul

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACoUkn77v8KiJWmJFQZOmDKAt7zwAP7yDrxG-yTMS_JodQaGyA%40mail.gmail.com.

Reply via email to