]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: only test SWIG if we have a new enough version
authorIan Lance Taylor <iant@golang.org>
Thu, 7 Dec 2017 02:09:11 +0000 (18:09 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 7 Dec 2017 15:40:28 +0000 (15:40 +0000)
Fixes #22858

Change-Id: I0478d5609e381f01c7345e7f53c24af05d7f78ad
Reviewed-on: https://go-review.googlesource.com/82415
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alberto Donizetti <alb.donizetti@gmail.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/dist/test.go

index f35fbd4cb5f5c801b034657f5837bae2464b83ef..808439439b521a7b17ce76a0a984551dbe6cbee7 100644 (file)
@@ -583,7 +583,7 @@ func (t *tester) registerTests() {
                                },
                        })
                }
-               if swig, _ := exec.LookPath("swig"); swig != "" && goos != "android" {
+               if t.hasSwig() && goos != "android" {
                        t.tests = append(t.tests, distTest{
                                name:    "swig_stdio",
                                heading: "../misc/swig/stdio",
@@ -1197,6 +1197,63 @@ func (t *tester) hasBash() bool {
        return true
 }
 
+func (t *tester) hasSwig() bool {
+       swig, err := exec.LookPath("swig")
+       if err != nil {
+               return false
+       }
+       out, err := exec.Command(swig, "-version").CombinedOutput()
+       if err != nil {
+               return false
+       }
+
+       re := regexp.MustCompile(`[vV]ersion +([\d]+)([.][\d]+)?([.][\d]+)?`)
+       matches := re.FindSubmatch(out)
+       if matches == nil {
+               // Can't find version number; hope for the best.
+               return true
+       }
+
+       major, err := strconv.Atoi(string(matches[1]))
+       if err != nil {
+               // Can't find version number; hope for the best.
+               return true
+       }
+       if major < 3 {
+               return false
+       }
+       if major > 3 {
+               // 4.0 or later
+               return true
+       }
+
+       // We have SWIG version 3.x.
+       if len(matches[2]) > 0 {
+               minor, err := strconv.Atoi(string(matches[2][1:]))
+               if err != nil {
+                       return true
+               }
+               if minor > 0 {
+                       // 3.1 or later
+                       return true
+               }
+       }
+
+       // We have SWIG version 3.0.x.
+       if len(matches[3]) > 0 {
+               patch, err := strconv.Atoi(string(matches[3][1:]))
+               if err != nil {
+                       return true
+               }
+               if patch < 6 {
+                       // Before 3.0.6.
+                       return false
+               }
+       }
+
+       return true
+}
+
 func (t *tester) raceDetectorSupported() bool {
        switch gohostos {
        case "linux", "darwin", "freebsd", "windows":