[package_spec] Make toString() a member function
MODIFY
include/package_spec.h
include/package_spec.h
@@ -18,13 +18,13 @@ namespace vcpkg
std::string dir() const;
+ std::string toString() const;
+
private:
std::string m_name;
triplet m_target_triplet;
};
- std::string to_string(const package_spec& spec);
-
std::string to_printf_arg(const package_spec& spec);
bool operator==(const package_spec& left, const package_spec& right);

MODIFY
src/commands_build.cpp
src/commands_build.cpp
@@ -44,20 +44,20 @@ namespace vcpkg::Commands::Build
timer.start();
int return_code = System::cmd_execute(command);
timer.stop();
- TrackMetric("buildtimeus-" + to_string(spec), timer.microseconds());
+ TrackMetric("buildtimeus-" + spec.toString(), timer.microseconds());
if (return_code != 0)
{
- System::println(System::color::error, "Error: building package %s failed", to_string(spec));
+ System::println(System::color::error, "Error: building package %s failed", spec.toString());
System::println("Please ensure sure you're using the latest portfiles with `vcpkg update`, then\n"
"submit an issue at https://github.com/Microsoft/vcpkg/issues including:\n"
" Package: %s\n"
" Vcpkg version: %s\n"
"\n"
"Additionally, attach any relevant sections from the log files above."
- , to_string(spec), Info::version());
+ , spec.toString(), Info::version());
TrackProperty("error", "build failed");
- TrackProperty("build_error", to_string(spec));
+ TrackProperty("build_error", spec.toString());
exit(EXIT_FAILURE);
}
@@ -118,7 +118,7 @@ namespace vcpkg::Commands::Build
System::println("");
for (const package_spec_with_install_plan& p : unmet_dependencies)
{
- System::println(" %s", to_string(p.spec));
+ System::println(" %s", p.spec.toString());
}
System::println("");
exit(EXIT_FAILURE);

MODIFY
src/commands_install.cpp
src/commands_install.cpp
@@ -192,11 +192,11 @@ namespace vcpkg::Commands::Install
std::vector<package_spec_with_install_plan> install_plan = Dependencies::create_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].spec);
+ std::string specs_string = install_plan[0].spec.toString();
for (size_t i = 1; i < install_plan.size(); ++i)
{
specs_string.push_back(',');
- specs_string.append(to_string(install_plan[i].spec));
+ specs_string.append(install_plan[i].spec.toString());
}
TrackProperty("installplan", specs_string);
Environment::ensure_utilities_on_path(paths);

MODIFY
src/package_spec.cpp
src/package_spec.cpp
@@ -55,14 +55,14 @@ namespace vcpkg
return Strings::format("%s_%s", this->m_name, this->m_target_triplet);
}
- std::string to_string(const package_spec& spec)
+ std::string package_spec::toString() const
{
- return Strings::format("%s:%s", spec.name(), spec.target_triplet());
+ return Strings::format("%s:%s", this->name(), this->target_triplet());
}
std::string to_printf_arg(const package_spec& spec)
{
- return to_string(spec);
+ return spec.toString();
}
bool operator==(const package_spec& left, const package_spec& right)
@@ -72,6 +72,6 @@ namespace vcpkg
std::ostream& operator<<(std::ostream& os, const package_spec& spec)
{
- return os << to_string(spec);
+ return os << spec.toString();
}
}

[package_spec] Make toString() a member function