Paschalis Tsilias has uploaded this change for review.
cmd/go: add 'go mod vendor -o' flag
Adds a new flag to 'go mod vendor' which overrides the default
'vendor' destination directory. This can be helpful for writing the
vendor tree to a temporary location so it can be uploaded to a remote
build system. The argument can be a relative or an absolute path. This
flag has no other influence on how the command behaves.
Fixes #47327
Change-Id: I4502931127616b181dc90a2066d2fb57bfe48f96
---
M src/cmd/go/alldocs.go
M src/cmd/go/internal/modcmd/vendor.go
M src/cmd/go/testdata/script/mod_vendor.txt
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index 954caae..460227a 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -1260,7 +1260,7 @@
//
// Usage:
//
-// go mod vendor [-e] [-v]
+// go mod vendor [-e] [-v] [-o outdir]
//
// Vendor resets the main module's vendor directory to include all packages
// needed to build and test all the main module's packages.
@@ -1272,6 +1272,9 @@
// The -e flag causes vendor to attempt to proceed despite errors
// encountered while loading packages.
//
+// The -o flag receives a relative or absolute path and causes vendor to
+// override the destination directory. Defaults to 'vendor'.
+//
// See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
//
//
diff --git a/src/cmd/go/internal/modcmd/vendor.go b/src/cmd/go/internal/modcmd/vendor.go
index 713d5f9..0b7528b 100644
--- a/src/cmd/go/internal/modcmd/vendor.go
+++ b/src/cmd/go/internal/modcmd/vendor.go
@@ -31,7 +31,7 @@
)
var cmdVendor = &base.Command{
- UsageLine: "go mod vendor [-e] [-v]",
+ UsageLine: "go mod vendor [-e] [-v] [-o outdir]",
Short: "make vendored copy of dependencies",
Long: `
Vendor resets the main module's vendor directory to include all packages
@@ -44,16 +44,21 @@
The -e flag causes vendor to attempt to proceed despite errors
encountered while loading packages.
+The -o flag receives a relative or absolute path and causes vendor to
+override the destination directory. Defaults to 'vendor'.
+
See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
`,
Run: runVendor,
}
-var vendorE bool // if true, report errors but proceed anyway
+var vendorE bool // if true, report errors but proceed anyway
+var vendorO string // if set, overrides the default output directory
func init() {
cmdVendor.Flag.BoolVar(&cfg.BuildV, "v", false, "")
cmdVendor.Flag.BoolVar(&vendorE, "e", false, "")
+ cmdVendor.Flag.StringVar(&vendorO, "o", "vendor", "")
base.AddModCommonFlags(&cmdVendor.Flag)
}
@@ -74,7 +79,13 @@
}
_, pkgs := modload.LoadPackages(ctx, loadOpts, "all")
- vdir := filepath.Join(modload.ModRoot(), "vendor")
+ var vdir string
+ if filepath.IsAbs(vendorO) {
+ vdir = vendorO
+ } else {
+ vdir = filepath.Join(modload.ModRoot(), vendorO)
+ }
+
if err := os.RemoveAll(vdir); err != nil {
base.Fatalf("go mod vendor: %v", err)
}
diff --git a/src/cmd/go/testdata/script/mod_vendor.txt b/src/cmd/go/testdata/script/mod_vendor.txt
index 2622916..0ea3152f 100644
--- a/src/cmd/go/testdata/script/mod_vendor.txt
+++ b/src/cmd/go/testdata/script/mod_vendor.txt
@@ -82,6 +82,39 @@
! exists vendor/x/x2
! exists vendor/x/x2/LICENSE
+# 'go mod vendor' should work with an alternative vendor directory if the -o flag is provided.
+go mod vendor -v -o alternative-vendor-dir
+stderr '^# x v1.0.0 => ./x'
+stderr '^x'
+stderr '^# y v1.0.0 => ./y'
+stderr '^y'
+stderr '^# z v1.0.0 => ./z'
+stderr '^z'
+! stderr '^w'
+grep 'a/foo/bar/b\na/foo/bar/c' alternative-vendor-dir/modules.txt # must be sorted
+
+# Test dependencies should not be copied.
+! exists alternative-vendor-dir/x/testdata
+! exists alternative-vendor-dir/a/foo/bar/b/ignored.go
+! exists alternative-vendor-dir/a/foo/bar/b/main_test.go
+
+# Licenses and other metadata for each module should be copied
+# if any package within their module is copied.
+exists alternative-vendor-dir/a/foo/AUTHORS.txt
+exists alternative-vendor-dir/a/foo/CONTRIBUTORS
+exists alternative-vendor-dir/a/foo/LICENSE
+exists alternative-vendor-dir/a/foo/PATENTS
+exists alternative-vendor-dir/a/foo/COPYING
+exists alternative-vendor-dir/a/foo/COPYLEFT
+exists alternative-vendor-dir/x/NOTICE!
+exists alternative-vendor-dir/mysite/myname/mypkg/LICENSE.txt
+
+! exists alternative-vendor-dir/a/foo/licensed-to-kill
+! exists alternative-vendor-dir/w
+! exists alternative-vendor-dir/w/LICENSE
+! exists alternative-vendor-dir/x/x2
+! exists alternative-vendor-dir/x/x2/LICENSE
+
[short] stop
# 'go build' and 'go test' using vendored packages should succeed.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Jay Conrod, Michael Matloob.
1 comment:
Patchset:
I'm not sure whether this required a new test script, or if we're okay with just expanding the current one. Let me know what you think and if I've missed anything obvious.
Thank you for your time!
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Paschalis Tsilias, Michael Matloob.
Patch set 1:Run-TryBot +1
5 comments:
Patchset:
I'm not sure whether this required a new test script, or if we're okay with just expanding the curre […]
This is good. Would be fine either way.
Thanks for working on this!
File src/cmd/go/internal/modcmd/vendor.go:
Patch Set #1, Line 47: receives a relative or absolute path and
Let's rephrase and add a bit more detail about when this should be used.
The -o flag causes vendor to create the vendor directory at the given
path instead of "vendor". The go command can only use a vendor directory
named "vendor" within the module root directory, so this flag is
primarily useful for other tools.
Patch Set #1, Line 61: cmdVendor.Flag.StringVar(&vendorO, "o", "vendor", "")
Let's export base.explicitStringFlag and use that here.
If -o is set to a relative path, I think that path should be interpreted relative to the current working directory (base.Cwd()) instead of the module root directory. But when -o is not set, "vendor" should definitely be in the module root directory.
File src/cmd/go/testdata/script/mod_vendor.txt:
Patch Set #1, Line 86: go mod vendor -v -o alternative-vendor-dir
To test the case I mentioned, let's mkdir and cd into a subdirectory, then run go mod vendor there.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Paschalis Tsilias, Michael Matloob.
Paschalis Tsilias uploaded patch set #2 to this change.
cmd/go: add 'go mod vendor -o' flag
Adds a new flag to 'go mod vendor' which overrides the default
'vendor' destination directory. This can be helpful for writing the
vendor tree to a temporary location for use by other tools.
The argument can be a relative or an absolute path.
This flag has no other influence on how the command behaves.
Fixes #47327
Change-Id: I4502931127616b181dc90a2066d2fb57bfe48f96
---
M src/cmd/go/alldocs.go
M src/cmd/go/internal/base/flag.go
M src/cmd/go/internal/modcmd/vendor.go
M src/cmd/go/testdata/script/mod_vendor.txt
4 files changed, 88 insertions(+), 15 deletions(-)
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Jay Conrod, Michael Matloob.
3 comments:
File src/cmd/go/internal/modcmd/vendor.go:
Patch Set #1, Line 47: receives a relative or absolute path and
Let's rephrase and add a bit more detail about when this should be used. […]
Done
Patch Set #1, Line 61: cmdVendor.Flag.StringVar(&vendorO, "o", "vendor", "")
Let's export base.explicitStringFlag and use that here. […]
Thank you for your feedback!
File src/cmd/go/testdata/script/mod_vendor.txt:
Patch Set #1, Line 86: go mod vendor -v -o alternative-vendor-dir
To test the case I mentioned, let's mkdir and cd into a subdirectory, then run go mod vendor there.
Done
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Jay Conrod, Michael Matloob.
3 comments:
File src/cmd/go/internal/modcmd/vendor.go:
case vendorDirExplicit && !filepath.IsAbs(vendorDirValue):
vdir = filepath.Join(base.Cwd(), vendorDirValue)
What does this do for `go mod vendor -o ''`?
I could see someone running that if they had `GOFLAGS=-o=foo` set for some reason; probably it should reset the behavior to the default rather than treating it the same as `-o .`.
File src/cmd/go/testdata/script/mod_vendor.txt:
# Test dependencies should not be copied.
! exists alternative-vendor-dir/x/testdata
! exists alternative-vendor-dir/a/foo/bar/b/ignored.go
! exists alternative-vendor-dir/a/foo/bar/b/main_test.go
# Licenses and other metadata for each module should be copied
# if any package within their module is copied.
exists alternative-vendor-dir/a/foo/AUTHORS.txt
exists alternative-vendor-dir/a/foo/CONTRIBUTORS
exists alternative-vendor-dir/a/foo/LICENSE
exists alternative-vendor-dir/a/foo/PATENTS
exists alternative-vendor-dir/a/foo/COPYING
exists alternative-vendor-dir/a/foo/COPYLEFT
exists alternative-vendor-dir/x/NOTICE!
exists alternative-vendor-dir/mysite/myname/mypkg/LICENSE.txt
! exists alternative-vendor-dir/a/foo/licensed-to-kill
! exists alternative-vendor-dir/w
! exists alternative-vendor-dir/w/LICENSE
! exists alternative-vendor-dir/x/x2
! exists alternative-vendor-dir/x/x2/LICENSE
(nit) I'm not sure that it's worth repeating all of these details for the test of the `-o` flag.
It should suffice to show the existence of modules.txt and perhaps a few key other files.
Patch Set #2, Line 123: go mod vendor -v -o relative-vendor-dir
Please also add a test for `-o ''`.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Jay Conrod, Michael Matloob.
1 comment:
File src/cmd/go/internal/modcmd/vendor.go:
case vendorDirExplicit && !filepath.IsAbs(vendorDirValue):
vdir = filepath.Join(base.Cwd(), vendorDirValue)
What does this do for `go mod vendor -o ''`? […]
Thanks for the observation!
If we run this with just `-o ""` it defaults to the previous behavior as `ExplicitStringFlag` doesn't count it as being explicitly set, which is fine.
Unfortunately, if -o is set in GOFLAGS beforehand, running `-o ""` destroys the current working directory, so it probably needs some kind of special handling.
I'll try adding a new condition and I'll ping you again.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Jay Conrod, Michael Matloob.
Paschalis Tsilias uploaded patch set #3 to this change.
cmd/go: add 'go mod vendor -o' flag
Adds a new flag to 'go mod vendor' which overrides the default
'vendor' destination directory. This can be helpful for writing the
vendor tree to a temporary location for use by other tools.
The argument can be a relative or an absolute path.
This flag has no other influence on how the command behaves.
Fixes #47327
Change-Id: I4502931127616b181dc90a2066d2fb57bfe48f96
---
M src/cmd/go/alldocs.go
M src/cmd/go/internal/base/flag.go
M src/cmd/go/internal/modcmd/vendor.go
M src/cmd/go/testdata/script/mod_vendor.txt
4 files changed, 75 insertions(+), 15 deletions(-)
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Jay Conrod, Michael Matloob.
3 comments:
File src/cmd/go/internal/modcmd/vendor.go:
case vendorDirExplicit && !filepath.IsAbs(vendorDirValue):
vdir = filepath.Join(base.Cwd(), vendorDirValue)
Thanks for the observation! […]
I used filepath.Clean to ensure that we don't end up deleting the current working directory, and fall back to the default behavior.
Let me know what you think, maybe there's a better way to achieve the same result. I could also extract this logic in a helper to keep the flow cleaner.
File src/cmd/go/testdata/script/mod_vendor.txt:
# Test dependencies should not be copied.
! exists alternative-vendor-dir/x/testdata
! exists alternative-vendor-dir/a/foo/bar/b/ignored.go
! exists alternative-vendor-dir/a/foo/bar/b/main_test.go
# Licenses and other metadata for each module should be copied
# if any package within their module is copied.
exists alternative-vendor-dir/a/foo/AUTHORS.txt
exists alternative-vendor-dir/a/foo/CONTRIBUTORS
exists alternative-vendor-dir/a/foo/LICENSE
exists alternative-vendor-dir/a/foo/PATENTS
exists alternative-vendor-dir/a/foo/COPYING
exists alternative-vendor-dir/a/foo/COPYLEFT
exists alternative-vendor-dir/x/NOTICE!
exists alternative-vendor-dir/mysite/myname/mypkg/LICENSE.txt
! exists alternative-vendor-dir/a/foo/licensed-to-kill
! exists alternative-vendor-dir/w
! exists alternative-vendor-dir/w/LICENSE
! exists alternative-vendor-dir/x/x2
! exists alternative-vendor-dir/x/x2/LICENSE
(nit) I'm not sure that it's worth repeating all of these details for the test of the `-o` flag. […]
You're right. I removed most extraneous checks, I think it looks easier to read now!
Patch Set #2, Line 123: go mod vendor -v -o relative-vendor-dir
Please also add a test for `-o ''`.
Done. I've added a test for `-o ""` with and without GOFLAGS, as well as a test for an absolute path.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Paschalis Tsilias, Michael Matloob.
Patch set 3:Run-TryBot +1
1 comment:
File src/cmd/go/internal/modcmd/vendor.go:
case vendorDirExplicit && !filepath.IsAbs(vendorDirValue):
vdir = filepath.Join(base.Cwd(), vendorDirValue)
I used filepath. […]
Let's simplify this a bit and just check for vendorDirExplicit && vendorDirValue == "". That makes the code a bit clearer.
Weird as it is, 'go mod vendor -o=.' should attempt to delete the current directory and create the vendor directory there. I don't expect that to succeed on all operating systems, but it will probably work on linux and darwin. For example, this works today:
mkdir vendor
cd vendor
go mod vendor
ls # nothing here?
cd .
ls. # files here now.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Paschalis Tsilias, Michael Matloob.
Paschalis Tsilias uploaded patch set #4 to this change.
cmd/go: add 'go mod vendor -o' flag
Adds a new flag to 'go mod vendor' which overrides the default
'vendor' destination directory. This can be helpful for writing the
vendor tree to a temporary location for use by other tools.
The argument can be a relative or an absolute path.
This flag has no other influence on how the command behaves.
Fixes #47327
Change-Id: I4502931127616b181dc90a2066d2fb57bfe48f96
---
M src/cmd/go/alldocs.go
M src/cmd/go/internal/base/flag.go
M src/cmd/go/internal/modcmd/vendor.go
M src/cmd/go/testdata/script/mod_vendor.txt
4 files changed, 71 insertions(+), 15 deletions(-)
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Jay Conrod, Michael Matloob.
1 comment:
File src/cmd/go/internal/modcmd/vendor.go:
case vendorDirExplicit && !filepath.IsAbs(vendorDirValue):
vdir = filepath.Join(base.Cwd(), vendorDirValue)
Let's simplify this a bit and just check for vendorDirExplicit && vendorDirValue == "". […]
You meant `vendorDirValue != ""` so that it falls back to the default behavior for an empty argument, right?
Thanks for the suggestion, indeed it looks cleaner now. I initially wanted to avoid deleting ModRoot by accident (would be a bummer), but it makes more sense to allow the current dir to be used.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Michael Matloob.
Patch set 4:Run-TryBot +1
Attention is currently required from: Bryan C. Mills, Paschalis Tsilias, Michael Matloob.
Jay Conrod removed a vote from this change.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Paschalis Tsilias, Michael Matloob.
Patch set 4:Run-TryBot +1Code-Review +2Trust +1
1 comment:
Patchset:
Looks good. Test timeout seems unrelated, but running TryBots again to be sure.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Patch set 4:Trust +1
2 comments:
File src/cmd/go/internal/modcmd/vendor.go:
Patch Set #4, Line 58: var vendorDirValue = "vendor"
I don't think this default matches the implementation in runVendor: outside of the root of the main module, `-o vendor` is relative to the current working directory, but `-o ""' is `$GOMOD/../vendor`.
I think we should default this to `""`, and then we can probably drop the vendorDirExplicit variable, because vendorDirValue != "" would then imply vendorDirExplicit in all cases.
File src/cmd/go/testdata/script/mod_vendor.txt:
cd dir1
go mod vendor -v -o relative-vendor-dir
go mod vendor -v -o ../dir2/relative-vendor-dir
Also test the behavior of `-o ''` when in a subdirectory? (Right now we only seem to be testing it in the module root.)
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Paschalis Tsilias uploaded patch set #5 to this change.
cmd/go: add 'go mod vendor -o' flag
Adds a new flag to 'go mod vendor' which overrides the default
'vendor' destination directory. This can be helpful for writing the
vendor tree to a temporary location for use by other tools.
The argument can be a relative or an absolute path.
This flag has no other influence on how the command behaves.
Fixes #47327
Change-Id: I4502931127616b181dc90a2066d2fb57bfe48f96
---
M src/cmd/go/alldocs.go
M src/cmd/go/internal/modcmd/vendor.go
M src/cmd/go/testdata/script/mod_vendor.txt
3 files changed, 67 insertions(+), 4 deletions(-)
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan C. Mills, Michael Matloob.
3 comments:
Patchset:
I realized that if this gets merged, we'd also need to update the reference page, but I couldn't it in a public repo.
File src/cmd/go/internal/modcmd/vendor.go:
Patch Set #4, Line 58: var vendorDirValue = "vendor"
I don't think this default matches the implementation in runVendor: outside of the root of the main […]
You're right. The way that we've structured the condition, this default was never being used.
If we can drop `vendorDirExplicit` then maybe we don't need to export ExplicitStringFlag after all. So, I've discarded the changes to the `base/flag.go`, used a plain StringVar flag and everything seems to work the same way.
File src/cmd/go/testdata/script/mod_vendor.txt:
cd dir1
go mod vendor -v -o relative-vendor-dir
go mod vendor -v -o ../dir2/relative-vendor-dir
Also test the behavior of `-o ''` when in a subdirectory? (Right now we only seem to be testing it i […]
I've added another testcase, it works on both latest patchsets.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Patch set 5:Code-Review +2Trust +1
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Patch set 5:Code-Review +2Trust +1
1 comment:
Patchset:
I realized that if this gets merged, we'd also need to update the reference page, but I couldn't it […]
https://pkg.go.dev/cmd/go#hdr-Make_vendored_copy_of_dependencies is generated from alldocs.go, so that's already done.
https://golang.org/ref/mod#go-mod-vendor does need to be updated. That's in golang.org/x/website/_content/ref/mod.md, which is hosted in https://go.googlesource.com/website.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
1 comment:
Patchset:
1 of 25 TryBots failed. […]
This was golang.org/issue/41014.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
1 comment:
Patchset:
https://pkg.go.dev/cmd/go#hdr-Make_vendored_copy_of_dependencies is generated from alldocs. […]
Thanks for the info! Yes, I was talking about https://golang.org/ref/mod#go-mod-vendor.
I'll mail a CL on https://go.googlesource.com/website describing our new flag if that's okay.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
Paschalis Tsilias uploaded patch set #6 to this change.
cmd/go: add 'go mod vendor -o' flag
Adds a new flag to 'go mod vendor' which overrides the default
'vendor' destination directory. This can be helpful for writing the
vendor tree to a temporary location for use by other tools.
The argument can be a relative or an absolute path.
This flag has no other influence on how the command behaves.
Fixes #47327
Change-Id: I4502931127616b181dc90a2066d2fb57bfe48f96
---
M src/cmd/go/internal/modcmd/vendor.go
M src/cmd/go/alldocs.go
M src/cmd/go/testdata/script/mod_vendor.txt
3 files changed, 83 insertions(+), 4 deletions(-)
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
1 comment:
Patchset:
After some recent changes in vendor.go I had to rebase and solve some conflicts. Could someone please just re-trigger the RunBots? (tests seems to pass locally though).
I still need to mail a CL on https://go.googlesource.com/website to describe the new flag, and post the link here so they can be merged together?
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Patch set 6:Run-TryBot +1Code-Review +2Trust +1
1 comment:
File src/cmd/go/internal/modcmd/vendor.go:
Patch Set #6, Line 58: vendorDirValue
(nit)
s/vendorDirValue/vendorO/
(for consistency with other flag variables in cmd/go)
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Paschalis Tsilias uploaded patch set #7 to this change.
cmd/go: add 'go mod vendor -o' flag
Adds a new flag to 'go mod vendor' which overrides the default
'vendor' destination directory. This can be helpful for writing the
vendor tree to a temporary location for use by other tools.
The argument can be a relative or an absolute path.
This flag has no other influence on how the command behaves.
Fixes #47327
Change-Id: I4502931127616b181dc90a2066d2fb57bfe48f96
---
M src/cmd/go/internal/modcmd/vendor.go
M src/cmd/go/alldocs.go
M src/cmd/go/testdata/script/mod_vendor.txt
3 files changed, 83 insertions(+), 4 deletions(-)
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
1 comment:
File src/cmd/go/internal/modcmd/vendor.go:
Patch Set #6, Line 58: vendorDirValue
(nit) […]
Done
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Patch set 7:Run-TryBot +1Code-Review +2Trust +1
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
1 comment:
Patchset:
I've also opened the following CL to update the modules reference page; tried to keep it short and concise. I really admire your work on the modules and the great reference page, so I'm looking forward to your feedback!
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Bryan C. Mills removed a vote from this change.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Bryan C. Mills removed a vote from this change.
Attention is currently required from: Paschalis Tsilias, Michael Matloob.
Patch set 7:Run-TryBot +1
1 comment:
Patchset:
TRY=longtest
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.
Bryan C. Mills submitted this change.
cmd/go: add 'go mod vendor -o' flag
Adds a new flag to 'go mod vendor' which overrides the default
'vendor' destination directory. This can be helpful for writing the
vendor tree to a temporary location for use by other tools.
The argument can be a relative or an absolute path.
This flag has no other influence on how the command behaves.
Fixes #47327
Change-Id: I4502931127616b181dc90a2066d2fb57bfe48f96
Reviewed-on: https://go-review.googlesource.com/c/go/+/338149
Reviewed-by: Bryan C. Mills <bcm...@google.com>
Reviewed-by: Jay Conrod <jayc...@google.com>
Trust: Bryan C. Mills <bcm...@google.com>
Trust: Jay Conrod <jayc...@google.com>
Run-TryBot: Bryan C. Mills <bcm...@google.com>
TryBot-Result: Go Bot <go...@golang.org>
---
M src/cmd/go/internal/modcmd/vendor.go
M src/cmd/go/alldocs.go
M src/cmd/go/testdata/script/mod_vendor.txt
3 files changed, 90 insertions(+), 4 deletions(-)
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index 81d2f70..ff144f9 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -1295,7 +1295,7 @@
//
// Usage:
//
-// go mod vendor [-e] [-v]
+// go mod vendor [-e] [-v] [-o outdir]
//
// Vendor resets the main module's vendor directory to include all packages
// needed to build and test all the main module's packages.
@@ -1307,6 +1307,11 @@
// The -e flag causes vendor to attempt to proceed despite errors
// encountered while loading packages.
//
+// The -o flag causes vendor to create the vendor directory at the given
+// path instead of "vendor". The go command can only use a vendor directory
+// named "vendor" within the module root directory, so this flag is
+// primarily useful for other tools.
+//
// See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
//
//
diff --git a/src/cmd/go/internal/modcmd/vendor.go b/src/cmd/go/internal/modcmd/vendor.go
index 484e095..ef12370 100644
--- a/src/cmd/go/internal/modcmd/vendor.go
+++ b/src/cmd/go/internal/modcmd/vendor.go
@@ -31,7 +31,7 @@
)
var cmdVendor = &base.Command{
- UsageLine: "go mod vendor [-e] [-v]",
+ UsageLine: "go mod vendor [-e] [-v] [-o outdir]",
Short: "make vendored copy of dependencies",
Long: `
Vendor resets the main module's vendor directory to include all packages
@@ -44,16 +44,23 @@
The -e flag causes vendor to attempt to proceed despite errors
encountered while loading packages.
+The -o flag causes vendor to create the vendor directory at the given
+path instead of "vendor". The go command can only use a vendor directory
+named "vendor" within the module root directory, so this flag is
+primarily useful for other tools.
+
See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
`,
Run: runVendor,
}
-var vendorE bool // if true, report errors but proceed anyway
+var vendorE bool // if true, report errors but proceed anyway
+var vendorO string // if set, overrides the default output directory
func init() {
cmdVendor.Flag.BoolVar(&cfg.BuildV, "v", false, "")
cmdVendor.Flag.BoolVar(&vendorE, "e", false, "")
+ cmdVendor.Flag.StringVar(&vendorO, "o", "", "")
base.AddModCommonFlags(&cmdVendor.Flag)
}
@@ -74,7 +81,15 @@
}
_, pkgs := modload.LoadPackages(ctx, loadOpts, "all")
- vdir := filepath.Join(modload.VendorDir())
+ var vdir string
+ switch {
+ case filepath.IsAbs(vendorO):
+ vdir = vendorO
+ case vendorO != "":
+ vdir = filepath.Join(base.Cwd(), vendorO)
+ default:
+ vdir = filepath.Join(modload.VendorDir())
+ }
if err := os.RemoveAll(vdir); err != nil {
base.Fatalf("go: %v", err)
}
diff --git a/src/cmd/go/testdata/script/mod_vendor.txt b/src/cmd/go/testdata/script/mod_vendor.txt
index 4eb80c2..a2727dd 100644
--- a/src/cmd/go/testdata/script/mod_vendor.txt
+++ b/src/cmd/go/testdata/script/mod_vendor.txt
@@ -82,6 +82,48 @@
! exists vendor/x/x2
! exists vendor/x/x2/LICENSE
+# 'go mod vendor' should work with an alternative vendor directory if the -o flag is provided.
+go mod vendor -v -o alternative-vendor-dir
+exists alternative-vendor-dir/modules.txt
+exists alternative-vendor-dir/a/foo/LICENSE
+
+# 'go mod vendor' should interpret paths relative to the current working directory when the -o flag is provided.
+mkdir dir1
+mkdir dir2
+
+cd dir1
+go mod vendor -v -o relative-vendor-dir
+
+go mod vendor -v -o ../dir2/relative-vendor-dir
+
+cd ..
+exists dir1/relative-vendor-dir/modules.txt
+exists dir1/relative-vendor-dir/a/foo/LICENSE
+exists dir2/relative-vendor-dir/modules.txt
+exists dir2/relative-vendor-dir/a/foo/LICENSE
+
+# 'go mod vendor' should fall back to the default 'vendor' directory when an empty argument is passed to the -o flag
+# the same behavior should be exhibited both on the module root directory, as well as nested subdirectories
+
+go mod vendor -v -o ''
+exists vendor/modules.txt
+
+env GOFLAGS=-o=foo
+go mod vendor -v -o ''
+exists vendor/modules.txt
+env GOFLAGS=''
+
+mkdir -p nested/dir
+cd nested/dir
+go mod vendor -v -o ''
+! exists vendor/
+exists ../../vendor/modules.txt
+cd ../..
+
+# 'go mod vendor' should work with absolute paths as well
+go mod vendor -v -o $WORK/tmp/absolute-vendor-dir
+exists $WORK/tmp/absolute-vendor-dir/modules.txt
+
[short] stop
# 'go build' and 'go test' using vendored packages should succeed.
To view, visit change 338149. To unsubscribe, or for help writing mail filters, visit settings.