Skip to content

Commit

Permalink
[setup]: windows installer improvement (#7633)
Browse files Browse the repository at this point in the history
* revert to desktop python

* change before do model file concat

* add trimmer

* revert an unrelated change

* incorporate model file trimmer

* revert a few unnecessary change

* lint fix

* remove an irrelevant command file

* backup python to storage accounts

* remove irrelevant comment

* simplify
  • Loading branch information
yugangw-msft authored and tjprescott committed Oct 24, 2018
1 parent cefe3f1 commit 939ca19
Show file tree
Hide file tree
Showing 2 changed files with 316 additions and 70 deletions.
104 changes: 34 additions & 70 deletions build_scripts/windows/scripts/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,41 @@ SetLocal EnableDelayedExpansion
echo build a msi installer using local cli sources and python executables. You need to have curl.exe, unzip.exe and msbuild.exe available under PATH
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;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.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://bootstrap.pypa.io/get-pip.py"
set WIX_DOWNLOAD_URL="https://azurecliprod.blob.core.windows.net/msi/wix310-binaries-mirror.zip"
set "PATH=%PATH%;%ProgramFiles%\Git\bin;%ProgramFiles%\Git\usr\bin;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\MSBuild\14.0\Bin;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin;"

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

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

:: Set up the output directory and temp. directories
echo Cleaning previous build artifacts...

set OUTPUT_DIR=%~dp0..\out
if exist %OUTPUT_DIR% rmdir /s /q %OUTPUT_DIR%
mkdir %OUTPUT_DIR%

set ARTIFACTS_DIR=%~dp0..\artifacts
mkdir %ARTIFACTS_DIR%

set TEMP_SCRATCH_FOLDER=%ARTIFACTS_DIR%\cli_scratch
set BUILDING_DIR=%ARTIFACTS_DIR%\cli
set PYTHON_DIR=%ARTIFACTS_DIR%\Python
set WIX_DIR=%ARTIFACTS_DIR%\wix
set PYTHON_DIR=%ARTIFACTS_DIR%\Python366-32

set REPO_ROOT=%~dp0..\..\..

::reset working folders
if exist %BUILDING_DIR% rmdir /s /q %BUILDING_DIR%

::rmdir always returns 0, so check folder's existence
if exist %BUILDING_DIR% (
echo Failed to delete %BUILDING_DIR%.
goto ERROR
)
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 All @@ -82,11 +49,10 @@ if exist %REPO_ROOT%\privates (
copy %REPO_ROOT%\privates\*.whl %TEMP_SCRATCH_FOLDER%
)

:: ensure wix is available
::ensure wix is available
if exist %WIX_DIR% (
echo Using existing Wix at %WIX_DIR%
)

if not exist %WIX_DIR% (
mkdir %WIX_DIR%
pushd %WIX_DIR%
Expand All @@ -99,40 +65,41 @@ if not exist %WIX_DIR% (
popd
)

:: Use the Python version on the machine that creates the MSI
::ensure Python is available
if exist %PYTHON_DIR% (
echo Using existing Python at %PYTHON_DIR%
)
if not exist %PYTHON_DIR% (
mkdir %PYTHON_DIR%
pushd %PYTHON_DIR%
echo Downloading Python.
curl -o Python366-32.zip %PYTHON_DOWNLOAD_URL% -k
unzip -q Python366-32.zip
if %errorlevel% neq 0 goto ERROR
del Python366-32.zip
echo Python downloaded and extracted successfully.
popd
)
set PYTHON_EXE=%PYTHON_DIR%\python.exe

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 %CLI_SRC%\azure-cli-telemetry) do (
pushd %%a
%BUILDING_DIR%\python.exe setup.py bdist_wheel -d %TEMP_SCRATCH_FOLDER%
popd
)

pushd %CLI_SRC%\command_modules
for /D %%a in (*) do (
pushd %CLI_SRC%\command_modules\%%a
%BUILDING_DIR%\python.exe setup.py bdist_wheel -d %TEMP_SCRATCH_FOLDER%
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 @@ -142,23 +109,20 @@ 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-warn-script-location --force-reinstall pycparser==2.18
%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

pushd %BUILDING_DIR%
%BUILDING_DIR%\python.exe %~dp0\patch_models_v2.py
popd

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%

: 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
)

:: Use universal files and remove Py3 only files
pushd %BUILDING_DIR%\Lib\site-packages\azure\mgmt
for /f %%a in ('dir /b /s *_py3.py') do (
Expand All @@ -172,11 +136,11 @@ for /f %%a in ('dir /b /s *_py3.*.pyc') do (
popd

:: Remove .py and only deploy .pyc files
pushd %BUILDING_DIR%\Lib\site-packages\azure
pushd %BUILDING_DIR%\Lib\site-packages
for /f %%f in ('dir /b /s *.pyc') do (
set PARENT_DIR=%%~df%%~pf..
echo !PARENT_DIR! | findstr /C:"!BUILDING_DIR!\Lib\site-packages\pip" 1>nul
if errorlevel 1 (
echo !PARENT_DIR! | findstr /C:\Lib\site-packages\pip\ 1>nul
if !errorlevel! neq 0 (
set FILENAME=%%~nf
set BASE_FILENAME=!FILENAME:~0,-11!
set pyc=!BASE_FILENAME!.pyc
Expand All @@ -196,7 +160,7 @@ for /d /r %BUILDING_DIR%\Lib\site-packages\pip %%d in (__pycache__) do (
if %errorlevel% neq 0 goto ERROR

echo Building MSI...
MSBuild.exe /t:rebuild /p:Configuration=Release %REPO_ROOT%\build_scripts\windows\azure-cli.wixproj
msbuild /t:rebuild /p:Configuration=Release %REPO_ROOT%\build_scripts\windows\azure-cli.wixproj

start %OUTPUT_DIR%

Expand All @@ -208,4 +172,4 @@ exit /b 1

:END
exit /b 0
popd
popd
Loading

0 comments on commit 939ca19

Please sign in to comment.