From 157ca06b09bb6c775e2469933335bd162a7cf6ae Mon Sep 17 00:00:00 2001 From: Yugang Wang Date: Mon, 14 Aug 2017 10:33:06 -0700 Subject: [PATCH] Installer: build debian bundle from a local clone (#28) --- packaged_releases/debian/debian_build.sh | 47 ++++++++++++++----- .../debian/debian_dir_creator.sh | 0 .../windows/scripts/build_local.cmd | 16 +++++-- .../windows/scripts/prepareBuild.cmd | 1 + 4 files changed, 46 insertions(+), 18 deletions(-) mode change 100644 => 100755 packaged_releases/debian/debian_build.sh mode change 100644 => 100755 packaged_releases/debian/debian_dir_creator.sh diff --git a/packaged_releases/debian/debian_build.sh b/packaged_releases/debian/debian_build.sh old mode 100644 new mode 100755 index cac900add59..3a23411b9b5 --- a/packaged_releases/debian/debian_build.sh +++ b/packaged_releases/debian/debian_build.sh @@ -7,7 +7,6 @@ set -ex : "${CLI_VERSION:?CLI_VERSION environment variable not set.}" -: "${CLI_DOWNLOAD_SHA256:?CLI_DOWNLOAD_SHA256 environment variable not set.}" : "${BUILD_ARTIFACT_DIR:?BUILD_ARTIFACT_DIR environment variable not set.}" if [ -z "$1" ] @@ -16,6 +15,12 @@ if [ -z "$1" ] exit 1 fi +local_repo=$2 +if [ -z "$local_repo" ] + then + : "${CLI_DOWNLOAD_SHA256:?CLI_DOWNLOAD_SHA256 environment variable not set.}" +fi + sudo apt-get update debian_directory_creator=$1 @@ -23,17 +28,34 @@ debian_directory_creator=$1 # Install dependencies for the build sudo apt-get install -y libssl-dev libffi-dev python3-dev debhelper # Download, Extract, Patch, Build CLI +tmp_pkg_dir=$(mktemp -d) working_dir=$(mktemp -d) -source_archive=$working_dir/azure-cli-${CLI_VERSION}.tar.gz -source_dir=$working_dir/azure-cli-${CLI_VERSION} cd $working_dir -wget https://azurecliprod.blob.core.windows.net/releases/azure-cli_packaged_${CLI_VERSION}.tar.gz -qO $source_archive -echo "$CLI_DOWNLOAD_SHA256 $source_archive" | sha256sum -c - -mkdir $source_dir -# Extract archive -archive_extract_dir=$(mktemp -d) -tar -xvzf $source_archive -C $archive_extract_dir -cp -r $archive_extract_dir/azure-cli_packaged_${CLI_VERSION}/* $source_dir +if [ -z "$local_repo" ] + then + source_archive=$working_dir/azure-cli-${CLI_VERSION}.tar.gz + source_dir=$working_dir/azure-cli-${CLI_VERSION} + deb_file=$working_dir/azure-cli_${CLI_VERSION}-1_all.deb + az_completion_file=$source_dir/az.completion + wget https://azurecliprod.blob.core.windows.net/releases/azure-cli_packaged_${CLI_VERSION}.tar.gz -qO $source_archive + echo "$CLI_DOWNLOAD_SHA256 $source_archive" | sha256sum -c - + mkdir $source_dir + # Extract archive + archive_extract_dir=$(mktemp -d) + tar -xvzf $source_archive -C $archive_extract_dir + cp -r $archive_extract_dir/azure-cli_packaged_${CLI_VERSION}/* $source_dir + else + source_dir=$local_repo + deb_file=$local_repo/../azure-cli_${CLI_VERSION}-1_all.deb + az_completion_file=$source_dir/packaged_releases/az.completion + # clean up old build output + if [ -d "$source_dir/debian" ] + then + rm -rf $source_dir/debian + fi + cp $local_repo/privates/*.whl $tmp_pkg_dir +fi + # Build Python from source and include python_dir=$(mktemp -d) python_archive=$(mktemp) @@ -47,7 +69,6 @@ make # required to run the 'make install' sudo apt-get install -y zlib1g-dev make install -tmp_pkg_dir=$(mktemp -d) # note: This installation step could happen in debian/rules but was unable to escape $ char. # It does not affect the built .deb file though. @@ -60,11 +81,11 @@ mkdir $source_dir/debian # Create temp dir for the debian/ directory used for CLI build. cli_debian_dir_tmp=$(mktemp -d) -$debian_directory_creator $cli_debian_dir_tmp $source_dir/az.completion $source_dir +$debian_directory_creator $cli_debian_dir_tmp $az_completion_file $source_dir cp -r $cli_debian_dir_tmp/* $source_dir/debian cd $source_dir dpkg-buildpackage -us -uc echo "The archive is available at $working_dir/azure-cli_${CLI_VERSION}-1_all.deb" -cp $working_dir/azure-cli_${CLI_VERSION}-1_all.deb ${BUILD_ARTIFACT_DIR} +cp $deb_file ${BUILD_ARTIFACT_DIR} echo "The archive has also been copied to ${BUILD_ARTIFACT_DIR}" echo "Done." diff --git a/packaged_releases/debian/debian_dir_creator.sh b/packaged_releases/debian/debian_dir_creator.sh old mode 100644 new mode 100755 diff --git a/packaged_releases/windows/scripts/build_local.cmd b/packaged_releases/windows/scripts/build_local.cmd index 452d373264b..b60f31cfdbf 100644 --- a/packaged_releases/windows/scripts/build_local.cmd +++ b/packaged_releases/windows/scripts/build_local.cmd @@ -9,6 +9,7 @@ if "%CLIVERSION%"=="" ( echo Please set the CLIVERSION 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" @@ -24,6 +25,12 @@ 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 @@ -32,13 +39,13 @@ FOR /f %%i IN ('where python') DO ( 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:"3." >nul 2>&1 + echo.!PYTHON_VER!|findstr /C:"%PYTHON_VERSION%" >nul 2>&1 if not errorlevel 1 ( goto PYTHON_FOUND ) ) ) -echo python 3.x is needed to create installer. +echo python %PYTHON_VERSION% is needed to create installer. exit /b 1 :PYTHON_FOUND echo Python Executables: %PYTHON_DIR%, %PYTHON_EXE% @@ -82,6 +89,7 @@ robocopy %PYTHON_DIR% %BUILDING_DIR% /s /NFL /NDL :: Build & install all the packages with bdist_wheel %BUILDING_DIR%\python %~dp0build-packages.py %TEMP_SCRATCH_FOLDER% %REPO_ROOT% +if %errorlevel% neq 0 goto ERROR :: Install them to the temp folder so to be packaged %BUILDING_DIR%\python.exe -m pip install -f %TEMP_SCRATCH_FOLDER% --no-cache-dir azure-cli %BUILDING_DIR%\python.exe -m pip install --force-reinstall --upgrade azure-nspkg azure-mgmt-nspkg @@ -100,9 +108,7 @@ if %errorlevel% neq 0 goto ERROR echo Building MSI... msbuild /t:rebuild /p:Configuration=Release %REPO_ROOT%\packaged_releases\windows\azure-cli.wixproj -if not "%1"=="-noprompt" ( - start %OUTPUT_DIR% -) +start %OUTPUT_DIR% goto END diff --git a/packaged_releases/windows/scripts/prepareBuild.cmd b/packaged_releases/windows/scripts/prepareBuild.cmd index 2d0e105a328..5b729b7fed3 100644 --- a/packaged_releases/windows/scripts/prepareBuild.cmd +++ b/packaged_releases/windows/scripts/prepareBuild.cmd @@ -10,6 +10,7 @@ if "%CLIVERSION%"=="" ( goto ERROR ) +::when change to a later version, please update ones in build_local.cmd set PYTHON_VERSION=3.6.1 pushd %~dp0..\