Browse Source

Merge pull request #38418 from thaJeztah/mega_power

PowerShell: various cleanups / fixes
Sebastiaan van Stijn 6 years ago
parent
commit
f9dbd383bb
3 changed files with 82 additions and 84 deletions
  1. 70 72
      hack/ci/windows.ps1
  2. 5 5
      hack/make.ps1
  3. 7 7
      hack/make/.go-autogen.ps1

+ 70 - 72
hack/ci/windows.ps1

@@ -125,7 +125,7 @@ Function Nuke-Everything {
 
     try {
 
-        if ($env:SKIP_ALL_CLEANUP -eq $null) {
+        if ($null -eq $env:SKIP_ALL_CLEANUP) {
             Write-Host -ForegroundColor green "INFO: Nuke-Everything..."
             $containerCount = ($(docker ps -aq | Measure-Object -line).Lines) 
             if (-not $LastExitCode -eq 0) {
@@ -156,11 +156,11 @@ Function Nuke-Everything {
             Stop-Process -Id $p -Force -ErrorAction SilentlyContinue
         }
 
-        if ($pidFile -ne $Null) {
+        if ($null -ne $pidFile) {
             Write-Host "INFO: Tidying pidfile $pidfile"
              if (Test-Path $pidFile) {
                 $p=Get-Content $pidFile -raw
-                if ($p -ne $null){
+                if ($null -ne $p){
                     Write-Host -ForegroundColor green "INFO: Stopping possible daemon pid $p"
                     taskkill -f -t -pid $p
                 }
@@ -186,7 +186,7 @@ Function Nuke-Everything {
 
         # Delete the directory using our dangerous utility unless told not to
         if (Test-Path "$env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR") {
-            if (($env:SKIP_ZAP_DUT -ne $null) -or ($env:SKIP_ALL_CLEANUP -eq $null)) {
+            if (($null -ne $env:SKIP_ZAP_DUT) -or ($null -eq $env:SKIP_ALL_CLEANUP)) {
                 Write-Host -ForegroundColor Green "INFO: Nuking $env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR"
                 docker-ci-zap "-folder=$env:TESTRUN_DRIVE`:\$env:TESTRUN_SUBDIR"
             } else {
@@ -252,25 +252,25 @@ Try {
     Get-ChildItem Env: | Out-String
 
     # PR
-    if (-not ($env:PR -eq $Null)) { echo "INFO: PR#$env:PR (https://github.com/docker/docker/pull/$env:PR)" }
+    if (-not ($null -eq $env:PR)) { Write-Output "INFO: PR#$env:PR (https://github.com/docker/docker/pull/$env:PR)" }
 
     # Make sure docker is installed
-    if ((Get-Command "docker" -ErrorAction SilentlyContinue) -eq $null) { Throw "ERROR: docker is not installed or not found on path" }
+    if ($null -eq (Get-Command "docker" -ErrorAction SilentlyContinue)) { Throw "ERROR: docker is not installed or not found on path" }
 
     # Make sure docker-ci-zap is installed
-    if ((Get-Command "docker-ci-zap" -ErrorAction SilentlyContinue) -eq $null) { Throw "ERROR: docker-ci-zap is not installed or not found on path" }
+    if ($null -eq (Get-Command "docker-ci-zap" -ErrorAction SilentlyContinue)) { Throw "ERROR: docker-ci-zap is not installed or not found on path" }
 
     # Make sure SOURCES_DRIVE is set
-    if ($env:SOURCES_DRIVE -eq $Null) { Throw "ERROR: Environment variable SOURCES_DRIVE is not set" }
+    if ($null -eq $env:SOURCES_DRIVE) { Throw "ERROR: Environment variable SOURCES_DRIVE is not set" }
 
     # Make sure TESTRUN_DRIVE is set
-    if ($env:TESTRUN_DRIVE -eq $Null) { Throw "ERROR: Environment variable TESTRUN_DRIVE is not set" }
+    if ($null -eq $env:TESTRUN_DRIVE) { Throw "ERROR: Environment variable TESTRUN_DRIVE is not set" }
 
     # Make sure SOURCES_SUBDIR is set
-    if ($env:SOURCES_SUBDIR -eq $Null) { Throw "ERROR: Environment variable SOURCES_SUBDIR is not set" }
+    if ($null -eq $env:SOURCES_SUBDIR) { Throw "ERROR: Environment variable SOURCES_SUBDIR is not set" }
 
     # Make sure TESTRUN_SUBDIR is set
-    if ($env:TESTRUN_SUBDIR -eq $Null) { Throw "ERROR: Environment variable TESTRUN_SUBDIR is not set" }
+    if ($null -eq $env:TESTRUN_SUBDIR) { Throw "ERROR: Environment variable TESTRUN_SUBDIR is not set" }
 
     # SOURCES_DRIVE\SOURCES_SUBDIR must be a directory and exist
     if (-not (Test-Path -PathType Container "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR")) { Throw "ERROR: $env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR must be an existing directory" }
@@ -287,12 +287,12 @@ Try {
     }
 
     # Make sure we start at the root of the sources
-    cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker"
-    Write-Host  -ForegroundColor Green "INFO: Running in $(pwd)"
+    Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker"
+    Write-Host  -ForegroundColor Green "INFO: Running in $(Get-Location)"
 
     # Make sure we are in repo
     if (-not (Test-Path -PathType Leaf -Path ".\Dockerfile.windows")) {
-        Throw "$(pwd) does not contain Dockerfile.windows!"
+        Throw "$(Get-Location) does not contain Dockerfile.windows!"
     }
     Write-Host  -ForegroundColor Green "INFO: docker/docker repository was found"
 
@@ -314,28 +314,26 @@ Try {
         # Try the internal azure CI image version or Microsoft internal corpnet where the base image is already pre-prepared on the disk,
         # either through Invoke-DockerCI or, in the case of Azure CI servers, baked into the VHD at the same location.
         if (Test-Path $("$env:SOURCES_DRIVE`:\baseimages\"+$ControlDaemonBaseImage+".tar")) {
-		
-			# An optimization for CI servers to copy it to the D: drive which is an SSD.
-			if ($env:SOURCES_DRIVE -ne $env:TESTRUN_DRIVE) {
-				$readBaseFrom=$env:TESTRUN_DRIVE
-				if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages")) {
-					New-Item "$env:TESTRUN_DRIVE`:\baseimages" -type directory | Out-Null
-				}
-				if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\windowsservercore.tar")) {
-					if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar") {
-						Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar to $env:TESTRUN_DRIVE`:\baseimages"
-						Copy-Item "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar" "$env:TESTRUN_DRIVE`:\baseimages"
-					}
-				}
-				if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\nanoserver.tar")) {
-					if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar") {
-						Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\nanoserver.tar to $env:TESTRUN_DRIVE`:\baseimages"
-						Copy-Item "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar" "$env:TESTRUN_DRIVE`:\baseimages"
-					}
-				}
-				$readBaseFrom=$env:TESTRUN_DRIVE
-			}
-		
+            # An optimization for CI servers to copy it to the D: drive which is an SSD.
+            if ($env:SOURCES_DRIVE -ne $env:TESTRUN_DRIVE) {
+                $readBaseFrom=$env:TESTRUN_DRIVE
+                if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages")) {
+                    New-Item "$env:TESTRUN_DRIVE`:\baseimages" -type directory | Out-Null
+                }
+                if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\windowsservercore.tar")) {
+                    if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar") {
+                        Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar to $env:TESTRUN_DRIVE`:\baseimages"
+                        Copy-Item "$env:SOURCES_DRIVE`:\baseimages\windowsservercore.tar" "$env:TESTRUN_DRIVE`:\baseimages"
+                    }
+                }
+                if (!(Test-Path "$env:TESTRUN_DRIVE`:\baseimages\nanoserver.tar")) {
+                    if (Test-Path "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar") {
+                        Write-Host -ForegroundColor Green "INFO: Optimisation - copying $env:SOURCES_DRIVE`:\baseimages\nanoserver.tar to $env:TESTRUN_DRIVE`:\baseimages"
+                        Copy-Item "$env:SOURCES_DRIVE`:\baseimages\nanoserver.tar" "$env:TESTRUN_DRIVE`:\baseimages"
+                    }
+                }
+                $readBaseFrom=$env:TESTRUN_DRIVE
+            }
             Write-Host  -ForegroundColor Green "INFO: Loading"$ControlDaemonBaseImage".tar from disk. This may take some time..."
             $ErrorActionPreference = "SilentlyContinue"
             docker load -i $("$readBaseFrom`:\baseimages\"+$ControlDaemonBaseImage+".tar")
@@ -418,7 +416,7 @@ Try {
     New-Item -ItemType Directory "$env:TEMP\localappdata" -ErrorAction SilentlyContinue | Out-Null
     New-Item -ItemType Directory "$env:TEMP\binary" -ErrorAction SilentlyContinue | Out-Null
     New-Item -ItemType Directory "$env:TEMP\installer" -ErrorAction SilentlyContinue | Out-Null
-    if ($env:SKIP_COPY_GO -eq $null) {
+    if ($null -eq $env:SKIP_COPY_GO) {
         # Wipe the previous version of GO - we're going to get it out of the image
         if (Test-Path "$env:TEMP\go") { Remove-Item "$env:TEMP\go" -Recurse -Force -ErrorAction SilentlyContinue | Out-Null }
         New-Item -ItemType Directory "$env:TEMP\go" -ErrorAction SilentlyContinue | Out-Null
@@ -427,21 +425,21 @@ Try {
     Write-Host -ForegroundColor Green "INFO: Location for testing is $env:TEMP"
 
     # CI Integrity check - ensure Dockerfile.windows and Dockerfile go versions match
-    $goVersionDockerfileWindows=$(Get-Content ".\Dockerfile.windows" | Select-String "^ENV GO_VERSION").ToString().Replace("ENV GO_VERSION=","").Replace("\","").Replace("``","").Trim()
-    $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^ENV GO_VERSION")
+    $goVersionDockerfileWindows=$(Get-Content ".\Dockerfile.windows" | Select-String "^ENV GO_VERSION" | Select-object -First 1).ToString().Replace("ENV GO_VERSION=","").Replace("\","").Replace("``","").Trim()
+    $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^ENV GO_VERSION" | Select-object -First 1)
     
     # As of go 1.11, Dockerfile changed to be in the format like "FROM golang:1.11.0 AS base".
     # If a version number ends with .0 (as in 1.11.0, a convention used in golang docker
     # image versions), it needs to be removed (i.e. "1.11.0" becomes "1.11").
-    if ($goVersionDockerfile -eq $Null) {
-        $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^FROM golang:")
-        if ($goVersionDockerfile -ne $Null) {
+    if ($null -eq $goVersionDockerfile) {
+        $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^FROM golang:" | Select-object -First 1)
+        if ($null -ne $goVersionDockerfile) {
             $goVersionDockerfile = $goVersionDockerfile.ToString().Split(" ")[1].Split(":")[1] -replace '\.0$',''
         }
     } else {
         $goVersionDockerfile = $goVersionDockerfile.ToString().Split(" ")[2]
     }
-    if ($goVersionDockerfile -eq $Null) {
+    if ($null -eq $goVersionDockerfile) {
         Throw "ERROR: Failed to extract golang version from Dockerfile"
     }
     Write-Host  -ForegroundColor Green "INFO: Validating GOLang consistency in Dockerfile.windows..."
@@ -450,7 +448,7 @@ Try {
     }
 
     # Build the image
-    if ($env:SKIP_IMAGE_BUILD -eq $null) {
+    if ($null -eq $env:SKIP_IMAGE_BUILD) {
         Write-Host  -ForegroundColor Cyan "`n`nINFO: Building the image from Dockerfile.windows at $(Get-Date)..."
         Write-Host
         $ErrorActionPreference = "SilentlyContinue"
@@ -476,7 +474,7 @@ Try {
     }
 
     # Build the binary in a container unless asked to skip it.
-    if ($env:SKIP_BINARY_BUILD -eq $null) {
+    if ($null -eq $env:SKIP_BINARY_BUILD) {
         Write-Host  -ForegroundColor Cyan "`n`nINFO: Building the test binaries at $(Get-Date)..."
         $ErrorActionPreference = "SilentlyContinue"
         docker rm -f $COMMITHASH 2>&1 | Out-Null
@@ -528,7 +526,7 @@ Try {
 
     # Grab the golang installer out of the built image. That way, we know we are consistent once extracted and paths set,
     # so there's no need to re-deploy on account of an upgrade to the version of GO being used in docker.
-    if ($env:SKIP_COPY_GO -eq $null) {
+    if ($null -eq $env:SKIP_COPY_GO) {
         Write-Host -ForegroundColor Green "INFO: Copying the golang package from the container to $env:TEMP\installer\go.zip..."
         docker cp "$COMMITHASH`:c`:\go.zip" $env:TEMP\installer\
         if (-not($LastExitCode -eq 0)) {
@@ -591,7 +589,7 @@ Try {
     New-Item -ItemType Directory $env:TEMP\daemon -ErrorAction SilentlyContinue  | Out-Null
 
     # In LCOW mode, for now we need to set an environment variable before starting the daemon under test
-    if (($env:LCOW_MODE -ne $Null) -or ($env:LCOW_BASIC_MODE -ne $Null)) {
+    if (($null -ne $env:LCOW_MODE) -or ($null -ne $env:LCOW_BASIC_MODE)) {
         $env:LCOW_SUPPORTED=1
     }
 
@@ -604,13 +602,13 @@ Try {
     $daemonStarted=1
 
     # In LCOW mode, turn off that variable
-    if (($env:LCOW_MODE -ne $Null) -or ($env:LCOW_BASIC_MODE -ne $Null)) {
+    if (($null -ne $env:LCOW_MODE) -or ($null -ne $env:LCOW_BASIC_MODE)) {
         $env:LCOW_SUPPORTED=""
     }
 
 
     # Start tailing the daemon under test if the command is installed
-    if ((Get-Command "tail" -ErrorAction SilentlyContinue) -ne $null) { 
+    if ($null -ne (Get-Command "tail" -ErrorAction SilentlyContinue)) {
         $tail = start-process "tail" -ArgumentList "-f $env:TEMP\dut.out" -ErrorAction SilentlyContinue
     }
 
@@ -672,11 +670,11 @@ Try {
     Write-Host
 
     # Don't need Windows images when in LCOW mode.
-    if (($env:LCOW_MODE -eq $Null) -and ($env:LCOW_BASIC_MODE -eq $Null)) {
+    if (($null -eq $env:LCOW_MODE) -and ($null -eq $env:LCOW_BASIC_MODE)) {
 
         # Default to windowsservercore for the base image used for the tests. The "docker" image
         # and the control daemon use microsoft/windowsservercore regardless. This is *JUST* for the tests.
-        if ($env:WINDOWS_BASE_IMAGE -eq $Null) {
+        if ($null -eq $env:WINDOWS_BASE_IMAGE) {
             $env:WINDOWS_BASE_IMAGE="microsoft/windowsservercore"
         }
 
@@ -725,7 +723,7 @@ Try {
     }
 
     # Run the validation tests unless SKIP_VALIDATION_TESTS is defined.
-    if ($env:SKIP_VALIDATION_TESTS -eq $null) {
+    if ($null -eq $env:SKIP_VALIDATION_TESTS) {
         Write-Host -ForegroundColor Cyan "INFO: Running validation tests at $(Get-Date)..."
         $ErrorActionPreference = "SilentlyContinue"
         $Duration=$(Measure-Command { hack\make.ps1 -DCO -GoFormat -PkgImports | Out-Host })
@@ -740,8 +738,8 @@ Try {
 
     # Note the unit tests won't work in LCOW mode as I turned off loading the base images above.
     # Run the unit tests inside a container unless SKIP_UNIT_TESTS is defined
-    if (($env:LCOW_MODE -eq $Null) -and ($env:LCOW_BASIC_MODE -eq $Null)) {
-        if ($env:SKIP_UNIT_TESTS -eq $null) {
+    if (($null -eq $env:LCOW_MODE) -and ($null -eq $env:LCOW_BASIC_MODE)) {
+        if ($null -eq $env:SKIP_UNIT_TESTS) {
             Write-Host -ForegroundColor Cyan "INFO: Running unit tests at $(Get-Date)..."
             $ErrorActionPreference = "SilentlyContinue"
             $Duration=$(Measure-Command {docker run -e DOCKER_GITCOMMIT=$COMMITHASH$CommitUnsupported docker hack\make.ps1 -TestUnit | Out-Host })
@@ -756,8 +754,8 @@ Try {
     }
 
     # Add the Windows busybox image. Needed for WCOW integration tests
-    if (($env:LCOW_MODE -eq $Null) -and ($env:LCOW_BASIC_MODE -eq $Null)) {
-        if ($env:SKIP_INTEGRATION_TESTS -eq $null) {
+    if (($null -eq $env:LCOW_MODE) -and ($null -eq $env:LCOW_BASIC_MODE)) {
+        if ($null -eq $env:SKIP_INTEGRATION_TESTS) {
             $ErrorActionPreference = "SilentlyContinue"
             # Build it regardless while switching between nanoserver and windowsservercore
             #$bbCount = $(& "$env:TEMP\binary\docker-$COMMITHASH" "-H=$($DASHH_CUT)" images | Select-String "busybox" | Measure-Object -line).Lines
@@ -797,8 +795,8 @@ Try {
     }
 
     # Run the WCOW integration tests unless SKIP_INTEGRATION_TESTS is defined
-    if (($env:LCOW_MODE -eq $Null) -and ($env:LCOW_BASIC_MODE -eq $Null)) {
-        if ($env:SKIP_INTEGRATION_TESTS -eq $null) {
+    if (($null -eq $env:LCOW_MODE) -and ($null -eq $env:LCOW_BASIC_MODE)) {
+        if ($null -eq $env:SKIP_INTEGRATION_TESTS) {
             Write-Host -ForegroundColor Cyan "INFO: Running integration tests at $(Get-Date)..."
             $ErrorActionPreference = "SilentlyContinue"
     
@@ -808,7 +806,7 @@ Try {
             #https://blogs.technet.microsoft.com/heyscriptingguy/2011/09/20/solve-problems-with-external-command-lines-in-powershell/ is useful to see tokenising
             $c = "go test "
             $c += "`"-check.v`" "
-            if ($env:INTEGRATION_TEST_NAME -ne $null) { # Makes is quicker for debugging to be able to run only a subset of the integration tests
+            if ($null -ne $env:INTEGRATION_TEST_NAME) { # Makes is quicker for debugging to be able to run only a subset of the integration tests
                 $c += "`"-check.f`" "
                 $c += "`"$env:INTEGRATION_TEST_NAME`" "
                 Write-Host -ForegroundColor Magenta "WARN: Only running integration tests matching $env:INTEGRATION_TEST_NAME"
@@ -817,7 +815,7 @@ Try {
             $c += "`"-check.timeout`" " + "`"10m`" "
             $c += "`"-test.timeout`" " + "`"200m`" "
     
-            if ($env:INTEGRATION_IN_CONTAINER -ne $null) {
+            if ($null -ne $env:INTEGRATION_IN_CONTAINER) {
                 Write-Host -ForegroundColor Green "INFO: Integration tests being run inside a container"
                 # Note we talk back through the containers gateway address
                 # And the ridiculous lengths we have to go to to get the default gateway address... (GetNetIPConfiguration doesn't work in nanoserver)
@@ -833,7 +831,7 @@ Try {
                                                         "`$env`:PATH`='c`:\target;'+`$env:PATH`;  `$env:DOCKER_HOST`='tcp`://'+(ipconfig | select -last 1).Substring(39)+'`:2357'; c:\target\runIntegrationCLI.ps1" | Out-Host } )
             } else  {
                 Write-Host -ForegroundColor Green "INFO: Integration tests being run from the host:"
-                cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli"
+                Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli"
                 $env:DOCKER_HOST=$DASHH_CUT  
                 $env:PATH="$env:TEMP\binary;$env:PATH;"  # Force to use the test binaries, not the host ones.
                 Write-Host -ForegroundColor Green "INFO: $c"
@@ -851,7 +849,7 @@ Try {
         }
     } else {
         # The LCOW version of the tests here
-        if ($env:SKIP_INTEGRATION_TESTS -eq $null) {
+        if ($null -eq $env:SKIP_INTEGRATION_TESTS) {
             Write-Host -ForegroundColor Cyan "INFO: Running LCOW tests at $(Get-Date)..."
 
             $ErrorActionPreference = "SilentlyContinue"
@@ -866,7 +864,7 @@ Try {
             # Force to use the test binaries, not the host ones.
             $env:PATH="$env:TEMP\binary;$env:PATH;"  
 
-            if ($env:LCOW_BASIC_MODE -ne $null) {
+            if ($null -ne $env:LCOW_BASIC_MODE) {
                 $wc = New-Object net.webclient
                 try {
                     Write-Host -ForegroundColor green "INFO: Downloading latest execution script..."
@@ -889,7 +887,7 @@ Try {
                 #https://blogs.technet.microsoft.com/heyscriptingguy/2011/09/20/solve-problems-with-external-command-lines-in-powershell/ is useful to see tokenising
                 $c = "go test "
                 $c += "`"-check.v`" "
-                if ($env:INTEGRATION_TEST_NAME -ne $null) { # Makes is quicker for debugging to be able to run only a subset of the integration tests
+                if ($null -ne $env:INTEGRATION_TEST_NAME) { # Makes is quicker for debugging to be able to run only a subset of the integration tests
                     $c += "`"-check.f`" "
                     $c += "`"$env:INTEGRATION_TEST_NAME`" "
                     Write-Host -ForegroundColor Magenta "WARN: Only running LCOW integration tests matching $env:INTEGRATION_TEST_NAME"
@@ -899,7 +897,7 @@ Try {
                 $c += "`"-test.timeout`" " + "`"200m`" "
 
                 Write-Host -ForegroundColor Green "INFO: LCOW Integration tests being run from the host:"
-                cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli"
+                Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli"
                 Write-Host -ForegroundColor Green "INFO: $c"
                 Write-Host -ForegroundColor Green "INFO: DOCKER_HOST at $DASHH_CUT"
                 # Explicit to not use measure-command otherwise don't get output as it goes
@@ -933,7 +931,7 @@ Try {
     # Stop the daemon under test
     if (Test-Path "$env:TEMP\docker.pid") {
         $p=Get-Content "$env:TEMP\docker.pid" -raw
-        if (($p -ne $null) -and ($daemonStarted -eq 1)) {
+        if (($null -ne $p) -and ($daemonStarted -eq 1)) {
             Write-Host -ForegroundColor green "INFO: Stopping daemon under test"
             taskkill -f -t -pid $p
             #sleep 5
@@ -958,18 +956,18 @@ Catch [Exception] {
 }
 Finally {
     $ErrorActionPreference="SilentlyContinue"
-	$global:ProgressPreference=$origProgressPreference
+    $global:ProgressPreference=$origProgressPreference
     Write-Host  -ForegroundColor Green "INFO: Tidying up at end of run"
 
     # Restore the path
-    if ($origPath -ne $null) { $env:PATH=$origPath }
+    if ($null -ne $origPath) { $env:PATH=$origPath }
 
     # Restore the DOCKER_HOST
-    if ($origDOCKER_HOST -ne $null) { $env:DOCKER_HOST=$origDOCKER_HOST }
+    if ($null -ne $origDOCKER_HOST) { $env:DOCKER_HOST=$origDOCKER_HOST }
 
     # Restore the GOROOT and GOPATH variables
-    if ($origGOROOT -ne $null) { $env:GOROOT=$origGOROOT }
-    if ($origGOPATH -ne $null) { $env:GOPATH=$origGOPATH }
+    if ($null -ne $origGOROOT) { $env:GOROOT=$origGOROOT }
+    if ($null -ne $origGOPATH) { $env:GOPATH=$origGOPATH }
 
     # Dump the daemon log if asked to 
     if ($daemonStarted -eq 1) {
@@ -986,7 +984,7 @@ Finally {
         Copy-Item  "$env:TEMP\dut.err" "$TEMPORIG\CIDUT.log" -Force -ErrorAction SilentlyContinue
     }
 
-    cd "$env:SOURCES_DRIVE\$env:SOURCES_SUBDIR" -ErrorAction SilentlyContinue
+    Set-Location "$env:SOURCES_DRIVE\$env:SOURCES_SUBDIR" -ErrorAction SilentlyContinue
     Nuke-Everything
     $Dur=New-TimeSpan -Start $StartTime -End $(Get-Date)
     Write-Host -ForegroundColor $FinallyColour "`nINFO: executeCI.ps1 exiting at $(date). Duration $dur`n"

+ 5 - 5
hack/make.ps1

@@ -218,7 +218,7 @@ Function Validate-DCO($headCommit, $upstreamCommit) {
     if ($LASTEXITCODE -ne 0) { Throw "Failed git log --format" }
     $commits = $($commits -split '\s+' -match '\S')
     $badCommits=@()
-    $commits | %{
+    $commits | ForEach-Object{
         # Skip commits with no content such as merge commits etc
         if ($(git log -1 --format=format: --name-status $_).Length -gt 0) {
             # Ignore exit code on next call - always process regardless
@@ -244,7 +244,7 @@ Function Validate-PkgImports($headCommit, $upstreamCommit) {
 
     # Get a list of go source-code files which have changed under pkg\. Ignore exit code on next call - always process regardless
     $files=@(); $files = Invoke-Expression "git diff $upstreamCommit...$headCommit --diff-filter=ACMR --name-only -- `'pkg\*.go`'"
-    $badFiles=@(); $files | %{
+    $badFiles=@(); $files | ForEach-Object{
         $file=$_
         # For the current changed file, get its list of dependencies, sorted and uniqued.
         $imports = Invoke-Expression "go list -e -f `'{{ .Deps }}`' $file"
@@ -255,13 +255,13 @@ Function Validate-PkgImports($headCommit, $upstreamCommit) {
                                   -NotMatch "^github.com/docker/docker/vendor" `
                                   -Match "^github.com/docker/docker" `
                                   -Replace "`n", ""
-        $imports | % { $badFiles+="$file imports $_`n" }
+        $imports | ForEach-Object{ $badFiles+="$file imports $_`n" }
     }
     if ($badFiles.Length -eq 0) {
         Write-Host 'Congratulations!  ".\pkg\*.go" is safely isolated from internal code.'
     } else {
         $e = "`nThese files import internal code: (either directly or indirectly)`n"
-        $badFiles | %{ $e+=" - $_"}
+        $badFiles | ForEach-Object{ $e+=" - $_"}
         Throw $e
     }
 }
@@ -297,7 +297,7 @@ Function Validate-GoFormat($headCommit, $upstreamCommit) {
         Write-Host 'Congratulations!  All Go source files are properly formatted.'
     } else {
         $e = "`nThese files are not properly gofmt`'d:`n"
-        $badFiles | %{ $e+=" - $_`n"}
+        $badFiles | ForEach-Object{ $e+=" - $_`n"}
         $e+= "`nPlease reformat the above files using `"gofmt -s -w`" and commit the result."
         Throw $e
     }

+ 7 - 7
hack/make/.go-autogen.ps1

@@ -43,19 +43,19 @@ package dockerversion
 // Default build-time variable for library-import.
 // This file is overridden on build with build-time information.
 const (
-    GitCommit             string = "'+$CommitString+'"
-    Version               string = "'+$DockerVersion+'"
-    BuildTime             string = "'+$buildDateTime+'"
-    PlatformName          string = "'+$Platform+'"
-    ProductName           string = "'+$Product+'"
-    DefaultProductLicense string = "'+$DefaultProductLicense+'"
+	GitCommit             string = "'+$CommitString+'"
+	Version               string = "'+$DockerVersion+'"
+	BuildTime             string = "'+$buildDateTime+'"
+	PlatformName          string = "'+$Platform+'"
+	ProductName           string = "'+$Product+'"
+	DefaultProductLicense string = "'+$DefaultProductLicense+'"
 )
 
 // AUTOGENERATED FILE; see hack\make\.go-autogen.ps1
 '
 
     # Write the file without BOM
-    $outputFile="$(pwd)\dockerversion\version_autogen.go"
+    $outputFile="$(Get-Location)\dockerversion\version_autogen.go"
     if (Test-Path $outputFile) { Remove-Item $outputFile }
     [System.IO.File]::WriteAllText($outputFile, $fileContents, (New-Object System.Text.UTF8Encoding($False)))