From patchwork Wed Apr 12 04:26:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 749726 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w2rTv1VHtz9sN7 for ; Wed, 12 Apr 2017 14:26:35 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="MgHlIAdF"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=NarnqwZMUXkDzDjXP5/DZNzkvWK4/PrCgpACOuF/Fe8CFy pdqNsR+XGlt5GnMTyfJQ9PUayEDPbG1yXqIK76iGCVqRPZQhlN5wJBK3hq43ke3l nOzjxNZcv0BhHhSA5WNGIIY72whThCVhuxRMLyhpzUAGmGxjkfCq3F2b7uQYA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=4p4xvk4i3AHNgVTlFiuNIGmYUVM=; b=MgHlIAdFn4ZFZ8TC1ORv SkiIT9iVyTWw4SHY36la7Er9wUNiQ4hvvRjIFdlfhk7VvAzkXnwg9RXSoxZULcW0 l4u9m3IaGS3XtfqzHgYgGpZgFEP13wB6cPJdEhlHyaN4w6SwvBjM+RO3wW6wudWy Cevzt23CUKXG86MHVRENns8= Received: (qmail 8718 invoked by alias); 12 Apr 2017 04:26:23 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 6817 invoked by uid 89); 12 Apr 2017 04:26:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2894, Boger, boger, ofile X-HELO: mail-oi0-f53.google.com Received: from mail-oi0-f53.google.com (HELO mail-oi0-f53.google.com) (209.85.218.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Apr 2017 04:26:20 +0000 Received: by mail-oi0-f53.google.com with SMTP id b187so19249403oif.0 for ; Tue, 11 Apr 2017 21:26:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=bJJtzMo9S7NmNkyF+c1rblDoeOLWUOXbCrC0tadv+NI=; b=LpQJqBK+ibK6XeLr5KQwnTjTExS5Uf4in2iH4CmbHb6dCqjvgVFoeUWLVaMMDEltcB zixNjQXdOHC8RuKOn5Zx/ABuYGnq3QeKY8cFoCMZuPsk1rZnt8wOrnr5cXnB+Jixt/W3 gKf0pIbtTuIaljGto02/zsCO/lim34IhKbnXSFy8NVejZr2BljlaxEcHYZUX4V3WntPx 2ju62zhri+ngwlQt8lxXGePl0dPJFNAm4UFJDQAwBUdXtuxUdGi2kJWvXDvZ1gAePlkq YW9RbFG0NJSzi3Z6FcR2N6EYQXHMswk0naRiTiI3BHzC1V8qye0qBLbLsi8KNpqFBL9o Ix6A== X-Gm-Message-State: AFeK/H33+79Alai9kWa7joJ8UB1A91IfUEsjr1thpOtdeX0n6aU0awfKxbAY9ICCsSgCejBiU+ChGwD9yW0xZw== X-Received: by 10.202.239.134 with SMTP id n128mr19182812oih.93.1491971180488; Tue, 11 Apr 2017 21:26:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.202.75.197 with HTTP; Tue, 11 Apr 2017 21:26:20 -0700 (PDT) From: Ian Lance Taylor Date: Tue, 11 Apr 2017 21:26:20 -0700 Message-ID: Subject: libgo patch committed: Fix support for vendor directories To: gcc-patches , "gofrontend-dev@googlegroups.com" 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 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))