golds icon indicating copy to clipboard operation
golds copied to clipboard

Allow passing a list of packages to be included

Open jonlundy opened this issue 3 years ago • 6 comments

I am looking for something similar to how the std mode works but where i have a number of related repos that i would like parsed together into one generated output.

Example: golds -wdpkgs-listing=promoted x.y.z/myapp1 x.y.z/myapp2 x.y.z/myapp3 x.y.z/myappN

where all of the packages related to the list provided are included in the promoted.

x.y.z/myapp1 
x.y.z/myapp1/cmd/bin 
x.y.z/myapp2
x.y.z/myapp2/internal/foo
x.y.z/myapp2/internal/bar 
x.y.z/myapp3
x.y.z/myapp3/pkg/baz
x.y.z/myappN

...other packages...

jonlundy avatar Feb 16 '22 22:02 jonlundy

Is each of the projects in a separated module?

zigo101 avatar Feb 17 '22 03:02 zigo101

Yes

jonlundy avatar Feb 17 '22 22:02 jonlundy

Yes

I assume that your projects (appN) have a go.mod file in their respective root directories.

It is a restriction that only one (non-major) version is chosen for each module in the current implementation. So in theory, if two of appN projects depend on two different versions of a module, golds will fail to process. And in current implementation, to prevent such situations happening, golds only supports parsing one Go project in each run.

The restriction comes from the https://pkg.go.dev/golang.org/x/tools/go/packages dependency used by golds. It needs much efforts to overcome this restriction.

If you can make sure that your projects don't depend on two different versions of a module, here is a (some inconvenient) workaround:

  • create a temp directory and create a go.mod file which specifies a line module x.y.z.
  • copy all your appN projects into the directory and remove all the go.mod files in them.
  • run golds in the temp directory

zigo101 avatar Feb 18 '22 02:02 zigo101

I will try that

jonlundy avatar Feb 18 '22 17:02 jonlundy

shouldn't tools/go provide mechanisms to resolve a dependency graph before you compute the details? @go101

amery avatar Mar 20 '23 13:03 amery

golang.org/x/tools/go/packages (and Golds) behaves the same as go build. If go build module1 module2 succeeds, then golds module1 module2 should too.

zigo101 avatar Mar 20 '23 15:03 zigo101