]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: generate correct vendor paths with -compiler gccgo option
authorLynn Boger <laboger@linux.vnet.ibm.com>
Wed, 12 Apr 2017 13:34:11 +0000 (09:34 -0400)
committerLynn Boger <laboger@linux.vnet.ibm.com>
Wed, 12 Apr 2017 14:51:47 +0000 (14:51 +0000)
Curently the vendor paths are not always searched for imports if
the compiler is gccgo.  This change generates the vendor paths
and adds them with -I as arguments to the gccgo compile.

Fixes #15628

Change-Id: I318accbbbd8e6af45475eda399377455a3565880
Reviewed-on: https://go-review.googlesource.com/40432
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/internal/work/build.go

index 462f495b5f5054218ad4b38c8d751caa5da78719..37c84887a42db4f4970b715c34ae46933972683f 100644 (file)
@@ -2538,6 +2538,57 @@ func (tools gccgoToolchain) gc(b *Builder, p *load.Package, archive, obj string,
        if p.Internal.LocalPrefix != "" {
                gcargs = append(gcargs, "-fgo-relative-import-path="+p.Internal.LocalPrefix)
        }
+
+       // Handle vendor directories
+       savedirs := []string{}
+       for _, incdir := range importArgs {
+               if incdir != "-I" {
+                       savedirs = append(savedirs, incdir)
+               }
+       }
+
+       for _, path := range p.Imports {
+               // If this is a new vendor path, add it to the list of importArgs
+               if i := strings.LastIndex(path, "/vendor"); i >= 0 {
+                       for _, dir := range savedirs {
+                               // Check if the vendor path is already included in dir
+                               if strings.HasSuffix(dir, path[:i+len("/vendor")]) {
+                                       continue
+                               }
+                               // Make sure this vendor path is not already in the list for importArgs
+                               vendorPath := dir + "/" + path[:i+len("/vendor")]
+                               for _, imp := range importArgs {
+                                       if imp == "-I" {
+                                               continue
+                                       }
+                                       // This vendorPath is already in the list
+                                       if imp == vendorPath {
+                                               goto nextSuffixPath
+                                       }
+                               }
+                               // New vendorPath not yet in the importArgs list, so add it
+                               importArgs = append(importArgs, "-I", vendorPath)
+                       nextSuffixPath:
+                       }
+               } else if strings.HasPrefix(path, "vendor/") {
+                       for _, dir := range savedirs {
+                               // Make sure this vendor path is not already in the list for importArgs
+                               vendorPath := dir + "/" + path[len("/vendor"):]
+                               for _, imp := range importArgs {
+                                       if imp == "-I" {
+                                               continue
+                                       }
+                                       if imp == vendorPath {
+                                               goto nextPrefixPath
+                                       }
+                               }
+                               // This vendor path is needed and not already in the list, so add it
+                               importArgs = append(importArgs, "-I", vendorPath)
+                       nextPrefixPath:
+                       }
+               }
+       }
+
        args := str.StringList(tools.compiler(), importArgs, "-c", gcargs, "-o", ofile, buildGccgoflags)
        for _, f := range gofiles {
                args = append(args, mkAbs(p.Dir, f))