* libgo patch committed: Fix support for vendor directories
@ 2017-04-12 4:26 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2017-04-12 4:26 UTC (permalink / raw)
To: gcc-patches, gofrontend-dev
[-- Attachment #1: Type: text/plain, Size: 403 bytes --]
Vendor directories are a concept supported by the go tool
(https://golang.org/cmd/go/#hdr-Vendor_Directories). They have never
worked properly for gccgo, as has been reported as PR 77857 and
https://golang.org/issue/15628. This patch by Lynn Boger fixes vendor
support for gccgo by adding appropriate -I options. Bootstrapped and
ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline.
Ian
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2593 bytes --]
Index: libgo/go/cmd/go/build.go
===================================================================
--- libgo/go/cmd/go/build.go (revision 245745)
+++ libgo/go/cmd/go/build.go (working copy)
@@ -2398,14 +2398,6 @@ func (gcToolchain) gc(b *builder, p *Pac
}
}
- 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 *builde
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))
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-04-12 4:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-12 4:26 libgo patch committed: Fix support for vendor directories Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).