diff options
Diffstat (limited to 'NvCloth/scripts')
| -rw-r--r-- | NvCloth/scripts/packman/config.packman.xml | 9 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/packages/cmake.packman.xml | 7 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/packman.cmd | 41 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/packman.sh | 97 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/packman_config.txt | 5 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/test_packman.cmd | 6 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/test_packman.sh | 8 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/test_postscript.bat | 2 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/win-bootstrap/configure.bat | 112 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/win-bootstrap/fetch_file_from_s3.cmd | 22 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/win-bootstrap/fetch_file_from_s3.ps1 | 60 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/win-bootstrap/fetch_file_from_url.ps1 | 37 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/win-bootstrap/generate_temp_file_name.ps1 | 2 | ||||
| -rw-r--r-- | NvCloth/scripts/packman/win-bootstrap/install_package.py | 39 |
14 files changed, 447 insertions, 0 deletions
diff --git a/NvCloth/scripts/packman/config.packman.xml b/NvCloth/scripts/packman/config.packman.xml new file mode 100644 index 0000000..6099556 --- /dev/null +++ b/NvCloth/scripts/packman/config.packman.xml @@ -0,0 +1,9 @@ +<config remotes="gtl"> + <remote name="s3" type="s3" packageLocation="packman"> + <credentials id="AKIAJHPSPBMWMTZS6TJA" key="vK3d0lHiQjEW9krFfvKA4OLpuHGxi2L4/Q4r4IuT" + errorUrl="https://gtl-gitlab.nvidia.com/halldor/packman/wikis/how-to-configure-s3-full-access"/> + </remote> + <remote name="gtl" type="gtl"> + <credentials id="svcgtlautomate" key="QHV0ME1AdDNHVEwkY3IxcHQk"/> + </remote> +</config> diff --git a/NvCloth/scripts/packman/packages/cmake.packman.xml b/NvCloth/scripts/packman/packages/cmake.packman.xml new file mode 100644 index 0000000..4115184 --- /dev/null +++ b/NvCloth/scripts/packman/packages/cmake.packman.xml @@ -0,0 +1,7 @@ +<project toolsVersion="3.1" remotes="s3"> + <dependency name="cmake"> + <package name="cmake-x64" version="3.7.0" platforms="windows"/> + <package name="cmake-linux-x86_64" version="3.7.2" platforms="linux"/> + <package name="cmake-mac-x86_64" version="3.7.2" platforms="mac"/> + </dependency> +</project> diff --git a/NvCloth/scripts/packman/packman.cmd b/NvCloth/scripts/packman/packman.cmd new file mode 100644 index 0000000..03e2cf8 --- /dev/null +++ b/NvCloth/scripts/packman/packman.cmd @@ -0,0 +1,41 @@ +:: Reset errorlevel status so we are not inheriting this state from the calling process: +@call :RESET_ERROR +:: You can remove the call below if you do your own manual configuration of the dev machines +@call "%~dp0\win-bootstrap\configure.bat" +@if errorlevel 1 exit /b 1 +:: Everything below is mandatory +@if not defined PM_PYTHON goto :PYTHON_ENV_ERROR +@if not defined PM_MODULE goto :MODULE_ENV_ERROR + +:: Generate temporary path for variable file +:TEMP_VAR_PATH_LOOP +@set "PM_VAR_PATH=%tmp%\tmp.%RANDOM%.pmvars" +@if exist "%PM_VAR_PATH%" goto :TEMP_VAR_PATH_LOOP + +@"%PM_PYTHON%" "%PM_MODULE%" %* --var-path="%PM_VAR_PATH%" +@if errorlevel 1 goto :eof + +:: Marshall environment variables into the current environment if they have been generated and remove temporary file +@if exist "%PM_VAR_PATH%" ( + @for /F "usebackq tokens=*" %%A in ("%PM_VAR_PATH%") do @set "%%A" + @if errorlevel 1 goto :VAR_ERROR + @del /F "%PM_VAR_PATH%" +) +@set PM_VAR_PATH= +@goto :eof + +:: Subroutines below +:PYTHON_ENV_ERROR +@echo User environment variable PM_PYTHON is not set! Please configure machine for packman or call configure.bat. +@exit /b 1 + +:MODULE_ENV_ERROR +@echo User environment variable PM_MODULE is not set! Please configure machine for packman or call configure.bat. +@exit /b 1 + +:VAR_ERROR +@echo Error while processing and setting environment variables! +@exit /b 1 + +:RESET_ERROR +@exit /b 0
\ No newline at end of file diff --git a/NvCloth/scripts/packman/packman.sh b/NvCloth/scripts/packman/packman.sh new file mode 100644 index 0000000..3fbd753 --- /dev/null +++ b/NvCloth/scripts/packman/packman.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +PM_PACKMAN_VERSION=5.0-rc2 + +# Specify where packman command exists +export PM_INSTALL_PATH=$(dirname ${BASH_SOURCE}) + +# The packages root may already be configured by the user +if [ -z "$PM_PACKAGES_ROOT" ]; then + # Set variable permanently using .profile for this user + echo "export PM_PACKAGES_ROOT=\$HOME/packman-repo" >> ~/.profile + # Set variable temporarily in this process so that the following execution will work + export PM_PACKAGES_ROOT="${HOME}/packman-repo" +fi + +# Ensure the packages root path exists: +if [ ! -d "$PM_PACKAGES_ROOT" ]; then + echo "Creating packman packages repository at $PM_PACKAGES_ROOT" + mkdir -p "$PM_PACKAGES_ROOT" +fi + +# The packman module may be externally configured +if [ -z "$PM_MODULE_EXT" ]; then + PM_MODULE_DIR="$PM_PACKAGES_ROOT/packman-common/$PM_PACKMAN_VERSION" + export PM_MODULE="$PM_MODULE_DIR/packman.py" +else + export PM_MODULE="$PM_MODULE_EXT" +fi + +fetch_file_from_s3() +{ + SOURCE=$1 + SOURCE_URL=http://packman.s3.amazonaws.com/$SOURCE + TARGET=$2 + echo "Fetching $SOURCE from S3 ..." + if command -v wget >/dev/null 2>&1; then + wget --quiet -O$TARGET $SOURCE_URL + else + curl -o $TARGET $SOURCE_URL -s -S + fi +} + +# Ensure the packman package exists: +if [ ! -f "$PM_MODULE" ]; then + PM_MODULE_PACKAGE="packman-common@$PM_PACKMAN_VERSION.zip" + TARGET="/tmp/$PM_MODULE_PACKAGE" + # We always fetch packman from S3: + fetch_file_from_s3 $PM_MODULE_PACKAGE $TARGET + if [ "$?" -eq "0" ]; then + echo "Unpacking ..." + mkdir -p "$PM_MODULE_DIR" + unzip -q $TARGET -d "$PM_MODULE_DIR" + rm $TARGET + else + echo "Failure while fetching packman module from S3!" + exit 1 + fi +fi + +# For now assume python is installed on the box and we just need to find it +if command -v python2 >/dev/null 2>&1; then + export PM_PYTHON=python2 +else + export PM_PYTHON=python +fi + +# Ensure 7za package exists: +PM_7za_VERSION=16.02 +export PM_7za_PATH="$PM_PACKAGES_ROOT/7za/$PM_7za_VERSION" +if [ ! -f "$PM_7za_PATH" ]; then + $PM_PYTHON "$PM_MODULE" install 7za $PM_7za_VERSION -r packman:s3 + if [ "$?" -ne 0 ]; then + echo "Failure while installing required 7za package" + exit 1 + fi +fi + +# Generate temporary file name for environment variables: +PM_VAR_PATH=`mktemp -u -t tmp.XXXXX.$$.pmvars` + +$PM_PYTHON "$PM_MODULE" $* --var-path="$PM_VAR_PATH" +exit_code=$? +# Export the variables if the file was used and remove the file: +if [ -f "$PM_VAR_PATH" ]; then + while read -r line + do + if [ ${#line} -gt 0 ]; then + export "$line" + fi + done < "$PM_VAR_PATH" + rm -f "$PM_VAR_PATH" +fi + +# Return the exit code from python +if [ "$exit_code" != 0 ]; then + exit "$exit_code" +fi diff --git a/NvCloth/scripts/packman/packman_config.txt b/NvCloth/scripts/packman/packman_config.txt new file mode 100644 index 0000000..a0a912b --- /dev/null +++ b/NvCloth/scripts/packman/packman_config.txt @@ -0,0 +1,5 @@ +PM_PACKAGES_SOURCE=gtl +PM_GTL_USER=svcgtlautomate +PM_GTL_KEY=QHV0ME1AdDNHVEwkY3IxcHQk +PM_S3_READ_KEY_ID=AKIAJHPSPBMWMTZS6TJA +PM_S3_READ_SECRET_KEY=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 diff --git a/NvCloth/scripts/packman/test_packman.cmd b/NvCloth/scripts/packman/test_packman.cmd new file mode 100644 index 0000000..f3982fd --- /dev/null +++ b/NvCloth/scripts/packman/test_packman.cmd @@ -0,0 +1,6 @@ +:: Use our local packman module for testing +@set PM_MODULE_EXT=%~dp0\..\common\packman.py +@call "%~dp0packman.cmd" %* +:: Clean out so this setting doesn't leak into the current console +@set PM_MODULE_EXT= +@if errorlevel 1 exit /b 1 diff --git a/NvCloth/scripts/packman/test_packman.sh b/NvCloth/scripts/packman/test_packman.sh new file mode 100644 index 0000000..246c7e0 --- /dev/null +++ b/NvCloth/scripts/packman/test_packman.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +export PM_MODULE_EXT="$(dirname ${BASH_SOURCE})/../common/packman.py" + +source "$(dirname ${BASH_SOURCE})/packman.sh" $* + +unset PM_MODULE_EXT + diff --git a/NvCloth/scripts/packman/test_postscript.bat b/NvCloth/scripts/packman/test_postscript.bat new file mode 100644 index 0000000..26793b7 --- /dev/null +++ b/NvCloth/scripts/packman/test_postscript.bat @@ -0,0 +1,2 @@ +@echo %PM_CMakeModules_PATH% +@echo %PM_PATHS%
\ No newline at end of file diff --git a/NvCloth/scripts/packman/win-bootstrap/configure.bat b/NvCloth/scripts/packman/win-bootstrap/configure.bat new file mode 100644 index 0000000..0528b09 --- /dev/null +++ b/NvCloth/scripts/packman/win-bootstrap/configure.bat @@ -0,0 +1,112 @@ +@set PM_PACKMAN_VERSION=5.0-rc2 + +:: Specify where packman command is rooted +@set PM_INSTALL_PATH=%~dp0.. + +:: The external root may already be configured and we should do minimal work in that case +@if defined PM_PACKAGES_ROOT goto ENSURE_DIR + +:: If the folder isn't set we assume that the best place for it is on the drive that we are currently +:: running from +@set PM_DRIVE=%CD:~0,2% + +@set PM_PACKAGES_ROOT=%PM_DRIVE%\packman-repo + +:: We use *setx* here so that the variable is persisted in the user environment +@echo Setting user environment variable PM_PACKAGES_ROOT to %PM_PACKAGES_ROOT% +@setx PM_PACKAGES_ROOT %PM_PACKAGES_ROOT% +@if errorlevel 1 goto ERROR + +:: The above doesn't work properly from a build step in VisualStudio because a separate process is +:: spawned for it so it will be lost for subsequent compilation steps - VisualStudio must +:: be launched from a new process. We catch this odd-ball case here: +@if defined PM_DISABLE_VS_WARNING goto ENSURE_DIR +@if not defined VSLANG goto ENSURE_DIR +@echo The above is a once-per-computer operation. Unfortunately VisualStudio cannot pick up environment change +@echo unless *VisualStudio is RELAUNCHED*. +@echo If you are launching VisualStudio from command line or command line utility make sure +@echo you have a fresh launch environment (relaunch the command line or utility). +@echo If you are using 'linkPath' and referring to packages via local folder links you can safely ignore this warning. +@echo You can disable this warning by setting the environment variable PM_DISABLE_VS_WARNING. +@echo. + +:: Check for the directory that we need. Note that mkdir will create any directories +:: that may be needed in the path +:ENSURE_DIR +@if not exist "%PM_PACKAGES_ROOT%" ( + @echo Creating directory %PM_PACKAGES_ROOT% + @mkdir "%PM_PACKAGES_ROOT%" + @if errorlevel 1 goto ERROR_MKDIR_PACKAGES_ROOT +) + +:: The Python interpreter may already be externally configured +@if defined PM_PYTHON_EXT ( + @set PM_PYTHON=%PM_PYTHON_EXT% + @goto PACKMAN +) + +@set PM_PYTHON_DIR=%PM_PACKAGES_ROOT%\python\2.7.6-windows-x86 +@set PM_PYTHON=%PM_PYTHON_DIR%\python.exe + +@if exist "%PM_PYTHON%" goto PACKMAN + +@set [email protected] +@for /f "delims=" %%a in ('powershell -ExecutionPolicy ByPass -NoLogo -NoProfile -File "%~dp0\generate_temp_file_name.ps1"') do @set TEMP_FILE_NAME=%%a +@set TARGET=%TEMP_FILE_NAME%.exe +@call "%~dp0fetch_file_from_s3.cmd" %PM_PYTHON_PACKAGE% "%TARGET%" +@if errorlevel 1 goto ERROR + +@echo Unpacking ... +@"%TARGET%" -o"%PM_PYTHON_DIR%" -y 1> nul +@if errorlevel 1 goto ERROR + +@del "%TARGET%" + +:PACKMAN +:: The packman module may already be externally configured +@if defined PM_MODULE_EXT ( + @set PM_MODULE=%PM_MODULE_EXT% + @goto ENSURE_7za +) + +@set PM_MODULE_DIR=%PM_PACKAGES_ROOT%\packman-common\%PM_PACKMAN_VERSION% +@set PM_MODULE=%PM_MODULE_DIR%\packman.py + +@if exist "%PM_MODULE%" goto ENSURE_7ZA + +@set PM_MODULE_PACKAGE=packman-common@%PM_PACKMAN_VERSION%.zip +@for /f "delims=" %%a in ('powershell -ExecutionPolicy ByPass -NoLogo -NoProfile -File "%~dp0\generate_temp_file_name.ps1"') do @set TEMP_FILE_NAME=%%a +@set TARGET=%TEMP_FILE_NAME% +@call "%~dp0fetch_file_from_s3.cmd" %PM_MODULE_PACKAGE% "%TARGET%" +@if errorlevel 1 goto ERROR + +@echo Unpacking ... +@"%PM_PYTHON%" "%~dp0\install_package.py" "%TARGET%" "%PM_MODULE_DIR%" +@if errorlevel 1 goto ERROR + +@del "%TARGET%" + +:ENSURE_7ZA +@set PM_7Za_VERSION=16.02 +@set PM_7Za_PATH=%PM_PACKAGES_ROOT%\7za\%PM_7ZA_VERSION% +@if exist "%PM_7Za_PATH%" goto END + +@"%PM_PYTHON%" "%PM_MODULE%" install 7za %PM_7za_VERSION% -r packman:s3 +@if errorlevel 1 goto ERROR + +@goto END + +:ERROR_MKDIR_PACKAGES_ROOT +@echo Failed to automatically create packman packages repo at %PM_PACKAGES_ROOT%. +@echo Please set a location explicitly that packman has permission to write to, by issuing: +@echo. +@echo setx PM_PACKAGES_ROOT {path-you-choose-for-storing-packman-packages-locally} +@echo. +@echo Then launch a new command console for the changes to take effect and run packman command again. +@exit /B 1 + +:ERROR +@echo !!! Failure while configuring local machine :( !!! +@exit /B 1 + +:END diff --git a/NvCloth/scripts/packman/win-bootstrap/fetch_file_from_s3.cmd b/NvCloth/scripts/packman/win-bootstrap/fetch_file_from_s3.cmd new file mode 100644 index 0000000..63766c1 --- /dev/null +++ b/NvCloth/scripts/packman/win-bootstrap/fetch_file_from_s3.cmd @@ -0,0 +1,22 @@ +:: You need to specify <package-name> <target-path> as input to this command +@setlocal +@set PACKAGE_NAME=%1 +@set TARGET_PATH=%2 + +@echo Fetching %PACKAGE_NAME% from s3 ... + +@powershell -ExecutionPolicy ByPass -NoLogo -NoProfile -File "%~dp0fetch_file_from_s3.ps1" -sourceName %PACKAGE_NAME% ^ + -output %TARGET_PATH% +:: A bug in powershell prevents the errorlevel code from being set when using the -File execution option +:: We must therefore do our own failure analysis, basically make sure the file exists and is larger than 0 bytes: +@if not exist %TARGET_PATH% goto ERROR_DOWNLOAD_FAILED +@if %~z2==0 goto ERROR_DOWNLOAD_FAILED + +@endlocal +@exit /b 0 + +:ERROR_DOWNLOAD_FAILED +@echo Failed to download file from %1 +@echo Most likely because endpoint cannot be reached (VPN connection down?) +@endlocal +@exit /b 1
\ No newline at end of file diff --git a/NvCloth/scripts/packman/win-bootstrap/fetch_file_from_s3.ps1 b/NvCloth/scripts/packman/win-bootstrap/fetch_file_from_s3.ps1 new file mode 100644 index 0000000..fc588d9 --- /dev/null +++ b/NvCloth/scripts/packman/win-bootstrap/fetch_file_from_s3.ps1 @@ -0,0 +1,60 @@ +param( +[Parameter(Mandatory=$true)][string]$sourceName=$null, +[string]$output="out.exe" +) +$source = "http://packman.s3.amazonaws.com/" + $sourceName +$filename = $output + +$triesLeft = 3 + +do +{ + $triesLeft -= 1 + $req = [System.Net.httpwebrequest]::Create($source) + $req.cookiecontainer = New-Object System.net.CookieContainer + + try + { + Write-Host "Connecting to S3 ..." + $res = $req.GetResponse() + if($res.StatusCode -eq "OK") { + Write-Host "Downloading ..." + [int]$goal = $res.ContentLength + $reader = $res.GetResponseStream() + $writer = new-object System.IO.FileStream $fileName, "Create" + [byte[]]$buffer = new-object byte[] 4096 + [int]$total = [int]$count = 0 + do + { + $count = $reader.Read($buffer, 0, $buffer.Length); + $writer.Write($buffer, 0, $count); + $total += $count + if($goal -gt 0) { + Write-Progress "Downloading $url" "Saving $total of $goal" -id 0 -percentComplete (($total/$goal)*100) + } else { + Write-Progress "Downloading $url" "Saving $total bytes..." -id 0 + } + } while ($count -gt 0) + + $triesLeft = 0 + } + } + catch + { + Write-Host "Error connecting to S3!" + Write-Host $_.Exception|format-list -force + } + finally + { + if ($reader) + { + $reader.Close() + } + if ($writer) + { + $writer.Flush() + $writer.Close() + } + } +} while ($triesLeft -gt 0) + diff --git a/NvCloth/scripts/packman/win-bootstrap/fetch_file_from_url.ps1 b/NvCloth/scripts/packman/win-bootstrap/fetch_file_from_url.ps1 new file mode 100644 index 0000000..5b566f1 --- /dev/null +++ b/NvCloth/scripts/packman/win-bootstrap/fetch_file_from_url.ps1 @@ -0,0 +1,37 @@ +param( +[Parameter(Mandatory=$true)][string]$sourceUrl=$null, +[Parameter(Mandatory=$true)][string]$output=$null +) +$source = $sourceUrl +$filename = $output + +$req = [System.Net.httpwebrequest]::Create($source) +$req.cookiecontainer = New-Object System.net.CookieContainer + +Write-Host "Connecting to $source ..." +$res = $req.GetResponse() + +if($res.StatusCode -eq "OK") { + Write-Host "Downloading ..." + [int]$goal = $res.ContentLength + $reader = $res.GetResponseStream() + $writer = new-object System.IO.FileStream $fileName, "Create" + [byte[]]$buffer = new-object byte[] 4096 + [int]$total = [int]$count = 0 + do + { + $count = $reader.Read($buffer, 0, $buffer.Length); + $writer.Write($buffer, 0, $count); + $total += $count + if($goal -gt 0) { + Write-Progress "Downloading $url" "Saving $total of $goal" -id 0 -percentComplete (($total/$goal)*100) + } else { + Write-Progress "Downloading $url" "Saving $total bytes..." -id 0 + } + } while ($count -gt 0) + + $reader.Close() + $writer.Flush() + $writer.Close() +} + diff --git a/NvCloth/scripts/packman/win-bootstrap/generate_temp_file_name.ps1 b/NvCloth/scripts/packman/win-bootstrap/generate_temp_file_name.ps1 new file mode 100644 index 0000000..cefbda4 --- /dev/null +++ b/NvCloth/scripts/packman/win-bootstrap/generate_temp_file_name.ps1 @@ -0,0 +1,2 @@ +$out = [System.IO.Path]::GetTempFileName() +Write-Host $out
\ No newline at end of file diff --git a/NvCloth/scripts/packman/win-bootstrap/install_package.py b/NvCloth/scripts/packman/win-bootstrap/install_package.py new file mode 100644 index 0000000..730962a --- /dev/null +++ b/NvCloth/scripts/packman/win-bootstrap/install_package.py @@ -0,0 +1,39 @@ +import logging +import zipfile +import tempfile +import sys +import shutil + +__author__ = 'hfannar' +logging.basicConfig(level=logging.WARNING, format="%(message)s") +logger = logging.getLogger('install_package') + + +class TemporaryDirectory: + def __init__(self): + self.path = None + + def __enter__(self): + self.path = tempfile.mkdtemp() + return self.path + + def __exit__(self, type, value, traceback ): + # Remove temporary data created + shutil.rmtree(self.path) + + +def install_package(package_src_path, package_dst_path): + with zipfile.ZipFile(package_src_path, allowZip64=True) as zip_file, TemporaryDirectory() as temp_dir: + zip_file.extractall(temp_dir) + # Recursively copy (temp_dir will be automatically cleaned up on exit) + try: + # Recursive copy is needed because both package name and version folder could be missing in + # target directory: + shutil.copytree(temp_dir, package_dst_path) + except OSError, exc: + logger.warning("Directory %s already present, packaged installation aborted" % package_dst_path) + else: + logger.info("Package successfully installed to %s" % package_dst_path) + + +install_package(sys.argv[1], sys.argv[2])
\ No newline at end of file |