forked from osmocom/wireshark
Start moving win-setup to PowerShell.
Add win-setup.ps1, which duplicates the following tasks performed by config.nmake + Makefile.nmake + win-setup.sh: - Create the windows library directory. - Download files. - Download and unpack zip files. - Check and set current-tag.txt Don't verify applications or libraries. CMakeLists.txt does that. Update the Developer's Guide. Have POWERSHELL_COMMAND use dot sourcing instead of "-File", which appears to be a synonym for "-IgnoreTheExitStatusReturnedByThisScript". This removes our dependencies on unzip and wget and reduces our dependency on bash. Change-Id: Ia9def24acbe183d81b9d477fa42e655e4a3a6614 Reviewed-on: https://code.wireshark.org/review/7990 Reviewed-by: Graham Bloice <graham.bloice@trihedral.com> Petri-Dish: Graham Bloice <graham.bloice@trihedral.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
parent
311758aff7
commit
1404605513
|
@ -32,11 +32,16 @@ cmake_policy(SET CMP0011 OLD)
|
||||||
# Policy since 2.8.1
|
# Policy since 2.8.1
|
||||||
cmake_policy(SET CMP0015 NEW)
|
cmake_policy(SET CMP0015 NEW)
|
||||||
|
|
||||||
|
#Where to find local cmake scripts
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
|
||||||
|
|
||||||
# If our target platform is enforced by our generator, set
|
# If our target platform is enforced by our generator, set
|
||||||
# WIRESHARK_TARGET_PLATFORM accordingly. Otherwise use
|
# WIRESHARK_TARGET_PLATFORM accordingly. Otherwise use
|
||||||
# %WIRESHARK_TARGET_PLATFORM%.
|
# %WIRESHARK_TARGET_PLATFORM%.
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
find_package(PowerShell REQUIRED)
|
||||||
|
|
||||||
if("${CMAKE_GENERATOR}" MATCHES "Win64")
|
if("${CMAKE_GENERATOR}" MATCHES "Win64")
|
||||||
set(WIRESHARK_TARGET_PLATFORM win64)
|
set(WIRESHARK_TARGET_PLATFORM win64)
|
||||||
set(PROCESSOR_ARCHITECTURE amd64)
|
set(PROCESSOR_ARCHITECTURE amd64)
|
||||||
|
@ -49,6 +54,7 @@ if(WIN32)
|
||||||
set(WIRESHARK_TARGET_PLATFORM $ENV{WIRESHARK_TARGET_PLATFORM})
|
set(WIRESHARK_TARGET_PLATFORM $ENV{WIRESHARK_TARGET_PLATFORM})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Sanity check
|
||||||
if(DEFINED ENV{PLATFORM})
|
if(DEFINED ENV{PLATFORM})
|
||||||
string(TOLOWER $ENV{PLATFORM} _vs_platform)
|
string(TOLOWER $ENV{PLATFORM} _vs_platform)
|
||||||
else()
|
else()
|
||||||
|
@ -62,10 +68,30 @@ if(WIN32)
|
||||||
message(FATAL_ERROR "The PLATFORM environment variable (${_vs_platform})"
|
message(FATAL_ERROR "The PLATFORM environment variable (${_vs_platform})"
|
||||||
" doesn't match the generator platform (${WIRESHARK_TARGET_PLATFORM})")
|
" doesn't match the generator platform (${WIRESHARK_TARGET_PLATFORM})")
|
||||||
endif()
|
endif()
|
||||||
endif(WIN32)
|
|
||||||
|
|
||||||
#Where to find local cmake scripts
|
# Download third-party libraries
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
|
file (TO_NATIVE_PATH ${CMAKE_SOURCE_DIR}/tools/win-setup.ps1 _win_setup)
|
||||||
|
file (TO_NATIVE_PATH "$ENV{WIRESHARK_BASE_DIR}/wireshark-${WIRESHARK_TARGET_PLATFORM}-libs" _ws_lib_dir)
|
||||||
|
if(MSVC12)
|
||||||
|
set(_vsversion_args "-VSVersion 12")
|
||||||
|
elseif(MSVC11)
|
||||||
|
set(_vsversion_args "-VSVersion 11")
|
||||||
|
elseif(MSVC10)
|
||||||
|
set(_vsversion_args "-VSVersion 10")
|
||||||
|
endif()
|
||||||
|
# Is it possible to have a one-time, non-cached option in CMake? If
|
||||||
|
# so, we could add a "-DFORCE_WIN_SETUP" which passes -Force to
|
||||||
|
# win-setup.ps1.
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${POWERSHELL_COMMAND} "${_win_setup}" -Destination "${_ws_lib_dir}" -Platform ${WIRESHARK_TARGET_PLATFORM} ${_vsversion_args}
|
||||||
|
RESULT_VARIABLE _win_setup_failed
|
||||||
|
)
|
||||||
|
if (${_win_setup_failed})
|
||||||
|
message(FATAL_ERROR "Windows setup (win-setup.ps1) failed.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# XXX Add a dependency on ${_ws_lib_dir}/current_tag.txt?
|
||||||
|
endif(WIN32)
|
||||||
|
|
||||||
include(UseCustomIncludes)
|
include(UseCustomIncludes)
|
||||||
ADD_CUSTOM_CMAKE_INCLUDE()
|
ADD_CUSTOM_CMAKE_INCLUDE()
|
||||||
|
@ -542,10 +568,7 @@ set(PythonInterp_FIND_VERSION 2)
|
||||||
set(Python_ADDITIONAL_VERSIONS 3)
|
set(Python_ADDITIONAL_VERSIONS 3)
|
||||||
set(YACC_REQUIRED TRUE)
|
set(YACC_REQUIRED TRUE)
|
||||||
|
|
||||||
if (WIN32)
|
if (NOT WIN32)
|
||||||
set(PACKAGELIST ${PACKAGELIST} PowerShell)
|
|
||||||
set(PowerShell_REQUIRED TRUE)
|
|
||||||
else()
|
|
||||||
set(M_REQUIRED TRUE)
|
set(M_REQUIRED TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -711,8 +734,6 @@ foreach(PACKAGE ${PACKAGELIST})
|
||||||
set(PACKAGE_VAR "HTML_VIEWER")
|
set(PACKAGE_VAR "HTML_VIEWER")
|
||||||
elseif(${PACKAGE} STREQUAL "Perl")
|
elseif(${PACKAGE} STREQUAL "Perl")
|
||||||
set(PACKAGE_VAR "PERL")
|
set(PACKAGE_VAR "PERL")
|
||||||
elseif(${PACKAGE} STREQUAL "PowerShell")
|
|
||||||
set(PACKAGE_VAR "POWERSHELL")
|
|
||||||
else()
|
else()
|
||||||
set(PACKAGE_VAR ${PACKAGE})
|
set(PACKAGE_VAR ${PACKAGE})
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -18,7 +18,10 @@ find_package_handle_standard_args(POWERSHELL DEFAULT_MSG POWERSHELL_EXECUTABLE)
|
||||||
|
|
||||||
set(_powershell_command "POWERSHELL_COMMAND-NOTFOUND")
|
set(_powershell_command "POWERSHELL_COMMAND-NOTFOUND")
|
||||||
if(POWERSHELL_FOUND)
|
if(POWERSHELL_FOUND)
|
||||||
set(_powershell_command "${POWERSHELL_EXECUTABLE}" -NoProfile -NonInteractive -executionpolicy bypass -File)
|
# Calling a script using "-File" doesn't properly return exit codes.
|
||||||
|
# Use dot sourcing instead
|
||||||
|
# https://connect.microsoft.com/PowerShell/feedback/details/777375/powershell-exe-does-not-set-an-exit-code-when-file-is-used
|
||||||
|
set(_powershell_command "${POWERSHELL_EXECUTABLE}" -NoProfile -NonInteractive -executionpolicy bypass .)
|
||||||
endif()
|
endif()
|
||||||
set(POWERSHELL_COMMAND ${_powershell_command}
|
set(POWERSHELL_COMMAND ${_powershell_command}
|
||||||
CACHE STRING "Command suitable for running PowerShell scripts."
|
CACHE STRING "Command suitable for running PowerShell scripts."
|
||||||
|
|
|
@ -197,8 +197,7 @@ Navigate to the required Category/Package row and, if the package
|
||||||
has a "Skip" item in the "New" column, click on the "Skip" item
|
has a "Skip" item in the "New" column, click on the "Skip" item
|
||||||
so it shows a version number for:
|
so it shows a version number for:
|
||||||
|
|
||||||
// Only used by win-setup.sh
|
* Archive/unzip (not needed if using CMake)
|
||||||
* Archive/unzip
|
|
||||||
|
|
||||||
* Devel/bison (or install Win flex-bison - see Chocolatey below)
|
* Devel/bison (or install Win flex-bison - see Chocolatey below)
|
||||||
|
|
||||||
|
@ -210,8 +209,7 @@ so it shows a version number for:
|
||||||
|
|
||||||
* Utils/patch (only if needed) (may be Devel/patch instead)
|
* Utils/patch (only if needed) (may be Devel/patch instead)
|
||||||
|
|
||||||
// Only used by win-setup.sh
|
* Web/wget (not needed if using CMake)
|
||||||
* Web/wget
|
|
||||||
|
|
||||||
* asciidoc
|
* asciidoc
|
||||||
|
|
||||||
|
@ -237,7 +235,7 @@ Alternatively you can install Cygwin and its packages using Chocolatey:
|
||||||
----
|
----
|
||||||
PS$>choco install cygwin
|
PS$>choco install cygwin
|
||||||
PS$>choco install cyg-get
|
PS$>choco install cyg-get
|
||||||
PS$>choco install unzip wget asciidoc [...] -source cygwin
|
PS$>choco install sed asciidoc [...] -source cygwin
|
||||||
----
|
----
|
||||||
|
|
||||||
Chocolatey installs Cygwin in 'C:\tools\cygwin' by default.
|
Chocolatey installs Cygwin in 'C:\tools\cygwin' by default.
|
||||||
|
|
|
@ -176,7 +176,7 @@ Chocolatey installs Cygwin in 'C:\tools\cygwin' by default.
|
||||||
One or more Cygwin packages can be installed using "-source cygwin":
|
One or more Cygwin packages can be installed using "-source cygwin":
|
||||||
|
|
||||||
----
|
----
|
||||||
PS$>choco install unzip wget asciidoc -source cygwin
|
PS$>choco install sed asciidoc -source cygwin
|
||||||
----
|
----
|
||||||
|
|
||||||
[[ChToolsGNUChain]]
|
[[ChToolsGNUChain]]
|
||||||
|
@ -1149,7 +1149,8 @@ installation should be straightforward.
|
||||||
|
|
||||||
=== Windows: GNU wget (optional)
|
=== Windows: GNU wget (optional)
|
||||||
|
|
||||||
GNU wget is used to download files from the internet using the command line.
|
GNU wget is used by the Nmake toolchain to download files from the internet
|
||||||
|
using the command line. It is not needed when building with CMake.
|
||||||
|
|
||||||
GNU wget is available for most of the UNIX-like platforms and as the wget
|
GNU wget is available for most of the UNIX-like platforms and as the wget
|
||||||
package from the <<ChToolsCygwin,Cygwin setup>> and also using Chocolatey.
|
package from the <<ChToolsCygwin,Cygwin setup>> and also using Chocolatey.
|
||||||
|
@ -1161,7 +1162,7 @@ PS$> choco install wget -source cygwin
|
||||||
----
|
----
|
||||||
|
|
||||||
You will only need wget if you want to use the Windows automated library
|
You will only need wget if you want to use the Windows automated library
|
||||||
download, see <<ChLibsSetup>>for details.
|
download. See <<ChLibsSetup>>for details.
|
||||||
|
|
||||||
If GNU wget isn't already installed or available as a package for your platform
|
If GNU wget isn't already installed or available as a package for your platform
|
||||||
(well, for Windows it is available as a Cygwin package), you can get it at
|
(well, for Windows it is available as a Cygwin package), you can get it at
|
||||||
|
@ -1186,12 +1187,13 @@ If you are unsure about the settings, you might ask your system administrator.
|
||||||
=== Windows: GNU unzip (optional)
|
=== Windows: GNU unzip (optional)
|
||||||
|
|
||||||
GNU unzip is used to, well, unzip the zip files downloaded using the wget tool.
|
GNU unzip is used to, well, unzip the zip files downloaded using the wget tool.
|
||||||
|
As with wget it is not needed when building with CMake.
|
||||||
|
|
||||||
GNU unzip is available for most of the UNIX-like platforms and as the unzip
|
GNU unzip is available for most of the UNIX-like platforms and as the unzip
|
||||||
package from the <<ChToolsCygwin,Cygwin setup>>.
|
package from the <<ChToolsCygwin,Cygwin setup>>.
|
||||||
|
|
||||||
You will only need unzip, if you want to use the Windows automated library
|
You will only need unzip if you want to use the Windows automated library
|
||||||
download, see <<ChLibsSetup>>for details.
|
download. See <<ChLibsSetup>>for details.
|
||||||
|
|
||||||
If GNU unzip isn't already installed or available as a package for your platform
|
If GNU unzip isn't already installed or available as a package for your platform
|
||||||
(well, for Windows it is available as a Cygwin package), you can get it at
|
(well, for Windows it is available as a Cygwin package), you can get it at
|
||||||
|
|
|
@ -0,0 +1,279 @@
|
||||||
|
#
|
||||||
|
# win-setup - Prepare a Windows development environment for building Wireshark.
|
||||||
|
#
|
||||||
|
# Copyright 2015 Gerald Combs <gerald@wireshark.org>
|
||||||
|
#
|
||||||
|
# Wireshark - Network traffic analyzer
|
||||||
|
# By Gerald Combs <gerald@wireshark.org>
|
||||||
|
# Copyright 1998 Gerald Combs
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
#requires -version 2
|
||||||
|
|
||||||
|
# Makefile.nmake + win-setup.sh does:
|
||||||
|
# - verify_tools: Checks required executables. CMake does this.
|
||||||
|
# - clean_setup: Removes current and past lib dirs.
|
||||||
|
# - process_libs: calls libverify or download for each lib.
|
||||||
|
|
||||||
|
# To do:
|
||||||
|
# - Make this the source of truth. Keep the list of libs here.
|
||||||
|
# - Download everything unconditionally, at least initially.
|
||||||
|
# - Download the Lua package for our compiler? It might make more
|
||||||
|
# sense to switch to Nuget instead.
|
||||||
|
|
||||||
|
# Bugs:
|
||||||
|
# - Unzipping from the shell seems to be slower than Cygwin's unzip or 7zip.
|
||||||
|
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Prepare a Windows development environment for building Wireshark.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
This script downloads and extracts third-party libraries required to compile
|
||||||
|
Wireshark.
|
||||||
|
|
||||||
|
.PARAMETER Destination
|
||||||
|
Specifies the destination directory for the text files. The path must
|
||||||
|
contain the pattern "wireshark-*-libs".
|
||||||
|
|
||||||
|
.PARAMETER Platform
|
||||||
|
Target platform. One of "win64" or "win32".
|
||||||
|
|
||||||
|
.PARAMETER VSVersion
|
||||||
|
Visual Studio version. Must be the numeric version (e.g. "12", "11"),
|
||||||
|
not the year.
|
||||||
|
|
||||||
|
.PARAMETER Force
|
||||||
|
Download each library even if exists on the local system.
|
||||||
|
|
||||||
|
.INPUTS
|
||||||
|
-Destination Destination directory.
|
||||||
|
-Platform Target platform.
|
||||||
|
-VSVersion Visual Studio version.
|
||||||
|
-Force Force fresh downloads.
|
||||||
|
|
||||||
|
.OUTPUTS
|
||||||
|
A set of libraries required to compile Wireshark on Windows, along with
|
||||||
|
their compressed archives.
|
||||||
|
A date stamp (current-tag.txt)
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
C:\PS> .\tools\win-setup.ps1 -Destination C:\wireshark-master-64-libs -Platform win64
|
||||||
|
#>
|
||||||
|
|
||||||
|
Param(
|
||||||
|
[Parameter(Mandatory=$true, Position=0)]
|
||||||
|
[ValidateScript({$_ -like "*\wireshark-*-libs"})]
|
||||||
|
[String]
|
||||||
|
$Destination,
|
||||||
|
|
||||||
|
[Parameter(Mandatory=$true, Position=1)]
|
||||||
|
[ValidateSet("win32", "win64")]
|
||||||
|
[String]
|
||||||
|
$Platform,
|
||||||
|
|
||||||
|
[Parameter(Mandatory=$false, Position=2)]
|
||||||
|
[ValidateSet("12", "11", "10")]
|
||||||
|
[String]
|
||||||
|
$VSVersion,
|
||||||
|
|
||||||
|
[Parameter(Mandatory=$false)]
|
||||||
|
[Switch]
|
||||||
|
$Force
|
||||||
|
)
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
|
||||||
|
# We create and delete files and directories. Bail out at the first sign of
|
||||||
|
# trouble instead of trying to catch exceptions everywhere.
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
$Win64CurrentTag = "2015-04-06"
|
||||||
|
$Win32CurrentTag = "2015-04-06"
|
||||||
|
|
||||||
|
# Archive file / subdir.
|
||||||
|
$Win64Archives = @{
|
||||||
|
"AirPcap_Devpack_4_1_0_1622.zip" = "AirPcap_Devpack_4_1_0_1622";
|
||||||
|
"c-ares-1.9.1-1-win64ws.zip" = "";
|
||||||
|
"GeoIP-1.5.1-2-win64ws.zip" = "GeoIP-1.5.1-2-win64ws";
|
||||||
|
"gnutls-3.2.15-2.9-win64ws.zip" = "";
|
||||||
|
"gtk+-bundle_2.24.23-3.39_win64ws.zip" = "gtk2";
|
||||||
|
"kfw-3-2-2-x64-ws.zip" = "";
|
||||||
|
"libsmi-svn-40773-win64ws.zip" = "";
|
||||||
|
"nasm-2.09.08-win32.zip" = "";
|
||||||
|
"portaudio_v19_2.zip" = "";
|
||||||
|
"upx303w.zip" = "";
|
||||||
|
"user-guide-g7ea0d6c.zip" = "user-guide";
|
||||||
|
"WinSparkle-0.3-44-g2c8d9d3-win64ws.zip" = "";
|
||||||
|
"WpdPack_4_1_2.zip" = "";
|
||||||
|
"zlib128.zip" = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$Win32Archives = @{
|
||||||
|
"AirPcap_Devpack_4_1_0_1622.zip" = "AirPcap_Devpack_4_1_0_1622";
|
||||||
|
"c-ares-1.9.1-1-win32ws.zip" = "";
|
||||||
|
"GeoIP-1.5.1-2-win32ws.zip" = "GeoIP-1.5.1-2-win32ws";
|
||||||
|
"gnutls-3.2.15-2.7-win32ws.zip" = "";
|
||||||
|
"gtk+-bundle_2.24.23-1.1_win32ws.zip" = "gtk2";
|
||||||
|
"kfw-3-2-2-i386-ws-vc6.zip" = "";
|
||||||
|
"libsmi-svn-40773-win32ws.zip" = "";
|
||||||
|
"nasm-2.09.08-win32.zip" = "";
|
||||||
|
"portaudio_v19_2.zip" = "";
|
||||||
|
"upx303w.zip" = "";
|
||||||
|
"user-guide-g7ea0d6c.zip" = "user-guide";
|
||||||
|
"WinSparkle-0.3-44-g2c8d9d3-win32ws.zip" = "";
|
||||||
|
"WpdPack_4_1_2.zip" = "";
|
||||||
|
"zlib128.zip" = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Lua
|
||||||
|
|
||||||
|
if ( @("12", "11", "10") -contains $VSVersion ) {
|
||||||
|
$Win64Archives["lua-5.2.3_Win64_dll$($VSVersion)_lib.zip"] = "lua5.2.3"
|
||||||
|
$Win32Archives["lua-5.2.3_Win32_dll$($VSVersion)_lib.zip"] = "lua5.2.3"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Plain file downloads
|
||||||
|
|
||||||
|
$Win32Files = @(
|
||||||
|
"WinPcap_4_1_3.exe";
|
||||||
|
)
|
||||||
|
|
||||||
|
$Win64Files = @(
|
||||||
|
"WinPcap_4_1_3.exe";
|
||||||
|
)
|
||||||
|
|
||||||
|
$Archives = $Win64Archives;
|
||||||
|
$Files = $Win64Files;
|
||||||
|
$CurrentTag = $Win64CurrentTag;
|
||||||
|
|
||||||
|
if ($Platform -eq "win32") {
|
||||||
|
$Archives = $Win32Archives;
|
||||||
|
$Files = $Win32Files;
|
||||||
|
$CurrentTag = $Win32CurrentTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
$CleanupItems = @(
|
||||||
|
"c-ares-1.9.1-1-win??ws"
|
||||||
|
"gnutls-3.1.22-*-win??ws"
|
||||||
|
"gnutls-3.2.15-*-win??ws"
|
||||||
|
"gtk2"
|
||||||
|
"gtk3"
|
||||||
|
"kfw-3-2-2-final"
|
||||||
|
"kfw-3-2-2-i386-ws-vc6"
|
||||||
|
"kfw-3-2-2-x64-ws"
|
||||||
|
"lua5.1.4"
|
||||||
|
"lua5.2.?"
|
||||||
|
"libsmi-0.4.8"
|
||||||
|
"libsmi-svn-40773-win??ws"
|
||||||
|
"nasm-2.09.08"
|
||||||
|
"portaudio_v19"
|
||||||
|
"portaudio_v19_2"
|
||||||
|
"upx301w"
|
||||||
|
"upx303w"
|
||||||
|
"user-guide"
|
||||||
|
"zlib-1.2.5"
|
||||||
|
"zlib-1.2.8"
|
||||||
|
"AirPcap_Devpack_4_1_0_1622"
|
||||||
|
"GeoIP-1.5.1-*-win??ws"
|
||||||
|
"WinSparkle-0.3-44-g2c8d9d3-win??ws"
|
||||||
|
"WpdPack"
|
||||||
|
"current-tag.txt"
|
||||||
|
)
|
||||||
|
|
||||||
|
[Uri] $DownloadPrefix = "https://anonsvn.wireshark.org/wireshark-$($Platform)-libs/tags/$($CurrentTag)/packages"
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
|
||||||
|
function DownloadFile($fileName) {
|
||||||
|
[Uri] $fileUrl = "$DownloadPrefix/$fileName"
|
||||||
|
$destinationFile = "$fileName"
|
||||||
|
if ((Test-Path $destinationFile -PathType 'Leaf') -and -not ($Force)) {
|
||||||
|
Write-Output "$destinationFile already there; not retrieving."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Write-Output "Downloading $fileUrl into $Destination"
|
||||||
|
$webClient = New-Object System.Net.WebClient
|
||||||
|
$webClient.DownloadFile($fileUrl, "$Destination\$destinationFile")
|
||||||
|
}
|
||||||
|
|
||||||
|
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb787866.aspx
|
||||||
|
$CopyHereFlags = 4 + 16 + 512 + 1024
|
||||||
|
|
||||||
|
function DownloadArchive($fileName, $subDir) {
|
||||||
|
DownloadFile $fileName
|
||||||
|
$shell = New-Object -com shell.application
|
||||||
|
$archiveFile = "$Destination\$fileName"
|
||||||
|
$archiveDir = "$Destination\$subDir"
|
||||||
|
if ($subDir -and -not (Test-Path $archiveDir -PathType 'Container')) {
|
||||||
|
New-Item -ItemType Directory -Path $archiveDir > $null
|
||||||
|
}
|
||||||
|
$activity = "Extracting $archiveFile into $($archiveDir)"
|
||||||
|
foreach ($item in $shell.NameSpace($archiveFile).items()) {
|
||||||
|
Write-Progress -Activity "$activity" -Status "Working on $($item.Name)"
|
||||||
|
# XXX Folder.CopyHere is really slow.
|
||||||
|
$shell.NameSpace($archiveDir).CopyHere($item, $CopyHereFlags)
|
||||||
|
}
|
||||||
|
Write-Progress -Activity "$activity" -Status "Done" -Completed
|
||||||
|
}
|
||||||
|
|
||||||
|
# On with the show
|
||||||
|
|
||||||
|
# Make sure $Destination exists and do our work there.
|
||||||
|
if ( -not (Test-Path $Destination -PathType 'Container') ) {
|
||||||
|
New-Item -ItemType 'Container' "$Destination" > $null
|
||||||
|
}
|
||||||
|
|
||||||
|
# CMake's file TO_NATIVE_PATH passive-aggressively omits the drive letter.
|
||||||
|
Set-Location "$Destination"
|
||||||
|
$Destination = $(Get-Item -Path ".\")
|
||||||
|
Write-Output "Working in $Destination"
|
||||||
|
|
||||||
|
# Check our last known state
|
||||||
|
$destinationTag = "INVALID"
|
||||||
|
$tagFile = "current_tag.txt"
|
||||||
|
if ((Test-Path $tagFile -PathType 'Leaf') -and -not ($Force)) {
|
||||||
|
$destinationTag = Get-Content $tagFile
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($destinationTag -ne $CurrentTag) {
|
||||||
|
Write-Output "Tag $CurrentTag not found. Refreshing."
|
||||||
|
$activity = "Removing directories"
|
||||||
|
foreach ($oldItem in $CleanupItems) {
|
||||||
|
if (Test-Path $oldItem) {
|
||||||
|
Write-Progress -Activity "$activity" -Status "Removing $oldItem"
|
||||||
|
Remove-Item -force -recurse $oldItem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Progress -Activity "$activity" -Status "Done" -Completed
|
||||||
|
} else {
|
||||||
|
Write-Output "Tag $CurrentTag found. Skipping."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download files
|
||||||
|
foreach ($item in $Files) {
|
||||||
|
DownloadFile $item
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download and extract archives
|
||||||
|
foreach ($item in $Archives.GetEnumerator() | Sort-Object -property key) {
|
||||||
|
DownloadArchive $item.Name $item.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
# Save our last known state
|
||||||
|
Set-Content -Path $tagFile -Value "$CurrentTag"
|
Loading…
Reference in New Issue