Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow redirection of the scripts folder. #6552

Merged
merged 7 commits into from
Jul 2, 2019
1 change: 1 addition & 0 deletions toolsrc/include/vcpkg/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace vcpkg
static VcpkgCmdArguments create_from_arg_sequence(const std::string* arg_begin, const std::string* arg_end);

std::unique_ptr<std::string> vcpkg_root_dir;
std::unique_ptr<std::string> scripts_root_dir;
std::unique_ptr<std::string> triplet;
std::unique_ptr<std::vector<std::string>> overlay_ports;
std::unique_ptr<std::vector<std::string>> overlay_triplets;
Expand Down
3 changes: 2 additions & 1 deletion toolsrc/include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace vcpkg

struct VcpkgPaths
{
static Expected<VcpkgPaths> create(const fs::path& vcpkg_root_dir,
static Expected<VcpkgPaths> create(const fs::path& vcpkg_root_dir,
const Optional<fs::path>& vcpkg_scripts_root_dir,
const std::string& default_vs_path,
const std::vector<std::string>* triplets_dirs);

Expand Down
6 changes: 4 additions & 2 deletions toolsrc/src/tests.arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ namespace UnitTest1
{
TEST_METHOD(create_from_arg_sequence_options_lower)
{
std::vector<std::string> t = {"--vcpkg-root", "C:\\vcpkg", "--debug", "--sendmetrics", "--printmetrics"};
std::vector<std::string> t = {"--vcpkg-root", "C:\\vcpkg", "--scripts-root", "C:\\scripts", "--debug", "--sendmetrics", "--printmetrics"};
auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size());
Assert::AreEqual("C:\\vcpkg", v.vcpkg_root_dir.get()->c_str());
Assert::AreEqual("C:\\scripts", v.scripts_root_dir.get()->c_str());
Assert::IsTrue(v.debug && *v.debug.get());
Assert::IsTrue(v.sendmetrics && v.sendmetrics.get());
Assert::IsTrue(v.printmetrics && *v.printmetrics.get());
}

TEST_METHOD(create_from_arg_sequence_options_upper)
{
std::vector<std::string> t = {"--VCPKG-ROOT", "C:\\vcpkg", "--DEBUG", "--SENDMETRICS", "--PRINTMETRICS"};
std::vector<std::string> t = {"--VCPKG-ROOT", "C:\\vcpkg", "--SCRIPTS-ROOT", "C:\\scripts", "--DEBUG", "--SENDMETRICS", "--PRINTMETRICS"};
auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size());
Assert::AreEqual("C:\\vcpkg", v.vcpkg_root_dir.get()->c_str());
Assert::AreEqual("C:\\scripts", v.scripts_root_dir.get()->c_str());
Assert::IsTrue(v.debug && *v.debug.get());
Assert::IsTrue(v.sendmetrics && v.sendmetrics.get());
Assert::IsTrue(v.printmetrics && *v.printmetrics.get());
Expand Down
10 changes: 10 additions & 0 deletions toolsrc/src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,19 @@ static void inner(const VcpkgCmdArguments& args)

Debug::print("Using vcpkg-root: ", vcpkg_root_dir.u8string(), '\n');

Optional<fs::path> vcpkg_scripts_root_dir = nullopt;
if (nullptr != args.scripts_root_dir)
{
vcpkg_scripts_root_dir = fs::stdfs::canonical(fs::u8path(*args.scripts_root_dir));
Debug::print("Using scripts-root: ", vcpkg_scripts_root_dir.value_or_exit(VCPKG_LINE_INFO).u8string(), '\n');
}

auto default_vs_path = System::get_environment_variable("VCPKG_VISUAL_STUDIO_PATH").value_or("");



const Expected<VcpkgPaths> expected_paths = VcpkgPaths::create(vcpkg_root_dir,
vcpkg_scripts_root_dir,
default_vs_path,
args.overlay_triplets.get());
Checks::check_exit(VCPKG_LINE_INFO,
Expand Down
2 changes: 2 additions & 0 deletions toolsrc/src/vcpkg/help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ namespace vcpkg::Help
" (default: " ENVVAR(VCPKG_ROOT) //
")\n"
"\n"
" --scripts-root=<path> Specify the scripts root directory\n"
"\n"
" @response_file Specify a "
"response file to provide additional parameters\n"
"\n"
Expand Down
30 changes: 28 additions & 2 deletions toolsrc/src/vcpkg/vcpkgcmdarguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ namespace vcpkg
option_field = std::make_unique<std::string>(*arg_begin);
}

static void parse_cojoined_value(std::string new_value,
const std::string& option_name,
std::unique_ptr<std::string>& option_field)
{
if (nullptr != option_field)
{
System::printf(System::Color::error, "Error: %s specified multiple times\n", option_name);
Metrics::g_metrics.lock()->track_property("error", "error option specified multiple times");
Help::print_usage();
Checks::exit_fail(VCPKG_LINE_INFO);
}

option_field = std::make_unique<std::string>(std::move(new_value));
}

static void parse_switch(bool new_setting, const std::string& option_name, Optional<bool>& option_field)
{
if (option_field && option_field != new_setting)
Expand Down Expand Up @@ -120,16 +135,24 @@ namespace vcpkg

if (arg[0] == '-' && arg[1] == '-')
{
// make argument case insensitive
// make argument case insensitive before the first =
auto& f = std::use_facet<std::ctype<char>>(std::locale());
f.tolower(&arg[0], &arg[0] + arg.size());
auto first_eq = std::find(std::begin(arg), std::end(arg), '=');
f.tolower(&arg[0], &arg[0] + (first_eq - std::begin(arg)));
// command switch
if (arg == "--vcpkg-root")
{
++arg_begin;
parse_value(arg_begin, arg_end, "--vcpkg-root", args.vcpkg_root_dir);
continue;
}
if (Strings::starts_with(arg, "--scripts-root="))
{
parse_cojoined_value(arg.substr(sizeof("--scripts-root=") - 1),
"--scripts-root",
args.scripts_root_dir);
continue;
}
if (arg == "--triplet")
{
++arg_begin;
Expand Down Expand Up @@ -411,5 +434,8 @@ namespace vcpkg
System::printf(" %-40s %s\n",
"--vcpkg-root <path>",
"Specify the vcpkg directory to use instead of current directory or tool directory");
System::printf(" %-40s %s\n",
"--scripts-root=<path>",
"Specify the scripts directory to use instead of default vcpkg scripts directory");
}
}
53 changes: 36 additions & 17 deletions toolsrc/src/vcpkg/vcpkgpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

namespace vcpkg
{
Expected<VcpkgPaths> VcpkgPaths::create(const fs::path& vcpkg_root_dir,
Expected<VcpkgPaths> VcpkgPaths::create(const fs::path& vcpkg_root_dir,
const Optional<fs::path>& vcpkg_scripts_root_dir,
const std::string& default_vs_path,
const std::vector<std::string>* triplets_dirs)
{
Expand Down Expand Up @@ -65,7 +66,25 @@ namespace vcpkg
paths.ports = paths.root / "ports";
paths.installed = paths.root / "installed";
paths.triplets = paths.root / "triplets";
paths.scripts = paths.root / "scripts";

if (auto scripts_dir = vcpkg_scripts_root_dir.get())
{
if (scripts_dir->empty() || !fs::stdfs::is_directory(*scripts_dir))
{
Metrics::g_metrics.lock()->track_property("error", "Invalid scripts override directory.");
Checks::exit_with_message(
VCPKG_LINE_INFO,
"Invalid scripts override directory: %s; "
"create that directory or unset --scripts-root to use the default scripts location.",
scripts_dir->u8string());
}

paths.scripts = *scripts_dir;
}
else
{
paths.scripts = paths.root / "scripts";
}

paths.tools = paths.downloads / "tools";
paths.buildsystems = paths.scripts / "buildsystems";
Expand Down Expand Up @@ -132,21 +151,21 @@ namespace vcpkg
}

const fs::path VcpkgPaths::get_triplet_file_path(const Triplet& triplet) const
{
return m_triplets_cache.get_lazy(triplet, [&]()-> auto {
for (auto&& triplet_dir : triplets_dirs)
{
auto&& path = triplet_dir / (triplet.canonical_name() + ".cmake");
if (this->get_filesystem().exists(path))
{
return path;
}
}
Checks::exit_with_message(VCPKG_LINE_INFO,
"Error: Triplet file %s.cmake not found",
triplet.canonical_name());
});
{
return m_triplets_cache.get_lazy(triplet, [&]()-> auto {
for (auto&& triplet_dir : triplets_dirs)
{
auto&& path = triplet_dir / (triplet.canonical_name() + ".cmake");
if (this->get_filesystem().exists(path))
{
return path;
}
}

Checks::exit_with_message(VCPKG_LINE_INFO,
"Error: Triplet file %s.cmake not found",
triplet.canonical_name());
});

}

Expand Down