mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-06-07 01:23:35 +08:00
[vcpkg] Apply fixes needed to extract vcpkg-tool (#16012)
utilities.cmake: Disable warnings that are firing on Azure Pipelines CI machines due to different Clang version. expected.h: Fix a bug I introduced in https://github.com/microsoft/vcpkg/pull/15638/ because I was under the impression expected worked like optional (in that value_or_exit for it should be treated as a program bug) build.cpp: Add (void)s to silence warnings. binarycaching.cpp: Repair assumption that the current directory is C: which isn't true on the Hosted Azure Pipelines agents. others: Make unit tests respect %VCPKG_ROOT%, as necessary in the vcpkg_tool repo. Note that this required splitting vcpkgcmdarguments::ImbueFromEnvironment into the once-only process modifying part and the just imbue from environment part.
This commit is contained in:
parent
dc4d1b735a
commit
ba03ad7c9d
@ -204,7 +204,13 @@ function(vcpkg_target_add_warning_options TARGET)
|
|||||||
if(VCPKG_DEVELOPMENT_WARNINGS)
|
if(VCPKG_DEVELOPMENT_WARNINGS)
|
||||||
target_compile_options(${TARGET} PRIVATE -W4)
|
target_compile_options(${TARGET} PRIVATE -W4)
|
||||||
if(VCPKG_COMPILER STREQUAL "clang")
|
if(VCPKG_COMPILER STREQUAL "clang")
|
||||||
target_compile_options(${TARGET} PRIVATE -Wmissing-prototypes -Wno-missing-field-initializers)
|
# -Wno-range-loop-analysis is due to an LLVM bug which will be fixed in a
|
||||||
|
# future version of clang https://reviews.llvm.org/D73007
|
||||||
|
target_compile_options(${TARGET} PRIVATE
|
||||||
|
-Wmissing-prototypes
|
||||||
|
-Wno-missing-field-initializers
|
||||||
|
-Wno-range-loop-analysis
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
target_compile_options(${TARGET} PRIVATE -analyze)
|
target_compile_options(${TARGET} PRIVATE -analyze)
|
||||||
endif()
|
endif()
|
||||||
@ -219,13 +225,21 @@ function(vcpkg_target_add_warning_options TARGET)
|
|||||||
if(VCPKG_DEVELOPMENT_WARNINGS)
|
if(VCPKG_DEVELOPMENT_WARNINGS)
|
||||||
target_compile_options(${TARGET} PRIVATE
|
target_compile_options(${TARGET} PRIVATE
|
||||||
-Wall -Wextra -Wpedantic
|
-Wall -Wextra -Wpedantic
|
||||||
-Wno-unknown-pragmas -Wno-missing-field-initializers -Wno-redundant-move)
|
-Wno-unknown-pragmas
|
||||||
|
-Wno-missing-field-initializers
|
||||||
|
-Wno-redundant-move
|
||||||
|
)
|
||||||
|
|
||||||
# GCC and clang have different names for the same warning
|
# GCC and clang have different names for the same warning
|
||||||
if(VCPKG_COMPILER STREQUAL "gcc")
|
if(VCPKG_COMPILER STREQUAL "gcc")
|
||||||
target_compile_options(${TARGET} PRIVATE -Wmissing-declarations)
|
target_compile_options(${TARGET} PRIVATE
|
||||||
|
-Wmissing-declarations
|
||||||
|
)
|
||||||
elseif(VCPKG_COMPILER STREQUAL "clang")
|
elseif(VCPKG_COMPILER STREQUAL "clang")
|
||||||
target_compile_options(${TARGET} PRIVATE -Wmissing-prototypes)
|
target_compile_options(${TARGET} PRIVATE
|
||||||
|
-Wmissing-prototypes
|
||||||
|
-Wno-range-loop-analysis
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ namespace vcpkg
|
|||||||
if (m_s.has_error())
|
if (m_s.has_error())
|
||||||
{
|
{
|
||||||
System::print2(System::Color::error, m_s.to_string(), "\n");
|
System::print2(System::Color::error, m_s.to_string(), "\n");
|
||||||
Checks::unreachable(line_info);
|
Checks::exit_fail(line_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,6 @@ namespace vcpkg
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool output_json() const { return json.value_or(false); }
|
bool output_json() const { return json.value_or(false); }
|
||||||
bool is_recursive_invocation() const { return m_is_recursive_invocation; }
|
|
||||||
|
|
||||||
std::string command;
|
std::string command;
|
||||||
std::vector<std::string> command_arguments;
|
std::vector<std::string> command_arguments;
|
||||||
@ -221,13 +220,16 @@ namespace vcpkg
|
|||||||
|
|
||||||
void imbue_from_environment();
|
void imbue_from_environment();
|
||||||
|
|
||||||
|
// Applies recursive settings from the environment or sets a global environment variable
|
||||||
|
// to be consumed by subprocesses; may only be called once per process.
|
||||||
|
static void imbue_or_apply_process_recursion(VcpkgCmdArguments& args);
|
||||||
|
|
||||||
void check_feature_flag_consistency() const;
|
void check_feature_flag_consistency() const;
|
||||||
|
|
||||||
void debug_print_feature_flags() const;
|
void debug_print_feature_flags() const;
|
||||||
void track_feature_flag_metrics() const;
|
void track_feature_flag_metrics() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_is_recursive_invocation = false;
|
|
||||||
std::unordered_set<std::string> command_switches;
|
std::unordered_set<std::string> command_switches;
|
||||||
std::unordered_map<std::string, std::vector<std::string>> command_options;
|
std::unordered_map<std::string, std::vector<std::string>> command_options;
|
||||||
};
|
};
|
||||||
|
@ -58,7 +58,11 @@ TEST_CASE ("generate_nuspec", "[generate_nuspec]")
|
|||||||
{
|
{
|
||||||
auto& fsWrapper = Files::get_real_filesystem();
|
auto& fsWrapper = Files::get_real_filesystem();
|
||||||
VcpkgCmdArguments args = VcpkgCmdArguments::create_from_arg_sequence(nullptr, nullptr);
|
VcpkgCmdArguments args = VcpkgCmdArguments::create_from_arg_sequence(nullptr, nullptr);
|
||||||
|
args.imbue_from_environment();
|
||||||
args.packages_root_dir = std::make_unique<std::string>("/");
|
args.packages_root_dir = std::make_unique<std::string>("/");
|
||||||
|
auto pkgPath = fsWrapper.absolute(VCPKG_LINE_INFO, fs::u8path("/zlib2_x64-windows")) / fs::u8path("**");
|
||||||
|
pkgPath.make_preferred();
|
||||||
|
const auto pkgPathStr = fs::u8string(pkgPath);
|
||||||
VcpkgPaths paths(fsWrapper, args);
|
VcpkgPaths paths(fsWrapper, args);
|
||||||
|
|
||||||
auto pghs = Paragraphs::parse_paragraphs(R"(
|
auto pghs = Paragraphs::parse_paragraphs(R"(
|
||||||
@ -101,11 +105,6 @@ Build-Depends: bzip
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto nuspec = generate_nuspec(paths, ipa, ref, {});
|
auto nuspec = generate_nuspec(paths, ipa, ref, {});
|
||||||
#ifdef _WIN32
|
|
||||||
#define PKGPATH "C:\\zlib2_x64-windows\\**"
|
|
||||||
#else
|
|
||||||
#define PKGPATH "/zlib2_x64-windows/**"
|
|
||||||
#endif
|
|
||||||
std::string expected = R"(<package>
|
std::string expected = R"(<package>
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>zlib2_x64-windows</id>
|
<id>zlib2_x64-windows</id>
|
||||||
@ -125,7 +124,8 @@ Dependencies:
|
|||||||
</description>
|
</description>
|
||||||
<packageTypes><packageType name="vcpkg"/></packageTypes>
|
<packageTypes><packageType name="vcpkg"/></packageTypes>
|
||||||
</metadata>
|
</metadata>
|
||||||
<files><file src=")" PKGPATH R"(" target=""/></files>
|
<files><file src=")" + pkgPathStr +
|
||||||
|
R"(" target=""/></files>
|
||||||
</package>
|
</package>
|
||||||
)";
|
)";
|
||||||
REQUIRE_EQUAL_TEXT(nuspec, expected);
|
REQUIRE_EQUAL_TEXT(nuspec, expected);
|
||||||
@ -133,11 +133,6 @@ Dependencies:
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto nuspec = generate_nuspec(paths, ipa, ref, {"urlvalue"});
|
auto nuspec = generate_nuspec(paths, ipa, ref, {"urlvalue"});
|
||||||
#ifdef _WIN32
|
|
||||||
#define PKGPATH "C:\\zlib2_x64-windows\\**"
|
|
||||||
#else
|
|
||||||
#define PKGPATH "/zlib2_x64-windows/**"
|
|
||||||
#endif
|
|
||||||
std::string expected = R"(<package>
|
std::string expected = R"(<package>
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>zlib2_x64-windows</id>
|
<id>zlib2_x64-windows</id>
|
||||||
@ -158,18 +153,14 @@ Dependencies:
|
|||||||
<packageTypes><packageType name="vcpkg"/></packageTypes>
|
<packageTypes><packageType name="vcpkg"/></packageTypes>
|
||||||
<repository type="git" url="urlvalue"/>
|
<repository type="git" url="urlvalue"/>
|
||||||
</metadata>
|
</metadata>
|
||||||
<files><file src=")" PKGPATH R"(" target=""/></files>
|
<files><file src=")" + pkgPathStr +
|
||||||
|
R"(" target=""/></files>
|
||||||
</package>
|
</package>
|
||||||
)";
|
)";
|
||||||
REQUIRE_EQUAL_TEXT(nuspec, expected);
|
REQUIRE_EQUAL_TEXT(nuspec, expected);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto nuspec = generate_nuspec(paths, ipa, ref, {"urlvalue", "branchvalue", "commitvalue"});
|
auto nuspec = generate_nuspec(paths, ipa, ref, {"urlvalue", "branchvalue", "commitvalue"});
|
||||||
#ifdef _WIN32
|
|
||||||
#define PKGPATH "C:\\zlib2_x64-windows\\**"
|
|
||||||
#else
|
|
||||||
#define PKGPATH "/zlib2_x64-windows/**"
|
|
||||||
#endif
|
|
||||||
std::string expected = R"(<package>
|
std::string expected = R"(<package>
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>zlib2_x64-windows</id>
|
<id>zlib2_x64-windows</id>
|
||||||
@ -190,7 +181,8 @@ Dependencies:
|
|||||||
<packageTypes><packageType name="vcpkg"/></packageTypes>
|
<packageTypes><packageType name="vcpkg"/></packageTypes>
|
||||||
<repository type="git" url="urlvalue" branch="branchvalue" commit="commitvalue"/>
|
<repository type="git" url="urlvalue" branch="branchvalue" commit="commitvalue"/>
|
||||||
</metadata>
|
</metadata>
|
||||||
<files><file src=")" PKGPATH R"(" target=""/></files>
|
<files><file src=")" + pkgPathStr +
|
||||||
|
R"(" target=""/></files>
|
||||||
</package>
|
</package>
|
||||||
)";
|
)";
|
||||||
REQUIRE_EQUAL_TEXT(nuspec, expected);
|
REQUIRE_EQUAL_TEXT(nuspec, expected);
|
||||||
|
@ -681,6 +681,7 @@ TEST_CASE ("Serialize all the ports", "[manifests]")
|
|||||||
std::vector<std::string> args_list = {"format-manifest"};
|
std::vector<std::string> args_list = {"format-manifest"};
|
||||||
auto& fs = Files::get_real_filesystem();
|
auto& fs = Files::get_real_filesystem();
|
||||||
auto args = VcpkgCmdArguments::create_from_arg_sequence(args_list.data(), args_list.data() + args_list.size());
|
auto args = VcpkgCmdArguments::create_from_arg_sequence(args_list.data(), args_list.data() + args_list.size());
|
||||||
|
args.imbue_from_environment();
|
||||||
VcpkgPaths paths{fs, args};
|
VcpkgPaths paths{fs, args};
|
||||||
|
|
||||||
std::vector<SourceControlFile> scfs;
|
std::vector<SourceControlFile> scfs;
|
||||||
|
@ -226,6 +226,7 @@ int main(const int argc, const char* const* const argv)
|
|||||||
VcpkgCmdArguments args = VcpkgCmdArguments::create_from_command_line(fs, argc, argv);
|
VcpkgCmdArguments args = VcpkgCmdArguments::create_from_command_line(fs, argc, argv);
|
||||||
if (const auto p = args.debug.get()) Debug::g_debugging = *p;
|
if (const auto p = args.debug.get()) Debug::g_debugging = *p;
|
||||||
args.imbue_from_environment();
|
args.imbue_from_environment();
|
||||||
|
VcpkgCmdArguments::imbue_or_apply_process_recursion(args);
|
||||||
args.check_feature_flag_consistency();
|
args.check_feature_flag_consistency();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -648,13 +648,6 @@ namespace vcpkg
|
|||||||
|
|
||||||
void VcpkgCmdArguments::imbue_from_environment()
|
void VcpkgCmdArguments::imbue_from_environment()
|
||||||
{
|
{
|
||||||
static bool s_reentrancy_guard = false;
|
|
||||||
Checks::check_exit(VCPKG_LINE_INFO,
|
|
||||||
!s_reentrancy_guard,
|
|
||||||
"VcpkgCmdArguments::imbue_from_environment() modifies global state and thus may only be "
|
|
||||||
"called once per process.");
|
|
||||||
s_reentrancy_guard = true;
|
|
||||||
|
|
||||||
if (!disable_metrics)
|
if (!disable_metrics)
|
||||||
{
|
{
|
||||||
const auto vcpkg_disable_metrics_env = System::get_environment_variable(DISABLE_METRICS_ENV);
|
const auto vcpkg_disable_metrics_env = System::get_environment_variable(DISABLE_METRICS_ENV);
|
||||||
@ -701,46 +694,52 @@ namespace vcpkg
|
|||||||
parse_feature_flags(flags, *this);
|
parse_feature_flags(flags, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VcpkgCmdArguments::imbue_or_apply_process_recursion(VcpkgCmdArguments& args)
|
||||||
|
{
|
||||||
|
static bool s_reentrancy_guard = false;
|
||||||
|
Checks::check_exit(
|
||||||
|
VCPKG_LINE_INFO,
|
||||||
|
!s_reentrancy_guard,
|
||||||
|
"VcpkgCmdArguments::imbue_or_apply_process_recursion() modifies global state and thus may only be "
|
||||||
|
"called once per process.");
|
||||||
|
s_reentrancy_guard = true;
|
||||||
|
|
||||||
|
auto maybe_vcpkg_recursive_data = System::get_environment_variable(RECURSIVE_DATA_ENV);
|
||||||
|
if (auto vcpkg_recursive_data = maybe_vcpkg_recursive_data.get())
|
||||||
{
|
{
|
||||||
auto maybe_vcpkg_recursive_data = System::get_environment_variable(RECURSIVE_DATA_ENV);
|
auto rec_doc = Json::parse(*vcpkg_recursive_data).value_or_exit(VCPKG_LINE_INFO).first;
|
||||||
if (auto vcpkg_recursive_data = maybe_vcpkg_recursive_data.get())
|
const auto& obj = rec_doc.object();
|
||||||
|
|
||||||
|
if (auto entry = obj.get(DOWNLOADS_ROOT_DIR_ENV))
|
||||||
{
|
{
|
||||||
m_is_recursive_invocation = true;
|
args.downloads_root_dir = std::make_unique<std::string>(entry->string().to_string());
|
||||||
|
|
||||||
auto rec_doc = Json::parse(*vcpkg_recursive_data).value_or_exit(VCPKG_LINE_INFO).first;
|
|
||||||
const auto& obj = rec_doc.object();
|
|
||||||
|
|
||||||
if (auto entry = obj.get(DOWNLOADS_ROOT_DIR_ENV))
|
|
||||||
{
|
|
||||||
downloads_root_dir = std::make_unique<std::string>(entry->string().to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj.get(DISABLE_METRICS_ENV))
|
|
||||||
{
|
|
||||||
disable_metrics = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setting the recursive data to 'poison' prevents more than one level of recursion because
|
|
||||||
// Json::parse() will fail.
|
|
||||||
System::set_environment_variable(RECURSIVE_DATA_ENV, "poison");
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (obj.get(DISABLE_METRICS_ENV))
|
||||||
{
|
{
|
||||||
Json::Object obj;
|
args.disable_metrics = true;
|
||||||
if (downloads_root_dir)
|
|
||||||
{
|
|
||||||
obj.insert(DOWNLOADS_ROOT_DIR_ENV, Json::Value::string(*downloads_root_dir.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (disable_metrics)
|
|
||||||
{
|
|
||||||
obj.insert(DISABLE_METRICS_ENV, Json::Value::boolean(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
System::set_environment_variable(RECURSIVE_DATA_ENV,
|
|
||||||
Json::stringify(obj, Json::JsonStyle::with_spaces(0)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setting the recursive data to 'poison' prevents more than one level of recursion because
|
||||||
|
// Json::parse() will fail.
|
||||||
|
System::set_environment_variable(RECURSIVE_DATA_ENV, "poison");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Json::Object obj;
|
||||||
|
if (args.downloads_root_dir)
|
||||||
|
{
|
||||||
|
obj.insert(DOWNLOADS_ROOT_DIR_ENV, Json::Value::string(*args.downloads_root_dir.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.disable_metrics)
|
||||||
|
{
|
||||||
|
obj.insert(DISABLE_METRICS_ENV, Json::Value::boolean(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
System::set_environment_variable(RECURSIVE_DATA_ENV, Json::stringify(obj, Json::JsonStyle::with_spaces(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user