Browse code

Windows: make.ps1 validate go version

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2017/02/02 03:31:27
Showing 1 changed files
... ...
@@ -126,6 +126,25 @@ Function Check-InContainer() {
126 126
         Write-Host ""
127 127
         Write-Warning "Not running in a container. The result might be an incorrect build."
128 128
         Write-Host ""
129
+        return $False
130
+    }
131
+    return $True
132
+}
133
+
134
+# Utility function to warn if the version of go is correct. Used for local builds
135
+# outside of a container where it may be out of date with master.
136
+Function Verify-GoVersion() {
137
+    Try {
138
+        $goVersionDockerfile=(Get-Content ".\Dockerfile" | Select-String "ENV GO_VERSION").ToString().Split(" ")[2]
139
+        $goVersionInstalled=(go version).ToString().Split(" ")[2].SubString(2)
140
+    }
141
+    Catch [Exception] {
142
+        Throw "Failed to validate go version correctness: $_"
143
+    }
144
+    if (-not($goVersionInstalled -eq $goVersionDockerfile)) {
145
+        Write-Host ""
146
+        Write-Warning "Building with golang version $goVersionInstalled. You should update to $goVersionDockerfile"
147
+        Write-Host ""
129 148
     }
130 149
 }
131 150
 
... ...
@@ -337,7 +356,10 @@ Try {
337 337
 
338 338
     # Give a warning if we are not running in a container and are building binaries or running unit tests.
339 339
     # Not relevant for validation tests as these are fine to run outside of a container.
340
-    if ($Client -or $Daemon -or $TestUnit) { Check-InContainer }
340
+    if ($Client -or $Daemon -or $TestUnit) { $inContainer=Check-InContainer }
341
+
342
+    # If we are not in a container, validate the version of GO that is installed.
343
+    if (-not $inContainer) { Verify-GoVersion }
341 344
 
342 345
     # Verify GOPATH is set
343 346
     if ($env:GOPATH.Length -eq 0) { Throw "Missing GOPATH environment variable. See https://golang.org/doc/code.html#GOPATH" }