[findVSInstances] Data lines are now placed within <sol><eol> tags. Text outside these tags is ignored

This means we can print text in powershell now and it won't break vcpkg.
This commit is contained in:
Alexander Karatarakis 2017-10-31 17:06:07 -07:00
parent eb7e1e481b
commit 7d0bcceaf0
3 changed files with 25 additions and 6 deletions

View File

@ -11,7 +11,7 @@ $VisualStudioInstallationInstances = & $scriptsDir\findVisualStudioInstallationI
Write-Verbose "VS Candidates:`n`r$([system.String]::Join([Environment]::NewLine, $VisualStudioInstallationInstances))"
foreach ($instanceCandidateWithEOL in $VisualStudioInstallationInstances)
{
$instanceCandidate = $instanceCandidateWithEOL -replace "::<eol>"
$instanceCandidate = $instanceCandidateWithEOL -replace "<sol>::" -replace "::<eol>"
Write-Verbose "Inspecting: $instanceCandidate"
$split = $instanceCandidate -split "::"
# $preferenceWeight = $split[0]

View File

@ -29,7 +29,7 @@ foreach ($instance in $asXml.instances.instance)
}
# Placed like that for easy sorting according to preference
$results.Add("${releaseType}::${installationVersion}::${installationPath}::<eol>") > $null
$results.Add("<sol>::${releaseType}::${installationVersion}::${installationPath}::<eol>") > $null
}
# If nothing is found, attempt to find VS2015 Build Tools (not detected by vswhere.exe)
@ -42,7 +42,7 @@ if ($results.Count -eq 0)
if ((Test-Path $clExe) -And (Test-Path $vcvarsallbat))
{
return "PreferenceWeight1::Legacy::14.0::$installationPath::<eol>"
return "<sol>::PreferenceWeight1::Legacy::14.0::$installationPath::<eol>"
}
}

View File

@ -320,6 +320,23 @@ namespace vcpkg
std::string major_version() const { return version.substr(0, 2); }
};
static std::vector<std::string> keep_data_lines(const std::string& data_blob)
{
static const std::regex DATA_LINE_REGEX(R"(<sol>::(.+?)(?=::<eol>))");
std::vector<std::string> data_lines;
const std::sregex_iterator it(data_blob.cbegin(), data_blob.cend(), DATA_LINE_REGEX);
const std::sregex_iterator end;
for (std::sregex_iterator i = it; i != end; ++i)
{
const std::smatch match = *i;
data_lines.push_back(match[1].str());
}
return data_lines;
}
static std::vector<VisualStudioInstance> get_visual_studio_instances(const VcpkgPaths& paths)
{
const fs::path script = paths.scripts / "findVisualStudioInstallationInstances.ps1";
@ -327,9 +344,11 @@ namespace vcpkg
Checks::check_exit(
VCPKG_LINE_INFO, ec_data.exit_code == 0, "Could not run script to detect Visual Studio instances");
const std::vector<std::string> instances_as_strings = Strings::split(ec_data.output, "::<eol>");
Checks::check_exit(
VCPKG_LINE_INFO, !instances_as_strings.empty(), "Could not detect any Visual Studio instances.\n");
const std::vector<std::string> instances_as_strings = keep_data_lines(ec_data.output);
Checks::check_exit(VCPKG_LINE_INFO,
!instances_as_strings.empty(),
"Could not detect any Visual Studio instances. Powershell returned: %s\n",
ec_data.output);
std::vector<VisualStudioInstance> output;
for (const std::string& instance_as_string : instances_as_strings)