From 7d0bcceaf028f28b0bc5ae666689f26d8de743a9 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 31 Oct 2017 17:06:07 -0700 Subject: [PATCH] [findVSInstances] Data lines are now placed within tags. Text outside these tags is ignored This means we can print text in powershell now and it won't break vcpkg. --- .../findAnyMSBuildWithCppPlatformToolset.ps1 | 2 +- .../findVisualStudioInstallationInstances.ps1 | 4 +-- toolsrc/src/vcpkg/vcpkgpaths.cpp | 25 ++++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 b/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 index 3269562dc8f..d9ffbd32a2a 100644 --- a/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 +++ b/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 @@ -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 "::" + $instanceCandidate = $instanceCandidateWithEOL -replace "::" -replace "::" Write-Verbose "Inspecting: $instanceCandidate" $split = $instanceCandidate -split "::" # $preferenceWeight = $split[0] diff --git a/scripts/findVisualStudioInstallationInstances.ps1 b/scripts/findVisualStudioInstallationInstances.ps1 index 566560cdb98..5470b57c001 100644 --- a/scripts/findVisualStudioInstallationInstances.ps1 +++ b/scripts/findVisualStudioInstallationInstances.ps1 @@ -29,7 +29,7 @@ foreach ($instance in $asXml.instances.instance) } # Placed like that for easy sorting according to preference - $results.Add("${releaseType}::${installationVersion}::${installationPath}::") > $null + $results.Add("::${releaseType}::${installationVersion}::${installationPath}::") > $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::" + return "::PreferenceWeight1::Legacy::14.0::$installationPath::" } } diff --git a/toolsrc/src/vcpkg/vcpkgpaths.cpp b/toolsrc/src/vcpkg/vcpkgpaths.cpp index c6a92f813ac..8b9e6c598b7 100644 --- a/toolsrc/src/vcpkg/vcpkgpaths.cpp +++ b/toolsrc/src/vcpkg/vcpkgpaths.cpp @@ -320,6 +320,23 @@ namespace vcpkg std::string major_version() const { return version.substr(0, 2); } }; + static std::vector keep_data_lines(const std::string& data_blob) + { + static const std::regex DATA_LINE_REGEX(R"(::(.+?)(?=::))"); + + std::vector 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 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 instances_as_strings = Strings::split(ec_data.output, "::"); - Checks::check_exit( - VCPKG_LINE_INFO, !instances_as_strings.empty(), "Could not detect any Visual Studio instances.\n"); + const std::vector 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 output; for (const std::string& instance_as_string : instances_as_strings)