From 7466d1a9b79324825f71bd91698fbccd0604fd69 Mon Sep 17 00:00:00 2001 From: Dan Jacques Date: Fri, 7 Jul 2017 19:05:44 +0000 Subject: [PATCH] [cipd] Run client in .bat to preserve STDIN. Currently, the PowerShell execution does not allow STDIN to be read by the CIPD client. Fix this by using PowerShell to acquire the client, but batch to actually invoke the client. This removes some indirection and allows STDIN to function as expected. BUG=None TEST=local - Ran w/ and w/out ".cipd_client.exe" locally, observed install and fallthrough. - Ran w/ an error code, observed exit code being preserved. - Ran "auth-login", was able to paste token. Change-Id: I4efafa7dc80aa093de0fbf5dfd188c299fa104db Reviewed-on: https://chromium-review.googlesource.com/563602 Commit-Queue: Daniel Jacques Reviewed-by: Robbie Iannucci --- cipd.bat | 22 ++++++++++++++++++++-- cipd.ps1 | 11 +---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cipd.bat b/cipd.bat index 1f2d7f6e7..90184cff4 100644 --- a/cipd.bat +++ b/cipd.bat @@ -3,10 +3,28 @@ :: Use of this source code is governed by a BSD-style license that can be :: found in the LICENSE file. +setlocal + :: To allow this powershell script to run if it was a byproduct of downloading :: and unzipping the depot_tools.zip distribution, we clear the Zone.Identifier :: alternate data stream. This is equivalent to clicking the "Unblock" button :: in the file's properties dialog. -echo.>"%~dp0\cipd.ps1:Zone.Identifier" +set errorlevel= +if not exist "%~dp0.cipd_client.exe" ( + echo.>%~dp0cipd.ps1:Zone.Identifier + + powershell -NoProfile -ExecutionPolicy RemoteSigned -Command "%~dp0cipd.ps1" < nul + if not errorlevel 0 goto :END +) + +set /p CIPD_CLIENT_VER=<%~dp0cipd_client_version +"%~dp0.cipd_client.exe" selfupdate -version "%CIPD_CLIENT_VER%" +if not errorlevel 0 goto :END + +"%~dp0.cipd_client.exe" %* -powershell -NoProfile -ExecutionPolicy RemoteSigned -Command "%~dp0\cipd.ps1" %* < nul +:END +endlocal & ( + set ERRORLEVEL=%ERRORLEVEL% +) +exit /b %ERRORLEVEL% diff --git a/cipd.ps1 b/cipd.ps1 index 32cbace24..78efcd635 100644 --- a/cipd.ps1 +++ b/cipd.ps1 @@ -68,13 +68,4 @@ while ($true) { $cipd_lock_file.close() } } -} - -$_ = & $client selfupdate -version "$cipdClientVer" -if ($LastExitCode -ne 0) { - Write-Host "selfupdate failed: " -ForegroundColor Red -NoNewline - Write-Host "run ``set CIPD_HTTP_USER_AGENT_PREFIX=$user_agent/manual && $client selfupdate -version $cipdClientVer`` to diagnose`n" -ForegroundColor White -} - -& $client @args -exit $LastExitCode +} \ No newline at end of file