Skip to content

Commit b110959

Browse files
authored
Fix x-download when downloads isn't in a vcpkg root (#96)
* Record --vcpkg-root into vcpkg recursive invocation block. * Change x-download into a basic command so that it doesn't need to find a vcpkg-root etc.
1 parent 74c95ca commit b110959

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

include/vcpkg/commands.xdownload.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace vcpkg::Commands::X_Download
66
{
7-
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
7+
void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs);
88

9-
struct XDownloadCommand : PathsCommand
9+
struct XDownloadCommand : BasicCommand
1010
{
11-
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
11+
virtual void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs) const override;
1212
};
1313
}

src/vcpkg-test/commands.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ TEST_CASE ("get_available_basic_commands works", "[commands]")
3232
check_all_commands(Commands::get_available_basic_commands(), {
3333
"contact",
3434
"version",
35+
"x-download",
3536
"x-init-registry",
3637
#if defined(_WIN32)
3738
"x-upload-metrics",
@@ -58,7 +59,6 @@ TEST_CASE ("get_available_paths_commands works", "[commands]")
5859
"fetch",
5960
"format-manifest",
6061
"x-ci-clean",
61-
"x-download",
6262
"x-history",
6363
"x-package-info",
6464
"x-vsinstances",

src/vcpkg/commands.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace vcpkg::Commands
4545
static const Version::VersionCommand version{};
4646
static const Contact::ContactCommand contact{};
4747
static const InitRegistry::InitRegistryCommand init_registry{};
48+
static const X_Download::XDownloadCommand xdownload{};
4849
#if defined(_WIN32)
4950
static const UploadMetrics::UploadMetricsCommand upload_metrics{};
5051
#endif // defined(_WIN32)
@@ -53,6 +54,7 @@ namespace vcpkg::Commands
5354
{"version", &version},
5455
{"contact", &contact},
5556
{"x-init-registry", &init_registry},
57+
{"x-download", &xdownload},
5658

5759
#if defined(_WIN32)
5860
{"x-upload-metrics", &upload_metrics},
@@ -80,7 +82,6 @@ namespace vcpkg::Commands
8082
static const CIClean::CICleanCommand ciclean{};
8183
static const PortHistory::PortHistoryCommand porthistory{};
8284
static const X_VSInstances::VSInstancesCommand vsinstances{};
83-
static const X_Download::XDownloadCommand xdownload{};
8485
static const FormatManifest::FormatManifestCommand format_manifest{};
8586
static const CIVerifyVersions::CIVerifyVersionsCommand ci_verify_versions{};
8687
static const AddVersion::AddVersionCommand add_version{};
@@ -104,7 +105,6 @@ namespace vcpkg::Commands
104105
{"x-package-info", &info},
105106
{"x-history", &porthistory},
106107
{"x-vsinstances", &vsinstances},
107-
{"x-download", &xdownload},
108108
{"format-manifest", &format_manifest},
109109
{"x-ci-verify-versions", &ci_verify_versions},
110110
{"x-add-version", &add_version},

src/vcpkg/commands.xdownload.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
#include <vcpkg/base/parse.h>
44
#include <vcpkg/base/system.debug.h>
55
#include <vcpkg/base/system.print.h>
6+
#include <vcpkg/base/util.h>
67

8+
#include <vcpkg/binarycaching.h>
79
#include <vcpkg/commands.xdownload.h>
810
#include <vcpkg/vcpkgcmdarguments.h>
9-
#include <vcpkg/vcpkgpaths.h>
1011

1112
namespace vcpkg::Commands::X_Download
1213
{
@@ -38,11 +39,11 @@ namespace vcpkg::Commands::X_Download
3839
}
3940
static bool is_lower_sha512(StringView sha) { return sha.size() == 128 && is_lower_hex(sha); }
4041

41-
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
42+
void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs)
4243
{
4344
auto parsed = args.parse_arguments(COMMAND_STRUCTURE);
44-
fs::path file = Files::combine(paths.original_cwd, fs::u8path(args.command_arguments[0]));
45-
file.make_preferred();
45+
auto download_manager = create_download_manager(args.asset_sources_template).value_or_exit(VCPKG_LINE_INFO);
46+
fs::path file = fs.absolute(VCPKG_LINE_INFO, fs::u8path(args.command_arguments[0]));
4647

4748
std::string sha = Strings::ascii_to_lowercase(std::string(args.command_arguments[1]));
4849
if (!is_lower_sha512(sha))
@@ -51,8 +52,6 @@ namespace vcpkg::Commands::X_Download
5152
VCPKG_LINE_INFO, "Error: SHA512's must be 128 hex characters: '%s'", args.command_arguments[1]);
5253
}
5354

