Skip to content

Commit

Permalink
cps: move platform abstractions out of search.cpp
Browse files Browse the repository at this point in the history
These will be useful outside of the cps search module.
  • Loading branch information
dcbaker committed Jul 25, 2024
1 parent b48ff33 commit ed979dc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_library(
cps
cps/env.cpp
cps/loader.cpp
cps/platform.cpp
cps/printer.cpp
cps/search.cpp
cps/utils.cpp
Expand Down
12 changes: 12 additions & 0 deletions src/cps/platform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
// Copyright © 2024 Dylan Baker

#include "cps/platform.hpp"

namespace cps::platform {

fs::path libdir() { return "lib"; }

fs::path datadir() { return "share"; }

} // namespace cps::platform
18 changes: 18 additions & 0 deletions src/cps/platform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
// Copyright © 2024 Dylan Baker

#include <filesystem>

namespace cps::platform {

namespace fs = std::filesystem;

/// @brief Get the platform specific location that libraries are installed in
/// @return A path segment for libraries to be installed in, relative to a prefix
fs::path libdir();

/// @brief Get the platform specific location to install architecture agnostic data to
/// @return A path segment for data to be installed in, relative to a prefix
fs::path datadir();

} // namespace cps::platform
18 changes: 3 additions & 15 deletions src/cps/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "cps/error.hpp"
#include "cps/loader.hpp"
#include "cps/platform.hpp"
#include "cps/utils.hpp"
#include "cps/version.hpp"

Expand Down Expand Up @@ -71,19 +72,6 @@ namespace cps::search {
return out;
}

fs::path libdir() {
// TODO: libdir needs to be configurable based on the personality,
// and different name schemes.
// This is complicated by the fact that different distros have
// different schemes.
return "lib";
}

fs::path datadir() {
// TODO: needs to be configurable. see libdir above.
return "share";
}

const std::vector<fs::path> nix_prefix{"/usr", "/usr/local"};
// TODO: const std::vector<std::string> mac_prefix{""};
// TODO: const std::vector<std::string> win_prefix{""};
Expand All @@ -100,8 +88,8 @@ namespace cps::search {
// TODO: Windows specific paths

// TODO: handle name-like search paths
paths.emplace_back(prefix / libdir() / "cps");
paths.emplace_back(prefix / datadir() / "cps");
paths.emplace_back(prefix / platform::libdir() / "cps");
paths.emplace_back(prefix / platform::datadir() / "cps");

return paths;
};
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ libcps = static_library(
'cps',
'cps/env.cpp',
'cps/loader.cpp',
'cps/platform.cpp',
'cps/printer.cpp',
'cps/search.cpp',
'cps/utils.cpp',
Expand Down

0 comments on commit ed979dc

Please sign in to comment.