Skip to content

Commit

Permalink
Fix compilation on Windows mingw
Browse files Browse the repository at this point in the history
MSSTL does not provide an implicit conversion from `fs::path` to
`std::string`.
  • Loading branch information
lunacd committed Sep 27, 2024
1 parent 452f739 commit df8f1bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/cps/pc_compat/pc_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
#include "cps/version.hpp"

#include <algorithm>
#include <fmt/format.h>
#include <filesystem>
#include <iterator>
#include <optional>
#include <ostream>
#include <stdexcept>
#include <tl/expected.hpp>
#include <variant>

#include <fmt/format.h>
#include <tl/expected.hpp>

namespace cps::pc_compat {

namespace fs = std::filesystem;

std::ostream & operator<<(std::ostream & ost, const std::optional<VersionOperation> & version_operation) {
if (!version_operation) {
return ost;
Expand Down Expand Up @@ -76,7 +80,7 @@ namespace cps::pc_compat {

PcLoader::PcLoader() = default;

tl::expected<loader::Package, std::string> PcLoader::load(std::istream & istream, std::string const & filename) {
tl::expected<loader::Package, std::string> PcLoader::load(std::istream & istream, fs::path const & filename) {
scan_begin(istream);
yy::parser parse(*this);
// To debug parser, uncomment the following line
Expand Down Expand Up @@ -123,7 +127,7 @@ namespace cps::pc_compat {
return loader::Package{.name = name,
.cps_version = std::string{loader::CPS_VERSION},
.components = components,
.cps_path = filename,
.cps_path = filename.string(),
.default_components = std::vector{name},
.platform = std::nullopt,
.require = {}, // TODO: Parse requires
Expand Down
5 changes: 3 additions & 2 deletions src/cps/pc_compat/pc_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include "cps/pc_compat/pc.parser.hpp"
#include "cps/pc_compat/pc_base.hpp"

#include <filesystem>
#include <unordered_map>
#include <variant>

#include <tl/expected.hpp>
#include <variant>

namespace cps::pc_compat {

Expand All @@ -29,7 +30,7 @@ namespace cps::pc_compat {
// For example, libdir=${PREFIX}/lib
std::unordered_map<std::string, std::string> variables;

tl::expected<loader::Package, std::string> load(std::istream & istream, std::string const & filename);
tl::expected<loader::Package, std::string> load(std::istream & istream, std::filesystem::path const & filename);

void scan_begin(std::istream & istream) const;

Expand Down
16 changes: 9 additions & 7 deletions tests/pc_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

#include <filesystem>
#include <fstream>
#include <gtest/gtest.h>
#include <variant>

#include <gtest/gtest.h>

namespace fs = std::filesystem;

namespace cps::utils::test {
using namespace cps::pc_compat;
namespace fs = std::filesystem;

namespace {

std::ifstream open_pc_test_file(const std::string & file_name) {
return std::ifstream{std::string(std::getenv("CPS_TEST_DIR")) + file_name};
std::ifstream open_pc_test_file(const fs::path & file_name) {
return std::ifstream{std::string(std::getenv("CPS_TEST_DIR")) + file_name.string()};
}

void assert_string_value(const PcPropertyValue & property_value, std::string_view expected) {
Expand All @@ -34,17 +36,17 @@ namespace cps::utils::test {
TEST(PcLoader, comments) {
PcLoader pc_loader;
fs::path file_path = "/cps-files/lib/pkgconfig/pc-comments.pc";
std::ifstream input = open_pc_test_file(file_path);
pc_loader.load(input, file_path.parent_path());
std::ifstream input = open_pc_test_file(file_path.string());
pc_loader.load(input, file_path.parent_path().string());
assert_string_value(pc_loader.properties["Name"], "libfoo");
assert_string_value(pc_loader.properties["Description"], "This is an example library");
}

TEST(PcLoader, minimal) {
PcLoader pc_loader;
fs::path file_path = "/cps-files/lib/pkgconfig/pc-minimal.pc";
std::ifstream input = open_pc_test_file(file_path);
pc_loader.load(input, file_path.parent_path());
std::ifstream input = open_pc_test_file(file_path.string());
pc_loader.load(input, file_path.parent_path().string());
assert_string_value(pc_loader.properties["Name"], "libfoo");
assert_string_value(pc_loader.properties["Description"], "An example library");
assert_string_value(pc_loader.properties["Version"], "1.0");
Expand Down

0 comments on commit df8f1bf

Please sign in to comment.