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: prune non-source files in 'go mod vendor' #33261

Open
ialidzhikov opened this issue Jul 24, 2019 · 1 comment
Open

cmd/go: prune non-source files in 'go mod vendor' #33261

ialidzhikov opened this issue Jul 24, 2019 · 1 comment
Labels
modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ialidzhikov
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.12.7 darwin/amd64

Does this issue reproduce with the latest release?

I would say that the issue is kind of enhancement or feature request rather than a bug. golang/dep has an option to prune non-go files under vendor with a config like:

[prune]
  go-tests = true
  unused-packages = true
  non-go = true

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

# The go mod way:

$ mkdir gomod-example
$ cd gomod-example
$ go mod init github.com/ialidzhikov/gomod-example

main.go

package main

import (
	"fmt"

	"github.com/ghodss/yaml"
)

func main() {
	j := []byte(`{"name": "John", "age": 30}`)
	y, err := yaml.JSONToYAML(j)
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return
	}
	fmt.Println(string(y))
	/* Output:
	name: John
	age: 30
	*/
	j2, err := yaml.YAMLToJSON(y)
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return
	}
	fmt.Println(string(j2))
	/* Output:
	{"age":30,"name":"John"}
	*/
}
$ go mod vendor
$ go mod tidy
$ ls -a vendor/github.com/ghodss/yaml/
./  ../  .gitignore  .travis.yml  LICENSE  README.md  fields.go  yaml.go  yaml_go110.go

Ensure that non-go files as .gitignore, .travis.yml and others are added under vendor/ and currently there is no way to clean them.

On the other hand golang/dep with non-go = true option:

$ mkdir -p $GOPATH/src/github.com/ialidzhikov/dep-example
$ cd $GOPATH/src/github.com/ialidzhikov/dep-example
$ dep init
$ dep ensure -v
$ ls -a vendor/github.com/ghodss/yaml/
./  ../  LICENSE  fields.go  yaml.go

What did you expect to see?

What did you see instead?

@bcmills
Copy link
Contributor

bcmills commented Jul 25, 2019

We already filter out test sources, testdata directories, and // +build ignore files (#31088).

Go generally eschews configuration flags, but perhaps we should filter out other non-source-code files by default. (We do presumably need to retain some sources for cgo-enabled builds, such as assembly files and .h and .c files, but perhaps we can identify a specific set that needs to be retained and prune out the rest.)

CC @jayconrod

@bcmills bcmills changed the title cmd/go: Add option to prune non-go files cmd/go: prune non-source files in 'go mod vendor' Jul 25, 2019
@bcmills bcmills added modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 25, 2019
@bcmills bcmills added this to the Unplanned milestone Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules 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

2 participants