On Sunday, March 10, 2019 at 5:01:01 PM UTC-7, Manlio Perillo wrote:
>
> On Monday, March 11, 2019 at 12:30:02 AM UTC+1, Wael Nasreddine wrote:
>>
>> TL;DR Given a Go module, assuming that I have already done `go mod 
>> download`: Is it possible to prevent network access if I delete the entire 
>> `$GOPATH/pkg/mod/cache`?
>>
>>
> Yes.  Use `go mod vendor` and the -mod=vendor build flag.
>

I found an issue: If one of the dependencies includes cgo dependencies, not 
every directory and file gets copied to the vendor directory.

Steps to reproduce:

λ export GO111MODULE=on
λ unset GOPATH
λ git clone https://github.com/gohugoio/hugo.git
λ cd hugo
λ go mod download
λ ls vendor/github.com/wellington/go-libsass
libs  LICENSE

But if you look at https://github.com/wellington/go-libsass, you can see 
that it's missing quite a bit, especially the submodule libsass-src and 
libsass-build and it made my build of Hugo fail!

I'm going to try the following patch:

diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/
modload/load.go
index 6d6c037af2..77765023be 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -968,11 +968,44 @@ func (r *mvsReqs) required(mod module.Version) ([]
module.Version, error) {
  base.Fatalf("go: internal error: %s@%s: unexpected invalid semantic 
version", mod.Path, mod.Version)
  }
 
- data, err := modfetch.GoMod(mod.Path, mod.Version)
- if err != nil {
- base.Errorf("go: %s@%s: %v\n", mod.Path, mod.Version, err)
- return nil, ErrRequire
+ // ~HACK~: Support for buildGoModule
+ //
+ // compute the content of go.mod for this module either by using
+ // modfetch.GoMod() in regular day by day use or by reading the version
+ // already on disk.
+ var (
+ data []byte
+ )
+ if _, ok := os.LookupEnv("__NIX_GO_SKIP_MOD_DOWNLOAD"); ok {
+ // XXX: Must not depend on hardcoded GOPATH
+ gomodPath := fmt.Sprintf("%s/pkg/mod/%s@%s/go.mod", os.Getenv("GOPATH"), 
mod.Path, mod.Version)
+
+ // does gomodPath exist? If so set data to the contents of this module. If
+ // it does not exist then we must set it to `module mod.Path`.
+ _, err := os.Stat(gomodPath)
+ if err == nil {
+ data, err = ioutil.ReadFile(gomodPath)
+ if err != nil {
+ base.Errorf("go [NIX-REQUIRED]: %s@%s: %v\n", mod.Path, mod.Version, err)
+ return nil, ErrRequire
+ }
+ } else {
+ data = []byte("module " + mod.Path)
+ }
+ } else {
+ // the following call has been taken as it existed before the patch. The
+ // `:=` had to be converted to an `=` as the data and error are now both
+ // defined at the top of the if block.
+ var err error
+ data, err = modfetch.GoMod(mod.Path, mod.Version)
+ if err != nil {
+ base.Errorf("go: %s@%s: %v\n", mod.Path, mod.Version, err)
+ return nil, ErrRequire
+ }
  }
+ //
+ // ~HACK~: Support for buildGoModule
+
  f, err := modfile.ParseLax("go.mod", data, nil)
  if err != nil {
  base.Errorf("go: %s@%s: parsing go.mod: %v", mod.Path, mod.Version, err)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to