Introduce BuildPolicies (not used by the post_build checks yet)
MODIFY
include/BuildInfo.h
include/BuildInfo.h
#include <unordered_map>
#include "Paragraphs.h"
#include <regex>
+#include "BuildPolicies.h"
+#include "opt_bool.h"
namespace vcpkg::PostBuildLint
{
@@ -119,10 +121,12 @@ namespace vcpkg::PostBuildLint
struct BuildInfo
{
- static BuildInfo create(const std::unordered_map<std::string, std::string>& pgh);
+ static BuildInfo create(std::unordered_map<std::string, std::string> pgh);
std::string crt_linkage;
std::string library_linkage;
+
+ std::map<BuildPolicies::type, opt_bool_t> policies;
};
BuildInfo read_build_info(const fs::path& filepath);

ADD
include/BuildPolicies.h
+#pragma once
+#include <string>
+
+namespace vcpkg::PostBuildLint::BuildPolicies
+{
+ enum class backing_enum_t
+ {
+ UNKNOWN = 0,
+ DLLS_WITHOUT_LIBS
+ };
+
+ struct type
+ {
+ static constexpr int length() { return 2; }
+ constexpr explicit type(backing_enum_t backing_enum) : backing_enum(backing_enum) { }
+ constexpr operator backing_enum_t() const { return backing_enum; }
+
+ const std::string& toString() const;
+ const std::string& cmake_variable() const;
+
+ private:
+ type();
+ backing_enum_t backing_enum;
+ };
+
+ static constexpr type UNKNOWN(backing_enum_t::UNKNOWN);
+ static constexpr type DLLS_WITHOUT_LIBS(backing_enum_t::DLLS_WITHOUT_LIBS);
+
+ type parse(const std::string& s);
+}

MODIFY
src/BuildInfo.cpp
src/BuildInfo.cpp
#include "pch.h"
#include "BuildInfo.h"
#include "vcpkg_Checks.h"
+#include "opt_bool.h"
#include "vcpkglib_helpers.h"
namespace vcpkg::PostBuildLint
@@ -44,11 +45,20 @@ namespace vcpkg::PostBuildLint
static const std::string LIBRARY_LINKAGE = "LibraryLinkage";
}
- BuildInfo BuildInfo::create(const std::unordered_map<std::string, std::string>& pgh)
+ BuildInfo BuildInfo::create(std::unordered_map<std::string, std::string> pgh)
{
BuildInfo build_info;
- build_info.crt_linkage = details::required_field(pgh, BuildInfoRequiredField::CRT_LINKAGE);
- build_info.library_linkage = details::required_field(pgh, BuildInfoRequiredField::LIBRARY_LINKAGE);
+ build_info.crt_linkage = details::remove_required_field(&pgh, BuildInfoRequiredField::CRT_LINKAGE);
+ build_info.library_linkage = details::remove_required_field(&pgh, BuildInfoRequiredField::LIBRARY_LINKAGE);
+
+ // The remaining entries are policies
+ for (const std::unordered_map<std::string, std::string>::value_type& p : pgh)
+ {
+ const BuildPolicies::type policy = BuildPolicies::parse(p.first);
+ Checks::check_exit(policy != BuildPolicies::UNKNOWN, "Unknown policy found: %s", p.first);
+ const opt_bool_t status = opt_bool::parse(p.second);
+ build_info.policies.emplace(policy, status);
+ }
return build_info;
}

ADD
src/BuildPolicies.cpp
+#include "pch.h"
+#include "BuildPolicies.h"
+#include "vcpkg_Checks.h"
+
+namespace vcpkg::PostBuildLint::BuildPolicies
+{
+ static const std::string NAME_UNKNOWN = "PolicyUnknown";
+ static const std::string NAME_DLLS_WITHOUT_LIBS = "PolicyDLLsWithoutLIBs";
+
+ const std::string& type::toString() const
+ {
+ switch (this->backing_enum)
+ {
+ case DLLS_WITHOUT_LIBS:
+ return NAME_DLLS_WITHOUT_LIBS;
+ case UNKNOWN:
+ return NAME_UNKNOWN;
+ default:
+ Checks::unreachable();
+ }
+ }
+
+ const std::string& type::cmake_variable() const
+ {
+ static const std::string CMAKE_VARIABLE_DLLS_WITHOUT_LIBS = "VCPKG_POLICY_DLLS_WITHOUT_LIBS";
+
+ switch (this->backing_enum)
+ {
+ case DLLS_WITHOUT_LIBS:
+ return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS;
+ case UNKNOWN:
+ Checks::exit_with_message("No CMake command corresponds to UNKNOWN");
+ default:
+ Checks::unreachable();
+ }
+ }
+
+ type::type(): backing_enum(backing_enum_t::UNKNOWN) {}
+
+ type parse(const std::string& s)
+ {
+ if (s == NAME_DLLS_WITHOUT_LIBS)
+ {
+ return BuildPolicies::DLLS_WITHOUT_LIBS;
+ }
+
+ return BuildPolicies::UNKNOWN;
+ }
+}

MODIFY
vcpkglib/vcpkglib.vcxproj
vcpkglib/vcpkglib.vcxproj
<ItemGroup>
<ClInclude Include="..\include\BinaryParagraph.h" />
<ClInclude Include="..\include\BuildInfo.h" />
+ <ClInclude Include="..\include\BuildPolicies.h" />
<ClInclude Include="..\include\coff_file_reader.h" />
<ClInclude Include="..\include\expected.h" />
<ClInclude Include="..\include\filesystem_fs.h" />
<ItemGroup>
<ClCompile Include="..\src\BinaryParagraph.cpp" />
<ClCompile Include="..\src\BuildInfo.cpp" />
+ <ClCompile Include="..\src\BuildPolicies.cpp" />
<ClCompile Include="..\src\coff_file_reader.cpp" />
<ClCompile Include="..\src\commands_available_commands.cpp" />
<ClCompile Include="..\src\commands_build.cpp" />

MODIFY
vcpkglib/vcpkglib.vcxproj.filters
vcpkglib/vcpkglib.vcxproj.filters
<ClCompile Include="..\src\opt_bool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\src\BuildPolicies.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\package_spec.h">
<ClInclude Include="..\include\vcpkg_optional.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\include\BuildPolicies.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file

Introduce BuildPolicies (not used by the post_build checks yet)