Rename "depenencies" to tools. Rework xml file to reduce fields.

This commit is contained in:
Alexander Karatarakis 2018-02-23 16:34:31 -08:00
parent f0cee21f7a
commit 4077678583
7 changed files with 128 additions and 144 deletions

View File

@ -14,9 +14,9 @@ $gitHash = "unknownhash"
$oldpath = $env:path
try
{
[xml]$asXml = Get-Content "$scriptsDir\vcpkgDependencies.xml"
$dependencyData = $asXml.SelectSingleNode("//dependencies/dependency[@name=`"git`"]")
$postExtractionExecutableRelativePath = $dependencyData.postExtractionExecutableRelativePath
[xml]$asXml = Get-Content "$scriptsDir\vcpkgTools.xml"
$toolData = $asXml.SelectSingleNode("//tools/tool[@name=`"git`"]")
$postExtractionExecutableRelativePath = $toolData.postExtractionExecutableRelativePath
$gitFromDownload = "$vcpkgRootDir\downloads\$postExtractionExecutableRelativePath"
$gitDir = split-path -parent $gitFromDownload

View File

@ -1,76 +0,0 @@
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$dependency
)
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
. "$scriptsDir\VcpkgPowershellUtils.ps1"
Write-Verbose "Fetching dependency: $dependency"
$vcpkgRootDir = vcpkgFindFileRecursivelyUp $scriptsDir .vcpkg-root
$downloadsDir = "$vcpkgRootDir\downloads"
function fetchDependencyInternal([Parameter(Mandatory=$true)][string]$dependency)
{
$dependency = $dependency.toLower()
[xml]$asXml = Get-Content "$scriptsDir\vcpkgDependencies.xml"
$dependencyData = $asXml.SelectSingleNode("//dependencies/dependency[@name=`"$dependency`"]") # Case-sensitive!
if ($dependencyData -eq $null)
{
throw "Unkown dependency $dependency"
}
$requiredVersion = $dependencyData.requiredVersion
$downloadVersion = $dependencyData.downloadVersion
$url = $dependencyData.x86url
$downloadRelativePath = $dependencyData.downloadRelativePath
$downloadPath = "$downloadsDir\$downloadRelativePath"
$expectedDownloadedFileHash = $dependencyData.sha256
$extension = $dependencyData.extension
if (!(Test-Path $downloadPath))
{
Write-Host "Downloading $dependency..."
vcpkgDownloadFile $url $downloadPath
Write-Host "Downloading $dependency has completed successfully."
}
$downloadedFileHash = vcpkgGetSHA256 $downloadPath
vcpkgCheckEqualFileHash -filePath $downloadPath -expectedHash $expectedDownloadedFileHash -actualHash $downloadedFileHash
if ($extension -eq "exe")
{
$executableFromDownload = $downloadPath
}
elseif ($extension -eq "zip")
{
$postExtractionExecutableRelativePath = $dependencyData.postExtractionExecutableRelativePath
$executableFromDownload = "$downloadsDir\$postExtractionExecutableRelativePath"
if (-not (Test-Path $executableFromDownload))
{
$outFilename = (Get-ChildItem $downloadPath).BaseName
Write-Host "Extracting $dependency..."
vcpkgExtractFile -File $downloadPath -DestinationDir $downloadsDir -outFilename $outFilename
Write-Host "Extracting $dependency has completed successfully."
}
}
else
{
throw "Unexpected file type"
}
if (-not (Test-Path $executableFromDownload))
{
throw ("Could not detect or download " + $dependency)
}
return $executableFromDownload
}
$path = fetchDependencyInternal $dependency
Write-Verbose "Fetching dependency: $dependency. Done."
return "<sol>::$path::<eol>"

73
scripts/fetchTool.ps1 Normal file
View File

@ -0,0 +1,73 @@
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$tool
)
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
. "$scriptsDir\VcpkgPowershellUtils.ps1"
Write-Verbose "Fetching tool: $tool"
$vcpkgRootDir = vcpkgFindFileRecursivelyUp $scriptsDir .vcpkg-root
$downloadsDir = "$vcpkgRootDir\downloads"
vcpkgCreateDirectoryIfNotExists $downloadsDir
function fetchToolInternal([Parameter(Mandatory=$true)][string]$tool)
{
$tool = $tool.toLower()
[xml]$asXml = Get-Content "$scriptsDir\vcpkgTools.xml"
$toolData = $asXml.SelectSingleNode("//tools/tool[@name=`"$tool`"]") # Case-sensitive!
if ($toolData -eq $null)
{
throw "Unkown tool $tool"
}
$exePath = "$downloadsDir\$($toolData.exeRelativePath)"
if (Test-Path $exePath)
{
return $exePath
}
if ($toolData.archiveRelativePath)
{
$downloadPath = "$downloadsDir\$($toolData.archiveRelativePath)"
}
else
{
$downloadPath = "$downloadsDir\$($toolData.exeRelativePath)"
}
$url = $toolData.url
if (!(Test-Path $downloadPath))
{
Write-Host "Downloading $tool..."
vcpkgDownloadFile $url $downloadPath
Write-Host "Downloading $tool has completed successfully."
}
$expectedDownloadedFileHash = $toolData.sha256
$downloadedFileHash = vcpkgGetSHA256 $downloadPath
vcpkgCheckEqualFileHash -filePath $downloadPath -expectedHash $expectedDownloadedFileHash -actualHash $downloadedFileHash
if ($toolData.archiveRelativePath)
{
$outFilename = (Get-ChildItem $downloadPath).BaseName
Write-Host "Extracting $tool..."
vcpkgExtractFile -File $downloadPath -DestinationDir $downloadsDir -outFilename $outFilename
Write-Host "Extracting $tool has completed successfully."
}
if (-not (Test-Path $exePath))
{
throw ("Could not detect or download " + $tool)
}
return $exePath
}
$path = fetchToolInternal $tool
Write-Verbose "Fetching tool: $tool. Done."
return "<sol>::$path::<eol>"

