From ba225654536dc298d954b2562978a4ae2b41bf61 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Wed, 13 Nov 2024 22:03:07 -0600 Subject: [PATCH 01/18] initial library building support --- src/BuildConfig.cc | 86 ++++++++++++++++++++++++++++++++++++++------- src/BuildConfig.hpp | 13 +++++++ src/Cmd/Build.cc | 58 +++++++++++++++++++++--------- 3 files changed, 129 insertions(+), 28 deletions(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index d4877c114..a1417a025 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -431,6 +431,15 @@ BuildConfig::defineLinkTarget( defineTarget(binTarget, commands, deps); } +void +BuildConfig::defineLibTarget( + const std::string& libTarget, const std::unordered_set& deps +) { + std::vector commands; + commands.emplace_back("ar rcs lib" + getPackageName() + ".a $^"); + defineTarget(libTarget, commands, deps); +} + // Map a path to header file to the corresponding object file. // // e.g., src/path/to/header.h -> poac.d/path/to/header.o @@ -716,6 +725,9 @@ BuildConfig::configureBuild() { const auto isMainSource = [](const fs::path& file) { return file.filename().stem() == "main"; }; + const auto isLibSource = [](const fs::path& file) { + return file.filename().stem() == "lib"; + }; fs::path mainSource; for (const auto& entry : fs::directory_iterator(srcDir)) { const fs::path& path = entry.path(); @@ -727,13 +739,31 @@ BuildConfig::configureBuild() { } if (mainSource.empty()) { mainSource = path; + executable = true; } else { throw PoacError("multiple main sources were found"); } } - if (mainSource.empty()) { - throw PoacError(fmt::format("src/main{} was not found", SOURCE_FILE_EXTS)); + fs::path libSource; + for (const auto& entry : fs::directory_iterator(srcDir)) { + const fs::path& path = entry.path(); + if (!SOURCE_FILE_EXTS.contains(path.extension())) { + continue; + } + if (!isLibSource(path)) { + continue; + } + if (libSource.empty()) { + libSource = path; + library = true; + } else { + throw PoacError("multiple lib sources were found"); + } + } + + if (mainSource.empty() && libSource.empty()) { + throw PoacError(fmt::format("neither src/main{} nor src/lib{} was not found", SOURCE_FILE_EXTS, SOURCE_FILE_EXTS)); } if (!fs::exists(outBasePath)) { @@ -742,8 +772,16 @@ BuildConfig::configureBuild() { setVariables(); + std::unordered_set buildAll = {}; + if (executable) { + buildAll.insert(packageName); + } + if (library) { + buildAll.insert("lib" + packageName + ".a"); + } + // Build rules - setAll({ packageName }); + setAll(buildAll); addPhony("all"); std::vector sourceFilePaths = listSourceFilePaths(srcDir); @@ -757,7 +795,16 @@ BuildConfig::configureBuild() { "Move it directly to 'src/' if intended as such.", sourceFilePath.string() )); + } else if (sourceFilePath != libSource && isLibSource(sourceFilePath)) { + logger::warn(fmt::format( + "source file `{}` is named `lib` but is not located directly in the " + "`src/` directory. " + "This file will not be treated as a library. " + "Move it directly to 'src/' if intended as such.", + sourceFilePath.string() + )); } + srcs += ' ' + sourceFilePath.string(); } @@ -767,16 +814,31 @@ BuildConfig::configureBuild() { const std::unordered_set buildObjTargets = processSources(sourceFilePaths); - // Project binary target. - const std::string mainObjTarget = buildOutPath / "main.o"; - std::unordered_set projTargetDeps = { mainObjTarget }; - collectBinDepObjs( - projTargetDeps, "", - targets.at(mainObjTarget).remDeps, // we don't need sourceFile - buildObjTargets - ); + if (executable) { + // Project binary target. + const std::string mainObjTarget = buildOutPath / "main.o"; + std::unordered_set projTargetDeps = { mainObjTarget }; - defineLinkTarget(outBasePath / packageName, projTargetDeps); + collectBinDepObjs( + projTargetDeps, "", + targets.at(mainObjTarget).remDeps, // we don't need sourceFile + buildObjTargets + ); + + defineLinkTarget(outBasePath / packageName, projTargetDeps); + } + + if (library) { + // Project library target. + const std::string libTarget = buildOutPath / "lib.o"; + std::unordered_set libTargetDeps = { libTarget }; + collectBinDepObjs( + libTargetDeps, "", + targets.at(libTarget).remDeps, // we don't need sourceFile + buildObjTargets + ); + defineLibTarget(outBasePath / ("lib" + packageName + ".a"), libTargetDeps); + } // Test Pass std::unordered_set testTargets; diff --git a/src/BuildConfig.hpp b/src/BuildConfig.hpp index 489cf0f88..971f1bd96 100644 --- a/src/BuildConfig.hpp +++ b/src/BuildConfig.hpp @@ -50,6 +50,11 @@ struct BuildConfig { fs::path unittestOutPath; bool isDebug; + // if we are building an executable + bool executable; + // if we are building a library + bool library; + std::unordered_map variables; std::unordered_map> varDeps; std::unordered_map targets; @@ -66,6 +71,9 @@ struct BuildConfig { public: explicit BuildConfig(const std::string& packageName, bool isDebug = true); + bool isExecutable() const { return executable; } + bool isLibrary() const { return library; } + void defineVar( const std::string& name, const Variable& value, const std::unordered_set& dependsOn = {} @@ -76,12 +84,14 @@ struct BuildConfig { varDeps[dep].push_back(name); } } + void defineSimpleVar( const std::string& name, const std::string& value, const std::unordered_set& dependsOn = {} ) { defineVar(name, { .value = value, .type = VarType::Simple }, dependsOn); } + void defineCondVar( const std::string& name, const std::string& value, const std::unordered_set& dependsOn = {} @@ -144,6 +154,9 @@ struct BuildConfig { void defineLinkTarget( const std::string& binTarget, const std::unordered_set& deps ); + void defineLibTarget( + const std::string& binTarget, const std::unordered_set& deps + ); void collectBinDepObjs( // NOLINT(misc-no-recursion) std::unordered_set& deps, std::string_view sourceFileName, diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index 684e3a08e..f6457a971 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -39,23 +39,49 @@ buildImpl(std::string& outDir, const bool isDebug) { outDir = config.outBasePath; const std::string& packageName = getPackageName(); - const Command makeCmd = getMakeCommand().addArg("-C").addArg(outDir).addArg( - (config.outBasePath / packageName).string() - ); - Command checkUpToDateCmd = makeCmd; - checkUpToDateCmd.addArg("--question"); - - int exitCode = execCmd(checkUpToDateCmd); - if (exitCode != EXIT_SUCCESS) { - // If packageName binary is not up-to-date, compile it. - logger::info( - "Compiling", - fmt::format( - "{} v{} ({})", packageName, getPackageVersion().toString(), - getProjectBasePath().string() - ) + int exitCode = 0; + if (config.isExecutable()) { + const Command makeCmd = getMakeCommand().addArg("-C").addArg(outDir).addArg( + (config.outBasePath / packageName).string() + ); + Command checkUpToDateCmd = makeCmd; + checkUpToDateCmd.addArg("--question"); + + exitCode = execCmd(checkUpToDateCmd); + if (exitCode != EXIT_SUCCESS) { + // If packageName binary is not up-to-date, compile it. + logger::info( + "Compiling", + fmt::format( + "{} v{} ({})", packageName, getPackageVersion().toString(), + getProjectBasePath().string() + ) + ); + exitCode = execCmd(makeCmd); + } + } + + if (config.isLibrary()) { + std::string libName = "lib" + packageName + ".a"; + const Command makeCmd = getMakeCommand().addArg("-C").addArg(outDir).addArg( + (config.outBasePath / libName).string() ); - exitCode = execCmd(makeCmd); + Command checkUpToDateCmd = makeCmd; + checkUpToDateCmd.addArg("--question"); + + exitCode = execCmd(checkUpToDateCmd); + std::cout << checkUpToDateCmd.toString() << std::endl; + if (exitCode != EXIT_SUCCESS) { + // If packageName binary is not up-to-date, compile it. + logger::info( + "Compiling", + fmt::format( + "{} v{} ({})", libName, getPackageVersion().toString(), + getProjectBasePath().string() + ) + ); + exitCode = execCmd(makeCmd); + } } const auto end = std::chrono::steady_clock::now(); From aef5ee259f4b3aef0bac1f0683edd5e39cd5702b Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Wed, 13 Nov 2024 22:04:14 -0600 Subject: [PATCH 02/18] remove debug print --- src/Cmd/Build.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index f6457a971..f1644a3e5 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -70,7 +70,6 @@ buildImpl(std::string& outDir, const bool isDebug) { checkUpToDateCmd.addArg("--question"); exitCode = execCmd(checkUpToDateCmd); - std::cout << checkUpToDateCmd.toString() << std::endl; if (exitCode != EXIT_SUCCESS) { // If packageName binary is not up-to-date, compile it. logger::info( From 8026e26966e92ed6f25002f83780b8cfa18c8873 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Wed, 13 Nov 2024 22:08:26 -0600 Subject: [PATCH 03/18] fmt --- src/BuildConfig.cc | 5 ++++- src/BuildConfig.hpp | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index a1417a025..010c6de74 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -763,7 +763,10 @@ BuildConfig::configureBuild() { } if (mainSource.empty() && libSource.empty()) { - throw PoacError(fmt::format("neither src/main{} nor src/lib{} was not found", SOURCE_FILE_EXTS, SOURCE_FILE_EXTS)); + throw PoacError(fmt::format( + "neither src/main{} nor src/lib{} was not found", SOURCE_FILE_EXTS, + SOURCE_FILE_EXTS + )); } if (!fs::exists(outBasePath)) { diff --git a/src/BuildConfig.hpp b/src/BuildConfig.hpp index 971f1bd96..81dfd8be2 100644 --- a/src/BuildConfig.hpp +++ b/src/BuildConfig.hpp @@ -71,8 +71,12 @@ struct BuildConfig { public: explicit BuildConfig(const std::string& packageName, bool isDebug = true); - bool isExecutable() const { return executable; } - bool isLibrary() const { return library; } + bool isExecutable() const { + return executable; + } + bool isLibrary() const { + return library; + } void defineVar( const std::string& name, const Variable& value, From 8765dcc36dfeef7c81825e43d0f9cc5e195c39aa Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Wed, 13 Nov 2024 22:15:38 -0600 Subject: [PATCH 04/18] merge master --- src/Cli.cc | 3 +- src/Cmd/Search.cc | 3 +- src/Exception.hpp | 6 +-- src/Logger.hpp | 5 +- src/Parallelism.cc | 4 +- src/Rustify/Tests.hpp | 20 ++------ src/Semver.cc | 4 +- src/VersionReq.cc | 10 ++-- srcOld/Archive.hpp | 4 +- srcOld/Cfg.hpp | 91 ++++++++++++++++++------------------- srcOld/Lockfile.hpp | 12 ++--- srcOld/Resolver.hpp | 16 +++---- srcOld/Resolver/Resolve.hpp | 24 +++++----- srcOld/Resolver/Sat.hpp | 4 +- 14 files changed, 98 insertions(+), 108 deletions(-) diff --git a/src/Cli.cc b/src/Cli.cc index 4c58b2a40..a9589a791 100644 --- a/src/Cli.cc +++ b/src/Cli.cc @@ -386,8 +386,7 @@ Cli::transformOptions( if (i + 1 < multioption.size()) { // Handle concatenated value (like -j1) transformed.push_back(multioption.substr(i + 1)); - } else if (argIdx + 1 < args.size() - && !args[argIdx + 1].starts_with("-")) { + } else if (argIdx + 1 < args.size() && !args[argIdx + 1].starts_with("-")) { // Handle space-separated value (like -j 1) transformed.push_back(args[++argIdx] ); // Consume the next argument as the option's value diff --git a/src/Cmd/Search.cc b/src/Cmd/Search.cc index 696617d65..4e1ea8622 100644 --- a/src/Cmd/Search.cc +++ b/src/Cmd/Search.cc @@ -81,7 +81,8 @@ printTable(const nlohmann::json& packages) { constexpr int verWidth = 10; std::cout << std::left << std::setw(nameWidth) << "Name" - << std::setw(verWidth) << "Version" << "Description" << '\n'; + << std::setw(verWidth) << "Version" + << "Description" << '\n'; std::cout << std::string(tableWidth, '-') << '\n'; for (const auto& package : packages) { const std::string name = package["name"]; diff --git a/src/Exception.hpp b/src/Exception.hpp index 38318669f..902d568bc 100644 --- a/src/Exception.hpp +++ b/src/Exception.hpp @@ -9,7 +9,7 @@ struct PoacError : public std::runtime_error { explicit PoacError(Display auto&&... args) : std::runtime_error( // - (std::ostringstream{} << ... << std::forward(args)) - .str() - ) {} + (std::ostringstream{} << ... << std::forward(args)) + .str() + ) {} }; diff --git a/src/Logger.hpp b/src/Logger.hpp index 10d13b07a..ab881279e 100644 --- a/src/Logger.hpp +++ b/src/Logger.hpp @@ -29,8 +29,9 @@ template concept MaybeWriter = Writer || Display; template -concept HeadProcessor = std::is_nothrow_invocable_v - && Display>; +concept HeadProcessor = + std::is_nothrow_invocable_v && Display< + std::invoke_result_t>; class Logger { Level level = Level::Info; diff --git a/src/Parallelism.cc b/src/Parallelism.cc index 1fc15e180..c5bbcb124 100644 --- a/src/Parallelism.cc +++ b/src/Parallelism.cc @@ -49,8 +49,8 @@ struct ParallelismState { ParallelismState() noexcept : status(std::make_unique( - tbb::global_control::max_allowed_parallelism, numThreads() - )) {} + tbb::global_control::max_allowed_parallelism, numThreads() + )) {} }; void diff --git a/src/Rustify/Tests.hpp b/src/Rustify/Tests.hpp index a7cdf7122..8ad06484a 100644 --- a/src/Rustify/Tests.hpp +++ b/src/Rustify/Tests.hpp @@ -125,9 +125,7 @@ assertFalse( } template - requires(Eq && Display && Display) -inline void -assertEq( +requires(Eq&& Display&& Display) inline void assertEq( Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", const std::source_location& loc = std::source_location::current() ) noexcept { @@ -147,9 +145,7 @@ assertEq( } template - requires(Ne && Display && Display) -inline void -assertNe( +requires(Ne&& Display&& Display) inline void assertNe( Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", const std::source_location& loc = std::source_location::current() ) noexcept { @@ -169,9 +165,7 @@ assertNe( } template - requires(Lt && Display && Display) -inline void -assertLt( +requires(Lt&& Display&& Display) inline void assertLt( Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", const std::source_location& loc = std::source_location::current() ) noexcept { @@ -191,9 +185,7 @@ assertLt( } template - requires(std::is_invocable_v) -inline void -assertException( +requires(std::is_invocable_v) inline void assertException( Fn&& func, const std::string_view msg, const std::source_location& loc = std::source_location::current() ) noexcept { @@ -217,9 +209,7 @@ assertException( } template - requires(std::is_invocable_v) -inline void -assertNoException( +requires(std::is_invocable_v) inline void assertNoException( Fn&& func, const std::source_location& loc = std::source_location::current() ) noexcept { try { diff --git a/src/Semver.cc b/src/Semver.cc index 82977799d..c816b96d9 100644 --- a/src/Semver.cc +++ b/src/Semver.cc @@ -361,8 +361,8 @@ struct SemverParseError : public SemverError { const std::string_view msg ) : SemverError( - lexer.s, '\n', std::string(lexer.pos, ' '), carets(tok), msg - ) {} + lexer.s, '\n', std::string(lexer.pos, ' '), carets(tok), msg + ) {} }; Version diff --git a/src/VersionReq.cc b/src/VersionReq.cc index 7d081a1da..a7dc05404 100644 --- a/src/VersionReq.cc +++ b/src/VersionReq.cc @@ -15,16 +15,16 @@ struct ComparatorError : public PoacError { explicit ComparatorError(auto&&... args) : PoacError( - "invalid comparator:\n", std::forward(args)... - ) {} + "invalid comparator:\n", std::forward(args)... + ) {} }; struct VersionReqError : public PoacError { explicit VersionReqError(auto&&... args) : PoacError( - "invalid version requirement:\n", - std::forward(args)... - ) {} + "invalid version requirement:\n", + std::forward(args)... + ) {} }; static std::string diff --git a/srcOld/Archive.hpp b/srcOld/Archive.hpp index 83733d136..dcfa74385 100644 --- a/srcOld/Archive.hpp +++ b/srcOld/Archive.hpp @@ -63,8 +63,8 @@ copy_data(Archive* reader, const Writer& writer) noexcept } [[nodiscard]] auto -archive_write_finish_entry(const Writer& writer -) noexcept -> Result { +archive_write_finish_entry(const Writer& writer) noexcept + -> Result { const i32 res = archive_write_finish_entry(writer.get()); if (res < ARCHIVE_OK) { return Err(archive_error_string(writer.get())); diff --git a/srcOld/Cfg.hpp b/srcOld/Cfg.hpp index 5546ebb35..645261dc5 100644 --- a/srcOld/Cfg.hpp +++ b/srcOld/Cfg.hpp @@ -51,8 +51,8 @@ struct IdentError : public cfg::Exception { public: explicit IdentError(const std::string& what_) : Exception( - "cfg expected parenthesis, comma, identifier, or string\n" + what_ - ) {} + "cfg expected parenthesis, comma, identifier, or string\n" + what_ + ) {} explicit IdentError(const char* what_) : IdentError(std::string(what_)) {} ~IdentError() noexcept override = default; @@ -153,23 +153,23 @@ struct Token { explicit Token(Kind k) : kind( - k != Kind::std::string && k != Kind::Ident - ? k - : throw std::invalid_argument("poac::util::cfg::Token") - ) {} + k != Kind::std::string && k != Kind::Ident + ? k + : throw std::invalid_argument("poac::util::cfg::Token") + ) {} Token(Kind k, StringType s) : kind( - k == Kind::std::string - ? k - : throw std::invalid_argument("poac::util::cfg::Token") - ), + k == Kind::std::string + ? k + : throw std::invalid_argument("poac::util::cfg::Token") + ), value(s) {} Token(Kind k, ident i) : kind( - k == Kind::Ident - ? k - : throw std::invalid_argument("poac::util::cfg::Token") - ), + k == Kind::Ident + ? k + : throw std::invalid_argument("poac::util::cfg::Token") + ), value(i) {} Token() = delete; @@ -290,43 +290,43 @@ struct Lexer { } private: - [[nodiscard]] inline auto generate_token( - SizeType index_, const std::optional& token - ) const -> std::pair> { + [[nodiscard]] inline auto + generate_token(SizeType index_, const std::optional& token) const + -> std::pair> { return { this->diff_step(index_), token }; } - [[nodiscard]] inline auto generate_token( - SizeType index_, std::string_view kind - ) const -> std::pair> { + [[nodiscard]] inline auto + generate_token(SizeType index_, std::string_view kind) const + -> std::pair> { return generate_token(index_, Token{ to_kind(kind) }); } [[nodiscard]] auto analyze_two_phrase(SizeType index_, char kind) const -> std::pair>; - [[nodiscard]] auto tokenize(SizeType index_ - ) const -> std::pair>; + [[nodiscard]] auto tokenize(SizeType index_) const + -> std::pair>; void step(SizeType& index_) const noexcept; void step_n(SizeType n) noexcept; - [[nodiscard]] inline auto diff_step(const SizeType index_ - ) const noexcept -> SizeType { + [[nodiscard]] inline auto diff_step(const SizeType index_) const noexcept + -> SizeType { return index_ - this->index; } - [[nodiscard]] inline auto one(const SizeType index_ - ) const noexcept -> ValueType { + [[nodiscard]] inline auto one(const SizeType index_) const noexcept + -> ValueType { return this->str[index_]; } - [[nodiscard]] auto string(SizeType index_ - ) const -> std::pair; + [[nodiscard]] auto string(SizeType index_) const + -> std::pair; [[nodiscard]] auto ident(SizeType index_) const -> std::pair; - static auto to_ident(std::string_view s - ) noexcept -> std::optional; + static auto to_ident(std::string_view s) noexcept + -> std::optional; }; auto @@ -341,8 +341,8 @@ Lexer::analyze_two_phrase(SizeType index_, const char kind) const } auto -Lexer::tokenize(SizeType index_ -) const -> std::pair> { +Lexer::tokenize(SizeType index_) const + -> std::pair> { if (index_ >= this->str.size()) { return generate_token(index_, std::nullopt); } @@ -521,24 +521,24 @@ struct CfgExpr { CfgExpr(Kind kind, ExprType&& expr) : kind( - kind == Kind::not_ || kind == Kind::cfg - ? kind - : throw std::invalid_argument("poac::util::cfg::CfgExpr") - ), + kind == Kind::not_ || kind == Kind::cfg + ? kind + : throw std::invalid_argument("poac::util::cfg::CfgExpr") + ), expr(std::move(expr)) {} CfgExpr(Kind kind, ExprListType&& expr) : kind( - kind == Kind::all || kind == Kind::any - ? kind - : throw std::invalid_argument("poac::util::cfg::CfgExpr") - ), + kind == Kind::all || kind == Kind::any + ? kind + : throw std::invalid_argument("poac::util::cfg::CfgExpr") + ), expr(std::move(expr)) {} CfgExpr(Kind kind, const Cfg& c) : kind( - kind == Kind::value - ? kind - : throw std::invalid_argument("poac::util::cfg::CfgExpr") - ), + kind == Kind::value + ? kind + : throw std::invalid_argument("poac::util::cfg::CfgExpr") + ), expr(c) {} CfgExpr() = delete; @@ -744,8 +744,7 @@ Parser::expr() -> CfgExpr { } else { return CfgExpr{ CfgExpr::any, std::move(e) }; } - } else if (token->get_ident() == Token::ident::not_ - || token->get_ident() == Token::ident::cfg) { + } else if (token->get_ident() == Token::ident::not_ || token->get_ident() == Token::ident::cfg) { this->lexer.next(); this->eat_left_paren(token->get_ident()); CfgExpr&& e = this->expr(); diff --git a/srcOld/Lockfile.hpp b/srcOld/Lockfile.hpp index 5da91707f..8b2562be3 100644 --- a/srcOld/Lockfile.hpp +++ b/srcOld/Lockfile.hpp @@ -83,8 +83,8 @@ export namespace poac::data::lockfile::inline v1 { // -------------------- INTO LOCKFILE -------------------- [[nodiscard]] auto -convert_to_lock(const resolver::UniqDeps& deps -) -> Result> { +convert_to_lock(const resolver::UniqDeps& deps) + -> Result> { std::vector packages; for (const auto& [pack, inner_deps] : deps) { if (pack.dep_info.type != "poac") { @@ -132,8 +132,8 @@ generate(const resolver::UniqDeps& deps) -> Result { // -------------------- FROM LOCKFILE -------------------- [[nodiscard]] auto -convert_to_deps(const Lockfile& lock -) -> resolver::UniqDeps { +convert_to_deps(const Lockfile& lock) + -> resolver::UniqDeps { resolver::UniqDeps deps; for (const auto& package : lock.package) { resolver::UniqDeps::mapped_type inner_deps = @@ -156,8 +156,8 @@ convert_to_deps(const Lockfile& lock } [[nodiscard]] auto -read(const fs::path& base_dir -) -> Result>> { +read(const fs::path& base_dir) + -> Result>> { if (!fs::exists(base_dir / LOCKFILE_NAME)) { return Ok(std::nullopt); } diff --git a/srcOld/Resolver.hpp b/srcOld/Resolver.hpp index 3e2c4a0fe..f2327304b 100644 --- a/srcOld/Resolver.hpp +++ b/srcOld/Resolver.hpp @@ -106,16 +106,16 @@ convert_to_download_link(std::string_view repository) -> std::string { } [[nodiscard]] inline auto -get_download_link(const resolve::Package& package -) -> Result, std::string> { +get_download_link(const resolve::Package& package) + -> Result, std::string> { const auto [repository, sha256sum] = Try(util::net::api::repoinfo(package.name, package.dep_info.version_rq)); return Ok(std::make_pair(convert_to_download_link(repository), sha256sum)); } [[nodiscard]] auto -fetch_impl(const resolve::Package& package -) noexcept -> Result> { +fetch_impl(const resolve::Package& package) noexcept + -> Result> { try { const auto [download_link, sha256sum] = Try(get_download_link(package).map_err(to_anyhow)); @@ -198,8 +198,8 @@ is_not_installed(const resolve::Package& package) -> bool { } auto -get_not_installed_deps(const ResolvedDeps& deps -) -> resolve::UniqDeps { +get_not_installed_deps(const ResolvedDeps& deps) + -> resolve::UniqDeps { return deps | boost::adaptors::map_keys | boost::adaptors::filtered(is_not_installed) // ref: https://stackoverflow.com/a/42251976 @@ -228,8 +228,8 @@ download_deps(const ResolvedDeps& deps) -> Result { } [[nodiscard]] auto -do_resolve(const resolve::UniqDeps& deps -) noexcept -> Result { +do_resolve(const resolve::UniqDeps& deps) noexcept + -> Result { try { const resolve::DupDeps duplicate_deps = Try(resolve::gather_all_deps(deps).map_err(to_anyhow)); diff --git a/srcOld/Resolver/Resolve.hpp b/srcOld/Resolver/Resolve.hpp index 4f54ae45c..2207dd8e0 100644 --- a/srcOld/Resolver/Resolve.hpp +++ b/srcOld/Resolver/Resolve.hpp @@ -34,8 +34,8 @@ import poac.util.verbosity; export namespace poac::core::resolver::resolve { inline auto -get_package(const UniqDeps::value_type& deps -) noexcept -> const Package& { +get_package(const UniqDeps::value_type& deps) noexcept + -> const Package& { return deps.first; } @@ -50,8 +50,8 @@ to_binary_numbers(const i32& x, const usize& digit) -> std::string { // ¬A ∨ ¬B ∨ C // ¬A ∨ ¬B ∨ ¬C auto -multiple_versions_cnf(const std::vector& clause -) -> std::vector> { +multiple_versions_cnf(const std::vector& clause) + -> std::vector> { return boost::irange(0, 1 << clause.size()) // number of combinations | boost::adaptors::transformed([&clause](const i32 i) { return boost::dynamic_bitset<>(to_binary_numbers(i, clause.size()) @@ -74,8 +74,8 @@ multiple_versions_cnf(const std::vector& clause } auto -create_cnf(const DupDeps& activated -) -> std::vector> { +create_cnf(const DupDeps& activated) + -> std::vector> { std::vector> clauses; std::vector already_added; @@ -172,8 +172,8 @@ solve_sat( } [[nodiscard]] auto -backtrack_loop(const DupDeps& activated -) -> Result, std::string> { +backtrack_loop(const DupDeps& activated) + -> Result, std::string> { const std::vector> clauses = create_cnf(activated); if (util::verbosity::is_verbose()) { for (const std::vector& c : clauses) { @@ -212,8 +212,8 @@ duplicate_loose(const SinglePassRange& rng) -> bool { // `>=0.1.2 and <3.4.0` -> { 2.4.0, 2.5.0 } // name is boost/config, no boost-config [[nodiscard]] auto -get_versions_satisfy_interval(const Package& package -) -> Result, std::string> { +get_versions_satisfy_interval(const Package& package) + -> Result, std::string> { // TODO(ken-matsui): (`>1.2 and <=1.3.2` -> NG,`>1.2.0-alpha and <=1.3.2` -> // OK) `2.0.0` specific version or `>=0.1.2 and <3.4.0` version interval const semver::Interval i(package.dep_info.version_rq); @@ -330,8 +330,8 @@ gather_deps( } [[nodiscard]] auto -gather_all_deps(const UniqDeps& deps -) -> Result, std::string> { +gather_all_deps(const UniqDeps& deps) + -> Result, std::string> { DupDeps duplicate_deps; IntervalCache interval_cache; diff --git a/srcOld/Resolver/Sat.hpp b/srcOld/Resolver/Sat.hpp index 653c3dd4d..70e82b3e0 100644 --- a/srcOld/Resolver/Sat.hpp +++ b/srcOld/Resolver/Sat.hpp @@ -69,8 +69,8 @@ literal_to_index(i32 l) -> i32 { // function, so the index of the variable with the highest number of variables // is returned from the variables in the current clauses. auto -maximum_literal_number_index(const std::vector>& clauses -) -> i32 { +maximum_literal_number_index(const std::vector>& clauses) + -> i32 { Map frequency; for (const auto& clause : clauses) { for (const auto& literal : clause) { From 3cb0dc7817eb781d9a5fa82594264dab3654b26d Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Wed, 13 Nov 2024 22:19:08 -0600 Subject: [PATCH 05/18] rollback formatting --- src/Cli.cc | 66 ++++++++++++++------------- src/Cmd/Search.cc | 13 +++--- src/Exception.hpp | 6 +-- src/Logger.hpp | 17 +++---- src/Parallelism.cc | 16 +++---- src/Rustify/Aliases.hpp | 68 ++++++++++++++++++++++++--- src/Rustify/Tests.hpp | 77 +++++++++++++------------------ src/Semver.cc | 48 ++++++++++--------- src/VersionReq.cc | 40 ++++++++-------- srcOld/Archive.hpp | 4 +- srcOld/Cfg.hpp | 91 +++++++++++++++++++------------------ srcOld/Lockfile.hpp | 12 ++--- srcOld/Resolver.hpp | 16 +++---- srcOld/Resolver/Resolve.hpp | 24 +++++----- srcOld/Resolver/Sat.hpp | 4 +- 15 files changed, 268 insertions(+), 234 deletions(-) diff --git a/src/Cli.cc b/src/Cli.cc index a9589a791..5be4e195c 100644 --- a/src/Cli.cc +++ b/src/Cli.cc @@ -2,6 +2,7 @@ #include "Algos.hpp" #include "Logger.hpp" +#include "Rustify.hpp" #include "TermColor.hpp" #include @@ -18,7 +19,7 @@ static constinit const std::string_view PADDING = " "; static void -setOffset(const size_t offset) noexcept { +setOffset(const usize offset) noexcept { std::cout << PADDING << std::left << std::setw(static_cast(offset + PADDING.size())); } @@ -56,9 +57,9 @@ addOptCandidates( } } -size_t +usize calcOptMaxShortSize(const std::vector& opts) noexcept { - size_t maxShortSize = 0; + usize maxShortSize = 0; for (const auto& opt : opts) { if (opt.isHidden) { // Hidden option should not affect maxShortSize. @@ -69,11 +70,11 @@ calcOptMaxShortSize(const std::vector& opts) noexcept { return maxShortSize; } -size_t +usize calcOptMaxOffset( - const std::vector& opts, const size_t maxShortSize + const std::vector& opts, const usize maxShortSize ) noexcept { - size_t maxOffset = 0; + usize maxOffset = 0; for (const auto& opt : opts) { if (opt.isHidden) { // Hidden option should not affect maxOffset. @@ -86,8 +87,8 @@ calcOptMaxOffset( void printOpts( - const std::vector& opts, const size_t maxShortSize, - const size_t maxOffset + const std::vector& opts, const usize maxShortSize, + const usize maxOffset ) noexcept { for (const auto& opt : opts) { if (opt.isHidden) { @@ -99,7 +100,7 @@ printOpts( } void -Opt::print(const size_t maxShortSize, size_t maxOffset) const noexcept { +Opt::print(const usize maxShortSize, usize maxOffset) const noexcept { std::string option; if (!shortName.empty()) { option += bold(cyan(shortName)); @@ -118,7 +119,7 @@ Opt::print(const size_t maxShortSize, size_t maxOffset) const noexcept { if (shouldColor()) { // Color escape sequences are not visible but affect std::setw. - constexpr size_t colorEscapeSeqLen = 31; + constexpr usize colorEscapeSeqLen = 31; maxOffset += colorEscapeSeqLen; } setOffset(maxOffset); @@ -153,11 +154,11 @@ Arg::getLeft() const noexcept { return cyan(left); } void -Arg::print(size_t maxOffset) const noexcept { +Arg::print(usize maxOffset) const noexcept { const std::string left = getLeft(); if (shouldColor()) { // Color escape sequences are not visible but affect std::setw. - constexpr size_t colorEscapeSeqLen = 9; + constexpr usize colorEscapeSeqLen = 9; maxOffset += colorEscapeSeqLen; } setOffset(maxOffset); @@ -226,9 +227,9 @@ Subcmd::missingArgumentForOpt(const std::string_view arg) { return EXIT_FAILURE; } -size_t +usize Subcmd::calcMaxShortSize() const noexcept { - size_t maxShortSize = 0; + usize maxShortSize = 0; if (globalOpts.has_value()) { maxShortSize = std::max(maxShortSize, calcOptMaxShortSize(globalOpts.value())); @@ -236,9 +237,9 @@ Subcmd::calcMaxShortSize() const noexcept { maxShortSize = std::max(maxShortSize, calcOptMaxShortSize(localOpts)); return maxShortSize; } -size_t -Subcmd::calcMaxOffset(const size_t maxShortSize) const noexcept { - size_t maxOffset = 0; +usize +Subcmd::calcMaxOffset(const usize maxShortSize) const noexcept { + usize maxOffset = 0; if (globalOpts.has_value()) { maxOffset = std::max(maxOffset, calcOptMaxOffset(globalOpts.value(), maxShortSize)); @@ -255,8 +256,8 @@ Subcmd::calcMaxOffset(const size_t maxShortSize) const noexcept { void Subcmd::printHelp() const noexcept { - const size_t maxShortSize = calcMaxShortSize(); - const size_t maxOffset = calcMaxOffset(maxShortSize); + const usize maxShortSize = calcMaxShortSize(); + const usize maxOffset = calcMaxOffset(maxShortSize); std::cout << desc << '\n'; std::cout << '\n'; @@ -276,7 +277,7 @@ Subcmd::printHelp() const noexcept { } void -Subcmd::print(size_t maxOffset) const noexcept { +Subcmd::print(usize maxOffset) const noexcept { std::string cmdStr = bold(cyan(name)); if (hasShort()) { cmdStr += ", "; @@ -288,7 +289,7 @@ Subcmd::print(size_t maxOffset) const noexcept { if (shouldColor()) { // Color escape sequences are not visible but affect std::setw. - constexpr size_t colorEscapeSeqLen = 22; + constexpr usize colorEscapeSeqLen = 22; maxOffset += colorEscapeSeqLen; } setOffset(maxOffset); @@ -386,7 +387,8 @@ Cli::transformOptions( if (i + 1 < multioption.size()) { // Handle concatenated value (like -j1) transformed.push_back(multioption.substr(i + 1)); - } else if (argIdx + 1 < args.size() && !args[argIdx + 1].starts_with("-")) { + } else if (argIdx + 1 < args.size() + && !args[argIdx + 1].starts_with("-")) { // Handle space-separated value (like -j 1) transformed.push_back(args[++argIdx] ); // Consume the next argument as the option's value @@ -415,20 +417,20 @@ Cli::printSubcmdHelp(const std::string_view subcmd) const noexcept { subcmds.at(subcmd).printHelp(); } -size_t +usize Cli::calcMaxShortSize() const noexcept { // This is for printing the help message of the poac command itself. So, // we don't need to consider the length of the subcommands' options. - size_t maxShortSize = 0; + usize maxShortSize = 0; maxShortSize = std::max(maxShortSize, calcOptMaxShortSize(globalOpts)); maxShortSize = std::max(maxShortSize, calcOptMaxShortSize(localOpts)); return maxShortSize; } -size_t -Cli::calcMaxOffset(const size_t maxShortSize) const noexcept { - size_t maxOffset = 0; +usize +Cli::calcMaxOffset(const usize maxShortSize) const noexcept { + usize maxOffset = 0; maxOffset = std::max(maxOffset, calcOptMaxOffset(globalOpts, maxShortSize)); maxOffset = std::max(maxOffset, calcOptMaxOffset(localOpts, maxShortSize)); @@ -438,7 +440,7 @@ Cli::calcMaxOffset(const size_t maxShortSize) const noexcept { continue; } - size_t offset = name.size(); // "build" + usize offset = name.size(); // "build" if (!cmd.shortName.empty()) { offset += 2; // ", " offset += cmd.shortName.size(); // "b" @@ -449,14 +451,14 @@ Cli::calcMaxOffset(const size_t maxShortSize) const noexcept { } void -Cli::printAllSubcmds(const bool showHidden, size_t maxOffset) const noexcept { +Cli::printAllSubcmds(const bool showHidden, usize maxOffset) const noexcept { for (const auto& [name, cmd] : subcmds) { if (!showHidden && cmd.isHidden) { // Hidden command should not affect maxOffset if `showHidden` is false. continue; } - size_t offset = name.size(); // "build" + usize offset = name.size(); // "build" if (!cmd.shortName.empty()) { offset += 2; // ", " offset += cmd.shortName.size(); // "b" @@ -480,8 +482,8 @@ Cli::printAllSubcmds(const bool showHidden, size_t maxOffset) const noexcept { void Cli::printCmdHelp() const noexcept { // Print help message for poac itself - const size_t maxShortSize = calcMaxShortSize(); - const size_t maxOffset = calcMaxOffset(maxShortSize); + const usize maxShortSize = calcMaxShortSize(); + const usize maxOffset = calcMaxOffset(maxShortSize); std::cout << desc << '\n'; std::cout << '\n'; diff --git a/src/Cmd/Search.cc b/src/Cmd/Search.cc index 4e1ea8622..867b50d42 100644 --- a/src/Cmd/Search.cc +++ b/src/Cmd/Search.cc @@ -2,8 +2,8 @@ #include "../Cli.hpp" #include "../Logger.hpp" +#include "../Rustify.hpp" -#include #include #include #include @@ -31,12 +31,12 @@ const Subcmd SEARCH_CMD = struct SearchArgs { std::string name; - size_t perPage = 10; - size_t page = 1; + usize perPage = 10; + usize page = 1; }; -static size_t -writeCallback(void* contents, size_t size, size_t nmemb, std::string* userp) { +static usize +writeCallback(void* contents, usize size, usize nmemb, std::string* userp) { userp->append(static_cast(contents), size * nmemb); return size * nmemb; } @@ -81,8 +81,7 @@ printTable(const nlohmann::json& packages) { constexpr int verWidth = 10; std::cout << std::left << std::setw(nameWidth) << "Name" - << std::setw(verWidth) << "Version" - << "Description" << '\n'; + << std::setw(verWidth) << "Version" << "Description" << '\n'; std::cout << std::string(tableWidth, '-') << '\n'; for (const auto& package : packages) { const std::string name = package["name"]; diff --git a/src/Exception.hpp b/src/Exception.hpp index 902d568bc..38318669f 100644 --- a/src/Exception.hpp +++ b/src/Exception.hpp @@ -9,7 +9,7 @@ struct PoacError : public std::runtime_error { explicit PoacError(Display auto&&... args) : std::runtime_error( // - (std::ostringstream{} << ... << std::forward(args)) - .str() - ) {} + (std::ostringstream{} << ... << std::forward(args)) + .str() + ) {} }; diff --git a/src/Logger.hpp b/src/Logger.hpp index ab881279e..27f193fad 100644 --- a/src/Logger.hpp +++ b/src/Logger.hpp @@ -1,22 +1,20 @@ #pragma once -#include "Rustify/Traits.hpp" +#include "Rustify.hpp" #include "TermColor.hpp" -#include #include #include #include #include #include -#include #include #include #include namespace logger { -enum class Level : uint8_t { +enum class Level : u8 { Off = 0, // --quiet, -q Error = 1, Warn = 2, @@ -29,9 +27,8 @@ template concept MaybeWriter = Writer || Display; template -concept HeadProcessor = - std::is_nothrow_invocable_v && Display< - std::invoke_result_t>; +concept HeadProcessor = std::is_nothrow_invocable_v + && Display>; class Logger { Level level = Level::Info; @@ -178,8 +175,7 @@ info(MaybeWriter auto&&... msgs) noexcept { template struct debug { // NOLINT(readability-identifier-naming) explicit debug( - Ts&&... msgs, - const std::source_location& loc = std::source_location::current() + Ts&&... msgs, const source_location& loc = source_location::current() ) noexcept { Logger::debug(loc.function_name(), std::forward(msgs)...); } @@ -190,8 +186,7 @@ debug(Ts&&...) -> debug; template struct trace { // NOLINT(readability-identifier-naming) explicit trace( - Ts&&... msgs, - const std::source_location& loc = std::source_location::current() + Ts&&... msgs, const source_location& loc = source_location::current() ) noexcept { Logger::trace(loc.function_name(), std::forward(msgs)...); } diff --git a/src/Parallelism.cc b/src/Parallelism.cc index c5bbcb124..4c25db4dd 100644 --- a/src/Parallelism.cc +++ b/src/Parallelism.cc @@ -1,13 +1,13 @@ #include "Parallelism.hpp" #include "Logger.hpp" +#include "Rustify.hpp" -#include #include #include #include -size_t +usize numThreads() noexcept { const unsigned int numThreads = std::thread::hardware_concurrency(); if (numThreads > 1) { @@ -24,7 +24,7 @@ struct ParallelismState { ParallelismState& operator=(ParallelismState&&) noexcept = delete; ~ParallelismState() noexcept = default; - void set(size_t numThreads) noexcept { + void set(usize numThreads) noexcept { if (numThreads == 0) { logger::warn("requested parallelism of 0, capping at 1"); numThreads = 1; @@ -34,7 +34,7 @@ struct ParallelismState { tbb::global_control::max_allowed_parallelism, numThreads ); } - size_t get() const noexcept { + usize get() const noexcept { // NOLINTNEXTLINE(readability-static-accessed-through-instance) return status->active_value(tbb::global_control::max_allowed_parallelism); } @@ -49,16 +49,16 @@ struct ParallelismState { ParallelismState() noexcept : status(std::make_unique( - tbb::global_control::max_allowed_parallelism, numThreads() - )) {} + tbb::global_control::max_allowed_parallelism, numThreads() + )) {} }; void -setParallelism(const size_t numThreads) noexcept { +setParallelism(const usize numThreads) noexcept { ParallelismState::instance().set(numThreads); } -size_t +usize getParallelism() noexcept { return ParallelismState::instance().get(); } diff --git a/src/Rustify/Aliases.hpp b/src/Rustify/Aliases.hpp index 5f0f72167..3ff519258 100644 --- a/src/Rustify/Aliases.hpp +++ b/src/Rustify/Aliases.hpp @@ -1,28 +1,85 @@ #pragma once -#include +#include +#include #include -#include +#include #include #include #include namespace fs = std::filesystem; +// NOLINTBEGIN(readability-identifier-naming) +using u8 = std::uint8_t; +using u16 = std::uint16_t; +using u32 = std::uint32_t; +using u64 = std::uint64_t; + +using i8 = std::int8_t; +using i16 = std::int16_t; +using i32 = std::int32_t; +using i64 = std::int64_t; + +using isize = std::ptrdiff_t; +using usize = std::size_t; + +using f32 = float; +using f64 = double; +// NOLINTEND(readability-identifier-naming) + // 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, size_t /*unused*/) { +operator""_path(const char* str, usize /*unused*/) { return str; } +// NOLINTBEGIN(readability-identifier-naming) +struct source_location { + constexpr source_location() noexcept = delete; + constexpr ~source_location() noexcept = default; + constexpr source_location(const source_location&) noexcept = default; + constexpr source_location(source_location&&) noexcept = default; + constexpr source_location& + operator=(const source_location&) noexcept = default; + constexpr source_location& operator=(source_location&&) noexcept = default; + + constexpr source_location( + const char* file, int line, const char* func + ) noexcept + : file_(file), line_(line), func_(func) {} + + static constexpr source_location current( + const char* file = __builtin_FILE(), const int line = __builtin_LINE(), + const char* func = __builtin_FUNCTION() + ) noexcept { + return { file, line, func }; + } + constexpr std::string_view file_name() const noexcept { + return file_; + } + constexpr int line() const noexcept { + return line_; + } + constexpr std::string_view function_name() const noexcept { + return func_; + } + +private: + const char* file_; + int line_{}; + const char* func_; +}; +// NOLINTEND(readability-identifier-naming) + [[noreturn]] inline void panic( const std::string_view msg, - const std::source_location& loc = std::source_location::current() + const source_location& loc = source_location::current() ) { std::ostringstream oss; oss << "panicked at '" << msg << "', " << loc.file_name() << ':' << loc.line() @@ -32,8 +89,7 @@ panic( [[noreturn]] inline void unreachable( - [[maybe_unused]] const std::source_location& loc = - std::source_location::current() + [[maybe_unused]] const source_location& loc = source_location::current() ) noexcept { #ifdef NDEBUG __builtin_unreachable(); diff --git a/src/Rustify/Tests.hpp b/src/Rustify/Tests.hpp index 8ad06484a..6aef90e1f 100644 --- a/src/Rustify/Tests.hpp +++ b/src/Rustify/Tests.hpp @@ -1,12 +1,11 @@ #pragma once +#include "Aliases.hpp" #include "Traits.hpp" -#include #include #include #include -#include #include #include #include @@ -37,12 +36,12 @@ modName(std::string_view file) noexcept { return file; } - const size_t start = file.find("src/"); + const usize start = file.find("src/"); if (start == std::string_view::npos) { return file; } - const size_t end = file.find_last_of('.'); + const usize end = file.find_last_of('.'); if (end == std::string_view::npos) { return file; } @@ -50,43 +49,21 @@ modName(std::string_view file) noexcept { return file.substr(start, end - start); } -constexpr std::string_view -modFunc(std::string_view func) noexcept { - if (func.empty()) { - return func; - } - - const size_t end = func.find_last_of('('); - if (end == std::string_view::npos) { - return func; - } - func = func.substr(0, end); - - const size_t start = func.find_last_of(' '); - if (start == std::string_view::npos) { - return func; - } - return func.substr(start + 1); -} - inline void -pass( - const std::source_location& loc = std::source_location::current() -) noexcept { +pass(const source_location& loc = source_location::current()) noexcept { std::cout << " test " << modName(loc.file_name()) - << "::" << modFunc(loc.function_name()) << " ... " << GREEN << "ok" - << RESET << '\n' + << "::" << loc.function_name() << " ... " << GREEN << "ok" << RESET + << '\n' << std::flush; } [[noreturn]] inline void -error(const std::source_location& loc, Display auto&&... msgs) { +error(const source_location& loc, Display auto&&... msgs) { std::ostringstream oss; oss << "\n test " << modName(loc.file_name()) - << "::" << modFunc(loc.function_name()) << " ... " << RED << "FAILED" - << RESET << "\n\n" - << '\'' << modFunc(loc.function_name()) << "' failed at '" - << std::boolalpha; + << "::" << loc.function_name() << " ... " << RED << "FAILED" << RESET + << "\n\n" + << '\'' << loc.function_name() << "' failed at '" << std::boolalpha; (oss << ... << std::forward(msgs)) << "', " << loc.file_name() << ':' << loc.line() << '\n'; throw std::logic_error(oss.str()); @@ -95,7 +72,7 @@ error(const std::source_location& loc, Display auto&&... msgs) { inline void assertTrue( const bool cond, const std::string_view msg = "", - const std::source_location& loc = std::source_location::current() + const source_location& loc = source_location::current() ) noexcept { if (cond) { return; // OK @@ -111,7 +88,7 @@ assertTrue( inline void assertFalse( const bool cond, const std::string_view msg = "", - const std::source_location& loc = std::source_location::current() + const source_location& loc = source_location::current() ) noexcept { if (!cond) { return; // OK @@ -125,9 +102,11 @@ assertFalse( } template -requires(Eq&& Display&& Display) inline void assertEq( + requires(Eq && Display && Display) +inline void +assertEq( Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", - const std::source_location& loc = std::source_location::current() + const source_location& loc = source_location::current() ) noexcept { if (lhs == rhs) { return; // OK @@ -145,9 +124,11 @@ requires(Eq&& Display&& Display) inline void assertEq( } template -requires(Ne&& Display&& Display) inline void assertNe( + requires(Ne && Display && Display) +inline void +assertNe( Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", - const std::source_location& loc = std::source_location::current() + const source_location& loc = source_location::current() ) noexcept { if (lhs != rhs) { return; // OK @@ -165,9 +146,11 @@ requires(Ne&& Display&& Display) inline void assertNe( } template -requires(Lt&& Display&& Display) inline void assertLt( + requires(Lt && Display && Display) +inline void +assertLt( Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", - const std::source_location& loc = std::source_location::current() + const source_location& loc = source_location::current() ) noexcept { if (lhs < rhs) { return; // OK @@ -185,9 +168,11 @@ requires(Lt&& Display&& Display) inline void assertLt( } template -requires(std::is_invocable_v) inline void assertException( + requires(std::is_invocable_v) +inline void +assertException( Fn&& func, const std::string_view msg, - const std::source_location& loc = std::source_location::current() + const source_location& loc = source_location::current() ) noexcept { try { std::forward(func)(); @@ -209,8 +194,10 @@ requires(std::is_invocable_v) inline void assertException( } template -requires(std::is_invocable_v) inline void assertNoException( - Fn&& func, const std::source_location& loc = std::source_location::current() + requires(std::is_invocable_v) +inline void +assertNoException( + Fn&& func, const source_location& loc = source_location::current() ) noexcept { try { std::forward(func)(); diff --git a/src/Semver.cc b/src/Semver.cc index c816b96d9..06882ced8 100644 --- a/src/Semver.cc +++ b/src/Semver.cc @@ -1,8 +1,8 @@ #include "Semver.hpp" +#include "Rustify.hpp" + #include -#include -#include #include #include #include @@ -14,7 +14,7 @@ std::ostream& operator<<(std::ostream& os, const VersionToken& tok) noexcept { switch (tok.kind) { case VersionToken::Num: - os << std::get(tok.value); + os << std::get(tok.value); break; case VersionToken::Ident: os << std::get(tok.value); @@ -42,7 +42,7 @@ VersionToken::toString() const noexcept { return oss.str(); } -size_t +usize VersionToken::size() const noexcept { return toString().size(); } @@ -54,7 +54,7 @@ operator==(const VersionToken& lhs, const VersionToken& rhs) noexcept { } switch (lhs.kind) { case VersionToken::Num: - return std::get(lhs.value) == std::get(rhs.value); + return std::get(lhs.value) == std::get(rhs.value); case VersionToken::Ident: return std::get(lhs.value) == std::get(rhs.value); @@ -71,7 +71,7 @@ operator==(const VersionToken& lhs, const VersionToken& rhs) noexcept { bool operator<(const VersionToken& lhs, const VersionToken& rhs) noexcept { if (lhs.kind == VersionToken::Num && rhs.kind == VersionToken::Num) { - return std::get(lhs.value) < std::get(rhs.value); + return std::get(lhs.value) < std::get(rhs.value); } return lhs.toString() < rhs.toString(); } @@ -100,7 +100,7 @@ Prerelease::empty() const noexcept { std::string Prerelease::toString() const noexcept { std::string str; - for (size_t i = 0; i < ident.size(); ++i) { + for (usize i = 0; i < ident.size(); ++i) { if (i > 0) { str += '.'; } @@ -125,7 +125,7 @@ operator<(const Prerelease& lhs, const Prerelease& rhs) noexcept { if (rhs.ident.empty()) { return true; // rhs is a normal version and is greater } - for (size_t i = 0; i < lhs.ident.size() && i < rhs.ident.size(); ++i) { + for (usize i = 0; i < lhs.ident.size() && i < rhs.ident.size(); ++i) { if (lhs.ident[i] < rhs.ident[i]) { return true; } else if (lhs.ident[i] > rhs.ident[i]) { @@ -155,7 +155,7 @@ BuildMetadata::empty() const noexcept { std::string BuildMetadata::toString() const noexcept { std::string str; - for (size_t i = 0; i < ident.size(); ++i) { + for (usize i = 0; i < ident.size(); ++i) { if (i > 0) { str += '.'; } @@ -170,7 +170,7 @@ operator==(const BuildMetadata& lhs, const BuildMetadata& rhs) noexcept { } bool operator<(const BuildMetadata& lhs, const BuildMetadata& rhs) noexcept { - for (size_t i = 0; i < lhs.ident.size() && i < rhs.ident.size(); ++i) { + for (usize i = 0; i < lhs.ident.size() && i < rhs.ident.size(); ++i) { if (lhs.ident[i] < rhs.ident[i]) { return true; } else if (lhs.ident[i] > rhs.ident[i]) { @@ -265,7 +265,7 @@ operator>=(const Version& lhs, const Version& rhs) noexcept { VersionToken VersionLexer::consumeIdent() noexcept { - size_t len = 0; + usize len = 0; while (pos < s.size() && (std::isalnum(s[pos]) || s[pos] == '-')) { step(); ++len; @@ -275,8 +275,8 @@ VersionLexer::consumeIdent() noexcept { VersionToken VersionLexer::consumeNum() { - size_t len = 0; - uint64_t value = 0; + usize len = 0; + u64 value = 0; while (pos < s.size() && std::isdigit(s[pos])) { if (len > 0 && value == 0) { throw SemverError( @@ -284,10 +284,10 @@ VersionLexer::consumeNum() { ); } - const uint64_t digit = s[pos] - '0'; - constexpr uint64_t base = 10; + const u64 digit = s[pos] - '0'; + constexpr u64 base = 10; // Check for overflow - if (value > (std::numeric_limits::max() - digit) / base) { + if (value > (std::numeric_limits::max() - digit) / base) { throw SemverError( s, '\n', std::string(pos - len, ' '), std::string(len, '^'), " number exceeds UINT64_MAX" @@ -304,7 +304,7 @@ VersionLexer::consumeNum() { // Note that 012 is an invalid number but 012d is a valid identifier. VersionToken VersionLexer::consumeNumOrIdent() { - const size_t oldPos = pos; // we need two passes + const usize oldPos = pos; // we need two passes bool isIdent = false; while (pos < s.size() && (std::isalnum(s[pos]) || s[pos] == '-')) { if (!std::isdigit(s[pos])) { @@ -349,7 +349,7 @@ VersionLexer::next() { VersionToken VersionLexer::peek() { - const size_t oldPos = pos; + const usize oldPos = pos; const VersionToken tok = next(); pos = oldPos; return tok; @@ -361,8 +361,8 @@ struct SemverParseError : public SemverError { const std::string_view msg ) : SemverError( - lexer.s, '\n', std::string(lexer.pos, ' '), carets(tok), msg - ) {} + lexer.s, '\n', std::string(lexer.pos, ' '), carets(tok), msg + ) {} }; Version @@ -404,12 +404,12 @@ VersionParser::parse() { // Even if the token can be parsed as an identifier, try to parse it as a // number. -uint64_t +u64 VersionParser::parseNum() { if (!std::isdigit(lexer.s[lexer.pos])) { throw SemverParseError(lexer, lexer.peek(), " expected number"); } - return std::get(lexer.consumeNum().value); + return std::get(lexer.consumeNum().value); } void @@ -484,8 +484,6 @@ Version::parse(const std::string_view str) { #ifdef POAC_TEST -# include "Rustify/Tests.hpp" - namespace tests { // Thanks to: @@ -769,7 +767,7 @@ testSpecOrder() { "1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-alpha.beta", "1.0.0-beta", "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", "1.0.0", }; - for (size_t i = 1; i < vers.size(); ++i) { + for (usize i = 1; i < vers.size(); ++i) { assertLt(Version::parse(vers[i - 1]), Version::parse(vers[i])); } diff --git a/src/VersionReq.cc b/src/VersionReq.cc index a7dc05404..3d614eba4 100644 --- a/src/VersionReq.cc +++ b/src/VersionReq.cc @@ -1,10 +1,9 @@ #include "VersionReq.hpp" #include "Exception.hpp" -#include "Rustify/Aliases.hpp" +#include "Rustify.hpp" #include -#include #include #include #include @@ -15,16 +14,16 @@ struct ComparatorError : public PoacError { explicit ComparatorError(auto&&... args) : PoacError( - "invalid comparator:\n", std::forward(args)... - ) {} + "invalid comparator:\n", std::forward(args)... + ) {} }; struct VersionReqError : public PoacError { explicit VersionReqError(auto&&... args) : PoacError( - "invalid version requirement:\n", - std::forward(args)... - ) {} + "invalid version requirement:\n", + std::forward(args)... + ) {} }; static std::string @@ -45,7 +44,7 @@ toString(const Comparator::Op op) noexcept { } struct ComparatorToken { - enum class Kind : uint8_t { + enum class Kind : std::uint8_t { Eq, // = Gt, // > Gte, // >= @@ -71,7 +70,7 @@ struct ComparatorToken { struct ComparatorLexer { std::string_view s; - size_t pos{ 0 }; + usize pos{ 0 }; explicit ComparatorLexer(const std::string_view str) noexcept : s(str) {} @@ -293,7 +292,7 @@ matchesGreater(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.minor.has_value()) { return false; } else { - const uint64_t minor = cmp.minor.value(); + const u64 minor = cmp.minor.value(); if (ver.minor != minor) { return ver.minor > minor; } @@ -302,7 +301,7 @@ matchesGreater(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.patch.has_value()) { return false; } else { - const uint64_t patch = cmp.patch.value(); + const u64 patch = cmp.patch.value(); if (ver.patch != patch) { return ver.patch > patch; } @@ -320,7 +319,7 @@ matchesLess(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.minor.has_value()) { return false; } else { - const uint64_t minor = cmp.minor.value(); + const u64 minor = cmp.minor.value(); if (ver.minor != minor) { return ver.minor < minor; } @@ -329,7 +328,7 @@ matchesLess(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.patch.has_value()) { return false; } else { - const uint64_t patch = cmp.patch.value(); + const u64 patch = cmp.patch.value(); if (ver.patch != patch) { return ver.patch < patch; } @@ -347,7 +346,7 @@ matchesNoOp(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.minor.has_value()) { return true; } - const uint64_t minor = cmp.minor.value(); + const u64 minor = cmp.minor.value(); if (!cmp.patch.has_value()) { if (cmp.major > 0) { @@ -356,7 +355,7 @@ matchesNoOp(const Comparator& cmp, const Version& ver) noexcept { return ver.minor == minor; } } - const uint64_t patch = cmp.patch.value(); + const u64 patch = cmp.patch.value(); if (cmp.major > 0) { if (ver.minor != minor) { @@ -439,7 +438,7 @@ Comparator::canonicalize() const noexcept { } struct VersionReqToken { - enum class Kind : uint8_t { + enum class Kind : std::uint8_t { Comp, And, Eof, @@ -466,7 +465,7 @@ isCompStart(const char c) noexcept { struct VersionReqLexer { std::string_view s; - size_t pos{ 0 }; + usize pos{ 0 }; explicit VersionReqLexer(const std::string_view str) noexcept : s(str) {} @@ -897,9 +896,6 @@ operator<<(std::ostream& os, const VersionReq& req) { #ifdef POAC_TEST -# include "Rustify/Tests.hpp" - -# include # include namespace tests { @@ -910,7 +906,7 @@ namespace tests { inline static void assertMatchAll( const VersionReq& req, const std::span versions, - const std::source_location& loc = std::source_location::current() + const source_location& loc = source_location::current() ) { for (const std::string_view ver : versions) { assertTrue(req.satisfiedBy(Version::parse(ver)), "", loc); @@ -920,7 +916,7 @@ assertMatchAll( inline static void assertMatchNone( const VersionReq& req, const std::span versions, - const std::source_location& loc = std::source_location::current() + const source_location& loc = source_location::current() ) { for (const std::string_view ver : versions) { assertFalse(req.satisfiedBy(Version::parse(ver)), "", loc); diff --git a/srcOld/Archive.hpp b/srcOld/Archive.hpp index dcfa74385..83733d136 100644 --- a/srcOld/Archive.hpp +++ b/srcOld/Archive.hpp @@ -63,8 +63,8 @@ copy_data(Archive* reader, const Writer& writer) noexcept } [[nodiscard]] auto -archive_write_finish_entry(const Writer& writer) noexcept - -> Result { +archive_write_finish_entry(const Writer& writer +) noexcept -> Result { const i32 res = archive_write_finish_entry(writer.get()); if (res < ARCHIVE_OK) { return Err(archive_error_string(writer.get())); diff --git a/srcOld/Cfg.hpp b/srcOld/Cfg.hpp index 645261dc5..5546ebb35 100644 --- a/srcOld/Cfg.hpp +++ b/srcOld/Cfg.hpp @@ -51,8 +51,8 @@ struct IdentError : public cfg::Exception { public: explicit IdentError(const std::string& what_) : Exception( - "cfg expected parenthesis, comma, identifier, or string\n" + what_ - ) {} + "cfg expected parenthesis, comma, identifier, or string\n" + what_ + ) {} explicit IdentError(const char* what_) : IdentError(std::string(what_)) {} ~IdentError() noexcept override = default; @@ -153,23 +153,23 @@ struct Token { explicit Token(Kind k) : kind( - k != Kind::std::string && k != Kind::Ident - ? k - : throw std::invalid_argument("poac::util::cfg::Token") - ) {} + k != Kind::std::string && k != Kind::Ident + ? k + : throw std::invalid_argument("poac::util::cfg::Token") + ) {} Token(Kind k, StringType s) : kind( - k == Kind::std::string - ? k - : throw std::invalid_argument("poac::util::cfg::Token") - ), + k == Kind::std::string + ? k + : throw std::invalid_argument("poac::util::cfg::Token") + ), value(s) {} Token(Kind k, ident i) : kind( - k == Kind::Ident - ? k - : throw std::invalid_argument("poac::util::cfg::Token") - ), + k == Kind::Ident + ? k + : throw std::invalid_argument("poac::util::cfg::Token") + ), value(i) {} Token() = delete; @@ -290,43 +290,43 @@ struct Lexer { } private: - [[nodiscard]] inline auto - generate_token(SizeType index_, const std::optional& token) const - -> std::pair> { + [[nodiscard]] inline auto generate_token( + SizeType index_, const std::optional& token + ) const -> std::pair> { return { this->diff_step(index_), token }; } - [[nodiscard]] inline auto - generate_token(SizeType index_, std::string_view kind) const - -> std::pair> { + [[nodiscard]] inline auto generate_token( + SizeType index_, std::string_view kind + ) const -> std::pair> { return generate_token(index_, Token{ to_kind(kind) }); } [[nodiscard]] auto analyze_two_phrase(SizeType index_, char kind) const -> std::pair>; - [[nodiscard]] auto tokenize(SizeType index_) const - -> std::pair>; + [[nodiscard]] auto tokenize(SizeType index_ + ) const -> std::pair>; void step(SizeType& index_) const noexcept; void step_n(SizeType n) noexcept; - [[nodiscard]] inline auto diff_step(const SizeType index_) const noexcept - -> SizeType { + [[nodiscard]] inline auto diff_step(const SizeType index_ + ) const noexcept -> SizeType { return index_ - this->index; } - [[nodiscard]] inline auto one(const SizeType index_) const noexcept - -> ValueType { + [[nodiscard]] inline auto one(const SizeType index_ + ) const noexcept -> ValueType { return this->str[index_]; } - [[nodiscard]] auto string(SizeType index_) const - -> std::pair; + [[nodiscard]] auto string(SizeType index_ + ) const -> std::pair; [[nodiscard]] auto ident(SizeType index_) const -> std::pair; - static auto to_ident(std::string_view s) noexcept - -> std::optional; + static auto to_ident(std::string_view s + ) noexcept -> std::optional; }; auto @@ -341,8 +341,8 @@ Lexer::analyze_two_phrase(SizeType index_, const char kind) const } auto -Lexer::tokenize(SizeType index_) const - -> std::pair> { +Lexer::tokenize(SizeType index_ +) const -> std::pair> { if (index_ >= this->str.size()) { return generate_token(index_, std::nullopt); } @@ -521,24 +521,24 @@ struct CfgExpr { CfgExpr(Kind kind, ExprType&& expr) : kind( - kind == Kind::not_ || kind == Kind::cfg - ? kind - : throw std::invalid_argument("poac::util::cfg::CfgExpr") - ), + kind == Kind::not_ || kind == Kind::cfg + ? kind + : throw std::invalid_argument("poac::util::cfg::CfgExpr") + ), expr(std::move(expr)) {} CfgExpr(Kind kind, ExprListType&& expr) : kind( - kind == Kind::all || kind == Kind::any - ? kind - : throw std::invalid_argument("poac::util::cfg::CfgExpr") - ), + kind == Kind::all || kind == Kind::any + ? kind + : throw std::invalid_argument("poac::util::cfg::CfgExpr") + ), expr(std::move(expr)) {} CfgExpr(Kind kind, const Cfg& c) : kind( - kind == Kind::value - ? kind - : throw std::invalid_argument("poac::util::cfg::CfgExpr") - ), + kind == Kind::value + ? kind + : throw std::invalid_argument("poac::util::cfg::CfgExpr") + ), expr(c) {} CfgExpr() = delete; @@ -744,7 +744,8 @@ Parser::expr() -> CfgExpr { } else { return CfgExpr{ CfgExpr::any, std::move(e) }; } - } else if (token->get_ident() == Token::ident::not_ || token->get_ident() == Token::ident::cfg) { + } else if (token->get_ident() == Token::ident::not_ + || token->get_ident() == Token::ident::cfg) { this->lexer.next(); this->eat_left_paren(token->get_ident()); CfgExpr&& e = this->expr(); diff --git a/srcOld/Lockfile.hpp b/srcOld/Lockfile.hpp index 8b2562be3..5da91707f 100644 --- a/srcOld/Lockfile.hpp +++ b/srcOld/Lockfile.hpp @@ -83,8 +83,8 @@ export namespace poac::data::lockfile::inline v1 { // -------------------- INTO LOCKFILE -------------------- [[nodiscard]] auto -convert_to_lock(const resolver::UniqDeps& deps) - -> Result> { +convert_to_lock(const resolver::UniqDeps& deps +) -> Result> { std::vector packages; for (const auto& [pack, inner_deps] : deps) { if (pack.dep_info.type != "poac") { @@ -132,8 +132,8 @@ generate(const resolver::UniqDeps& deps) -> Result { // -------------------- FROM LOCKFILE -------------------- [[nodiscard]] auto -convert_to_deps(const Lockfile& lock) - -> resolver::UniqDeps { +convert_to_deps(const Lockfile& lock +) -> resolver::UniqDeps { resolver::UniqDeps deps; for (const auto& package : lock.package) { resolver::UniqDeps::mapped_type inner_deps = @@ -156,8 +156,8 @@ convert_to_deps(const Lockfile& lock) } [[nodiscard]] auto -read(const fs::path& base_dir) - -> Result>> { +read(const fs::path& base_dir +) -> Result>> { if (!fs::exists(base_dir / LOCKFILE_NAME)) { return Ok(std::nullopt); } diff --git a/srcOld/Resolver.hpp b/srcOld/Resolver.hpp index f2327304b..3e2c4a0fe 100644 --- a/srcOld/Resolver.hpp +++ b/srcOld/Resolver.hpp @@ -106,16 +106,16 @@ convert_to_download_link(std::string_view repository) -> std::string { } [[nodiscard]] inline auto -get_download_link(const resolve::Package& package) - -> Result, std::string> { +get_download_link(const resolve::Package& package +) -> Result, std::string> { const auto [repository, sha256sum] = Try(util::net::api::repoinfo(package.name, package.dep_info.version_rq)); return Ok(std::make_pair(convert_to_download_link(repository), sha256sum)); } [[nodiscard]] auto -fetch_impl(const resolve::Package& package) noexcept - -> Result> { +fetch_impl(const resolve::Package& package +) noexcept -> Result> { try { const auto [download_link, sha256sum] = Try(get_download_link(package).map_err(to_anyhow)); @@ -198,8 +198,8 @@ is_not_installed(const resolve::Package& package) -> bool { } auto -get_not_installed_deps(const ResolvedDeps& deps) - -> resolve::UniqDeps { +get_not_installed_deps(const ResolvedDeps& deps +) -> resolve::UniqDeps { return deps | boost::adaptors::map_keys | boost::adaptors::filtered(is_not_installed) // ref: https://stackoverflow.com/a/42251976 @@ -228,8 +228,8 @@ download_deps(const ResolvedDeps& deps) -> Result { } [[nodiscard]] auto -do_resolve(const resolve::UniqDeps& deps) noexcept - -> Result { +do_resolve(const resolve::UniqDeps& deps +) noexcept -> Result { try { const resolve::DupDeps duplicate_deps = Try(resolve::gather_all_deps(deps).map_err(to_anyhow)); diff --git a/srcOld/Resolver/Resolve.hpp b/srcOld/Resolver/Resolve.hpp index 2207dd8e0..4f54ae45c 100644 --- a/srcOld/Resolver/Resolve.hpp +++ b/srcOld/Resolver/Resolve.hpp @@ -34,8 +34,8 @@ import poac.util.verbosity; export namespace poac::core::resolver::resolve { inline auto -get_package(const UniqDeps::value_type& deps) noexcept - -> const Package& { +get_package(const UniqDeps::value_type& deps +) noexcept -> const Package& { return deps.first; } @@ -50,8 +50,8 @@ to_binary_numbers(const i32& x, const usize& digit) -> std::string { // ¬A ∨ ¬B ∨ C // ¬A ∨ ¬B ∨ ¬C auto -multiple_versions_cnf(const std::vector& clause) - -> std::vector> { +multiple_versions_cnf(const std::vector& clause +) -> std::vector> { return boost::irange(0, 1 << clause.size()) // number of combinations | boost::adaptors::transformed([&clause](const i32 i) { return boost::dynamic_bitset<>(to_binary_numbers(i, clause.size()) @@ -74,8 +74,8 @@ multiple_versions_cnf(const std::vector& clause) } auto -create_cnf(const DupDeps& activated) - -> std::vector> { +create_cnf(const DupDeps& activated +) -> std::vector> { std::vector> clauses; std::vector already_added; @@ -172,8 +172,8 @@ solve_sat( } [[nodiscard]] auto -backtrack_loop(const DupDeps& activated) - -> Result, std::string> { +backtrack_loop(const DupDeps& activated +) -> Result, std::string> { const std::vector> clauses = create_cnf(activated); if (util::verbosity::is_verbose()) { for (const std::vector& c : clauses) { @@ -212,8 +212,8 @@ duplicate_loose(const SinglePassRange& rng) -> bool { // `>=0.1.2 and <3.4.0` -> { 2.4.0, 2.5.0 } // name is boost/config, no boost-config [[nodiscard]] auto -get_versions_satisfy_interval(const Package& package) - -> Result, std::string> { +get_versions_satisfy_interval(const Package& package +) -> Result, std::string> { // TODO(ken-matsui): (`>1.2 and <=1.3.2` -> NG,`>1.2.0-alpha and <=1.3.2` -> // OK) `2.0.0` specific version or `>=0.1.2 and <3.4.0` version interval const semver::Interval i(package.dep_info.version_rq); @@ -330,8 +330,8 @@ gather_deps( } [[nodiscard]] auto -gather_all_deps(const UniqDeps& deps) - -> Result, std::string> { +gather_all_deps(const UniqDeps& deps +) -> Result, std::string> { DupDeps duplicate_deps; IntervalCache interval_cache; diff --git a/srcOld/Resolver/Sat.hpp b/srcOld/Resolver/Sat.hpp index 70e82b3e0..653c3dd4d 100644 --- a/srcOld/Resolver/Sat.hpp +++ b/srcOld/Resolver/Sat.hpp @@ -69,8 +69,8 @@ literal_to_index(i32 l) -> i32 { // function, so the index of the variable with the highest number of variables // is returned from the variables in the current clauses. auto -maximum_literal_number_index(const std::vector>& clauses) - -> i32 { +maximum_literal_number_index(const std::vector>& clauses +) -> i32 { Map frequency; for (const auto& clause : clauses) { for (const auto& literal : clause) { From bac7f9447ac1e6203e956e10ec2f8d4225b47f77 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Wed, 13 Nov 2024 22:26:24 -0600 Subject: [PATCH 06/18] rollback something --- src/Cli.cc | 63 +++++++++++++++++++------------------- src/Cmd/Search.cc | 10 +++--- src/Logger.hpp | 12 +++++--- src/Parallelism.cc | 12 ++++---- src/Rustify/Aliases.hpp | 68 ++++------------------------------------- src/Rustify/Tests.hpp | 57 +++++++++++++++++++++++----------- src/Semver.cc | 44 +++++++++++++------------- src/VersionReq.cc | 30 ++++++++++-------- 8 files changed, 136 insertions(+), 160 deletions(-) diff --git a/src/Cli.cc b/src/Cli.cc index 5be4e195c..4c58b2a40 100644 --- a/src/Cli.cc +++ b/src/Cli.cc @@ -2,7 +2,6 @@ #include "Algos.hpp" #include "Logger.hpp" -#include "Rustify.hpp" #include "TermColor.hpp" #include @@ -19,7 +18,7 @@ static constinit const std::string_view PADDING = " "; static void -setOffset(const usize offset) noexcept { +setOffset(const size_t offset) noexcept { std::cout << PADDING << std::left << std::setw(static_cast(offset + PADDING.size())); } @@ -57,9 +56,9 @@ addOptCandidates( } } -usize +size_t calcOptMaxShortSize(const std::vector& opts) noexcept { - usize maxShortSize = 0; + size_t maxShortSize = 0; for (const auto& opt : opts) { if (opt.isHidden) { // Hidden option should not affect maxShortSize. @@ -70,11 +69,11 @@ calcOptMaxShortSize(const std::vector& opts) noexcept { return maxShortSize; } -usize +size_t calcOptMaxOffset( - const std::vector& opts, const usize maxShortSize + const std::vector& opts, const size_t maxShortSize ) noexcept { - usize maxOffset = 0; + size_t maxOffset = 0; for (const auto& opt : opts) { if (opt.isHidden) { // Hidden option should not affect maxOffset. @@ -87,8 +86,8 @@ calcOptMaxOffset( void printOpts( - const std::vector& opts, const usize maxShortSize, - const usize maxOffset + const std::vector& opts, const size_t maxShortSize, + const size_t maxOffset ) noexcept { for (const auto& opt : opts) { if (opt.isHidden) { @@ -100,7 +99,7 @@ printOpts( } void -Opt::print(const usize maxShortSize, usize maxOffset) const noexcept { +Opt::print(const size_t maxShortSize, size_t maxOffset) const noexcept { std::string option; if (!shortName.empty()) { option += bold(cyan(shortName)); @@ -119,7 +118,7 @@ Opt::print(const usize maxShortSize, usize maxOffset) const noexcept { if (shouldColor()) { // Color escape sequences are not visible but affect std::setw. - constexpr usize colorEscapeSeqLen = 31; + constexpr size_t colorEscapeSeqLen = 31; maxOffset += colorEscapeSeqLen; } setOffset(maxOffset); @@ -154,11 +153,11 @@ Arg::getLeft() const noexcept { return cyan(left); } void -Arg::print(usize maxOffset) const noexcept { +Arg::print(size_t maxOffset) const noexcept { const std::string left = getLeft(); if (shouldColor()) { // Color escape sequences are not visible but affect std::setw. - constexpr usize colorEscapeSeqLen = 9; + constexpr size_t colorEscapeSeqLen = 9; maxOffset += colorEscapeSeqLen; } setOffset(maxOffset); @@ -227,9 +226,9 @@ Subcmd::missingArgumentForOpt(const std::string_view arg) { return EXIT_FAILURE; } -usize +size_t Subcmd::calcMaxShortSize() const noexcept { - usize maxShortSize = 0; + size_t maxShortSize = 0; if (globalOpts.has_value()) { maxShortSize = std::max(maxShortSize, calcOptMaxShortSize(globalOpts.value())); @@ -237,9 +236,9 @@ Subcmd::calcMaxShortSize() const noexcept { maxShortSize = std::max(maxShortSize, calcOptMaxShortSize(localOpts)); return maxShortSize; } -usize -Subcmd::calcMaxOffset(const usize maxShortSize) const noexcept { - usize maxOffset = 0; +size_t +Subcmd::calcMaxOffset(const size_t maxShortSize) const noexcept { + size_t maxOffset = 0; if (globalOpts.has_value()) { maxOffset = std::max(maxOffset, calcOptMaxOffset(globalOpts.value(), maxShortSize)); @@ -256,8 +255,8 @@ Subcmd::calcMaxOffset(const usize maxShortSize) const noexcept { void Subcmd::printHelp() const noexcept { - const usize maxShortSize = calcMaxShortSize(); - const usize maxOffset = calcMaxOffset(maxShortSize); + const size_t maxShortSize = calcMaxShortSize(); + const size_t maxOffset = calcMaxOffset(maxShortSize); std::cout << desc << '\n'; std::cout << '\n'; @@ -277,7 +276,7 @@ Subcmd::printHelp() const noexcept { } void -Subcmd::print(usize maxOffset) const noexcept { +Subcmd::print(size_t maxOffset) const noexcept { std::string cmdStr = bold(cyan(name)); if (hasShort()) { cmdStr += ", "; @@ -289,7 +288,7 @@ Subcmd::print(usize maxOffset) const noexcept { if (shouldColor()) { // Color escape sequences are not visible but affect std::setw. - constexpr usize colorEscapeSeqLen = 22; + constexpr size_t colorEscapeSeqLen = 22; maxOffset += colorEscapeSeqLen; } setOffset(maxOffset); @@ -417,20 +416,20 @@ Cli::printSubcmdHelp(const std::string_view subcmd) const noexcept { subcmds.at(subcmd).printHelp(); } -usize +size_t Cli::calcMaxShortSize() const noexcept { // This is for printing the help message of the poac command itself. So, // we don't need to consider the length of the subcommands' options. - usize maxShortSize = 0; + size_t maxShortSize = 0; maxShortSize = std::max(maxShortSize, calcOptMaxShortSize(globalOpts)); maxShortSize = std::max(maxShortSize, calcOptMaxShortSize(localOpts)); return maxShortSize; } -usize -Cli::calcMaxOffset(const usize maxShortSize) const noexcept { - usize maxOffset = 0; +size_t +Cli::calcMaxOffset(const size_t maxShortSize) const noexcept { + size_t maxOffset = 0; maxOffset = std::max(maxOffset, calcOptMaxOffset(globalOpts, maxShortSize)); maxOffset = std::max(maxOffset, calcOptMaxOffset(localOpts, maxShortSize)); @@ -440,7 +439,7 @@ Cli::calcMaxOffset(const usize maxShortSize) const noexcept { continue; } - usize offset = name.size(); // "build" + size_t offset = name.size(); // "build" if (!cmd.shortName.empty()) { offset += 2; // ", " offset += cmd.shortName.size(); // "b" @@ -451,14 +450,14 @@ Cli::calcMaxOffset(const usize maxShortSize) const noexcept { } void -Cli::printAllSubcmds(const bool showHidden, usize maxOffset) const noexcept { +Cli::printAllSubcmds(const bool showHidden, size_t maxOffset) const noexcept { for (const auto& [name, cmd] : subcmds) { if (!showHidden && cmd.isHidden) { // Hidden command should not affect maxOffset if `showHidden` is false. continue; } - usize offset = name.size(); // "build" + size_t offset = name.size(); // "build" if (!cmd.shortName.empty()) { offset += 2; // ", " offset += cmd.shortName.size(); // "b" @@ -482,8 +481,8 @@ Cli::printAllSubcmds(const bool showHidden, usize maxOffset) const noexcept { void Cli::printCmdHelp() const noexcept { // Print help message for poac itself - const usize maxShortSize = calcMaxShortSize(); - const usize maxOffset = calcMaxOffset(maxShortSize); + const size_t maxShortSize = calcMaxShortSize(); + const size_t maxOffset = calcMaxOffset(maxShortSize); std::cout << desc << '\n'; std::cout << '\n'; diff --git a/src/Cmd/Search.cc b/src/Cmd/Search.cc index 867b50d42..696617d65 100644 --- a/src/Cmd/Search.cc +++ b/src/Cmd/Search.cc @@ -2,8 +2,8 @@ #include "../Cli.hpp" #include "../Logger.hpp" -#include "../Rustify.hpp" +#include #include #include #include @@ -31,12 +31,12 @@ const Subcmd SEARCH_CMD = struct SearchArgs { std::string name; - usize perPage = 10; - usize page = 1; + size_t perPage = 10; + size_t page = 1; }; -static usize -writeCallback(void* contents, usize size, usize nmemb, std::string* userp) { +static size_t +writeCallback(void* contents, size_t size, size_t nmemb, std::string* userp) { userp->append(static_cast(contents), size * nmemb); return size * nmemb; } diff --git a/src/Logger.hpp b/src/Logger.hpp index 27f193fad..10d13b07a 100644 --- a/src/Logger.hpp +++ b/src/Logger.hpp @@ -1,20 +1,22 @@ #pragma once -#include "Rustify.hpp" +#include "Rustify/Traits.hpp" #include "TermColor.hpp" +#include #include #include #include #include #include +#include #include #include #include namespace logger { -enum class Level : u8 { +enum class Level : uint8_t { Off = 0, // --quiet, -q Error = 1, Warn = 2, @@ -175,7 +177,8 @@ info(MaybeWriter auto&&... msgs) noexcept { template struct debug { // NOLINT(readability-identifier-naming) explicit debug( - Ts&&... msgs, const source_location& loc = source_location::current() + Ts&&... msgs, + const std::source_location& loc = std::source_location::current() ) noexcept { Logger::debug(loc.function_name(), std::forward(msgs)...); } @@ -186,7 +189,8 @@ debug(Ts&&...) -> debug; template struct trace { // NOLINT(readability-identifier-naming) explicit trace( - Ts&&... msgs, const source_location& loc = source_location::current() + Ts&&... msgs, + const std::source_location& loc = std::source_location::current() ) noexcept { Logger::trace(loc.function_name(), std::forward(msgs)...); } diff --git a/src/Parallelism.cc b/src/Parallelism.cc index 4c25db4dd..1fc15e180 100644 --- a/src/Parallelism.cc +++ b/src/Parallelism.cc @@ -1,13 +1,13 @@ #include "Parallelism.hpp" #include "Logger.hpp" -#include "Rustify.hpp" +#include #include #include #include -usize +size_t numThreads() noexcept { const unsigned int numThreads = std::thread::hardware_concurrency(); if (numThreads > 1) { @@ -24,7 +24,7 @@ struct ParallelismState { ParallelismState& operator=(ParallelismState&&) noexcept = delete; ~ParallelismState() noexcept = default; - void set(usize numThreads) noexcept { + void set(size_t numThreads) noexcept { if (numThreads == 0) { logger::warn("requested parallelism of 0, capping at 1"); numThreads = 1; @@ -34,7 +34,7 @@ struct ParallelismState { tbb::global_control::max_allowed_parallelism, numThreads ); } - usize get() const noexcept { + size_t get() const noexcept { // NOLINTNEXTLINE(readability-static-accessed-through-instance) return status->active_value(tbb::global_control::max_allowed_parallelism); } @@ -54,11 +54,11 @@ struct ParallelismState { }; void -setParallelism(const usize numThreads) noexcept { +setParallelism(const size_t numThreads) noexcept { ParallelismState::instance().set(numThreads); } -usize +size_t getParallelism() noexcept { return ParallelismState::instance().get(); } diff --git a/src/Rustify/Aliases.hpp b/src/Rustify/Aliases.hpp index 3ff519258..5f0f72167 100644 --- a/src/Rustify/Aliases.hpp +++ b/src/Rustify/Aliases.hpp @@ -1,85 +1,28 @@ #pragma once -#include -#include +#include #include -#include +#include #include #include #include namespace fs = std::filesystem; -// NOLINTBEGIN(readability-identifier-naming) -using u8 = std::uint8_t; -using u16 = std::uint16_t; -using u32 = std::uint32_t; -using u64 = std::uint64_t; - -using i8 = std::int8_t; -using i16 = std::int16_t; -using i32 = std::int32_t; -using i64 = std::int64_t; - -using isize = std::ptrdiff_t; -using usize = std::size_t; - -using f32 = float; -using f64 = double; -// NOLINTEND(readability-identifier-naming) - // 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, usize /*unused*/) { +operator""_path(const char* str, size_t /*unused*/) { return str; } -// NOLINTBEGIN(readability-identifier-naming) -struct source_location { - constexpr source_location() noexcept = delete; - constexpr ~source_location() noexcept = default; - constexpr source_location(const source_location&) noexcept = default; - constexpr source_location(source_location&&) noexcept = default; - constexpr source_location& - operator=(const source_location&) noexcept = default; - constexpr source_location& operator=(source_location&&) noexcept = default; - - constexpr source_location( - const char* file, int line, const char* func - ) noexcept - : file_(file), line_(line), func_(func) {} - - static constexpr source_location current( - const char* file = __builtin_FILE(), const int line = __builtin_LINE(), - const char* func = __builtin_FUNCTION() - ) noexcept { - return { file, line, func }; - } - constexpr std::string_view file_name() const noexcept { - return file_; - } - constexpr int line() const noexcept { - return line_; - } - constexpr std::string_view function_name() const noexcept { - return func_; - } - -private: - const char* file_; - int line_{}; - const char* func_; -}; -// NOLINTEND(readability-identifier-naming) - [[noreturn]] inline void panic( const std::string_view msg, - const source_location& loc = source_location::current() + const std::source_location& loc = std::source_location::current() ) { std::ostringstream oss; oss << "panicked at '" << msg << "', " << loc.file_name() << ':' << loc.line() @@ -89,7 +32,8 @@ panic( [[noreturn]] inline void unreachable( - [[maybe_unused]] const source_location& loc = source_location::current() + [[maybe_unused]] const std::source_location& loc = + std::source_location::current() ) noexcept { #ifdef NDEBUG __builtin_unreachable(); diff --git a/src/Rustify/Tests.hpp b/src/Rustify/Tests.hpp index 6aef90e1f..a7cdf7122 100644 --- a/src/Rustify/Tests.hpp +++ b/src/Rustify/Tests.hpp @@ -1,11 +1,12 @@ #pragma once -#include "Aliases.hpp" #include "Traits.hpp" +#include #include #include #include +#include #include #include #include @@ -36,12 +37,12 @@ modName(std::string_view file) noexcept { return file; } - const usize start = file.find("src/"); + const size_t start = file.find("src/"); if (start == std::string_view::npos) { return file; } - const usize end = file.find_last_of('.'); + const size_t end = file.find_last_of('.'); if (end == std::string_view::npos) { return file; } @@ -49,21 +50,43 @@ modName(std::string_view file) noexcept { return file.substr(start, end - start); } +constexpr std::string_view +modFunc(std::string_view func) noexcept { + if (func.empty()) { + return func; + } + + const size_t end = func.find_last_of('('); + if (end == std::string_view::npos) { + return func; + } + func = func.substr(0, end); + + const size_t start = func.find_last_of(' '); + if (start == std::string_view::npos) { + return func; + } + return func.substr(start + 1); +} + inline void -pass(const source_location& loc = source_location::current()) noexcept { +pass( + const std::source_location& loc = std::source_location::current() +) noexcept { std::cout << " test " << modName(loc.file_name()) - << "::" << loc.function_name() << " ... " << GREEN << "ok" << RESET - << '\n' + << "::" << modFunc(loc.function_name()) << " ... " << GREEN << "ok" + << RESET << '\n' << std::flush; } [[noreturn]] inline void -error(const source_location& loc, Display auto&&... msgs) { +error(const std::source_location& loc, Display auto&&... msgs) { std::ostringstream oss; oss << "\n test " << modName(loc.file_name()) - << "::" << loc.function_name() << " ... " << RED << "FAILED" << RESET - << "\n\n" - << '\'' << loc.function_name() << "' failed at '" << std::boolalpha; + << "::" << modFunc(loc.function_name()) << " ... " << RED << "FAILED" + << RESET << "\n\n" + << '\'' << modFunc(loc.function_name()) << "' failed at '" + << std::boolalpha; (oss << ... << std::forward(msgs)) << "', " << loc.file_name() << ':' << loc.line() << '\n'; throw std::logic_error(oss.str()); @@ -72,7 +95,7 @@ error(const source_location& loc, Display auto&&... msgs) { inline void assertTrue( const bool cond, const std::string_view msg = "", - const source_location& loc = source_location::current() + const std::source_location& loc = std::source_location::current() ) noexcept { if (cond) { return; // OK @@ -88,7 +111,7 @@ assertTrue( inline void assertFalse( const bool cond, const std::string_view msg = "", - const source_location& loc = source_location::current() + const std::source_location& loc = std::source_location::current() ) noexcept { if (!cond) { return; // OK @@ -106,7 +129,7 @@ template inline void assertEq( Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", - const source_location& loc = source_location::current() + const std::source_location& loc = std::source_location::current() ) noexcept { if (lhs == rhs) { return; // OK @@ -128,7 +151,7 @@ template inline void assertNe( Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", - const source_location& loc = source_location::current() + const std::source_location& loc = std::source_location::current() ) noexcept { if (lhs != rhs) { return; // OK @@ -150,7 +173,7 @@ template inline void assertLt( Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", - const source_location& loc = source_location::current() + const std::source_location& loc = std::source_location::current() ) noexcept { if (lhs < rhs) { return; // OK @@ -172,7 +195,7 @@ template inline void assertException( Fn&& func, const std::string_view msg, - const source_location& loc = source_location::current() + const std::source_location& loc = std::source_location::current() ) noexcept { try { std::forward(func)(); @@ -197,7 +220,7 @@ template requires(std::is_invocable_v) inline void assertNoException( - Fn&& func, const source_location& loc = source_location::current() + Fn&& func, const std::source_location& loc = std::source_location::current() ) noexcept { try { std::forward(func)(); diff --git a/src/Semver.cc b/src/Semver.cc index 06882ced8..82977799d 100644 --- a/src/Semver.cc +++ b/src/Semver.cc @@ -1,8 +1,8 @@ #include "Semver.hpp" -#include "Rustify.hpp" - #include +#include +#include #include #include #include @@ -14,7 +14,7 @@ std::ostream& operator<<(std::ostream& os, const VersionToken& tok) noexcept { switch (tok.kind) { case VersionToken::Num: - os << std::get(tok.value); + os << std::get(tok.value); break; case VersionToken::Ident: os << std::get(tok.value); @@ -42,7 +42,7 @@ VersionToken::toString() const noexcept { return oss.str(); } -usize +size_t VersionToken::size() const noexcept { return toString().size(); } @@ -54,7 +54,7 @@ operator==(const VersionToken& lhs, const VersionToken& rhs) noexcept { } switch (lhs.kind) { case VersionToken::Num: - return std::get(lhs.value) == std::get(rhs.value); + return std::get(lhs.value) == std::get(rhs.value); case VersionToken::Ident: return std::get(lhs.value) == std::get(rhs.value); @@ -71,7 +71,7 @@ operator==(const VersionToken& lhs, const VersionToken& rhs) noexcept { bool operator<(const VersionToken& lhs, const VersionToken& rhs) noexcept { if (lhs.kind == VersionToken::Num && rhs.kind == VersionToken::Num) { - return std::get(lhs.value) < std::get(rhs.value); + return std::get(lhs.value) < std::get(rhs.value); } return lhs.toString() < rhs.toString(); } @@ -100,7 +100,7 @@ Prerelease::empty() const noexcept { std::string Prerelease::toString() const noexcept { std::string str; - for (usize i = 0; i < ident.size(); ++i) { + for (size_t i = 0; i < ident.size(); ++i) { if (i > 0) { str += '.'; } @@ -125,7 +125,7 @@ operator<(const Prerelease& lhs, const Prerelease& rhs) noexcept { if (rhs.ident.empty()) { return true; // rhs is a normal version and is greater } - for (usize i = 0; i < lhs.ident.size() && i < rhs.ident.size(); ++i) { + for (size_t i = 0; i < lhs.ident.size() && i < rhs.ident.size(); ++i) { if (lhs.ident[i] < rhs.ident[i]) { return true; } else if (lhs.ident[i] > rhs.ident[i]) { @@ -155,7 +155,7 @@ BuildMetadata::empty() const noexcept { std::string BuildMetadata::toString() const noexcept { std::string str; - for (usize i = 0; i < ident.size(); ++i) { + for (size_t i = 0; i < ident.size(); ++i) { if (i > 0) { str += '.'; } @@ -170,7 +170,7 @@ operator==(const BuildMetadata& lhs, const BuildMetadata& rhs) noexcept { } bool operator<(const BuildMetadata& lhs, const BuildMetadata& rhs) noexcept { - for (usize i = 0; i < lhs.ident.size() && i < rhs.ident.size(); ++i) { + for (size_t i = 0; i < lhs.ident.size() && i < rhs.ident.size(); ++i) { if (lhs.ident[i] < rhs.ident[i]) { return true; } else if (lhs.ident[i] > rhs.ident[i]) { @@ -265,7 +265,7 @@ operator>=(const Version& lhs, const Version& rhs) noexcept { VersionToken VersionLexer::consumeIdent() noexcept { - usize len = 0; + size_t len = 0; while (pos < s.size() && (std::isalnum(s[pos]) || s[pos] == '-')) { step(); ++len; @@ -275,8 +275,8 @@ VersionLexer::consumeIdent() noexcept { VersionToken VersionLexer::consumeNum() { - usize len = 0; - u64 value = 0; + size_t len = 0; + uint64_t value = 0; while (pos < s.size() && std::isdigit(s[pos])) { if (len > 0 && value == 0) { throw SemverError( @@ -284,10 +284,10 @@ VersionLexer::consumeNum() { ); } - const u64 digit = s[pos] - '0'; - constexpr u64 base = 10; + const uint64_t digit = s[pos] - '0'; + constexpr uint64_t base = 10; // Check for overflow - if (value > (std::numeric_limits::max() - digit) / base) { + if (value > (std::numeric_limits::max() - digit) / base) { throw SemverError( s, '\n', std::string(pos - len, ' '), std::string(len, '^'), " number exceeds UINT64_MAX" @@ -304,7 +304,7 @@ VersionLexer::consumeNum() { // Note that 012 is an invalid number but 012d is a valid identifier. VersionToken VersionLexer::consumeNumOrIdent() { - const usize oldPos = pos; // we need two passes + const size_t oldPos = pos; // we need two passes bool isIdent = false; while (pos < s.size() && (std::isalnum(s[pos]) || s[pos] == '-')) { if (!std::isdigit(s[pos])) { @@ -349,7 +349,7 @@ VersionLexer::next() { VersionToken VersionLexer::peek() { - const usize oldPos = pos; + const size_t oldPos = pos; const VersionToken tok = next(); pos = oldPos; return tok; @@ -404,12 +404,12 @@ VersionParser::parse() { // Even if the token can be parsed as an identifier, try to parse it as a // number. -u64 +uint64_t VersionParser::parseNum() { if (!std::isdigit(lexer.s[lexer.pos])) { throw SemverParseError(lexer, lexer.peek(), " expected number"); } - return std::get(lexer.consumeNum().value); + return std::get(lexer.consumeNum().value); } void @@ -484,6 +484,8 @@ Version::parse(const std::string_view str) { #ifdef POAC_TEST +# include "Rustify/Tests.hpp" + namespace tests { // Thanks to: @@ -767,7 +769,7 @@ testSpecOrder() { "1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-alpha.beta", "1.0.0-beta", "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", "1.0.0", }; - for (usize i = 1; i < vers.size(); ++i) { + for (size_t i = 1; i < vers.size(); ++i) { assertLt(Version::parse(vers[i - 1]), Version::parse(vers[i])); } diff --git a/src/VersionReq.cc b/src/VersionReq.cc index 3d614eba4..7d081a1da 100644 --- a/src/VersionReq.cc +++ b/src/VersionReq.cc @@ -1,9 +1,10 @@ #include "VersionReq.hpp" #include "Exception.hpp" -#include "Rustify.hpp" +#include "Rustify/Aliases.hpp" #include +#include #include #include #include @@ -44,7 +45,7 @@ toString(const Comparator::Op op) noexcept { } struct ComparatorToken { - enum class Kind : std::uint8_t { + enum class Kind : uint8_t { Eq, // = Gt, // > Gte, // >= @@ -70,7 +71,7 @@ struct ComparatorToken { struct ComparatorLexer { std::string_view s; - usize pos{ 0 }; + size_t pos{ 0 }; explicit ComparatorLexer(const std::string_view str) noexcept : s(str) {} @@ -292,7 +293,7 @@ matchesGreater(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.minor.has_value()) { return false; } else { - const u64 minor = cmp.minor.value(); + const uint64_t minor = cmp.minor.value(); if (ver.minor != minor) { return ver.minor > minor; } @@ -301,7 +302,7 @@ matchesGreater(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.patch.has_value()) { return false; } else { - const u64 patch = cmp.patch.value(); + const uint64_t patch = cmp.patch.value(); if (ver.patch != patch) { return ver.patch > patch; } @@ -319,7 +320,7 @@ matchesLess(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.minor.has_value()) { return false; } else { - const u64 minor = cmp.minor.value(); + const uint64_t minor = cmp.minor.value(); if (ver.minor != minor) { return ver.minor < minor; } @@ -328,7 +329,7 @@ matchesLess(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.patch.has_value()) { return false; } else { - const u64 patch = cmp.patch.value(); + const uint64_t patch = cmp.patch.value(); if (ver.patch != patch) { return ver.patch < patch; } @@ -346,7 +347,7 @@ matchesNoOp(const Comparator& cmp, const Version& ver) noexcept { if (!cmp.minor.has_value()) { return true; } - const u64 minor = cmp.minor.value(); + const uint64_t minor = cmp.minor.value(); if (!cmp.patch.has_value()) { if (cmp.major > 0) { @@ -355,7 +356,7 @@ matchesNoOp(const Comparator& cmp, const Version& ver) noexcept { return ver.minor == minor; } } - const u64 patch = cmp.patch.value(); + const uint64_t patch = cmp.patch.value(); if (cmp.major > 0) { if (ver.minor != minor) { @@ -438,7 +439,7 @@ Comparator::canonicalize() const noexcept { } struct VersionReqToken { - enum class Kind : std::uint8_t { + enum class Kind : uint8_t { Comp, And, Eof, @@ -465,7 +466,7 @@ isCompStart(const char c) noexcept { struct VersionReqLexer { std::string_view s; - usize pos{ 0 }; + size_t pos{ 0 }; explicit VersionReqLexer(const std::string_view str) noexcept : s(str) {} @@ -896,6 +897,9 @@ operator<<(std::ostream& os, const VersionReq& req) { #ifdef POAC_TEST +# include "Rustify/Tests.hpp" + +# include # include namespace tests { @@ -906,7 +910,7 @@ namespace tests { inline static void assertMatchAll( const VersionReq& req, const std::span versions, - const source_location& loc = source_location::current() + const std::source_location& loc = std::source_location::current() ) { for (const std::string_view ver : versions) { assertTrue(req.satisfiedBy(Version::parse(ver)), "", loc); @@ -916,7 +920,7 @@ assertMatchAll( inline static void assertMatchNone( const VersionReq& req, const std::span versions, - const source_location& loc = source_location::current() + const std::source_location& loc = std::source_location::current() ) { for (const std::string_view ver : versions) { assertFalse(req.satisfiedBy(Version::parse(ver)), "", loc); From 47f8ec8ab1e0c59999c3a612190ca771748e5659 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Thu, 14 Nov 2024 18:47:51 -0600 Subject: [PATCH 07/18] use format for lib build command --- src/BuildConfig.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index eedb0621d..7d89c207d 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -499,7 +499,7 @@ BuildConfig::defineLibTarget( const std::string& libTarget, const std::unordered_set& deps ) { std::vector commands; - commands.emplace_back("ar rcs lib" + getPackageName() + ".a $^"); + commands.emplace_back(fmt::format("ar rcs lib{}.a $^", getPackageName())); defineTarget(libTarget, commands, deps); } From f12e0076b4eb709189106512a085105fd1a2d432 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Thu, 14 Nov 2024 19:20:06 -0600 Subject: [PATCH 08/18] formatting, fix uninitialized vars --- src/BuildConfig.cc | 5 ++++- src/Cmd/Build.cc | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index eaa63a88c..60ac2a9a3 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -796,6 +796,9 @@ BuildConfig::configureBuild() { throw PoacError(srcDir, " is required but not found"); } + executable = false; + library = false; + // find main source file const auto isMainSource = [](const fs::path& file) { return file.filename().stem() == "main"; @@ -837,7 +840,7 @@ BuildConfig::configureBuild() { } } - if (mainSource.empty() && libSource.empty()) { + if (!executable && !library) { throw PoacError(fmt::format( "neither src/main{} nor src/lib{} was not found", SOURCE_FILE_EXTS, SOURCE_FILE_EXTS diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index ae72e186c..c335bba63 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -63,7 +63,7 @@ buildImpl(std::string& outDir, const bool isDebug) { } if (config.isLibrary()) { - std::string libName = "lib" + packageName + ".a"; + std::string libName = fmt::format("lib{}.a", packageName); const Command makeCmd = getMakeCommand().addArg("-C").addArg(outDir).addArg( (config.outBasePath / libName).string() ); From 396798483aca1144a7d142e06c8fef072290e798 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Thu, 14 Nov 2024 19:28:25 -0600 Subject: [PATCH 09/18] formatting, fix uninitialized vars --- src/BuildConfig.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index 60ac2a9a3..c24532b9e 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -63,7 +63,8 @@ operator<<(std::ostream& os, VarType type) { } BuildConfig::BuildConfig(const std::string& packageName, const bool isDebug) - : packageName{ packageName }, isDebug{ isDebug } { + : packageName{ packageName }, isDebug{ isDebug }, + executable{ false }, library{ false } { const fs::path projectBasePath = getProjectBasePath(); if (isDebug) { outBasePath = projectBasePath / "poac-out" / "debug"; @@ -796,9 +797,6 @@ BuildConfig::configureBuild() { throw PoacError(srcDir, " is required but not found"); } - executable = false; - library = false; - // find main source file const auto isMainSource = [](const fs::path& file) { return file.filename().stem() == "main"; From 7fc11528f3164400656c40e477adea2d31898838 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Thu, 14 Nov 2024 19:41:32 -0600 Subject: [PATCH 10/18] fix lint errors --- src/BuildConfig.cc | 3 +-- src/BuildConfig.hpp | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index c24532b9e..fb1879ea6 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -63,8 +63,7 @@ operator<<(std::ostream& os, VarType type) { } BuildConfig::BuildConfig(const std::string& packageName, const bool isDebug) - : packageName{ packageName }, isDebug{ isDebug }, - executable{ false }, library{ false } { + : packageName{ packageName }, isDebug{ isDebug } { const fs::path projectBasePath = getProjectBasePath(); if (isDebug) { outBasePath = projectBasePath / "poac-out" / "debug"; diff --git a/src/BuildConfig.hpp b/src/BuildConfig.hpp index f2a018aa1..eaa94e352 100644 --- a/src/BuildConfig.hpp +++ b/src/BuildConfig.hpp @@ -52,9 +52,9 @@ struct BuildConfig { bool isDebug; // if we are building an executable - bool executable; + bool executable{ false }; // if we are building a library - bool library; + bool library{ false }; std::unordered_map variables; std::unordered_map> varDeps; @@ -160,7 +160,7 @@ struct BuildConfig { const std::string& binTarget, const std::unordered_set& deps ); void defineLibTarget( - const std::string& binTarget, const std::unordered_set& deps + const std::string& libTarget, const std::unordered_set& deps ); void collectBinDepObjs( // NOLINT(misc-no-recursion) From a32a4a63f5c0d0d9727d2bdda87b9012e9049cb9 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Thu, 14 Nov 2024 22:30:16 -0600 Subject: [PATCH 11/18] change to fmt::format --- src/BuildConfig.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index fb1879ea6..ded749051 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -855,7 +855,7 @@ BuildConfig::configureBuild() { buildAll.insert(packageName); } if (library) { - buildAll.insert("lib" + packageName + ".a"); + buildAll.insert(fmt::format("lib{}.a", packageName)); } // Build rules @@ -915,7 +915,7 @@ BuildConfig::configureBuild() { targets.at(libTarget).remDeps, // we don't need sourceFile buildObjTargets ); - defineLibTarget(outBasePath / ("lib" + packageName + ".a"), libTargetDeps); + defineLibTarget(outBasePath / fmt::format("lib{}.a", packageName), libTargetDeps); } // Test Pass From b822f85c7813797bbe0a914a9ec4af71c626d07c Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Fri, 15 Nov 2024 07:33:14 -0600 Subject: [PATCH 12/18] format --- src/BuildConfig.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index ded749051..60d465d87 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -915,7 +915,9 @@ BuildConfig::configureBuild() { targets.at(libTarget).remDeps, // we don't need sourceFile buildObjTargets ); - defineLibTarget(outBasePath / fmt::format("lib{}.a", packageName), libTargetDeps); + defineLibTarget( + outBasePath / fmt::format("lib{}.a", packageName), libTargetDeps + ); } // Test Pass From 911d6e0ae8928d5497bb6a845dd1a37278b451b9 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Fri, 15 Nov 2024 22:43:01 -0600 Subject: [PATCH 13/18] format --- src/Cmd/Build.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index e2b13ceb7..fc2fe8da2 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -54,8 +54,8 @@ buildImpl(std::string& outDir, const bool isDebug) { logger::info( "Compiling", - "{} v{} ({})", packageName, getPackageVersion().toString(), - getProjectBasePath().string() + "{} v{} ({})", packageName, getPackageVersion().toString(), + getProjectBasePath().string() ); exitCode = execCmd(makeCmd); From b28f9a9df88c90d6087a2f7dba1acad129421c13 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Fri, 15 Nov 2024 22:48:48 -0600 Subject: [PATCH 14/18] fix build --- src/BuildConfig.cc | 4 ++-- src/Cmd/Build.cc | 15 +++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index 7f26eeec9..62763393e 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -874,13 +874,13 @@ BuildConfig::configureBuild() { sourceFilePath.string() ); } else if (sourceFilePath != libSource && isLibSource(sourceFilePath)) { - logger::warn(fmt::format( + logger::warn( "source file `{}` is named `lib` but is not located directly in the " "`src/` directory. " "This file will not be treated as a library. " "Move it directly to 'src/' if intended as such.", sourceFilePath.string() - )); + ); } srcs += ' ' + sourceFilePath.string(); diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index fc2fe8da2..fc78cf5ce 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -52,11 +52,8 @@ buildImpl(std::string& outDir, const bool isDebug) { if (exitCode != EXIT_SUCCESS) { // If packageName binary is not up-to-date, compile it. logger::info( - "Compiling", - - "{} v{} ({})", packageName, getPackageVersion().toString(), - getProjectBasePath().string() - + "Compiling", "{} v{} ({})", packageName, + getPackageVersion().toString(), getProjectBasePath().string() ); exitCode = execCmd(makeCmd); } @@ -74,11 +71,9 @@ buildImpl(std::string& outDir, const bool isDebug) { if (exitCode != EXIT_SUCCESS) { // If packageName binary is not up-to-date, compile it. logger::info( - "Compiling", - fmt::format( - "{} v{} ({})", libName, getPackageVersion().toString(), - getProjectBasePath().string() - ) + "Compiling", "{} v{} ({})", libName, getPackageVersion().toString(), + getProjectBasePath().string() + ); exitCode = execCmd(makeCmd); } From 9e58bf4c4d38f640e26e9ace37d6dad9f29959d1 Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Sat, 16 Nov 2024 08:44:21 -0600 Subject: [PATCH 15/18] refactor build command into function --- src/Cmd/Build.cc | 60 ++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index fc78cf5ce..a560b2afe 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -32,6 +32,29 @@ const Subcmd BUILD_CMD = .addOpt(OPT_JOBS) .setMainFn(buildMain); +int +runBuildCommand( + const std::string& outDir, const BuildConfig& config, + const std::string& objectName +) { + const Command makeCmd = getMakeCommand().addArg("-C").addArg(outDir).addArg( + (config.outBasePath / objectName).string() + ); + Command checkUpToDateCmd = makeCmd; + checkUpToDateCmd.addArg("--question"); + + int exitCode = execCmd(checkUpToDateCmd); + if (exitCode != EXIT_SUCCESS) { + // If objectName binary is not up-to-date, compile it. + logger::info( + "Compiling", "{} v{} ({})", objectName, getPackageVersion().toString(), + getProjectBasePath().string() + ); + exitCode = execCmd(makeCmd); + } + return exitCode; +} + int buildImpl(std::string& outDir, const bool isDebug) { const auto start = std::chrono::steady_clock::now(); @@ -42,41 +65,12 @@ buildImpl(std::string& outDir, const bool isDebug) { const std::string& packageName = getPackageName(); int exitCode = 0; if (config.isExecutable()) { - const Command makeCmd = getMakeCommand().addArg("-C").addArg(outDir).addArg( - (config.outBasePath / packageName).string() - ); - Command checkUpToDateCmd = makeCmd; - checkUpToDateCmd.addArg("--question"); - - exitCode = execCmd(checkUpToDateCmd); - if (exitCode != EXIT_SUCCESS) { - // If packageName binary is not up-to-date, compile it. - logger::info( - "Compiling", "{} v{} ({})", packageName, - getPackageVersion().toString(), getProjectBasePath().string() - ); - exitCode = execCmd(makeCmd); - } + exitCode = runBuildCommand(outDir, config, packageName); } - if (config.isLibrary()) { - std::string libName = fmt::format("lib{}.a", packageName); - const Command makeCmd = getMakeCommand().addArg("-C").addArg(outDir).addArg( - (config.outBasePath / libName).string() - ); - Command checkUpToDateCmd = makeCmd; - checkUpToDateCmd.addArg("--question"); - - exitCode = execCmd(checkUpToDateCmd); - if (exitCode != EXIT_SUCCESS) { - // If packageName binary is not up-to-date, compile it. - logger::info( - "Compiling", "{} v{} ({})", libName, getPackageVersion().toString(), - getProjectBasePath().string() - - ); - exitCode = execCmd(makeCmd); - } + if (config.isLibrary() && exitCode == 0) { + std::string const libName = fmt::format("lib{}.a", packageName); + exitCode = runBuildCommand(outDir, config, libName); } const auto end = std::chrono::steady_clock::now(); From 0ed1788f6bcd1c370aabfd723e1a3d78c1b821bd Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Sat, 16 Nov 2024 08:51:13 -0600 Subject: [PATCH 16/18] preallocate commands vec and make const --- src/BuildConfig.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index 62763393e..4fee82f92 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -489,8 +489,9 @@ void BuildConfig::defineLinkTarget( const std::string& binTarget, const std::unordered_set& deps ) { - std::vector commands; - commands.emplace_back("$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@"); + const std::vector commands = { + "$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@" + }; defineTarget(binTarget, commands, deps); } @@ -498,8 +499,9 @@ void BuildConfig::defineLibTarget( const std::string& libTarget, const std::unordered_set& deps ) { - std::vector commands; - commands.emplace_back(fmt::format("ar rcs lib{}.a $^", getPackageName())); + const std::vector commands = { + fmt::format("ar rcs lib{}.a $^", getPackageName()) + }; defineTarget(libTarget, commands, deps); } From a2bebc95cd556c0dd761618f0c5fe83666429adb Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Thu, 21 Nov 2024 08:53:53 -0600 Subject: [PATCH 17/18] change var names, introduce library name variables --- src/BuildConfig.cc | 15 +++++++-------- src/BuildConfig.hpp | 1 + src/Cmd/Build.cc | 10 +++++----- src/Manifest.cc | 4 ++++ src/Manifest.hpp | 1 + 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index 4fee82f92..2011e09b4 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -64,6 +64,7 @@ operator<<(std::ostream& os, VarType type) { BuildConfig::BuildConfig(const std::string& packageName, const bool isDebug) : packageName{ packageName }, isDebug{ isDebug } { + libName = fmt::format("lib{}.a", packageName); const fs::path projectBasePath = getProjectBasePath(); if (isDebug) { outBasePath = projectBasePath / "poac-out" / "debug"; @@ -500,7 +501,7 @@ BuildConfig::defineLibTarget( const std::string& libTarget, const std::unordered_set& deps ) { const std::vector commands = { - fmt::format("ar rcs lib{}.a $^", getPackageName()) + fmt::format("ar rcs {} $^", libName) }; defineTarget(libTarget, commands, deps); } @@ -852,16 +853,16 @@ BuildConfig::configureBuild() { setVariables(); - std::unordered_set buildAll = {}; + std::unordered_set allTargets = {}; if (executable) { - buildAll.insert(packageName); + allTargets.insert(packageName); } if (library) { - buildAll.insert(fmt::format("lib{}.a", packageName)); + allTargets.insert(libName); } // Build rules - setAll(buildAll); + setAll(allTargets); addPhony("all"); std::vector sourceFilePaths = listSourceFilePaths(srcDir); @@ -917,9 +918,7 @@ BuildConfig::configureBuild() { targets.at(libTarget).remDeps, // we don't need sourceFile buildObjTargets ); - defineLibTarget( - outBasePath / fmt::format("lib{}.a", packageName), libTargetDeps - ); + defineLibTarget(outBasePath / libName, libTargetDeps); } // Test Pass diff --git a/src/BuildConfig.hpp b/src/BuildConfig.hpp index eaa94e352..5dce4401c 100644 --- a/src/BuildConfig.hpp +++ b/src/BuildConfig.hpp @@ -47,6 +47,7 @@ struct BuildConfig { private: std::string packageName; + std::string libName; fs::path buildOutPath; fs::path unittestOutPath; bool isDebug; diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index a560b2afe..88d5d23c9 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -35,19 +35,19 @@ const Subcmd BUILD_CMD = int runBuildCommand( const std::string& outDir, const BuildConfig& config, - const std::string& objectName + const std::string& targetName ) { const Command makeCmd = getMakeCommand().addArg("-C").addArg(outDir).addArg( - (config.outBasePath / objectName).string() + (config.outBasePath / targetName).string() ); Command checkUpToDateCmd = makeCmd; checkUpToDateCmd.addArg("--question"); int exitCode = execCmd(checkUpToDateCmd); if (exitCode != EXIT_SUCCESS) { - // If objectName binary is not up-to-date, compile it. + // If targetName binary is not up-to-date, compile it. logger::info( - "Compiling", "{} v{} ({})", objectName, getPackageVersion().toString(), + "Compiling", "{} v{} ({})", targetName, getPackageVersion().toString(), getProjectBasePath().string() ); exitCode = execCmd(makeCmd); @@ -69,7 +69,7 @@ buildImpl(std::string& outDir, const bool isDebug) { } if (config.isLibrary() && exitCode == 0) { - std::string const libName = fmt::format("lib{}.a", packageName); + const std::string libName = getLibraryName(); exitCode = runBuildCommand(outDir, config, libName); } diff --git a/src/Manifest.cc b/src/Manifest.cc index 71812d100..7e148ca37 100644 --- a/src/Manifest.cc +++ b/src/Manifest.cc @@ -272,6 +272,10 @@ const std::string& getPackageName() { return parsePackage().name; } +std::string +getLibraryName() { + return fmt::format("lib{}.a", getPackageName()); +} const Edition& getPackageEdition() { return parsePackage().edition; diff --git a/src/Manifest.hpp b/src/Manifest.hpp index 1fe4d5222..b742886f2 100644 --- a/src/Manifest.hpp +++ b/src/Manifest.hpp @@ -64,6 +64,7 @@ const fs::path& getManifestPath(); fs::path getProjectBasePath(); std::optional validatePackageName(std::string_view name) noexcept; const std::string& getPackageName(); +std::string getLibraryName(); const Edition& getPackageEdition(); const Version& getPackageVersion(); const Profile& getDevProfile(); From 1bc082f49758e79acfee97698ff6494171cbafda Mon Sep 17 00:00:00 2001 From: Krist Pregracke Date: Sat, 23 Nov 2024 08:26:16 -0600 Subject: [PATCH 18/18] move libname to BuildConfig and fix formatting --- src/BuildConfig.hpp | 3 +++ src/Cmd/Build.cc | 2 +- src/Manifest.cc | 4 ---- src/Manifest.hpp | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/BuildConfig.hpp b/src/BuildConfig.hpp index 34f843e57..5f242ea51 100644 --- a/src/BuildConfig.hpp +++ b/src/BuildConfig.hpp @@ -79,6 +79,9 @@ struct BuildConfig { bool isLibrary() const { return library; } + std::string getLibName() const { + return this->libName; + } void defineVar( const std::string& name, const Variable& value, diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index 88d5d23c9..dbab3a3aa 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -69,7 +69,7 @@ buildImpl(std::string& outDir, const bool isDebug) { } if (config.isLibrary() && exitCode == 0) { - const std::string libName = getLibraryName(); + const std::string libName = config.getLibName(); exitCode = runBuildCommand(outDir, config, libName); } diff --git a/src/Manifest.cc b/src/Manifest.cc index 56a4e2aef..400031b73 100644 --- a/src/Manifest.cc +++ b/src/Manifest.cc @@ -272,10 +272,6 @@ const std::string& getPackageName() { return parsePackage().name; } -std::string -getLibraryName() { - return fmt::format("lib{}.a", getPackageName()); -} const Edition& getPackageEdition() { return parsePackage().edition; diff --git a/src/Manifest.hpp b/src/Manifest.hpp index 6f9718dc5..0de4330ad 100644 --- a/src/Manifest.hpp +++ b/src/Manifest.hpp @@ -64,7 +64,6 @@ const fs::path& getManifestPath(); fs::path getProjectBasePath(); std::optional validatePackageName(std::string_view name) noexcept; const std::string& getPackageName(); -std::string getLibraryName(); const Edition& getPackageEdition(); const Version& getPackageVersion(); const Profile& getDevProfile();