Skip to content

Commit

Permalink
Triplets Overlay Implementation (#7053)
Browse files Browse the repository at this point in the history
* Triplets Overlay Implementation

* Use cache for get_triplet_file_path()

* Code cleanup
  • Loading branch information
vicroms authored Jun 27, 2019
1 parent 82cd021 commit 35e985d
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 40 deletions.
2 changes: 1 addition & 1 deletion scripts/ports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions toolsrc/include/vcpkg/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions toolsrc/include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
}
4 changes: 3 additions & 1 deletion toolsrc/src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 10 additions & 3 deletions toolsrc/src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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},
Expand Down Expand Up @@ -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,
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 @@ -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) //
Expand Down
30 changes: 10 additions & 20 deletions toolsrc/src/vcpkg/vcpkgcmdarguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -418,6 +405,9 @@ namespace vcpkg
System::printf(" %-40s %s\n",
"--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");
Expand Down
61 changes: 49 additions & 12 deletions toolsrc/src/vcpkg/vcpkgpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand Down

0 comments on commit 35e985d

Please sign in to comment.