54-
auto& fs = paths.get_filesystem();
55-
5655
// Is this a store command?
5756
if (Util::Sets::contains(parsed.switches, OPTION_STORE))
5857
{
@@ -65,7 +64,7 @@ namespace vcpkg::Commands::X_Download
6564
auto hash =
6665
Strings::ascii_to_lowercase(Hash::get_file_hash(VCPKG_LINE_INFO, fs, file, Hash::Algorithm::Sha512));
6766
if (hash != sha) Checks::exit_with_message(VCPKG_LINE_INFO, "Error: file to store does not match hash");
68-
paths.get_download_manager().put_file_to_mirror(fs, file, sha).value_or_exit(VCPKG_LINE_INFO);
67+
download_manager.put_file_to_mirror(fs, file, sha).value_or_exit(VCPKG_LINE_INFO);
6968
Checks::exit_success(VCPKG_LINE_INFO);
7069
}
7170
else
@@ -81,18 +80,18 @@ namespace vcpkg::Commands::X_Download
8180
auto it_urls = parsed.multisettings.find(OPTION_URL);
8281
if (it_urls == parsed.multisettings.end())
8382
{
84-
paths.get_download_manager().download_file(fs, View<std::string>{}, headers, file, sha);
83+
download_manager.download_file(fs, View<std::string>{}, headers, file, sha);
8584
}
8685
else
8786
{
88-
paths.get_download_manager().download_file(fs, it_urls->second, headers, file, sha);
87+
download_manager.download_file(fs, it_urls->second, headers, file, sha);
8988
}
9089
Checks::exit_success(VCPKG_LINE_INFO);
9190
}
9291
}
9392

94-
void XDownloadCommand::perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const
93+
void XDownloadCommand::perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs) const
9594
{
96-
X_Download::perform_and_exit(args, paths);
95+
X_Download::perform_and_exit(args, fs);
9796
}
9897
}

src/vcpkg/vcpkgcmdarguments.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,11 @@ namespace vcpkg
731731
auto rec_doc = Json::parse(*vcpkg_recursive_data).value_or_exit(VCPKG_LINE_INFO).first;
732732
const auto& obj = rec_doc.object();
733733

734+
if (auto entry = obj.get(VCPKG_ROOT_DIR_ENV))
735+
{
736+
args.vcpkg_root_dir = std::make_unique<std::string>(entry->string().to_string());
737+
}
738+
734739
if (auto entry = obj.get(DOWNLOADS_ROOT_DIR_ENV))
735740
{
736741
args.downloads_root_dir = std::make_unique<std::string>(entry->string().to_string());
@@ -753,6 +758,11 @@ namespace vcpkg
753758
else
754759
{
755760
Json::Object obj;
761+
if (args.vcpkg_root_dir)
762+
{
763+
obj.insert(VCPKG_ROOT_DIR_ENV, Json::Value::string(*args.vcpkg_root_dir.get()));
764+
}
765+
756766
if (args.downloads_root_dir)
757767
{
758768
obj.insert(DOWNLOADS_ROOT_DIR_ENV, Json::Value::string(*args.downloads_root_dir.get()));

0 commit comments

Comments
 (0)