Skip to content

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

Duplicate of#67233
@ialidzhikov

Description

@ialidzhikov

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?

Activity

bcmills

bcmills commented on Jul 25, 2019

@bcmills
Contributor

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

changed the title [-]cmd/go: Add option to prune non-go files[/-] [+]cmd/go: prune non-source files in 'go mod vendor'[/+] on Jul 25, 2019
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Jul 25, 2019
added this to the Unplanned milestone on Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.modules

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bcmills@ialidzhikov@seankhliao

        Issue actions

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