From 7d31d74380a66d2d351f4a749b2c98a6ae0e87ea Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Tue, 21 Jan 2025 20:54:39 -0500 Subject: [PATCH] Aliases: removed (#1117) resolves #1027, resolves #1047 --- src/Algos.cc | 2 +- src/BuildConfig.cc | 6 ++++-- src/BuildConfig.hpp | 1 - src/Cli.hpp | 3 ++- src/Cmd/New.cc | 16 +++++++-------- src/Command.cc | 3 +-- src/Git2/Exception.hpp | 3 +-- src/Manifest.hpp | 4 +++- src/Rustify.hpp | 5 ----- src/Rustify/Aliases.hpp | 43 ----------------------------------------- src/VersionReq.cc | 7 ++++--- 11 files changed, 24 insertions(+), 69 deletions(-) delete mode 100644 src/Rustify.hpp delete mode 100644 src/Rustify/Aliases.hpp diff --git a/src/Algos.cc b/src/Algos.cc index 38cfbc97d..f0ad52d35 100644 --- a/src/Algos.cc +++ b/src/Algos.cc @@ -193,7 +193,6 @@ findSimilarStr( #ifdef CABIN_TEST -# include "Rustify/Aliases.hpp" # include "Rustify/Tests.hpp" # include @@ -202,6 +201,7 @@ findSimilarStr( namespace tests { using namespace cabin; // NOLINT(build/namespaces,google-build-using-namespace) +using std::string_view_literals::operator""sv; static void testLevDistance() { diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index dbc2bbf9b..5511bf669 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -527,7 +527,7 @@ BuildConfig::mapHeaderToObj( const fs::path& headerPath, const fs::path& buildOutPath ) const { fs::path objBaseDir = fs::relative( - headerPath.parent_path(), manifest.path.parent_path() / "src"_path + headerPath.parent_path(), manifest.path.parent_path() / "src" ); if (objBaseDir != ".") { objBaseDir = buildOutPath / objBaseDir; @@ -778,7 +778,7 @@ BuildConfig::processUnittestSrc( parseMMOutput(Try(runMM(sourceFilePath, /*isTest=*/true)), objTarget); const fs::path targetBaseDir = fs::relative( - sourceFilePath.parent_path(), manifest.path.parent_path() / "src"_path + sourceFilePath.parent_path(), manifest.path.parent_path() / "src" ); fs::path testTargetBaseDir = unittestOutPath; if (targetBaseDir != ".") { @@ -1083,6 +1083,8 @@ getMakeCommand() { #ifdef CABIN_TEST +# include "Rustify/Tests.hpp" + namespace tests { using namespace cabin; // NOLINT(build/namespaces,google-build-using-namespace) diff --git a/src/BuildConfig.hpp b/src/BuildConfig.hpp index 16ec26e70..d97305950 100644 --- a/src/BuildConfig.hpp +++ b/src/BuildConfig.hpp @@ -2,7 +2,6 @@ #include "Command.hpp" #include "Manifest.hpp" -#include "Rustify.hpp" #include #include diff --git a/src/Cli.hpp b/src/Cli.hpp index a47b67488..75fc6f5d4 100644 --- a/src/Cli.hpp +++ b/src/Cli.hpp @@ -1,7 +1,6 @@ #pragma once #include "Logger.hpp" -#include "Rustify/Aliases.hpp" #include "Rustify/Result.hpp" #include "TermColor.hpp" @@ -226,6 +225,8 @@ class Cli : public CliBase { std::forward_iterator auto& itr, const std::forward_iterator auto end, std::string_view subcmd = "" ) { + using std::string_view_literals::operator""sv; + if (*itr == "-h"sv || *itr == "--help"sv) { if (!subcmd.empty()) { // {{ }} is a workaround for std::span until C++26. diff --git a/src/Cmd/New.cc b/src/Cmd/New.cc index 5978464b5..5d765a1e5 100644 --- a/src/Cmd/New.cc +++ b/src/Cmd/New.cc @@ -99,25 +99,25 @@ createTemplateFiles(const bool isBin, const std::string_view projectName) { std::ofstream ofs; if (isBin) { - fs::create_directories(projectName / "src"_path); + fs::create_directories(projectName / fs::path("src")); Try(writeToFile( - ofs, projectName / "cabin.toml"_path, createCabinToml(projectName) + ofs, projectName / fs::path("cabin.toml"), createCabinToml(projectName) )); - Try(writeToFile(ofs, projectName / ".gitignore"_path, "/cabin-out")); - Try(writeToFile(ofs, projectName / "src"_path / "main.cc", MAIN_CC)); + Try(writeToFile(ofs, projectName / fs::path(".gitignore"), "/cabin-out")); + Try(writeToFile(ofs, projectName / fs::path("src") / "main.cc", MAIN_CC)); logger::info("Created", "binary (application) `{}` package", projectName); } else { - fs::create_directories(projectName / "include"_path / projectName); + fs::create_directories(projectName / fs::path("include") / projectName); Try(writeToFile( - ofs, projectName / "cabin.toml"_path, createCabinToml(projectName) + ofs, projectName / fs::path("cabin.toml"), createCabinToml(projectName) )); Try(writeToFile( - ofs, projectName / ".gitignore"_path, "/cabin-out\ncabin.lock" + ofs, projectName / fs::path(".gitignore"), "/cabin-out\ncabin.lock" )); Try(writeToFile( ofs, - (projectName / "include"_path / projectName / projectName).string() + (projectName / fs::path("include") / projectName / projectName).string() + ".hpp", getHeader(projectName) )); diff --git a/src/Command.cc b/src/Command.cc index eab73222c..8ebcee482 100644 --- a/src/Command.cc +++ b/src/Command.cc @@ -1,6 +1,5 @@ #include "Command.hpp" -#include "Rustify/Aliases.hpp" #include "Rustify/Result.hpp" #include @@ -206,7 +205,7 @@ Command::spawn() const noexcept { _exit(1); } - unreachable(); + __builtin_unreachable(); } else { // Parent process diff --git a/src/Git2/Exception.hpp b/src/Git2/Exception.hpp index b47ffc61a..b1580e1fc 100644 --- a/src/Git2/Exception.hpp +++ b/src/Git2/Exception.hpp @@ -1,7 +1,5 @@ #pragma once -#include "../Rustify.hpp" - #include #include #include @@ -71,4 +69,5 @@ struct Exception final : public std::exception { }; int git2Throw(int ret); + } // namespace git2 diff --git a/src/Manifest.hpp b/src/Manifest.hpp index f97d7ae04..029a0de4f 100644 --- a/src/Manifest.hpp +++ b/src/Manifest.hpp @@ -1,6 +1,5 @@ #pragma once -#include "Rustify/Aliases.hpp" #include "Rustify/Result.hpp" #include "Semver.hpp" #include "VersionReq.hpp" @@ -20,6 +19,9 @@ namespace cabin { +namespace fs = std::filesystem; +using std::string_view_literals::operator""sv; + struct Edition { enum class Year : uint16_t { Cpp98 = 1998, diff --git a/src/Rustify.hpp b/src/Rustify.hpp deleted file mode 100644 index 49e1df782..000000000 --- a/src/Rustify.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "Rustify/Aliases.hpp" -#include "Rustify/Tests.hpp" -#include "Rustify/Traits.hpp" diff --git a/src/Rustify/Aliases.hpp b/src/Rustify/Aliases.hpp deleted file mode 100644 index a5d09c9da..000000000 --- a/src/Rustify/Aliases.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace fs = std::filesystem; - -// NOLINTBEGIN(google-global-names-in-headers) -using std::literals::string_literals::operator""s; -using std::literals::string_view_literals::operator""sv; -// NOLINTEND(google-global-names-in-headers) - -inline fs::path -operator""_path(const char* str, std::size_t /*unused*/) { - return str; -} - -[[noreturn]] inline void -panic( - const std::string_view msg, - const std::source_location& loc = std::source_location::current() -) { - std::ostringstream oss; - oss << "panicked at '" << msg << "', " << loc.file_name() << ':' << loc.line() - << '\n'; - throw std::logic_error(oss.str()); -} - -[[noreturn]] inline void -unreachable( - [[maybe_unused]] const std::source_location& loc = - std::source_location::current() -) noexcept { -#ifdef NDEBUG - __builtin_unreachable(); -#else - panic("unreachable", loc); -#endif -} diff --git a/src/VersionReq.cc b/src/VersionReq.cc index 3d4da8f8e..7d89fd5c0 100644 --- a/src/VersionReq.cc +++ b/src/VersionReq.cc @@ -1,6 +1,5 @@ #include "VersionReq.hpp" -#include "Rustify/Aliases.hpp" #include "Rustify/Result.hpp" #include @@ -31,7 +30,7 @@ toString(const Comparator::Op op) noexcept { case Comparator::Lte: return "<="; } - unreachable(); + __builtin_unreachable(); } struct ComparatorToken { @@ -385,7 +384,7 @@ Comparator::satisfiedBy(const Version& ver) const noexcept { case Op::Lte: return matchesExact(*this, ver) || matchesLess(*this, ver); } - unreachable(); + __builtin_unreachable(); } Comparator @@ -895,6 +894,8 @@ operator<<(std::ostream& os, const VersionReq& req) { namespace tests { +using std::string_literals::operator""s; + // Thanks to: // https://github.com/dtolnay/semver/blob/b6171889ac7e8f47ec6f12003571bdcc7f737b10/tests/test_version_req.rs