aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg.cpp
diff options
context:
space:
mode:
authormartin-s <webmaster@macside.net>2017-10-15 02:00:19 +0200
committermartin-s <webmaster@macside.net>2017-10-15 02:00:19 +0200
commit9c2fa042ee451f5ec1e5781c8daccd9fd6875de0 (patch)
tree250b18fea62d58e2138de12f78e25d0ed8c69678 /toolsrc/src/vcpkg.cpp
parent630bcd84b8325217c440def11681e375f5ef4652 (diff)
parent561cfe89e653aef903488f7af7d4d17cfb11a26c (diff)
downloadvcpkg-9c2fa042ee451f5ec1e5781c8daccd9fd6875de0.tar.gz
vcpkg-9c2fa042ee451f5ec1e5781c8daccd9fd6875de0.zip
Merge branch 'master' of https://github.com/Microsoft/vcpkg into patch-vs2013
# Conflicts: # toolsrc/include/vcpkg/vcpkgpaths.h # toolsrc/src/vcpkg/vcpkgpaths.cpp
Diffstat (limited to 'toolsrc/src/vcpkg.cpp')
-rw-r--r--toolsrc/src/vcpkg.cpp67
1 files changed, 46 insertions, 21 deletions
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp
index 706c641fb..f1a86ae22 100644
--- a/toolsrc/src/vcpkg.cpp
+++ b/toolsrc/src/vcpkg.cpp
@@ -1,16 +1,18 @@
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
-#include "Paragraphs.h"
-#include "metrics.h"
-#include "vcpkg_Chrono.h"
-#include "vcpkg_Commands.h"
-#include "vcpkg_Files.h"
-#include "vcpkg_GlobalState.h"
-#include "vcpkg_Input.h"
-#include "vcpkg_Strings.h"
-#include "vcpkg_System.h"
-#include "vcpkglib.h"
+#include <vcpkg/base/chrono.h>
+#include <vcpkg/base/files.h>
+#include <vcpkg/base/strings.h>
+#include <vcpkg/base/system.h>
+#include <vcpkg/commands.h>
+#include <vcpkg/globalstate.h>
+#include <vcpkg/help.h>
+#include <vcpkg/input.h>
+#include <vcpkg/metrics.h>
+#include <vcpkg/paragraphs.h>
+#include <vcpkg/vcpkglib.h>
+
#pragma warning(push)
#pragma warning(disable : 4768)
#include <Shlobj.h>
@@ -19,12 +21,15 @@
#include <fstream>
#include <memory>
+#pragma comment(lib, "ole32")
+#pragma comment(lib, "shell32")
+
using namespace vcpkg;
void invalid_command(const std::string& cmd)
{
System::println(System::Color::error, "invalid command: %s", cmd);
- Commands::Help::print_usage();
+ Help::print_usage();
Checks::exit_fail(VCPKG_LINE_INFO);
}
@@ -33,13 +38,26 @@ static void inner(const VcpkgCmdArguments& args)
Metrics::g_metrics.lock()->track_property("command", args.command);
if (args.command.empty())
{
- Commands::Help::print_usage();
+ Help::print_usage();
Checks::exit_fail(VCPKG_LINE_INFO);
}
- if (const auto command_function = Commands::find(args.command, Commands::get_available_commands_type_c()))
+ static const auto find_command = [&](auto&& commands) {
+ auto it = Util::find_if(commands, [&](auto&& commandc) {
+ return Strings::case_insensitive_ascii_compare(commandc.name, args.command);
+ });
+ using std::end;
+ if (it != end(commands))
+ {
+ return &*it;
+ }
+ else
+ return static_cast<decltype(&*it)>(nullptr);
+ };
+
+ if (const auto command_function = find_command(Commands::get_available_commands_type_c()))
{
- return command_function(args);
+ return command_function->function(args);
}
fs::path vcpkg_root_dir;
@@ -56,8 +74,14 @@ static void inner(const VcpkgCmdArguments& args)
}
else
{
- vcpkg_root_dir = Files::get_real_filesystem().find_file_recursively_up(
- fs::stdfs::absolute(System::get_exe_path_of_current_process()), ".vcpkg-root");
+ const fs::path current_path = fs::stdfs::current_path();
+ vcpkg_root_dir = Files::get_real_filesystem().find_file_recursively_up(current_path, ".vcpkg-root");
+
+ if (vcpkg_root_dir.empty())
+ {
+ vcpkg_root_dir = Files::get_real_filesystem().find_file_recursively_up(
+ fs::stdfs::absolute(System::get_exe_path_of_current_process()), ".vcpkg-root");
+ }
}
}
@@ -70,13 +94,14 @@ static void inner(const VcpkgCmdArguments& args)
vcpkg_root_dir.string(),
expected_paths.error().message());
const VcpkgPaths paths = expected_paths.value_or_exit(VCPKG_LINE_INFO);
+
const int exit_code = _wchdir(paths.root.c_str());
Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Changing the working dir failed");
Commands::Version::warn_if_vcpkg_version_mismatch(paths);
- if (const auto command_function = Commands::find(args.command, Commands::get_available_commands_type_b()))
+ if (const auto command_function = find_command(Commands::get_available_commands_type_b()))
{
- return command_function(args, paths);
+ return command_function->function(args, paths);
}
Triplet default_triplet;
@@ -100,9 +125,9 @@ static void inner(const VcpkgCmdArguments& args)
Input::check_triplet(default_triplet, paths);
- if (const auto command_function = Commands::find(args.command, Commands::get_available_commands_type_a()))
+ if (const auto command_function = find_command(Commands::get_available_commands_type_a()))
{
- return command_function(args, paths, default_triplet);
+ return command_function->function(args, paths, default_triplet);
}
return invalid_command(args.command);
@@ -202,7 +227,7 @@ int wmain(const int argc, const wchar_t* const* const argv)
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
- *GlobalState::timer.lock() = ElapsedTime::create_started();
+ *GlobalState::timer.lock() = Chrono::ElapsedTime::create_started();
const std::string trimmed_command_line = trim_path_from_command_line(Strings::to_utf8(GetCommandLineW()));