mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-28 19:25:27 +08:00
[vcpkg-integrate-install] Add vcpkg.path.txt to localappdata for more generic consumption.
This commit is contained in:
parent
ed3f943259
commit
a9d989ec05
@ -17,4 +17,6 @@ namespace vcpkg
|
||||
|
||||
void try_write_data(Files::Filesystem& fs) const;
|
||||
};
|
||||
|
||||
fs::path get_user_dir();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <vcpkg/base/system.h>
|
||||
#include <vcpkg/base/util.h>
|
||||
#include <vcpkg/commands.h>
|
||||
#include <vcpkg/userconfig.h>
|
||||
|
||||
namespace vcpkg::Commands::Integrate
|
||||
{
|
||||
@ -156,8 +157,10 @@ namespace vcpkg::Commands::Integrate
|
||||
}
|
||||
#endif
|
||||
|
||||
static fs::path get_path_txt_path() { return get_user_dir() / "vcpkg.path.txt"; }
|
||||
|
||||
#if defined(_WIN32)
|
||||
static void integrate_install(const VcpkgPaths& paths)
|
||||
static void integrate_install_msbuild14(Files::Filesystem& fs, const fs::path& tmp_dir)
|
||||
{
|
||||
static const std::array<fs::path, 2> OLD_SYSTEM_TARGET_FILES = {
|
||||
System::get_program_files_32_bit().value_or_exit(VCPKG_LINE_INFO) /
|
||||
@ -168,8 +171,6 @@ namespace vcpkg::Commands::Integrate
|
||||
System::get_program_files_32_bit().value_or_exit(VCPKG_LINE_INFO) /
|
||||
"MSBuild/Microsoft.Cpp/v4.0/V140/ImportBefore/Default/vcpkg.system.props";
|
||||
|
||||
auto& fs = paths.get_filesystem();
|
||||
|
||||
// TODO: This block of code should eventually be removed
|
||||
for (auto&& old_system_wide_targets_file : OLD_SYSTEM_TARGET_FILES)
|
||||
{
|
||||
@ -188,12 +189,6 @@ namespace vcpkg::Commands::Integrate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
const fs::path tmp_dir = paths.buildsystems / "tmp";
|
||||
fs.create_directory(paths.buildsystems, ec);
|
||||
fs.create_directory(tmp_dir, ec);
|
||||
|
||||
bool should_install_system = true;
|
||||
const Expected<std::string> system_wide_file_contents = fs.read_contents(SYSTEM_WIDE_TARGETS_FILE);
|
||||
static const std::regex RE(R"###(<!-- version (\d+) -->)###");
|
||||
@ -232,24 +227,52 @@ namespace vcpkg::Commands::Integrate
|
||||
"Error: failed to copy targets file to %s",
|
||||
SYSTEM_WIDE_TARGETS_FILE.string());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
const fs::path appdata_src_path = tmp_dir / "vcpkg.user.targets";
|
||||
fs.write_contents(appdata_src_path,
|
||||
create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string()));
|
||||
auto appdata_dst_path = get_appdata_targets_path();
|
||||
static void integrate_install(const VcpkgPaths& paths)
|
||||
{
|
||||
auto& fs = paths.get_filesystem();
|
||||
|
||||
const auto rc = fs.copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing, ec);
|
||||
|
||||
if (!rc || ec)
|
||||
#if defined(_WIN32)
|
||||
{
|
||||
System::println(System::Color::error,
|
||||
"Error: Failed to copy file: %s -> %s",
|
||||
appdata_src_path.string(),
|
||||
appdata_dst_path.string());
|
||||
std::error_code ec;
|
||||
const fs::path tmp_dir = paths.buildsystems / "tmp";
|
||||
fs.create_directory(paths.buildsystems, ec);
|
||||
fs.create_directory(tmp_dir, ec);
|
||||
|
||||
integrate_install_msbuild14(fs, tmp_dir);
|
||||
|
||||
const fs::path appdata_src_path = tmp_dir / "vcpkg.user.targets";
|
||||
fs.write_contents(appdata_src_path,
|
||||
create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string()));
|
||||
auto appdata_dst_path = get_appdata_targets_path();
|
||||
|
||||
const auto rc = fs.copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing, ec);
|
||||
|
||||
if (!rc || ec)
|
||||
{
|
||||
System::println(System::Color::error,
|
||||
"Error: Failed to copy file: %s -> %s",
|
||||
appdata_src_path.string(),
|
||||
appdata_dst_path.string());
|
||||
Checks::exit_fail(VCPKG_LINE_INFO);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
const auto pathtxt = get_path_txt_path();
|
||||
std::error_code ec;
|
||||
fs.write_contents(pathtxt, paths.root.generic_u8string(), ec);
|
||||
if (ec)
|
||||
{
|
||||
System::println(System::Color::error, "Error: Failed to write file: %s", pathtxt.string());
|
||||
Checks::exit_fail(VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
System::println(System::Color::success, "Applied user-wide integration for this vcpkg root.");
|
||||
const fs::path cmake_toolchain = paths.buildsystems / "vcpkg.cmake";
|
||||
#if defined(_WIN32)
|
||||
System::println(
|
||||
R"(
|
||||
All MSBuild C++ projects can now #include any installed libraries.
|
||||
@ -258,17 +281,29 @@ Installing new libraries will make them instantly available.
|
||||
|
||||
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=%s")",
|
||||
cmake_toolchain.generic_string());
|
||||
#else
|
||||
System::println(
|
||||
R"(
|
||||
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=%s")",
|
||||
cmake_toolchain.generic_string());
|
||||
#endif
|
||||
|
||||
Checks::exit_success(VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
static void integrate_remove(Files::Filesystem& fs)
|
||||
{
|
||||
std::error_code ec;
|
||||
bool was_deleted = false;
|
||||
|
||||
#if defined(_WIN32)
|
||||
const fs::path path = get_appdata_targets_path();
|
||||
|
||||
std::error_code ec;
|
||||
const bool was_deleted = fs.remove(path, ec);
|
||||
was_deleted |= fs.remove(path, ec);
|
||||
Checks::check_exit(VCPKG_LINE_INFO, !ec, "Error: Unable to remove user-wide integration: %s", ec.message());
|
||||
#endif
|
||||
|
||||
was_deleted |= fs.remove(get_path_txt_path(), ec);
|
||||
Checks::check_exit(VCPKG_LINE_INFO, !ec, "Error: Unable to remove user-wide integration: %s", ec.message());
|
||||
|
||||
if (was_deleted)
|
||||
@ -282,7 +317,6 @@ CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=%s")",
|
||||
|
||||
Checks::exit_success(VCPKG_LINE_INFO);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
static void integrate_project(const VcpkgPaths& paths)
|
||||
@ -343,7 +377,8 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
|
||||
" vcpkg integrate powershell Enable PowerShell Tab-Completion\n";
|
||||
#else
|
||||
const char* const INTEGRATE_COMMAND_HELPSTRING =
|
||||
"No user-wide integration methods are available on this platform\n";
|
||||
" vcpkg integrate install Make installed packages available user-wide.\n"
|
||||
" vcpkg integrate remove Remove user-wide integration\n";
|
||||
#endif
|
||||
|
||||
namespace Subcommand
|
||||
@ -373,7 +408,6 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
|
||||
{
|
||||
Util::unused(args.parse_arguments(COMMAND_STRUCTURE));
|
||||
|
||||
#if defined(_WIN32)
|
||||
if (args.command_arguments[0] == Subcommand::INSTALL)
|
||||
{
|
||||
return integrate_install(paths);
|
||||
@ -382,6 +416,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
|
||||
{
|
||||
return integrate_remove(paths.get_filesystem());
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
if (args.command_arguments[0] == Subcommand::PROJECT)
|
||||
{
|
||||
return integrate_project(paths);
|
||||
@ -392,10 +427,8 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
|
||||
paths.scripts / "addPoshVcpkgToPowershellProfile.ps1");
|
||||
Checks::exit_success(VCPKG_LINE_INFO);
|
||||
}
|
||||
#endif
|
||||
|
||||
Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown parameter %s for integrate", args.command_arguments[0]);
|
||||
#else
|
||||
Checks::exit_success(VCPKG_LINE_INFO);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,21 @@ namespace
|
||||
|
||||
namespace vcpkg
|
||||
{
|
||||
static fs::path get_config_path()
|
||||
fs::path get_user_dir()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return get_localappdata() / "vcpkg" / "config";
|
||||
return get_localappdata() / "vcpkg";
|
||||
#else
|
||||
auto maybe_home = System::get_environment_variable("HOME");
|
||||
return fs::path(maybe_home.value_or("/var")) / ".vcpkg" / "config";
|
||||
return fs::path(maybe_home.value_or("/var")) / ".vcpkg";
|
||||
#endif
|
||||
}
|
||||
|
||||
static fs::path get_config_path()
|
||||
{
|
||||
return get_user_dir() / "config";
|
||||
}
|
||||
|
||||
UserConfig UserConfig::try_read_data(const Files::Filesystem& fs)
|
||||
{
|
||||
UserConfig ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user