aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Romero <romerosanchezv@gmail.com>2019-06-27 12:20:12 -0700
committerGitHub <noreply@github.com>2019-06-27 12:20:12 -0700
commit35e985d3ccf60235bc4881df4d934610cd507090 (patch)
treecc50cdccbffe94f765dfbe812e9cb241f55f27b2
parent82cd021b42ddce34b487a9665cf2614b563919de (diff)
downloadvcpkg-35e985d3ccf60235bc4881df4d934610cd507090.tar.gz
vcpkg-35e985d3ccf60235bc4881df4d934610cd507090.zip
Triplets Overlay Implementation (#7053)
* Triplets Overlay Implementation * Use cache for get_triplet_file_path() * Code cleanup
-rw-r--r--scripts/ports.cmake2
-rw-r--r--toolsrc/include/vcpkg/vcpkgcmdarguments.h1
-rw-r--r--toolsrc/include/vcpkg/vcpkgpaths.h11
-rw-r--r--toolsrc/src/vcpkg.cpp4
-rw-r--r--toolsrc/src/vcpkg/build.cpp13
-rw-r--r--toolsrc/src/vcpkg/help.cpp2
-rw-r--r--toolsrc/src/vcpkg/vcpkgcmdarguments.cpp30
-rw-r--r--toolsrc/src/vcpkg/vcpkgpaths.cpp61
8 files changed, 84 insertions, 40 deletions
diff --git a/scripts/ports.cmake b/scripts/ports.cmake
index 118cc9481..860d08893 100644
--- a/scripts/ports.cmake
+++ b/scripts/ports.cmake
@@ -32,7 +32,7 @@ endif()
if(CMD MATCHES "^BUILD$")
- set(CMAKE_TRIPLET_FILE ${VCPKG_ROOT_DIR}/triplets/${TARGET_TRIPLET}.cmake)
+ set(CMAKE_TRIPLET_FILE ${TARGET_TRIPLET_FILE})
if(NOT EXISTS ${CMAKE_TRIPLET_FILE})
message(FATAL_ERROR "Unsupported target triplet. Triplet file does not exist: ${CMAKE_TRIPLET_FILE}")
endif()
diff --git a/toolsrc/include/vcpkg/vcpkgcmdarguments.h b/toolsrc/include/vcpkg/vcpkgcmdarguments.h
index cad013eb8..ff13ae6bf 100644
--- a/toolsrc/include/vcpkg/vcpkgcmdarguments.h
+++ b/toolsrc/include/vcpkg/vcpkgcmdarguments.h
@@ -88,6 +88,7 @@ namespace vcpkg
std::unique_ptr<std::string> vcpkg_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;
Optional<bool> debug = nullopt;
Optional<bool> sendmetrics = nullopt;
Optional<bool> printmetrics = nullopt;
diff --git a/toolsrc/include/vcpkg/vcpkgpaths.h b/toolsrc/include/vcpkg/vcpkgpaths.h
index b09169b02..a30e0c653 100644
--- a/toolsrc/include/vcpkg/vcpkgpaths.h
+++ b/toolsrc/include/vcpkg/vcpkgpaths.h
@@ -47,14 +47,17 @@ namespace vcpkg
struct VcpkgPaths
{
- static Expected<VcpkgPaths> create(const fs::path& vcpkg_root_dir, const std::string& default_vs_path);
+ static Expected<VcpkgPaths> create(const fs::path& vcpkg_root_dir,
+ const std::string& default_vs_path,
+ const std::vector<std::string>* triplets_dirs);
fs::path package_dir(const PackageSpec& spec) const;
fs::path build_info_file_path(const PackageSpec& spec) const;
fs::path listfile_path(const BinaryParagraph& pgh) const;
-
- const std::vector<std::string>& get_available_triplets() const;
+
bool is_valid_triplet(const Triplet& t) const;
+ const std::vector<std::string>& get_available_triplets() const;
+ const fs::path get_triplet_file_path(const Triplet& triplet) const;
fs::path root;
fs::path packages;
@@ -93,7 +96,9 @@ namespace vcpkg
Lazy<std::vector<Toolset>> toolsets_vs2013;
fs::path default_vs_path;
+ std::vector<fs::path> triplets_dirs;
mutable std::unique_ptr<ToolCache> m_tool_cache;
+ mutable vcpkg::Cache<Triplet, fs::path> m_triplets_cache;
};
}
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp
index e02bdc71f..5da97b136 100644
--- a/toolsrc/src/vcpkg.cpp
+++ b/toolsrc/src/vcpkg.cpp
@@ -118,7 +118,9 @@ static void inner(const VcpkgCmdArguments& args)
auto default_vs_path = System::get_environment_variable("VCPKG_VISUAL_STUDIO_PATH").value_or("");
- const Expected<VcpkgPaths> expected_paths = VcpkgPaths::create(vcpkg_root_dir, default_vs_path);
+ const Expected<VcpkgPaths> expected_paths = VcpkgPaths::create(vcpkg_root_dir,
+ default_vs_path,
+ args.overlay_triplets.get());
Checks::check_exit(VCPKG_LINE_INFO,
!expected_paths.error(),
"Error: Invalid vcpkg root directory %s: %s",
diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp
index 059a09432..f826a4865 100644
--- a/toolsrc/src/vcpkg/build.cpp
+++ b/toolsrc/src/vcpkg/build.cpp
@@ -361,9 +361,15 @@ namespace vcpkg::Build
{
auto& fs = paths.get_filesystem();
const Triplet& triplet = spec.triplet();
+ const auto& triplet_file_path = paths.get_triplet_file_path(spec.triplet()).u8string();
- if (!Strings::starts_with(Strings::ascii_to_lowercase(config.port_dir.u8string()),
- Strings::ascii_to_lowercase(paths.ports.u8string())))
+ if (!Strings::case_insensitive_ascii_starts_with(triplet_file_path,
+ paths.triplets.u8string()))
+ {
+ System::printf("-- Loading triplet configuration from: %s\n", triplet_file_path);
+ }
+ if (!Strings::case_insensitive_ascii_starts_with(config.port_dir.u8string(),
+ paths.ports.u8string()))
{
System::printf("-- Installing port from location: %s\n", config.port_dir.u8string());
}
@@ -390,6 +396,7 @@ namespace vcpkg::Build
{"PORT", config.scf.core_paragraph->name},
{"CURRENT_PORT_DIR", config.port_dir},
{"TARGET_TRIPLET", spec.triplet().canonical_name()},
+ {"TARGET_TRIPLET_FILE", triplet_file_path},
{"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()},
{"VCPKG_USE_HEAD_VERSION", Util::Enum::to_bool(config.build_package_options.use_head_version) ? "1" : "0"},
{"DOWNLOADS", paths.downloads},
@@ -890,7 +897,7 @@ namespace vcpkg::Build
const fs::path& cmake_exe_path = paths.get_tool_exe(Tools::CMAKE);
const fs::path ports_cmake_script_path = paths.scripts / "get_triplet_environment.cmake";
- const fs::path triplet_file_path = paths.triplets / (triplet.canonical_name() + ".cmake");
+ const fs::path triplet_file_path = paths.get_triplet_file_path(triplet);
const auto cmd_launch_cmake = System::make_cmake_cmd(cmake_exe_path,
ports_cmake_script_path,
diff --git a/toolsrc/src/vcpkg/help.cpp b/toolsrc/src/vcpkg/help.cpp
index 6ee573dfc..896f62661 100644
--- a/toolsrc/src/vcpkg/help.cpp
+++ b/toolsrc/src/vcpkg/help.cpp
@@ -117,6 +117,8 @@ namespace vcpkg::Help
"\n"
" --overlay-ports=<path> Specify directories to be used when searching for ports\n"
"\n"
+ " --overlay-triplets=<path> Specify directories containing triplets files\n"
+ "\n"
" --vcpkg-root <path> Specify the vcpkg root "
"directory\n"
" (default: " ENVVAR(VCPKG_ROOT) //
diff --git a/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp b/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp
index 21bf4d028..3c1452d47 100644
--- a/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp
+++ b/toolsrc/src/vcpkg/vcpkgcmdarguments.cpp
@@ -45,26 +45,6 @@ namespace vcpkg
option_field = new_setting;
}
- static void parse_multivalue(const std::string* arg_begin,
- const std::string* arg_end,
- const std::string& option_name,
- std::unique_ptr<std::vector<std::string>>& option_field)
- {
- if (arg_begin == arg_end)
- {
- System::print2(System::Color::error, "Error: expected value after ", option_name, '\n');
- Metrics::g_metrics.lock()->track_property("error", "error option name");
- Help::print_usage();
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
-
- if (!option_field)
- {
- option_field = std::make_unique<std::vector<std::string>>();
- }
- option_field->emplace_back(*arg_begin);
- }
-
static void parse_cojoined_multivalue(std::string new_value,
const std::string& option_name,
std::unique_ptr<std::vector<std::string>>& option_field)
@@ -163,6 +143,13 @@ namespace vcpkg
args.overlay_ports);
continue;
}
+ if (Strings::starts_with(arg, "--overlay-triplets="))
+ {
+ parse_cojoined_multivalue(arg.substr(sizeof("--overlay-triplets=") - 1),
+ "--overlay-triplets",
+ args.overlay_triplets);
+ continue;
+ }
if (arg == "--debug")
{
parse_switch(true, "debug", args.debug);
@@ -419,6 +406,9 @@ namespace vcpkg
"--overlay-ports=<path>",
"Specify directories to be used when searching for ports");
System::printf(" %-40s %s\n",
+ "--overlay-triplets=<path>",
+ "Specify directories containing triplets files");
+ System::printf(" %-40s %s\n",
"--vcpkg-root <path>",
"Specify the vcpkg directory to use instead of current directory or tool directory");
}
diff --git a/toolsrc/src/vcpkg/vcpkgpaths.cpp b/toolsrc/src/vcpkg/vcpkgpaths.cpp
index 562a18c9b..909fbeb44 100644
--- a/toolsrc/src/vcpkg/vcpkgpaths.cpp
+++ b/toolsrc/src/vcpkg/vcpkgpaths.cpp
@@ -13,7 +13,9 @@
namespace vcpkg
{
- Expected<VcpkgPaths> VcpkgPaths::create(const fs::path& vcpkg_root_dir, const std::string& default_vs_path)
+ Expected<VcpkgPaths> VcpkgPaths::create(const fs::path& vcpkg_root_dir,
+ const std::string& default_vs_path,
+ const std::vector<std::string>* triplets_dirs)
{
std::error_code ec;
const fs::path canonical_vcpkg_root_dir = fs::stdfs::canonical(vcpkg_root_dir, ec);
@@ -76,6 +78,20 @@ namespace vcpkg
paths.ports_cmake = paths.scripts / "ports.cmake";
+ if (triplets_dirs)
+ {
+ for (auto&& triplets_dir : *triplets_dirs)
+ {
+ auto path = fs::u8path(triplets_dir);
+ Checks::check_exit(VCPKG_LINE_INFO,
+ paths.get_filesystem().exists(path),
+ "Error: Path does not exist '%s'",
+ triplets_dir);
+ paths.triplets_dirs.emplace_back(fs::stdfs::canonical(path));
+ }
+ }
+ paths.triplets_dirs.emplace_back(fs::stdfs::canonical(paths.root / "triplets"));
+
return paths;
}
@@ -91,26 +107,47 @@ namespace vcpkg
return this->vcpkg_dir_info / (pgh.fullstem() + ".list");
}
+ bool VcpkgPaths::is_valid_triplet(const Triplet& t) const
+ {
+ const auto it = Util::find_if(this->get_available_triplets(), [&](auto&& available_triplet) {
+ return t.canonical_name() == available_triplet;
+ });
+ return it != this->get_available_triplets().cend();
+ }
+
const std::vector<std::string>& VcpkgPaths::get_available_triplets() const
{
return this->available_triplets.get_lazy([this]() -> std::vector<std::string> {
std::vector<std::string> output;
- for (auto&& path : this->get_filesystem().get_files_non_recursive(this->triplets))
+ for (auto&& triplets_dir : triplets_dirs)
{
- output.push_back(path.stem().filename().string());
+ for (auto&& path : this->get_filesystem().get_files_non_recursive(triplets_dir))
+ {
+ output.push_back(path.stem().filename().string());
+ }
}
- Util::sort(output);
-
+ Util::sort_unique_erase(output);
return output;
- });
+ });
}
- bool VcpkgPaths::is_valid_triplet(const Triplet& t) const
- {
- const auto it = Util::find_if(this->get_available_triplets(), [&](auto&& available_triplet) {
- return t.canonical_name() == available_triplet;
- });
- return it != this->get_available_triplets().cend();
+ 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());
+ });
+
}
const fs::path& VcpkgPaths::get_tool_exe(const std::string& tool) const