View File

@ -4,7 +4,7 @@ param(
)
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
$vswhereExe = (& $scriptsDir\fetchDependency.ps1 "vswhere") -replace "<sol>::" -replace "::<eol>"
$vswhereExe = (& $scriptsDir\fetchTool.ps1 "vswhere") -replace "<sol>::" -replace "::<eol>"
$output = & $vswhereExe -prerelease -legacy -products * -format xml
[xml]$asXml = $output

View File

@ -1,48 +0,0 @@
<?xml version="1.0"?>
<dependencies>
<dependency name="cmake">
<requiredVersion>3.10.2</requiredVersion>
<downloadVersion>3.10.2</downloadVersion>
<x86url>https://cmake.org/files/v3.10/cmake-3.10.2-win32-x86.zip</x86url>
<downloadRelativePath>cmake-3.10.2-win32-x86.zip</downloadRelativePath>
<sha256>f5f7e41a21d0e9b655aca58498b08e17ecd27796bf82837e2c84435359169dd6</sha256>
<extension>zip</extension>
<postExtractionExecutableRelativePath>cmake-3.10.2-win32-x86\bin\cmake.exe</postExtractionExecutableRelativePath>
</dependency>
<dependency name="git">
<requiredVersion>2.16.2</requiredVersion>
<downloadVersion>2.16.2</downloadVersion>
<x86url>https://github.com/git-for-windows/git/releases/download/v2.16.2.windows.1/MinGit-2.16.2-32-bit.zip</x86url>
<downloadRelativePath>MinGit-2.16.2-32-bit.zip</downloadRelativePath>
<sha256>322c727e482aa97522c64a5ac68bdda3780111e8670bcfb532beac8e11ece5da</sha256>
<extension>zip</extension>
<!--There is another copy of git.exe in MinGit\bin. However, an installed version of git add the cmd dir to the PATH.
Therefore, choosing the cmd dir here as well.-->
<postExtractionExecutableRelativePath>MinGit-2.16.2-32-bit\cmd\git.exe</postExtractionExecutableRelativePath>
</dependency>
<dependency name="vswhere">
<requiredVersion>2.3.2</requiredVersion>
<downloadVersion>2.3.2</downloadVersion>
<x86url>https://github.com/Microsoft/vswhere/releases/download/2.3.2/vswhere.exe</x86url>
<downloadRelativePath>vswhere-2.3.2\vswhere.exe</downloadRelativePath>
<sha256>103f2784c4b2c8e70c7c1c03687abbf22bce052aae30639406e4e13ffa29ee04</sha256>
<extension>exe</extension>
</dependency>
<dependency name="nuget">
<requiredVersion>4.4.0</requiredVersion>
<downloadVersion>4.4.0</downloadVersion>
<x86url>https://dist.nuget.org/win-x86-commandline/v4.4.0/nuget.exe</x86url>
<downloadRelativePath>nuget-4.4.0\nuget.exe</downloadRelativePath>
<sha256>2cf9b118937eef825464e548f0c44f7f64090047746de295d75ac3dcffa3e1f6</sha256>
<extension>exe</extension>
</dependency>
<dependency name="installerbase">
<requiredVersion>3.1.81</requiredVersion>
<downloadVersion>3.1.81</downloadVersion>
<x86url>https://github.com/podsvirov/installer-framework/releases/download/cr203958-9/QtInstallerFramework-win-x86.zip</x86url>
<downloadRelativePath>QtInstallerFramework-win-x86.zip</downloadRelativePath>
<sha256>f2ce23cf5cf9fc7ce409bdca49328e09a070c0026d3c8a04e4dfde7b05b83fe8</sha256>
<extension>zip</extension>
<postExtractionExecutableRelativePath>QtInstallerFramework-win-x86\bin\installerbase.exe</postExtractionExecutableRelativePath>
</dependency>
</dependencies>

