mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-27 10:21:07 +08:00
allow tests to run on older standard libraries
This commit is contained in:
parent
c55ea0a0d5
commit
0d8bba52e4
@ -35,7 +35,7 @@ if(GCC OR CLANG)
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE VCPKGLIB_SOURCES src/vcpkg/*.cpp)
|
||||
file(GLOB_RECURSE VCPKGTEST_SOURCES src/vcpkg-tests/*.cpp)
|
||||
file(GLOB_RECURSE VCPKGTEST_SOURCES src/vcpkg-test/*.cpp)
|
||||
|
||||
if (DEFINE_DISABLE_METRICS)
|
||||
set(DISABLE_METRICS_VALUE "1")
|
||||
@ -95,3 +95,4 @@ endif()
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(vcpkg PRIVATE Threads::Threads)
|
||||
target_link_libraries(vcpkg-test PRIVATE Threads::Threads)
|
||||
|
@ -35,4 +35,8 @@ extern const bool SYMLINKS_ALLOWED;
|
||||
|
||||
extern const fs::path TEMPORARY_DIRECTORY;
|
||||
|
||||
void create_symlink(const fs::path& file, const fs::path& target, std::error_code& ec);
|
||||
|
||||
void create_directory_symlink(const fs::path& file, const fs::path& target, std::error_code& ec);
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
|
||||
#include <vcpkg/vcpkgcmdarguments.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
|
||||
#include <vcpkg/base/system.debug.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
|
||||
#include <vcpkg/base/chrono.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
|
||||
#include <vcpkg/sourceparagraph.h>
|
||||
|
@ -1,10 +1,9 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-tests/util.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
#include <vcpkg-test/util.h>
|
||||
|
||||
#include <vcpkg/base/files.h>
|
||||
#include <vcpkg/base/strings.h>
|
||||
|
||||
#include <filesystem> // required for filesystem::create_{directory_}symlink
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
@ -20,7 +19,7 @@ namespace
|
||||
std::mt19937_64 get_urbg(std::uint64_t index)
|
||||
{
|
||||
// smallest prime > 2**63 - 1
|
||||
return std::mt19937_64{index + 9223372036854775837};
|
||||
return std::mt19937_64{index + 9223372036854775837ULL};
|
||||
}
|
||||
|
||||
std::string get_random_filename(std::mt19937_64& urbg) { return vcpkg::Strings::b32_encode(uid{}(urbg)); }
|
||||
@ -83,16 +82,14 @@ namespace
|
||||
// regular symlink
|
||||
fs.write_contents(base, "", ec);
|
||||
REQUIRE_FALSE(ec);
|
||||
const std::filesystem::path basep = base.native();
|
||||
auto basep_link = basep;
|
||||
basep_link.replace_filename(basep.filename().native() + L"-link");
|
||||
std::filesystem::create_symlink(basep, basep_link, ec);
|
||||
auto base_link = base;
|
||||
base_link.replace_filename(base.filename().u8string() + "-link");
|
||||
vcpkg::Test::create_symlink(base, base_link, ec);
|
||||
}
|
||||
else // type == directory_symlink_tag
|
||||
{
|
||||
// directory symlink
|
||||
std::filesystem::path basep = base.native();
|
||||
std::filesystem::create_directory_symlink(basep / "..", basep, ec);
|
||||
vcpkg::Test::create_directory_symlink(base / "..", base, ec);
|
||||
}
|
||||
|
||||
REQUIRE_FALSE(ec);
|
@ -1,5 +1,5 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-tests/util.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
#include <vcpkg-test/util.h>
|
||||
|
||||
#include <vcpkg/base/strings.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-tests/util.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
#include <vcpkg-test/util.h>
|
||||
|
||||
#include <vcpkg/dependencies.h>
|
||||
#include <vcpkg/sourceparagraph.h>
|
@ -1,4 +1,4 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
|
||||
#include <vcpkg/base/util.h>
|
||||
#include <vcpkg/packagespec.h>
|
@ -1,5 +1,5 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-tests/util.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
#include <vcpkg-test/util.h>
|
||||
|
||||
#include <vcpkg/base/util.h>
|
||||
#include <vcpkg/paragraphs.h>
|
@ -1,4 +1,4 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
|
||||
#include <vcpkg/base/strings.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
|
||||
#include <vcpkg/sourceparagraph.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-tests/util.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
#include <vcpkg-test/util.h>
|
||||
|
||||
#include <vcpkg/base/sortedvector.h>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <vcpkg-tests/catch.h>
|
||||
#include <vcpkg-tests/util.h>
|
||||
#include <vcpkg-test/catch.h>
|
||||
#include <vcpkg-test/util.h>
|
||||
|
||||
#include <vcpkg/base/checks.h>
|
||||
#include <vcpkg/base/files.h>
|
||||
#include <vcpkg/statusparagraph.h>
|
||||
|
||||
@ -11,6 +12,18 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1914
|
||||
|
||||
#define USE_STD_FILESYSTEM
|
||||
|
||||
#include <filesystem> // required for filesystem::create_{directory_}symlink
|
||||
|
||||
#elif !defined(_MSC_VER)
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#endif
|
||||
|
||||
namespace vcpkg::Test
|
||||
{
|
||||
std::unique_ptr<vcpkg::StatusParagraph> make_status_pgh(const char* name,
|
||||
@ -51,9 +64,14 @@ namespace vcpkg::Test
|
||||
}
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
// I am so sorry for this awful mix of macros
|
||||
|
||||
static bool system_allows_symlinks() {
|
||||
#if defined(_WIN32)
|
||||
#if !defined(USE_STD_FILESYSTEM)
|
||||
return false;
|
||||
#else
|
||||
HKEY key;
|
||||
bool allow_symlinks = true;
|
||||
|
||||
@ -69,9 +87,14 @@ namespace vcpkg::Test
|
||||
if (status == ERROR_SUCCESS) RegCloseKey(key);
|
||||
|
||||
return allow_symlinks;
|
||||
#endif
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
static fs::path internal_temporary_directory() {
|
||||
#if defined(_WIN32)
|
||||
wchar_t* tmp = static_cast<wchar_t*>(std::calloc(32'767, 2));
|
||||
|
||||
if (!GetEnvironmentVariableW(L"TEMP", tmp, 32'767)) {
|
||||
@ -83,19 +106,53 @@ namespace vcpkg::Test
|
||||
std::free(tmp);
|
||||
|
||||
return result / L"vcpkg-test";
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
constexpr static bool system_allows_symlinks() {
|
||||
return true;
|
||||
}
|
||||
static fs::path internal_temporary_directory() {
|
||||
#else
|
||||
return "/tmp/vcpkg-test";
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const bool SYMLINKS_ALLOWED = system_allows_symlinks();
|
||||
const fs::path TEMPORARY_DIRECTORY = internal_temporary_directory();
|
||||
|
||||
void create_symlink(const fs::path& target, const fs::path& file, std::error_code& ec) {
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(USE_STD_FILESYSTEM)
|
||||
if (SYMLINKS_ALLOWED)
|
||||
{
|
||||
std::filesystem::path targetp = target.native();
|
||||
std::filesystem::path filep = file.native();
|
||||
|
||||
std::filesystem::create_symlink(targetp, filep);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, "Symlinks are not allowed on this system");
|
||||
}
|
||||
#else
|
||||
if(symlink(target.c_str(), file.c_str()) != 0) {
|
||||
ec.assign(errno, std::system_category());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void create_directory_symlink(const fs::path& target, const fs::path& file, std::error_code& ec) {
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(USE_STD_FILESYSTEM)
|
||||
if (SYMLINKS_ALLOWED)
|
||||
{
|
||||
std::filesystem::path targetp = target.native();
|
||||
std::filesystem::path filep = file.native();
|
||||
|
||||
std::filesystem::create_symlink(targetp, filep);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, "Symlinks are not allowed on this system");
|
||||
}
|
||||
#else
|
||||
::vcpkg::Test::create_symlink(target, file, ec);
|
||||
#endif
|
||||
}
|
||||
}
|
@ -21,8 +21,8 @@
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{34671B80-54F9-46F5-8310-AC429C11D4FB}</ProjectGuid>
|
||||
<RootNamespace>vcpkg</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
@ -147,4 +147,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -21,8 +21,8 @@
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{B98C92B7-2874-4537-9D46-D14E5C237F04}</ProjectGuid>
|
||||
<RootNamespace>vcpkglib</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
@ -274,4 +274,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -21,8 +21,8 @@
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{7D6FDEEB-B299-4A23-85EE-F67C4DED47BE}</ProjectGuid>
|
||||
<RootNamespace>vcpkgmetricsuploader</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
@ -144,4 +144,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -46,8 +46,8 @@
|
||||
<ProjectGuid>{F27B8DB0-1279-4AF8-A2E3-1D49C4F0220D}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>vcpkgtest</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
|
Loading…
x
Reference in New Issue
Block a user