aboutsummaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2017-04-12 04:26:15 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2017-04-12 04:26:15 +0000
commit3da31ee0daaabc2fd278dae0de9f571e72e43160 (patch)
tree8779dfadd15de6e87f5bab30fdc18126be9c47ab /libgo
parent2bbdf239b186a7c72bc6ea14af76c234965c8dcf (diff)
PR go/77857
cmd/go: generate vendor paths for -I arg on compile This change generates the vendor path to be used with -I on a gccgo compile to find imports from the vendor directories. Fixes golang/go#15628 Reviewed-on: https://go-review.googlesource.com/39590 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@246864 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo')
-rw-r--r--libgo/go/cmd/go/build.go57
1 files changed, 49 insertions, 8 deletions
diff --git a/libgo/go/cmd/go/build.go b/libgo/go/cmd/go/build.go
index a8f90344c30..f2d11f43f19 100644
--- a/libgo/go/cmd/go/build.go
+++ b/libgo/go/cmd/go/build.go
@@ -2398,14 +2398,6 @@ func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool,
}
}
- for _, path := range p.Imports {
- if i := strings.LastIndex(path, "/vendor/"); i >= 0 {
- gcargs = append(gcargs, "-importmap", path[i+len("/vendor/"):]+"="+path)
- } else if strings.HasPrefix(path, "vendor/") {
- gcargs = append(gcargs, "-importmap", path[len("vendor/"):]+"="+path)
- }
- }
-
args := []interface{}{buildToolExec, tool("compile"), "-o", ofile, "-trimpath", b.work, buildGcflags, gcargs, "-D", p.localPrefix, importArgs}
if ofile == archive {
args = append(args, "-pack")
@@ -2706,6 +2698,55 @@ func (tools gccgoToolchain) gc(b *builder, p *Package, archive, obj string, asmh
if p.localPrefix != "" {
gcargs = append(gcargs, "-fgo-relative-import-path="+p.localPrefix)
}
+ 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 := stringList(tools.compiler(), importArgs, "-c", gcargs, "-o", ofile, buildGccgoflags)
for _, f := range gofiles {
args = append(args, mkAbs(p.Dir, f))