36
scripts/vcpkgTools.xml Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0"?>
<tools version="1">
<tool name="cmake">
<requiredVersion>3.10.2</requiredVersion>
<exeRelativePath>cmake-3.10.2-win32-x86\bin\cmake.exe</exeRelativePath>
<url>https://cmake.org/files/v3.10/cmake-3.10.2-win32-x86.zip</url>
<sha256>f5f7e41a21d0e9b655aca58498b08e17ecd27796bf82837e2c84435359169dd6</sha256>
<archiveRelativePath>cmake-3.10.2-win32-x86.zip</archiveRelativePath>
</tool>
<tool name="git">
<requiredVersion>2.16.2</requiredVersion>
<exeRelativePath>MinGit-2.16.2-32-bit\cmd\git.exe</exeRelativePath>
<url>https://github.com/git-for-windows/git/releases/download/v2.16.2.windows.1/MinGit-2.16.2-32-bit.zip</url>
<sha256>322c727e482aa97522c64a5ac68bdda3780111e8670bcfb532beac8e11ece5da</sha256>
<archiveRelativePath>MinGit-2.16.2-32-bit.zip</archiveRelativePath>
</tool>
<tool name="vswhere">
<requiredVersion>2.3.2</requiredVersion>
<exeRelativePath>vswhere-2.3.2\vswhere.exe</exeRelativePath>
<url>https://github.com/Microsoft/vswhere/releases/download/2.3.2/vswhere.exe</url>
<sha256>103f2784c4b2c8e70c7c1c03687abbf22bce052aae30639406e4e13ffa29ee04</sha256>
</tool>
<tool name="nuget">
<requiredVersion>4.4.0</requiredVersion>
<exeRelativePath>nuget-4.4.0\nuget.exe</exeRelativePath>
<url>https://dist.nuget.org/win-x86-commandline/v4.4.0/nuget.exe</url>
<sha256>2cf9b118937eef825464e548f0c44f7f64090047746de295d75ac3dcffa3e1f6</sha256>
</tool>
<tool name="installerbase">
<requiredVersion>3.1.81</requiredVersion>
<exeRelativePath>QtInstallerFramework-win-x86\bin\installerbase.exe</exeRelativePath>
<url>https://github.com/podsvirov/installer-framework/releases/download/cr203958-9/QtInstallerFramework-win-x86.zip</url>
<sha256>f2ce23cf5cf9fc7ce409bdca49328e09a070c0026d3c8a04e4dfde7b05b83fe8</sha256>
<archiveRelativePath>QtInstallerFramework-win-x86.zip</archiveRelativePath>
</tool>
</tools>

