Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: list the Go resources in a physical directory #30469

Open
nim-nim opened this issue Feb 28, 2019 · 4 comments
Open

cmd/go: list the Go resources in a physical directory #30469

nim-nim opened this issue Feb 28, 2019 · 4 comments
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@nim-nim
Copy link

nim-nim commented Feb 28, 2019

go 1.11/1.12

A lot of Go projects have been using the historical unpacked filesystem property of GOPATH to mix Go source files with other things (human documentation md files, non-Go resource files, etc).

This mixing does not make sense in module mode, since the Go compiler is the only thing that is smart enough to locate and access the content of module zip files.

Therefore there is a need to inspect existing Go project trees, to separate Go project source files from other things. And you have a bootstrapping problem, because GOPATH is not used in module mode, and the whole point of the inspection is to sort what must end up in the zip files, and what should end up elsewhere, so at this point the project is no longer in GOPATH but not in a zip module yet.

Is there a way to ask Go
"tell me what part of this directory is useful to the builder and should end up in a zip module, and what part needs to be exposed some other way?"

Aside from calling exec.Command("go", "list", "-f"…, ".") recursively that is?

(Of course one could just zip brutally the whole tree and look what breaks afterwards, but that is not a very efficient way to switch to modules)

@bcmills
Copy link
Contributor

bcmills commented Feb 28, 2019

I suspect that the command you're looking for is:

go list -f '{{.Dir}}' $(dirname $(go env GOMOD))/...

@bcmills bcmills changed the title list the Go resources in a physical directory cmd/go: list the Go resources in a physical directory Feb 28, 2019
@bcmills
Copy link
Contributor

bcmills commented Feb 28, 2019

Hmm, that's not strictly sufficient, though: it won't tell you what testdata will be included, for example.

CC @jayconrod @ianthehat @matloob

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed Question labels Feb 28, 2019
@bcmills bcmills added this to the Go1.13 milestone Feb 28, 2019
@jayconrod
Copy link
Contributor

Related #28835

@nim-nim
Copy link
Author

nim-nim commented Feb 28, 2019

Hum, unless I'm missing something:

  • one can not use GOMOD because the project has not been transformed in a module yet
  • go list -f '{{.Dir}}' will give you the package list but won't sort what files in the package directories should end up in the modules and what files should not

So you probably need to switch to the module directory root (because otherwise go list can inspect something else than the target directory) and use something like

 go list -f '{{$d := .Dir}}{{range $f := .GoFiles}}{{printf "%s/%s\n" $d $f}}{{end}}}{{range $f := .CgoFiles}}{{printf "%s/%s\n" $d $f}}{{end}}{{range $f := .CFiles}}{{range $f := .CXXFiles}}{{printf "%s/%s\n" $d $f}}{{end}}{{printf "%s/%s\n" $d $f}}{{end}}{{range $f := .TestGoFiles}}{{printf "%s/%s\n" $d $f}}{{end}}' ./...

which is not terribly convenient (and it is not even complete, there are other kinds of source files to add)

And having to os.exec go list from a Go program is not terribly elegant either

@bcmills bcmills modified the milestones: Go1.13, Unplanned May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants