Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MSI installer install/upgrade perf. #6309

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build_scripts/windows/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Compressed="yes"
InstallScope="perMachine" />

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." Schedule="afterInstallInitialize" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." Schedule="afterInstallExecute" />

<Media Id="1" Cabinet="WindowsAzureCLI.cab" EmbedCab="yes" CompressionLevel="high" />

Expand Down
5 changes: 0 additions & 5 deletions build_scripts/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ Prerequisites
4. Install 'Microsoft Build Tools 2015'.
https://www.microsoft.com/en-us/download/details.aspx?id=48159

5. Install Python 3.6
- https://www.python.org/ftp/python/3.6.1/python-3.6.1.exe
- python-installer.exe /quiet InstallAllUsers=0 TargetDir=%PYTHON_DIR% PrependPath=0 AssociateFiles=0 CompileAll=1 Shortcuts=0 Include_test=0 Include_doc=0 Include_dev=0 Include_launcher=0 Include_tcltk=0 Include_tools=0
- %PYTHON_DIR% should be on PATH.

5. Clone the repository.
- git clone https://github.com/azure/azure-cli

Expand Down
2 changes: 1 addition & 1 deletion build_scripts/windows/scripts/az.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
::

@IF EXIST "%~dp0\..\python.exe" (
"%~dp0\..\python.exe" -Im azure.cli %*
"%~dp0\..\python.exe" -IBm azure.cli %*
) ELSE (
echo Failed to load python executable.
exit /b 1
Expand Down
97 changes: 63 additions & 34 deletions build_scripts/windows/scripts/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ echo.

set "PATH=%PATH%;%ProgramFiles%\Git\bin;%ProgramFiles%\Git\usr\bin;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\MSBuild\14.0\Bin;"

set PYTHON_DOWNLOAD_URL="https://www.python.org/ftp/python/3.6.5/python-3.6.5-embed-win32.zip"
set GET_PIP_DOWNLOAD_URL="https://raw.githubusercontent.com/pypa/get-pip/master/get-pip.py"
set WIX_DOWNLOAD_URL="https://azurecliprod.blob.core.windows.net/msi/wix310-binaries-mirror.zip"

if "%CLI_VERSION%"=="" (
echo Please set the CLI_VERSION environment variable, e.g. 2.0.13
goto ERROR
)
set PYTHON_VERSION=3.6.1

set WIX_DOWNLOAD_URL="https://azurecliprod.blob.core.windows.net/msi/wix310-binaries-mirror.zip"

:: Set up the output directory and temp. directories
echo Cleaning previous build artifacts...
Expand All @@ -21,35 +23,10 @@ mkdir %OUTPUT_DIR%

set TEMP_SCRATCH_FOLDER=%HOMEDRIVE%%HOMEPATH%\zcli_scratch
set BUILDING_DIR=%HOMEDRIVE%%HOMEPATH%\zcli
set PYTHON_DIR=%HOMEDRIVE%%HOMEPATH%\zPython
set WIX_DIR=%HOMEDRIVE%%HOMEPATH%\zwix
set REPO_ROOT=%~dp0..\..\..

:: look for python 3.x so we can build into the installer
if not "%1"=="" (
set PYTHON_DIR=%1
set PYTHON_EXE=%1\python.exe
goto PYTHON_FOUND
)

FOR /f %%i IN ('where python') DO (
set PY_FILE_DRIVE=%%~di
set PY_FILE_PATH=%%~pi
set PY_FILE_NAME=%%~ni
set PYTHON_EXE=!PY_FILE_DRIVE!!PY_FILE_PATH!!PY_FILE_NAME!.exe
set PYTHON_DIR=!PY_FILE_DRIVE!!PY_FILE_PATH!
FOR /F "delims=" %%j IN ('!PYTHON_EXE! --version') DO (
set PYTHON_VER=%%j
echo.!PYTHON_VER!|findstr /C:"%PYTHON_VERSION%" >nul 2>&1
if not errorlevel 1 (
goto PYTHON_FOUND
)
)
)
echo python %PYTHON_VERSION% is needed to create installer.
exit /b 1
:PYTHON_FOUND
echo Python Executables: %PYTHON_DIR%, %PYTHON_EXE%

::reset working folders
if exist %BUILDING_DIR% rmdir /s /q %BUILDING_DIR%
::rmdir always returns 0, so check folder's existence
Expand All @@ -59,6 +36,31 @@ if exist %BUILDING_DIR% (
)
mkdir %BUILDING_DIR%

:: get Python
if exist %PYTHON_DIR% rmdir /s /q %PYTHON_DIR%
::rmdir always returns 0, so check folder's existence
if exist %PYTHON_DIR% (
echo Failed to delete %PYTHON_DIR%.
goto ERROR
)
mkdir %PYTHON_DIR%
pushd %PYTHON_DIR%
echo Downloading Python.
curl -o python-archive.zip %PYTHON_DOWNLOAD_URL% -k
unzip -q python-archive.zip
unzip -q python36.zip
if %errorlevel% neq 0 goto ERROR
del python-archive.zip
del python36.zip
echo Python downloaded and extracted successfully.
echo Setting up pip
curl -o get-pip.py %GET_PIP_DOWNLOAD_URL% -k
%PYTHON_DIR%\python.exe get-pip.py
del get-pip.py
echo Pip set up successful.
popd


if exist %TEMP_SCRATCH_FOLDER% rmdir /s /q %TEMP_SCRATCH_FOLDER%
if exist %TEMP_SCRATCH_FOLDER% (
echo Failed to delete %TEMP_SCRATCH_FOLDER%.
Expand Down Expand Up @@ -90,8 +92,12 @@ if not exist %WIX_DIR% (
robocopy %PYTHON_DIR% %BUILDING_DIR% /s /NFL /NDL

:: Build & install all the packages with bdist_wheel
%BUILDING_DIR%\python.exe -m pip install wheel
echo Building CLI packages...

:: Workaround for get bdist_wheel to complete otherwise it fails to import azure_bdist_wheel
set PYTHONPATH=%BUILDING_DIR%\Lib\site-packages
del %BUILDING_DIR%\python36._pth

set CLI_SRC=%REPO_ROOT%\src
for %%a in (%CLI_SRC%\azure-cli %CLI_SRC%\azure-cli-core %CLI_SRC%\azure-cli-nspkg) do (
pushd %%a
Expand All @@ -105,6 +111,15 @@ for /D %%a in (*) do (
popd
)
popd
:: Undo the rest of the workaround and add site-packages to ._pth.
:: See https://docs.python.org/3/using/windows.html#finding-modules
set PYTHONPATH=
(
echo python36.zip
echo .
echo Lib\site-packages
) > %BUILDING_DIR%\python36._pth

echo Built CLI packages successfully.

if %errorlevel% neq 0 goto ERROR
Expand All @@ -114,18 +129,32 @@ for %%i in (%TEMP_SCRATCH_FOLDER%\*.whl) do (
set ALL_MODULES=!ALL_MODULES! %%i
)
echo All modules: %ALL_MODULES%
%BUILDING_DIR%\python.exe -m pip install --no-cache-dir %ALL_MODULES%
%BUILDING_DIR%\python.exe -m pip install --force-reinstall --upgrade azure-nspkg azure-mgmt-nspkg
%BUILDING_DIR%\python.exe -m pip install --no-warn-script-location --no-cache-dir %ALL_MODULES%
%BUILDING_DIR%\python.exe -m pip install --no-warn-script-location --force-reinstall --upgrade azure-nspkg azure-mgmt-nspkg

echo Creating the wbin (Windows binaries) folder that will be added to the path...
mkdir %BUILDING_DIR%\wbin
copy %REPO_ROOT%\build_scripts\windows\scripts\az.cmd %BUILDING_DIR%\wbin\
if %errorlevel% neq 0 goto ERROR
copy %REPO_ROOT%\build_scripts\windows\resources\CLI_LICENSE.rtf %BUILDING_DIR%
copy %REPO_ROOT%\build_scripts\windows\resources\ThirdPartyNotices.txt %BUILDING_DIR%
del %BUILDING_DIR%\Scripts\pip.exe
del %BUILDING_DIR%\Scripts\pip3.exe
del %BUILDING_DIR%\Scripts\pip3.6.exe

: Delete some files we don't need
rmdir /s /q %BUILDING_DIR%\Scripts
for /f %%a in ('dir %BUILDING_DIR%\Lib\site-packages\*.egg-info /b /s /a:d') do (
rmdir /s /q %%a
)
for /d /r %BUILDING_DIR%\Lib\site-packages %%d in (__pycache__) do (
if exist %%d rmdir /s /q "%%d"
)
:: Use universal files and remove Py3 only files
pushd %BUILDING_DIR%\Lib\site-packages\azure\mgmt
Copy link
Member

@lmazuel lmazuel May 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "mgmt" only? There is already some py3 in dataplane generated (eventgrid, keyvault, etc.)

If you fear touching something which is not Autorest, you can look files are in "models". Something like "models/*_py3.py"

for /f %%a in ('dir /b /s *_py3.py') do (
set PY3_FILE=%%a
if exist !PY3_FILE! del !PY3_FILE!
)
popd

if %errorlevel% neq 0 goto ERROR

echo Building MSI...
Expand Down