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

Default triplet #70

Merged
merged 6 commits into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions toolsrc/include/triplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace vcpkg
{
struct vcpkg_paths;

struct triplet
{
static const triplet X86_WINDOWS;
Expand All @@ -17,6 +19,8 @@ namespace vcpkg
std::string architecture() const;

std::string system() const;

bool validate(const vcpkg_paths& paths);
};

bool operator==(const triplet& left, const triplet& right);
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/include/vcpkg_cmd_arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace vcpkg
std::unordered_set<std::string> check_and_get_optional_command_arguments(const std::vector<std::string>& valid_options) const;

void check_max_args(size_t arg_count, const char* example_text = nullptr) const;
std::vector<package_spec> parse_all_arguments_as_package_specs(const triplet& default_target_triplet, const char* example_text = nullptr) const;
std::vector<package_spec> parse_all_arguments_as_package_specs(const vcpkg_paths& paths, const triplet& default_target_triplet, const char* example_text = nullptr) const;

private:
std::unordered_set<std::string> optional_command_arguments;
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/commands_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace vcpkg
void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
{
args.check_max_args(3);
package_spec spec = args.parse_all_arguments_as_package_specs(default_target_triplet).at(0);
package_spec spec = args.parse_all_arguments_as_package_specs(paths, default_target_triplet).at(0);
if (args.command_arguments.size() < 2)
{
System::println(System::color::error, "Error: create requires the archive's URL as the second argument.");
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/commands_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace vcpkg
{
static auto example = "edit zlib";
args.check_max_args(1, example);
package_spec spec = args.parse_all_arguments_as_package_specs(default_target_triplet, example).at(0);
package_spec spec = args.parse_all_arguments_as_package_specs(paths, default_target_triplet, example).at(0);

// Find editor
std::wstring env_EDITOR = System::wdupenv_str(L"EDITOR");
Expand Down
4 changes: 2 additions & 2 deletions toolsrc/src/commands_installation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace vcpkg
{
StatusParagraphs status_db = database_load_check(paths);

std::vector<package_spec> specs = args.parse_all_arguments_as_package_specs(default_target_triplet);
std::vector<package_spec> specs = args.parse_all_arguments_as_package_specs(paths, default_target_triplet);
std::vector<package_spec> install_plan = Dependencies::create_dependency_ordered_install_plan(paths, specs, status_db);
Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty");
std::string specs_string = to_string(install_plan[0]);
Expand Down Expand Up @@ -119,7 +119,7 @@ namespace vcpkg

StatusParagraphs status_db = database_load_check(paths);

std::vector<package_spec> specs = args.parse_all_arguments_as_package_specs(default_target_triplet);
std::vector<package_spec> specs = args.parse_all_arguments_as_package_specs(paths, default_target_triplet);
std::unordered_set<package_spec> unmet_dependencies = Dependencies::find_unmet_dependencies(paths, specs, status_db);
if (!unmet_dependencies.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/commands_other.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace vcpkg
//"\n"
"Options:\n"
" --triplet <t> Specify the target architecture triplet.\n"
" (default: x86-windows, see 'vcpkg help triplet')\n"
" (default: %%VCPKG_DEFAULT_TRIPLET%%, see 'vcpkg help triplet')\n"
"\n"
" --vcpkg-root <path> Specify the vcpkg root directory\n"
" (default: %%VCPKG_ROOT%%)\n"
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/commands_remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace vcpkg
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({OPTION_PURGE});
auto status_db = database_load_check(paths);

std::vector<package_spec> specs = args.parse_all_arguments_as_package_specs(default_target_triplet);
std::vector<package_spec> specs = args.parse_all_arguments_as_package_specs(paths, default_target_triplet);
bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end();

for (const package_spec& spec : specs)
Expand Down
38 changes: 19 additions & 19 deletions toolsrc/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,32 @@ static void inner(const vcpkg_cmd_arguments& args)
return command_function(args, paths);
}

triplet default_target_triplet = triplet::X86_WINDOWS;

if (args.target_triplet != nullptr)
triplet default_target_triplet;
if(args.target_triplet != nullptr)
{
const std::string& target_triplet = *args.target_triplet;

auto it = fs::directory_iterator(paths.triplets);
for (; it != fs::directory_iterator(); ++it)
default_target_triplet = {*args.target_triplet};
}
else
{
const auto vcpkg_default_triplet_env = System::wdupenv_str(L"VCPKG_DEFAULT_TRIPLET");
if(!vcpkg_default_triplet_env.empty())
{
std::string triplet_file_name = it->path().stem().generic_u8string();
if (target_triplet == triplet_file_name) // TODO: fuzzy compare
{
default_target_triplet = {triplet_file_name};
break;
}
default_target_triplet = {Strings::utf16_to_utf8(vcpkg_default_triplet_env)};
}

if (it == fs::directory_iterator())
else
{
System::println(System::color::error, "Error: invalid triplet: %s", target_triplet);
TrackProperty("error", "invalid triplet: " + target_triplet);
help_topic_valid_triplet(paths);
exit(EXIT_FAILURE);
default_target_triplet = triplet::X86_WINDOWS;
}
}

if(!default_target_triplet.validate(paths))
{
System::println(System::color::error, "Error: invalid triplet: %s", default_target_triplet.value);
TrackProperty("error", "invalid triplet: " + default_target_triplet.value);
help_topic_valid_triplet(paths);
exit(EXIT_FAILURE);
}

if (auto command_function = find_command(args.command, get_available_commands_type_a()))
{
return command_function(args, paths, default_target_triplet);
Expand Down
16 changes: 16 additions & 0 deletions toolsrc/src/triplet.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "triplet.h"
#include "vcpkg.h"
#include "vcpkg_System.h"
#include "vcpkg_Checks.h"

Expand Down Expand Up @@ -56,4 +57,19 @@ namespace vcpkg

Checks::exit_with_message("Unknown system: %s", value);
}

bool triplet::validate(const vcpkg_paths & paths)
{
auto it = fs::directory_iterator(paths.triplets);
for(; it != fs::directory_iterator(); ++it)
{
std::string triplet_file_name = it->path().stem().generic_u8string();
if(value == triplet_file_name) // TODO: fuzzy compare
{
//value = triplet_file_name; // NOTE: uncomment when implementing fuzzy compare
return true;
}
}
return false;
}
}
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg_cmd_arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace vcpkg
}
}

std::vector<package_spec> vcpkg_cmd_arguments::parse_all_arguments_as_package_specs(const triplet& default_target_triplet, const char* example_text) const
std::vector<package_spec> vcpkg_cmd_arguments::parse_all_arguments_as_package_specs(const vcpkg_paths& paths, const triplet& default_target_triplet, const char* example_text) const
{
size_t arg_count = command_arguments.size();
if (arg_count < 1)
Expand Down