aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authornicole mazzuca <mazzucan@outlook.com>2020-04-14 22:08:50 -0700
committerGitHub <noreply@github.com>2020-04-14 22:08:50 -0700
commit22623e35016cae6061e0d9e502577077b3c33fd9 (patch)
tree0a8cc4e43fd871bacb3010e9ff06b21dba4e800d /toolsrc/src
parent1e19af09e53e5f306ed89c2033817a21e5ee0bcf (diff)
downloadvcpkg-22623e35016cae6061e0d9e502577077b3c33fd9.tar.gz
vcpkg-22623e35016cae6061e0d9e502577077b3c33fd9.zip
[vcpkg] Clean up CMake build system (#10834)
There are quite a few changes to the CMake build system packaged up into one set here: * Added `toolsrc/cmake/utilities.cmake`, which contains the following: * `vcpkg_detect_compiler` -- get the name of the C++ compiler, as one of {gcc, clang, msvc} * `vcpkg_detect_standard_library` -- get the name of the standard library we're linking to, as one of {libstdc++, libc++, msvc-stl} * `vcpkg_detect_std_filesystem` -- figure out how to link and call into C++17's filesystem; whether one needs to link to `stdc++fs` or `c++fs`, and whether to use `<filesystem>` or `<experimental/filesystem>`. * Added a `VCPKG_WARNINGS_AS_ERRORS`, split off from `VCPKG_DEVELOPMENT_WARNINGS`, which allows one to use the development warnings without passing -Werror * Rename `DEFINE_DISABLE_METRICS` to `VCPKG_DISABLE_METRICS` -- the former will now print a deprecation message and set the latter. * Now, print a deprecation message on `WERROR`; it doesn't do anything since the behavior it requested is now the default. * Pass `-std=c++17` if the compiler allows it, instead of `-std=c++1z` * Do some code movement * Pass `USE_STD_FILESYSTEM` if possible, instead of only on minGW * Renamed to `VCPKG_USE_STD_FILESYSTEM` Additionally, we now pass `/W4` in Debug mode on x86 in the Visual Studio build system; this brings it in line with the CMake build system, and the x64 Visual Studio build system. And finally, we make some minor code changes to support compiling in VCPKG_DEVELOPMENT_WARNINGS mode.
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/vcpkg-test/paragraph.cpp4
-rw-r--r--toolsrc/src/vcpkg-test/system.cpp20
-rw-r--r--toolsrc/src/vcpkg/base/hash.cpp15
-rw-r--r--toolsrc/src/vcpkg/base/system.process.cpp2
-rw-r--r--toolsrc/src/vcpkg/build.cpp5
-rw-r--r--toolsrc/src/vcpkg/export.cpp7
-rw-r--r--toolsrc/src/vcpkg/export.prefab.cpp40
-rw-r--r--toolsrc/src/vcpkg/install.cpp2
-rw-r--r--toolsrc/src/vcpkg/metrics.cpp4
-rw-r--r--toolsrc/src/vcpkg/postbuildlint.cpp4
10 files changed, 59 insertions, 44 deletions
diff --git a/toolsrc/src/vcpkg-test/paragraph.cpp b/toolsrc/src/vcpkg-test/paragraph.cpp
index ba929ac56..678064f1c 100644
--- a/toolsrc/src/vcpkg-test/paragraph.cpp
+++ b/toolsrc/src/vcpkg-test/paragraph.cpp
@@ -8,6 +8,8 @@
namespace Strings = vcpkg::Strings;
using vcpkg::Parse::Paragraph;
+namespace {
+
auto test_parse_control_file(const std::vector<std::unordered_map<std::string, std::string>>& v)
{
std::vector<Paragraph> pghs;
@@ -29,6 +31,8 @@ auto test_make_binary_paragraph(const std::unordered_map<std::string, std::strin
return vcpkg::BinaryParagraph(std::move(pgh));
}
+}
+
TEST_CASE ("SourceParagraph construct minimum", "[paragraph]")
{
auto m_pgh = test_parse_control_file({{
diff --git a/toolsrc/src/vcpkg-test/system.cpp b/toolsrc/src/vcpkg-test/system.cpp
index 41e27fe6d..70424f0b5 100644
--- a/toolsrc/src/vcpkg-test/system.cpp
+++ b/toolsrc/src/vcpkg-test/system.cpp
@@ -1,6 +1,5 @@
#include <catch2/catch.hpp>
-#include <Windows.h>
#include <string>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/stringview.h>
@@ -8,6 +7,14 @@
#include <vcpkg/base/strings.h>
#include <vcpkg/base/system.h>
+#if defined(_WIN32)
+#define _NOMINMAX
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#else
+#include <stdlib.h>
+#endif
+
using vcpkg::Optional;
using vcpkg::StringView;
using vcpkg::ZStringView;
@@ -39,16 +46,17 @@ namespace
check_exit(VCPKG_LINE_INFO, exit_code != 0);
#else // ^^^ defined(_WIN32) / !defined(_WIN32) vvv
std::string tmp;
- tmp.reserve(varname.size() + value.size() + 1);
tmp.append(varname.data(), varname.size());
tmp.push_back('=');
- if (value)
+ if (auto v = value.get())
{
- const auto& unpacked = value.value_or_exit(VCPKG_LINE_INFO);
- tmp.append(unpacked);
+ tmp.append(*v);
}
- const int exit_code = putenv(tmp.c_str());
+ // putenv expects the string to never go out of scope
+ char* env_string = new char[tmp.size() + 1]; // overflow checked by tmp's null allocation
+ memcpy(env_string, tmp.data(), tmp.size());
+ const int exit_code = putenv(env_string);
check_exit(VCPKG_LINE_INFO, exit_code == 0);
#endif // defined(_WIN32)
}
diff --git a/toolsrc/src/vcpkg/base/hash.cpp b/toolsrc/src/vcpkg/base/hash.cpp
index b54f0c40c..45ce43cdd 100644
--- a/toolsrc/src/vcpkg/base/hash.cpp
+++ b/toolsrc/src/vcpkg/base/hash.cpp
@@ -51,13 +51,14 @@ namespace vcpkg::Hash
}
}
- template<class T>
- void top_bits(T) = delete;
-
- [[maybe_unused]] static uchar top_bits(uchar x) noexcept { return x; }
- [[maybe_unused]] static uchar top_bits(std::uint32_t x) noexcept { return (x >> 24) & 0xFF; }
- [[maybe_unused]] static uchar top_bits(std::uint64_t x) noexcept { return (x >> 56) & 0xFF; }
- [[maybe_unused]] static uchar top_bits(UInt128 x) noexcept { return top_bits(x.top_64_bits()); }
+ template <class UIntTy>
+ auto top_bits(UIntTy x) -> std::enable_if_t<std::is_unsigned<UIntTy>::value, uchar> {
+ return static_cast<uchar>(x >> ((sizeof(x) - 1) * 8));
+ }
+ template <class UIntTy>
+ auto top_bits(UIntTy x) -> decltype(top_bits(x.top_64_bits())) {
+ return top_bits(x.top_64_bits());
+ }
// treats UIntTy as big endian for the purpose of this mapping
template<class UIntTy>
diff --git a/toolsrc/src/vcpkg/base/system.process.cpp b/toolsrc/src/vcpkg/base/system.process.cpp
index 5f34ace2a..2bb61455e 100644
--- a/toolsrc/src/vcpkg/base/system.process.cpp
+++ b/toolsrc/src/vcpkg/base/system.process.cpp
@@ -532,6 +532,7 @@ namespace vcpkg
Debug::print(
"cmd_execute() returned ", exit_code, " after ", static_cast<unsigned int>(timer.microseconds()), " us\n");
#else
+ (void)env;
Debug::print("system(", cmd_line, ")\n");
fflush(nullptr);
int exit_code = system(cmd_line.c_str());
@@ -587,6 +588,7 @@ namespace vcpkg
}();
g_ctrl_c_state.transition_from_spawn_process();
#else
+ (void)env;
const auto actual_cmd_line = Strings::format(R"###(%s 2>&1)###", cmd_line);
Debug::print("popen(", actual_cmd_line, ")\n");
diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp
index e4c7667d5..fe17c490a 100644
--- a/toolsrc/src/vcpkg/build.cpp
+++ b/toolsrc/src/vcpkg/build.cpp
@@ -255,6 +255,7 @@ namespace vcpkg::Build
}));
}
+#if defined(_WIN32)
static const std::unordered_map<std::string, std::string>& make_env_passthrough(const PreBuildInfo& pre_build_info)
{
static Cache<std::vector<std::string>, std::unordered_map<std::string, std::string>> envs;
@@ -274,6 +275,7 @@ namespace vcpkg::Build
return env;
});
}
+#endif
std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset)
{
@@ -824,7 +826,6 @@ namespace vcpkg::Build
auto binary_caching_enabled = binaries_provider && action.build_options.binary_caching == BinaryCaching::YES;
auto& fs = paths.get_filesystem();
- Triplet triplet = action.spec.triplet();
auto& spec = action.spec;
const std::string& name = action.source_control_file_location.value_or_exit(VCPKG_LINE_INFO)
.source_control_file->core_paragraph->name;
@@ -1056,7 +1057,7 @@ namespace vcpkg::Build
public_abi_override = variable_value.empty() ? nullopt : Optional<std::string>{variable_value};
break;
case VcpkgTripletVar::LOAD_VCVARS_ENV:
- if (variable_value.empty())
+ if (variable_value.empty())
{
load_vcvars_env = true;
if(external_toolchain_file)
diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp
index f6226ead6..b41d88dc1 100644
--- a/toolsrc/src/vcpkg/export.cpp
+++ b/toolsrc/src/vcpkg/export.cpp
@@ -197,7 +197,6 @@ namespace vcpkg::Export
{
constexpr const ArchiveFormat ZIP(ArchiveFormat::BackingEnum::ZIP, "zip", "zip");
constexpr const ArchiveFormat SEVEN_ZIP(ArchiveFormat::BackingEnum::SEVEN_ZIP, "7z", "7zip");
- constexpr const ArchiveFormat AAR(ArchiveFormat::BackingEnum::ZIP, "aar", "zip");
}
static fs::path do_archive_export(const VcpkgPaths& paths,
@@ -297,7 +296,7 @@ namespace vcpkg::Export
static constexpr StringLiteral OPTION_CHOCOLATEY_MAINTAINER = "--x-maintainer";
static constexpr StringLiteral OPTION_CHOCOLATEY_VERSION_SUFFIX = "--x-version-suffix";
static constexpr StringLiteral OPTION_ALL_INSTALLED = "--x-all-installed";
-
+
static constexpr StringLiteral OPTION_PREFAB = "--prefab";
static constexpr StringLiteral OPTION_PREFAB_GROUP_ID = "--prefab-group-id";
static constexpr StringLiteral OPTION_PREFAB_ARTIFACT_ID = "--prefab-artifact-id";
@@ -306,7 +305,7 @@ namespace vcpkg::Export
static constexpr StringLiteral OPTION_PREFAB_SDK_TARGET_VERSION = "--prefab-target-sdk";
static constexpr StringLiteral OPTION_PREFAB_ENABLE_MAVEN = "--prefab-maven";
static constexpr StringLiteral OPTION_PREFAB_ENABLE_DEBUG = "--prefab-debug";
-
+
@@ -444,7 +443,7 @@ namespace vcpkg::Export
{OPTION_IFW_CONFIG_FILE_PATH, ret.ifw_options.maybe_config_file_path},
{OPTION_IFW_INSTALLER_FILE_PATH, ret.ifw_options.maybe_installer_file_path},
});
-
+
options_implies(OPTION_PREFAB,
ret.prefab,
{
diff --git a/toolsrc/src/vcpkg/export.prefab.cpp b/toolsrc/src/vcpkg/export.prefab.cpp
index 57b7ea99d..9a3f240fa 100644
--- a/toolsrc/src/vcpkg/export.prefab.cpp
+++ b/toolsrc/src/vcpkg/export.prefab.cpp
@@ -18,9 +18,9 @@ namespace vcpkg::Export::Prefab
using Install::InstallDir;
using System::CPUArchitecture;
-
- std::vector<fs::path> find_modules(const VcpkgPaths& system, const fs::path& root, const std::string& ext)
+
+ static std::vector<fs::path> find_modules(const VcpkgPaths& system, const fs::path& root, const std::string& ext)
{
std::vector<fs::path> paths;
Files::Filesystem& utils = system.get_filesystem();
@@ -58,7 +58,7 @@ namespace vcpkg::Export::Prefab
.append("}");
}
- std::string jsonify(const std::vector<std::string>& dependencies)
+ static std::string jsonify(const std::vector<std::string>& dependencies)
{
std::vector<std::string> deps;
for (const auto& dep : dependencies)
@@ -68,7 +68,7 @@ namespace vcpkg::Export::Prefab
return Strings::join(",", deps);
}
- std::string null_if_empty(const std::string& str)
+ static std::string null_if_empty(const std::string& str)
{
std::string copy = str;
if (copy.size() == 0)
@@ -82,7 +82,7 @@ namespace vcpkg::Export::Prefab
return copy;
}
- std::string null_if_empty_array(const std::string& str)
+ static std::string null_if_empty_array(const std::string& str)
{
std::string copy = str;
if (copy.size() == 0)
@@ -218,7 +218,7 @@ namespace vcpkg::Export::Prefab
#endif
}
- void maven_install(const fs::path& aar, const fs::path& pom, const Options& prefab_options)
+ static void maven_install(const fs::path& aar, const fs::path& pom, const Options& prefab_options)
{
if(prefab_options.enable_debug){
System::print2("\n[DEBUG] Installing POM and AAR file to ~/.m2\n\n");
@@ -234,7 +234,7 @@ namespace vcpkg::Export::Prefab
Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Error: %s installing maven file", aar.generic_u8string());
}
- Build::PreBuildInfo build_info_from_triplet(const VcpkgPaths& paths,
+ static Build::PreBuildInfo build_info_from_triplet(const VcpkgPaths& paths,
const std::unique_ptr<CMakeVars::CMakeVarProvider>& provider,
const Triplet& triplet)
{
@@ -244,7 +244,7 @@ namespace vcpkg::Export::Prefab
return pre_build_info;
}
- bool is_supported(const Build::PreBuildInfo& info)
+ static bool is_supported(const Build::PreBuildInfo& info)
{
return Strings::case_insensitive_ascii_equals(info.cmake_system_name, "android");
}
@@ -271,7 +271,7 @@ namespace vcpkg::Export::Prefab
{CPUArchitecture::ARM, 16},
{CPUArchitecture::X64, 21},
{CPUArchitecture::X86, 16}};
-
+
std::vector<Triplet> triplets;
std::unordered_map<Triplet, std::string> triplet_abi_map;
@@ -280,9 +280,9 @@ namespace vcpkg::Export::Prefab
for (auto& triplet_file : available_triplets){
if (triplet_file.name.size() > 0){
Triplet triplet = Triplet::from_canonical_name(std::move(triplet_file.name));
- auto build_info = build_info_from_triplet(paths, provider, triplet);
- if (is_supported(build_info)){
- auto cpu_architecture =System::to_cpu_architecture(build_info.target_architecture).value_or_exit(VCPKG_LINE_INFO);
+ auto triplet_build_info = build_info_from_triplet(paths, provider, triplet);
+ if (is_supported(triplet_build_info)){
+ auto cpu_architecture = System::to_cpu_architecture(triplet_build_info.target_architecture).value_or_exit(VCPKG_LINE_INFO);
auto required_arch = required_archs.find(cpu_architecture);
if (required_arch != required_archs.end()){
triplets.push_back(triplet);
@@ -378,8 +378,8 @@ namespace vcpkg::Export::Prefab
const std::string name = action.spec.name();
auto dependencies = action.dependencies(default_triplet);
- const auto build_info = Build::read_build_info(utils, paths.build_info_file_path(action.spec));
- const bool is_empty_package = build_info.policies.is_enabled(Build::BuildPolicy::EMPTY_PACKAGE);
+ const auto action_build_info = Build::read_build_info(utils, paths.build_info_file_path(action.spec));
+ const bool is_empty_package = action_build_info.policies.is_enabled(Build::BuildPolicy::EMPTY_PACKAGE);
if(is_empty_package){
@@ -503,7 +503,7 @@ namespace vcpkg::Export::Prefab
for(auto triplet: triplets){
triplet_names.push_back(triplet.canonical_name());
}
- System::print2(Strings::format("[DEBUG] Found %d triplets\n\t%s\n\n", triplets.size(),
+ System::print2(Strings::format("[DEBUG] Found %d triplets\n\t%s\n\n", triplets.size(),
Strings::join("\n\t", triplet_names)));
}
@@ -562,14 +562,14 @@ namespace vcpkg::Export::Prefab
ABIMetadata ab;
ab.abi = triplet_abi_map[triplet];
ab.api = triplet_api_map[triplet];
-
+
ab.stl = Strings::contains(extension, "a") ?"c++_static": "c++_shared";
ab.ndk = version.major();
if(prefab_options.enable_debug){
System::print2(Strings::format("[DEBUG] Found module %s:%s\n", module_name, ab.abi));
}
-
+
module_name = Strings::trim(std::move(module_name));
if (Strings::starts_with(module_name, "lib"))
@@ -580,7 +580,7 @@ namespace vcpkg::Export::Prefab
fs::path module_libs_dir =
module_dir / "libs" / Strings::format("android.%s", ab.abi);
utils.create_directories(module_libs_dir, error_code);
-
+
fs::path abi_path = module_libs_dir / "abi.json";
if(prefab_options.enable_debug){
@@ -597,7 +597,7 @@ namespace vcpkg::Export::Prefab
fs::copy_options::overwrite_existing,
error_code);
if(prefab_options.enable_debug){
- System::print2(Strings::format("\tCopying libs\n\tFrom %s\n\tTo %s\n",
+ System::print2(Strings::format("\tCopying libs\n\tFrom %s\n\tTo %s\n",
installed_module_path.generic_u8string(), exported_module_path.generic_u8string()));
}
fs::path installed_headers_dir = installed_dir / "include";
@@ -629,7 +629,7 @@ namespace vcpkg::Export::Prefab
fs::path pom_path = per_package_dir_path / "pom.xml";
if(prefab_options.enable_debug){
- System::print2(Strings::format("[DEBUG] Exporting AAR And POM\n\tAAR Path %s\n\tPOM Path %s\n",
+ System::print2(Strings::format("[DEBUG] Exporting AAR And POM\n\tAAR Path %s\n\tPOM Path %s\n",
exported_archive_path.generic_u8string(), pom_path.generic_u8string()));
}
diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp
index 5084ac918..1b9b7db34 100644
--- a/toolsrc/src/vcpkg/install.cpp
+++ b/toolsrc/src/vcpkg/install.cpp
@@ -297,7 +297,7 @@ namespace vcpkg::Install
using Build::BuildResult;
using Build::ExtendedBuildResult;
- ExtendedBuildResult perform_install_plan_action(const VcpkgPaths& paths,
+ static ExtendedBuildResult perform_install_plan_action(const VcpkgPaths& paths,
InstallPlanAction& action,
StatusParagraphs& status_db,
IBinaryProvider* binaries_provider)
diff --git a/toolsrc/src/vcpkg/metrics.cpp b/toolsrc/src/vcpkg/metrics.cpp
index 308ee0d51..06478d3f4 100644
--- a/toolsrc/src/vcpkg/metrics.cpp
+++ b/toolsrc/src/vcpkg/metrics.cpp
@@ -240,7 +240,7 @@ namespace vcpkg::Metrics
static MetricMessage g_metricmessage;
static bool g_should_send_metrics =
-#if defined(NDEBUG) && (DISABLE_METRICS == 0)
+#if defined(NDEBUG) && (VCPKG_DISABLE_METRICS == 0)
true
#else
false
@@ -248,7 +248,7 @@ namespace vcpkg::Metrics
;
static bool g_should_print_metrics = false;
- bool get_compiled_metrics_enabled() { return DISABLE_METRICS == 0; }
+ bool get_compiled_metrics_enabled() { return VCPKG_DISABLE_METRICS == 0; }
std::string get_MAC_user()
{
diff --git a/toolsrc/src/vcpkg/postbuildlint.cpp b/toolsrc/src/vcpkg/postbuildlint.cpp
index 8b2810200..c6d5f04be 100644
--- a/toolsrc/src/vcpkg/postbuildlint.cpp
+++ b/toolsrc/src/vcpkg/postbuildlint.cpp
@@ -738,7 +738,7 @@ namespace vcpkg::PostBuildLint
System::printf(System::Color::warning,
"Expected %s crt linkage, but the following libs had invalid crt linkage:\n\n",
expected_build_type.to_string());
- for (const BuildTypeAndFile btf : libs_with_invalid_crt)
+ for (const BuildTypeAndFile& btf : libs_with_invalid_crt)
{
System::printf(" %s: %s\n", btf.file.generic_string(), btf.build_type.to_string());
}
@@ -786,7 +786,7 @@ namespace vcpkg::PostBuildLint
if (!dlls_with_outdated_crt.empty())
{
System::print2(System::Color::warning, "Detected outdated dynamic CRT in the following files:\n\n");
- for (const OutdatedDynamicCrtAndFile btf : dlls_with_outdated_crt)
+ for (const OutdatedDynamicCrtAndFile& btf : dlls_with_outdated_crt)
{
System::print2(" ", btf.file.u8string(), ": ", btf.outdated_crt.name, "\n");
}