View File

@ -80,10 +80,10 @@ namespace vcpkg
return data_lines;
}
static fs::path fetch_dependency(const fs::path& scripts_folder,
const std::string& tool_name,
const fs::path& expected_downloaded_path,
const std::array<int, 3>& version)
static fs::path fetch_tool(const fs::path& scripts_folder,
const std::string& tool_name,
const fs::path& expected_downloaded_path,
const std::array<int, 3>& version)
{
const std::string version_as_string = Strings::format("%d.%d.%d", version[0], version[1], version[2]);
System::println("A suitable version of %s was not found (required v%s). Downloading portable %s v%s...",
@ -91,22 +91,21 @@ namespace vcpkg
version_as_string,
tool_name,
version_as_string);
const fs::path script = scripts_folder / "fetchDependency.ps1";
const fs::path script = scripts_folder / "fetchtool.ps1";
const std::string title = Strings::format(
"Fetching %s version %s (No sufficient installed version was found)", tool_name, version_as_string);
const System::PowershellParameter dependency_param("Dependency", tool_name);
const std::string output = System::powershell_execute_and_capture_output(title, script, {dependency_param});
const System::PowershellParameter tool_param("tool", tool_name);
const std::string output = System::powershell_execute_and_capture_output(title, script, {tool_param});
const std::vector<std::string> dependency_path = keep_data_lines(output);
Checks::check_exit(
VCPKG_LINE_INFO, dependency_path.size() == 1, "Expected dependency path, but got %s", output);
const std::vector<std::string> tool_path = keep_data_lines(output);
Checks::check_exit(VCPKG_LINE_INFO, tool_path.size() == 1, "Expected tool path, but got %s", output);
const fs::path actual_downloaded_path = Strings::trim(std::string{dependency_path.at(0)});
const fs::path actual_downloaded_path = Strings::trim(std::string{tool_path.at(0)});
std::error_code ec;
const auto eq = fs::stdfs::equivalent(expected_downloaded_path, actual_downloaded_path, ec);
Checks::check_exit(VCPKG_LINE_INFO,
eq && !ec,
"Expected dependency downloaded path to be %s, but was %s",
"Expected tool downloaded path to be %s, but was %s",
expected_downloaded_path.u8string(),
actual_downloaded_path.u8string());
return actual_downloaded_path;
@ -141,7 +140,7 @@ namespace vcpkg
return *p;
}
return fetch_dependency(scripts_folder, "cmake", downloaded_copy, EXPECTED_VERSION);
return fetch_tool(scripts_folder, "cmake", downloaded_copy, EXPECTED_VERSION);
}
fs::path get_nuget_path(const fs::path& downloads_folder, const fs::path& scripts_folder)
@ -161,7 +160,7 @@ namespace vcpkg
return *p;
}
return fetch_dependency(scripts_folder, "nuget", downloaded_copy, EXPECTED_VERSION);
return fetch_tool(scripts_folder, "nuget", downloaded_copy, EXPECTED_VERSION);
}
fs::path get_git_path(const fs::path& downloads_folder, const fs::path& scripts_folder)
@ -193,7 +192,7 @@ namespace vcpkg
return *p;
}
return fetch_dependency(scripts_folder, "git", downloaded_copy, EXPECTED_VERSION);
return fetch_tool(scripts_folder, "git", downloaded_copy, EXPECTED_VERSION);
}
static fs::path get_ifw_installerbase_path(const fs::path& downloads_folder, const fs::path& scripts_folder)
@ -221,7 +220,7 @@ namespace vcpkg
return *p;
}
return fetch_dependency(scripts_folder, "installerbase", downloaded_copy, EXPECTED_VERSION);
return fetch_tool(scripts_folder, "installerbase", downloaded_copy, EXPECTED_VERSION);
}
Expected<VcpkgPaths> VcpkgPaths::create(const fs::path& vcpkg_root_dir)