From cd92a51307b647bea0bb03f9b6404e3895fd3ca2 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Tue, 5 Jan 2021 03:19:10 +0900 Subject: [PATCH 01/32] Refactor core/resolver/resolve.hpp --- include/poac/core/resolver/resolve.hpp | 167 +++++++++++++------------ 1 file changed, 90 insertions(+), 77 deletions(-) diff --git a/include/poac/core/resolver/resolve.hpp b/include/poac/core/resolver/resolve.hpp index 8db516f99..ca8892095 100644 --- a/include/poac/core/resolver/resolve.hpp +++ b/include/poac/core/resolver/resolve.hpp @@ -2,6 +2,7 @@ #define POAC_CORE_RESOLVER_RESOLVE_HPP // std +#include #include #include #include @@ -20,7 +21,12 @@ #include #include #include -#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -129,20 +135,34 @@ namespace poac::core::resolver::resolve { // ¬A ∨ B ∨ ¬C // ¬A ∨ ¬B ∨ C // ¬A ∨ ¬B ∨ ¬C - void multiple_versions_cnf(const std::vector& clause, std::vector>& clauses) { - const int combinations = 1 << clause.size(); - for (int i = 0; i < combinations; ++i) { // index sequence - boost::dynamic_bitset<> bs(to_binary_numbers(i, clause.size())); - if (bs.count() == 1) { - continue; - } - - std::vector new_clause; - for (std::size_t j = 0; j < bs.size(); ++j) { - new_clause.emplace_back(bs[j] ? clause[j] * -1 : clause[j]); - } - clauses.emplace_back(new_clause); - } + std::vector> + multiple_versions_cnf(const std::vector& clause) { + return boost::irange(0, 1 << clause.size()) // number of combinations + | boost::adaptors::transformed( + [&clause](const auto& i){ + return boost::dynamic_bitset<>( + to_binary_numbers(i, clause.size()) + ); + } + ) + | boost::adaptors::filtered( + [](const boost::dynamic_bitset<>& bs){ + return bs.count() != 1; + } + ) + | boost::adaptors::transformed( + [&clause](const boost::dynamic_bitset<>& bs) -> std::vector { + return + boost::irange(std::size_t{0}, bs.size()) + | boost::adaptors::transformed( + [&clause, &bs](const auto& i){ + return bs[i] ? clause[i] * -1 : clause[i]; + } + ) + | util::meta::containerized; + } + ) + | util::meta::containerized; } std::vector> @@ -181,8 +201,7 @@ namespace poac::core::resolver::resolve { } clauses.emplace_back(clause); } - } - else if (count > 1) { + } else if (count > 1) { std::vector clause; for (auto found = first; found != last; found = std::find_if(found, last, name_lambda)) { @@ -210,7 +229,7 @@ namespace poac::core::resolver::resolve { } ++found; } - multiple_versions_cnf(clause, clauses); + boost::range::push_back(clauses, multiple_versions_cnf(clause)); } } return clauses; @@ -239,12 +258,13 @@ namespace poac::core::resolver::resolve { IF_PLOG(plog::debug) { for (const auto& c : clauses) { for (const auto& l : c) { - const auto& [package, deps] = - activated[l > 0 ? l - 1 : (l * -1) - 1]; + const auto deps = activated[std::abs(l) - 1]; PLOG_DEBUG << fmt::format( "{}-{}: {}, ", - get_name(package), get_version(package), l + get_name(get_package(deps)), + get_version(get_package(deps)), + l ); } PLOG_DEBUG << ""; @@ -266,43 +286,28 @@ namespace poac::core::resolver::resolve { // Interval to multiple versions // `>=0.1.2 and <3.4.0` -> { 2.4.0, 2.5.0 } - // `latest` -> { 2.5.0 } + // `latest` -> { 2.5.0 }: (removed) // name is boost/config, no boost-config - std::vector + [[nodiscard]] mitama::result, std::string> get_versions_satisfy_interval(const package_t& package) { // TODO: (`>1.2 and <=1.3.2` -> NG,`>1.2.0-alpha and <=1.3.2` -> OK) - const std::vector versions = - util::net::api::versions(get_name(package)).unwrap(); - if (get_interval(package) == "latest") { - return { - *std::max_element( - versions.cbegin(), - versions.cend(), - [](auto a, auto b){ - return semver::Version(a) > b; - } + // `2.0.0` specific version or `>=0.1.2 and <3.4.0` version interval + const semver::Interval i(get_interval(package)); + const auto satisfied_versions = + MITAMA_TRY(util::net::api::versions(get_name(package))) + | boost::adaptors::filtered( + [&i](std::string_view s){ return i.satisfies(s); } + ); + + if (satisfied_versions.empty()) { + return mitama::failure( + fmt::format( + "`{}: {}` not found; seem dependencies are broken", + get_name(package), get_interval(package) ) - }; - } else { // `2.0.0` specific version or `>=0.1.2 and <3.4.0` version interval - std::vector res; - semver::Interval i(get_interval(package)); - std::copy_if( - versions.cbegin(), - versions.cend(), - back_inserter(res), - [&](std::string s) { return i.satisfies(s); } ); - if (res.empty()) { - throw except::error( - fmt::format( - "`{}: {}` not found. seem dependencies are broken", - get_name(package), get_interval(package) - ) - ); - } else { - return res; - } } + return mitama::success(satisfied_versions | util::meta::containerized); } using interval_cache_t = @@ -322,6 +327,23 @@ namespace poac::core::resolver::resolve { return std::get<1>(cache); } + inline bool + exist_cache_impl(const package_t& a, const package_t& b) noexcept { + return get_name(a) == get_name(b) && + get_version(a) == get_version(b); + } + + template + inline bool + exist_cache(Range&& cache, const package_t& package) { + return util::meta::find_if( + std::forward(cache), + [&package](const auto& c) { + return exist_cache_impl(package, get_package(c)); + } + ); + } + duplicate_deps_t gather_deps_of_deps( const unique_deps_t& deps_api_res, @@ -330,25 +352,24 @@ namespace poac::core::resolver::resolve { duplicate_deps_t cur_deps_deps; for (const auto& package : deps_api_res) { // Check if node package is resolved dependency (by interval) - const auto itr = + const auto found_cache = boost::range::find_if( interval_cache, [&package](const auto& cache) { - return get_name(get_package(cache)) == get_name(package) && - get_interval(get_package(cache)) == get_interval(package); + return exist_cache_impl(package, get_package(cache)); } ); - if (itr != interval_cache.cend()) { // cache found - for (const auto& dep_version : get_versions(*itr)) { - cur_deps_deps.emplace_back(get_name(package), dep_version); - } - } else { - const auto dep_versions = get_versions_satisfy_interval(package); + + const auto dep_versions = + found_cache != interval_cache.cend() + ? get_versions(*found_cache) + : get_versions_satisfy_interval(package).unwrap(); + if (found_cache == interval_cache.cend()) { // Cache interval and versions pair interval_cache.emplace_back(package, dep_versions); - for (const auto& dep_version : dep_versions) { - cur_deps_deps.emplace_back(get_name(package), dep_version); - } + } + for (const auto& dep_version : dep_versions) { + cur_deps_deps.emplace_back(get_name(package), dep_version); } } return cur_deps_deps; @@ -362,10 +383,7 @@ namespace poac::core::resolver::resolve { // Check if root package resolved dependency // (whether the specific version is the same), // and check circulating - if (util::meta::find_if(new_deps, [&](const auto& d) { - return get_name(get_package(d)) == get_name(package) && - get_version(get_package(d)) == get_version(package); - })) { + if (exist_cache(new_deps, package)) { return; } @@ -380,7 +398,7 @@ namespace poac::core::resolver::resolve { // Store dependency and the dependency's dependencies. new_deps.emplace_back(package, deps_of_deps); - // Gather dependencies of dependencies of dependencies. lol + // Gather dependencies of dependencies of dependencies. for (const auto& dep_package : deps_of_deps) { gather_deps(dep_package, new_deps, interval_cache); } @@ -398,19 +416,14 @@ namespace poac::core::resolver::resolve { // are already resolved which includes // that package's dependencies and package's versions // by checking whether package's interval is the same. - if (util::meta::find_if( - interval_cache, - [&package](const auto& cache){ - return get_name(package) == get_name(get_package(cache)) && - get_interval(package) == get_interval(get_package(cache)); - } - )) { + if (exist_cache(interval_cache, package)) { continue; } // Get versions using interval // FIXME: versions API and deps API are received the almost same responses - const auto versions = get_versions_satisfy_interval(package); + const std::vector versions = + MITAMA_TRY(get_versions_satisfy_interval(package)); // Cache interval and versions pair interval_cache.emplace_back(package, versions); for (const auto& version : versions) { From eff1875712734d835312549fb65ed9a3c7f934e1 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Tue, 5 Jan 2021 03:46:47 +0900 Subject: [PATCH 02/32] Fix bug that failing to resolve packages --- include/poac/core/resolver/resolve.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/poac/core/resolver/resolve.hpp b/include/poac/core/resolver/resolve.hpp index ca8892095..a3291011b 100644 --- a/include/poac/core/resolver/resolve.hpp +++ b/include/poac/core/resolver/resolve.hpp @@ -293,11 +293,12 @@ namespace poac::core::resolver::resolve { // TODO: (`>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(get_interval(package)); - const auto satisfied_versions = + const std::vector satisfied_versions = MITAMA_TRY(util::net::api::versions(get_name(package))) | boost::adaptors::filtered( [&i](std::string_view s){ return i.satisfies(s); } - ); + ) + | util::meta::containerized; if (satisfied_versions.empty()) { return mitama::failure( @@ -307,7 +308,7 @@ namespace poac::core::resolver::resolve { ) ); } - return mitama::success(satisfied_versions | util::meta::containerized); + return mitama::success(satisfied_versions); } using interval_cache_t = From cd56d7bd2cb6cb719b9d7796bfbcb40e2689b5bf Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Tue, 5 Jan 2021 04:34:35 +0900 Subject: [PATCH 03/32] Remove core::except from core::resolver --- include/poac/core/resolver.hpp | 2 -- include/poac/core/resolver/resolve.hpp | 1 - 2 files changed, 3 deletions(-) diff --git a/include/poac/core/resolver.hpp b/include/poac/core/resolver.hpp index 58368b611..902f9ff1c 100644 --- a/include/poac/core/resolver.hpp +++ b/include/poac/core/resolver.hpp @@ -186,8 +186,6 @@ namespace poac::core::resolver { } else { return resolve::backtrack_loop(duplicate_deps); } - } catch (const core::except::error& e) { - return mitama::failure(e.what()); } catch (...) { return mitama::failure("resolving packages failed"); } diff --git a/include/poac/core/resolver/resolve.hpp b/include/poac/core/resolver/resolve.hpp index a3291011b..0c33e2fad 100644 --- a/include/poac/core/resolver/resolve.hpp +++ b/include/poac/core/resolver/resolve.hpp @@ -33,7 +33,6 @@ // internal #include -#include #include #include #include From 08c22cce1195a03ce2f8c4239dcd98185dea0b84 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Tue, 5 Jan 2021 06:11:40 +0900 Subject: [PATCH 04/32] Improve build command --- include/poac/cmd/build.hpp | 15 +++++----- include/poac/core/builder/builder.hpp | 43 ++++++++++----------------- include/poac/core/resolver.hpp | 7 +++-- src/main.cpp | 6 ++-- 4 files changed, 31 insertions(+), 40 deletions(-) diff --git a/include/poac/cmd/build.hpp b/include/poac/cmd/build.hpp index 0def93251..8301a37ea 100644 --- a/include/poac/cmd/build.hpp +++ b/include/poac/cmd/build.hpp @@ -2,6 +2,7 @@ #define POAC_CMD_BUILD_HPP // std +#include #include // external @@ -15,22 +16,22 @@ namespace poac::cmd::build { struct Options { - core::builder::Mode mode; + core::builder::mode_t mode; }; - [[nodiscard]] mitama::result + [[nodiscard]] mitama::result build([[maybe_unused]] Options&& opts, const toml::value& config) { - MITAMA_TRY(core::resolver::install_deps(config)); -// core::Builder bs(config.get(), opts.mode, opts.verbose); -// MITAMA_TRY(bs.build()); - return mitama::success(); + [[maybe_unused]] const auto resolved_deps = MITAMA_TRY(core::resolver::install_deps(config)); +// [[maybe_unused]] const auto output_binary = MITAMA_TRY(core::builder::build(config, opts.mode, resolved_deps)); + return mitama::success(""); } [[nodiscard]] mitama::result exec(Options&& opts) { MITAMA_TRY(core::validator::require_config_exists()); const toml::value config = toml::parse("poac.toml"); - return build(std::move(opts), config); + MITAMA_TRY(build(std::move(opts), config)); + return mitama::success(); } } // end namespace diff --git a/include/poac/core/builder/builder.hpp b/include/poac/core/builder/builder.hpp index 431b352dc..684bb7d61 100644 --- a/include/poac/core/builder/builder.hpp +++ b/include/poac/core/builder/builder.hpp @@ -1,52 +1,44 @@ #ifndef POAC_CORE_BUILDER_BUILDER_HPP #define POAC_CORE_BUILDER_BUILDER_HPP +// std #include #include #include #include #include #include +#include #include #include -//#include -//#include -//#include -//#include -//#include -//#include -//#include +// external +#include namespace poac::core::builder { - enum class Mode { - Debug, - Release, + enum class mode_t { + debug, + release, }; std::ostream& - operator<<(std::ostream& os, Mode mode) { + operator<<(std::ostream& os, mode_t mode) { switch (mode) { - case Mode::Debug: + case mode_t::debug: return (os << "dev"); - case Mode::Release: + case mode_t::release: return (os << "release"); default: throw std::logic_error( - "To access out of range of the " - "enumeration values is undefined behavior."); + "To access out of range of the " + "enumeration values is undefined behavior." + ); } } - std::string - make_definition(const std::string& first, const std::string& second) { - return "-D" + first + "=" + R"(\")" + second + R"(\")"; - } - std::string - make_definition(const std::string& first, const std::uint_fast64_t& second) { - std::ostringstream oss; - oss << second; - return make_definition(first, oss.str()); + template + std::string make_definition(std::string_view key, T&& value) { + return fmt::format("-D{}=\\\"{}\\\"", key, std::forward(value)); } // struct Builder { @@ -179,8 +171,5 @@ namespace poac::core::builder { // } // }; } // end namespace -//namespace poac::core { -// using Builder = builder::Builder; -//} #endif // POAC_CORE_BUILDER_BUILDER_HPP diff --git a/include/poac/core/resolver.hpp b/include/poac/core/resolver.hpp index 58368b611..f2eb41705 100644 --- a/include/poac/core/resolver.hpp +++ b/include/poac/core/resolver.hpp @@ -209,15 +209,16 @@ namespace poac::core::resolver { } } - [[nodiscard]] mitama::result + [[nodiscard]] mitama::result, std::string> install_deps(const toml::value& config) noexcept { if (!config.contains("dependencies")) { - return mitama::success(); + return mitama::success(resolve::unique_deps_t{}); } const toml::value deps = toml::get(config).at("dependencies"); const auto resolvable_deps = MITAMA_TRY(to_resolvable_deps(deps)); const auto resolved_deps = MITAMA_TRY(do_resolve(resolvable_deps)); - return download_deps(resolved_deps); + MITAMA_TRY(download_deps(resolved_deps)); + return mitama::success(resolved_deps); } } diff --git a/src/main.cpp b/src/main.cpp index 3164d941b..a57b311e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,17 +52,17 @@ main(const int argc, char* argv[]) { subcommand subcmd = subcommand::nothing; auto build_opts = poac::cmd::build::Options { - poac::core::builder::Mode::Debug, + poac::core::builder::mode_t::debug, }; const clipp::group build_cmd = ( clipp::command("build") .set(subcmd, subcommand::build) .doc("Compile a project and all sources that depend on its") , ( clipp::option("--debug", "-d") - .set(build_opts.mode, poac::core::builder::Mode::Debug) + .set(build_opts.mode, poac::core::builder::mode_t::debug) .doc("Build artifacts in debug mode [default]") | clipp::option("--release", "-r") - .set(build_opts.mode, poac::core::builder::Mode::Release) + .set(build_opts.mode, poac::core::builder::mode_t::release) .doc("Build artifacts in release mode, with optimizations") ) , ( clipp::option("--verbose", "-v") From 0f6176a3d8f7f09d8c8faa16e18197c69348821c Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Tue, 5 Jan 2021 05:22:36 +0900 Subject: [PATCH 05/32] Remove core::except completely --- .github/workflows/linux.yml | 1 + include/poac/config.hpp | 3 +- include/poac/core.hpp | 1 - include/poac/core/builder/standard.hpp | 188 ++++++++++++++----------- include/poac/core/except.hpp | 22 --- include/poac/core/resolver.hpp | 2 +- include/poac/util/misc.hpp | 15 +- include/poac/util/net.hpp | 60 ++++---- tests/CMakeLists.txt | 1 - tests/except.cpp | 16 --- tests/standard.cpp | 38 +++-- 11 files changed, 160 insertions(+), 187 deletions(-) delete mode 100644 include/poac/core/except.hpp delete mode 100644 tests/except.cpp diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index c09182b47..429b01516 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -65,6 +65,7 @@ jobs: sudo apt-get install -y -qq pkg-config cmake ${{ matrix.compiler.pacakge }} - name: Restore & Cache CMake build results + if: matrix.build_type != 'Coverage' uses: actions/cache@v2.1.3 with: path: build diff --git a/include/poac/config.hpp b/include/poac/config.hpp index 262ca1723..e554dd4cd 100644 --- a/include/poac/config.hpp +++ b/include/poac/config.hpp @@ -25,7 +25,8 @@ namespace poac { } // end namespace namespace poac::config::path { - inline const std::filesystem::path root(util::misc::expand_user() / std::filesystem::path(".poac")); + inline const std::filesystem::path user = util::misc::expand_user().unwrap(); + inline const std::filesystem::path root(user / ".poac"); inline const std::filesystem::path cache_dir(root / "cache"); inline const std::filesystem::path archive_dir(cache_dir / "archive"); inline const std::filesystem::path extract_dir(cache_dir / "extract"); diff --git a/include/poac/core.hpp b/include/poac/core.hpp index 51d311516..20cc5bec0 100644 --- a/include/poac/core.hpp +++ b/include/poac/core.hpp @@ -2,7 +2,6 @@ #define POAC_CORE_HPP #include -#include #include #include diff --git a/include/poac/core/builder/standard.hpp b/include/poac/core/builder/standard.hpp index 54d7b024e..f473f738e 100644 --- a/include/poac/core/builder/standard.hpp +++ b/include/poac/core/builder/standard.hpp @@ -11,9 +11,9 @@ // external #include +#include // internal -#include #include #include #include @@ -26,87 +26,93 @@ namespace poac::core::builder::standard { const std::string ANY = R"([\s\S]*)"; - std::string get_compiler_version(const std::string& compiler) { + [[nodiscard]] mitama::result + get_compiler_version(const std::string& compiler) { if (util::shell::has_command(compiler)) { if (const auto res = util::shell::cmd(compiler + " --version").stderr_to_stdout().exec()) { const std::regex SEARCH_VERSION("^" + ANY + "(" + semver::MAIN_VERSION + ")" + ANY + "$"); std::smatch match; if (std::regex_match(*res, match, SEARCH_VERSION)) { - return match[1]; + return mitama::success(match[1]); } } } - throw except::error( + return mitama::failure( fmt::format("Could not get {} version", compiler) ); } - std::string apple_llvm_convert(const std::uint_fast8_t& cpp_version, const bool& enable_gnu) { + [[nodiscard]] mitama::result + apple_llvm_convert(const std::uint_fast8_t& cpp_version, const bool& enable_gnu) noexcept { // Apple LLVMは,コンパイラバージョンによる差異がないものとする.(半ば強制的にupdateされるため) if (cpp_version == 98) { - return version_prefix(enable_gnu) + "98"; + return mitama::success(version_prefix(enable_gnu) + "98"); } else if (cpp_version == 3 || cpp_version == 11) { - return version_prefix(enable_gnu) + "11"; + return mitama::success(version_prefix(enable_gnu) + "11"); } else if (cpp_version == 14) { - return version_prefix(enable_gnu) + "14"; + return mitama::success(version_prefix(enable_gnu) + "14"); } else if (cpp_version == 17) { - return version_prefix(enable_gnu) + "17"; + return mitama::success(version_prefix(enable_gnu) + "17"); } else if (cpp_version == 20) { - throw except::error("Currently, Apple LLVM does not support C++20.\n" - "If this error is displayed in spite of C++20 is supported,\n" - " please report the issue to https://github.com/poacpm/poac/issues."); + return mitama::failure( + "Currently, Apple LLVM does not support C++20.\n" + "If this error is displayed in spite of C++20 is supported,\n" + " please report the issue to https://github.com/poacpm/poac/issues." + ); } else { - throw except::error( + return mitama::failure( fmt::format("Unknown C++ version: {}", cpp_version) ); } } - std::string gcc_convert( + [[nodiscard]] mitama::result + gcc_convert( const std::uint_fast8_t& cpp_version, const std::string& compiler_version, const bool& enable_gnu - ) { + ) noexcept { const semver::Version cv(compiler_version); if (cpp_version == 98) { - return ""; // unneeded version prefix + return mitama::success(""); // unneeded version prefix } else if (cpp_version == 3 || cpp_version == 11) { if (cv < "4.3") { - throw except::error("Invalid using C++11 less than gcc-4.3.0"); + return mitama::failure("Invalid using C++11 less than gcc-4.3.0"); } else if (cv >= "4.3" && cv < "4.7") { - return version_prefix(enable_gnu) + "0x"; + return mitama::success(version_prefix(enable_gnu) + "0x"); } else { - return version_prefix(enable_gnu) + "11"; + return mitama::success(version_prefix(enable_gnu) + "11"); } } else if (cpp_version == 14) { if (cv < "4.8") { - throw except::error("Invalid using C++14 less than gcc-4.8.0"); + return mitama::failure("Invalid using C++14 less than gcc-4.8.0"); } else if (cv >= "4.8" && cv < "4.9") { - return version_prefix(enable_gnu) + "1y"; + return mitama::success(version_prefix(enable_gnu) + "1y"); } else { - return version_prefix(enable_gnu) + "14"; + return mitama::success(version_prefix(enable_gnu) + "14"); } } else if (cpp_version == 17) { if (cv < "5") { - throw except::error("Invalid using C++17 less than gcc-5.0.0"); + return mitama::failure("Invalid using C++17 less than gcc-5.0.0"); } else { - return version_prefix(enable_gnu) + "17"; + return mitama::success(version_prefix(enable_gnu) + "17"); } } else if (cpp_version == 20) { if (cv < "8") { - throw except::error("Invalid using C++20 less than gcc-8.0.0"); + return mitama::failure("Invalid using C++20 less than gcc-8.0.0"); } else { - return version_prefix(enable_gnu) + "2a"; + return mitama::success(version_prefix(enable_gnu) + "2a"); } } else { - throw except::error( + return mitama::failure( fmt::format("Unknown C++ version: {}", cpp_version) ); } } - std::string clang_convert( + [[nodiscard]] mitama::result + clang_convert( const std::uint_fast8_t& cpp_version, const std::string& compiler_version, const bool& enable_gnu @@ -114,93 +120,99 @@ namespace poac::core::builder::standard { const semver::Version cv(compiler_version); if (cpp_version == 98) { - return ""; // unneeded version prefix + return mitama::success(""); // unneeded version prefix } else if (cpp_version == 3 || cpp_version == 11) { - return version_prefix(enable_gnu) + "11"; + return mitama::success(version_prefix(enable_gnu) + "11"); } else if (cpp_version == 14) { if (cv < "3.2") { - throw except::error("Invalid using C++14 less than clang-3.2"); + return mitama::failure("Invalid using C++14 less than clang-3.2"); } else if (cv >= "3.2" && cv < "3.5") { - return version_prefix(enable_gnu) + "1y"; + return mitama::success(version_prefix(enable_gnu) + "1y"); } else { - return version_prefix(enable_gnu) + "14"; + return mitama::success(version_prefix(enable_gnu) + "14"); } } else if (cpp_version == 17) { if (cv < "3.5.0") { - throw except::error("Invalid using C++17 less than clang-3.5.0"); + return mitama::failure("Invalid using C++17 less than clang-3.5.0"); } else if (cv >= "3.5.0" && cv < "5.0.0") { - return version_prefix(enable_gnu) + "1z"; + return mitama::success(version_prefix(enable_gnu) + "1z"); } else { - return version_prefix(enable_gnu) + "17"; + return mitama::success(version_prefix(enable_gnu) + "17"); } } else if (cpp_version == 20) { if (cv < "6.0.0") { - throw except::error("Invalid using C++20 less than clang-5.0.0"); + return mitama::failure("Invalid using C++20 less than clang-5.0.0"); } else { - return version_prefix(enable_gnu) + "2a"; + return mitama::success(version_prefix(enable_gnu) + "2a"); } } else { - throw except::error( + return mitama::failure( fmt::format("Unknown C++ version: {}", cpp_version) ); } } - std::string icc_convert(const std::uint_fast8_t& cpp_version) { + [[nodiscard]] mitama::result + icc_convert(const std::uint_fast8_t& cpp_version) noexcept { if (cpp_version == 98) { - return ""; // unneeded version prefix + return mitama::success(""); // unneeded version prefix } else if (cpp_version == 3 || cpp_version == 11) { #ifndef _WIN32 - return version_prefix(false) + "11"; + return mitama::success(version_prefix(false) + "11"); #else - return "/Qstd:c++11"; + return mitama::success("/Qstd:c++11"); #endif } else if (cpp_version == 14) { #ifndef _WIN32 - return version_prefix(false) + "14"; + return mitama::success(version_prefix(false) + "14"); #else - return "/Qstd:c++14"; + return mitama::success("/Qstd:c++14"); #endif } else if (cpp_version == 17) { #ifndef _WIN32 - return version_prefix(false) + "17"; + return mitama::success(version_prefix(false) + "17"); #else - return "/Qstd:c++17"; + return mitama::success("/Qstd:c++17"); #endif } else if (cpp_version == 20) { - throw except::error("Currently, Intel C++ Compiler does not support C++20.\n" - "If this error is displayed in spite of C++20 is supported,\n" - " please report the issue to https://github.com/poacpm/poac/issues."); + return mitama::failure( + "Currently, Intel C++ Compiler does not support C++20.\n" + "If this error is displayed in spite of C++20 is supported,\n" + " please report the issue to https://github.com/poacpm/poac/issues." + ); } else { - throw except::error( + return mitama::failure( fmt::format("Unknown C++ version: {}", cpp_version) ); } } - std::string msvc_convert(const std::uint_fast8_t& cpp_version) { + [[nodiscard]] mitama::result + msvc_convert(const std::uint_fast8_t& cpp_version) noexcept { if (cpp_version == 98 || cpp_version == 3 || cpp_version == 11) { - return ""; // unneeded version prefix + return mitama::success(""); // unneeded version prefix } else if (cpp_version == 14) { - return "/std:c++14"; + return mitama::success("/std:c++14"); } else if (cpp_version == 17) { - return "/std:c++17"; + return mitama::success("/std:c++17"); } else if (cpp_version == 20) { - throw except::error("Currently, MSVC does not support C++20.\n" - "If this error is displayed in spite of C++20 is supported,\n" - " please report the issue to https://github.com/poacpm/poac/issues."); + return mitama::failure( + "Currently, MSVC does not support C++20.\n" + "If this error is displayed in spite of C++20 is supported,\n" + " please report the issue to https://github.com/poacpm/poac/issues." + ); } else { - throw except::error( + return mitama::failure( fmt::format("Unknown C++ version: {}", cpp_version) ); } // TODO: latestを活用 } - util::cfg::compiler + [[nodiscard]] mitama::result command_to_name(std::string_view cmd) { if (cmd == "icpc") { - return util::cfg::compiler::icc; + return mitama::success(util::cfg::compiler::icc); } #ifndef _WIN32 else if (cmd == "g++" || cmd == "clang++") { @@ -210,38 +222,47 @@ namespace poac::core::builder::standard { const std::regex SEARCH("^" + ANY + "(Apple LLVM)" + ANY + "$"); std::smatch match; if (std::regex_match(*res, match, SEARCH)) { - return util::cfg::compiler::apple_clang; + return mitama::success(util::cfg::compiler::apple_clang); } } # endif if (cmd == "g++") { - return util::cfg::compiler::gcc; + return mitama::success(util::cfg::compiler::gcc); } else if (cmd == "clang++") { - return util::cfg::compiler::clang; + return mitama::success(util::cfg::compiler::clang); } } #else else if (cmd == "cl.exe") { - return util::cfg::compiler::msvc; + return mitama::success(util::cfg::compiler::msvc); } #endif - throw except::error( + return mitama::failure( fmt::format("Unknown compiler command: {}", cmd) ); } - std::string convert(const std::uint_fast8_t& cpp_version, const std::string& command, const bool& enable_gnu) { + [[nodiscard]] mitama::result + convert(const std::uint_fast8_t& cpp_version, const std::string& command, const bool& enable_gnu) { // Match a poac binary architecture and an architecture available to each compiler. - switch (command_to_name(command)) { + switch (MITAMA_TRY(command_to_name(command))) { // Support OS: macos, linux, mingw, cygwin, _WIN32 case util::cfg::compiler::icc: return icc_convert(cpp_version); // Support OS: macos, linux, mingw, cygwin (exclude _WIN32) case util::cfg::compiler::gcc: - return gcc_convert(cpp_version, get_compiler_version("g++"), enable_gnu); + return gcc_convert( + cpp_version, + MITAMA_TRY(get_compiler_version("g++")), + enable_gnu + ); // Support OS: macos, linux, mingw, cygwin (exclude _WIN32) case util::cfg::compiler::clang: - return clang_convert(cpp_version, get_compiler_version("clang++"), enable_gnu); + return clang_convert( + cpp_version, + MITAMA_TRY(get_compiler_version("clang++")), + enable_gnu + ); // Support OS: Only _WIN32 case util::cfg::compiler::msvc: return msvc_convert(cpp_version); @@ -249,33 +270,36 @@ namespace poac::core::builder::standard { case util::cfg::compiler::apple_clang: return apple_llvm_convert(cpp_version, enable_gnu); default: - throw std::logic_error( - "To access out of range of the " - "enumeration values is undefined behavior."); + return mitama::failure( + "To access out of range of the " + "enumeration values is undefined behavior." + ); } } - std::string detect_command() { + [[nodiscard]] mitama::result + detect_command() noexcept { if (const auto cxx = util::misc::dupenv("CXX")) { - return *cxx; + return mitama::success(*cxx); } else if (util::shell::has_command("icpc")) { - return "icpc"; + return mitama::success("icpc"); } #ifndef _WIN32 else if (util::shell::has_command("g++")) { - return "g++"; + return mitama::success("g++"); } else if (util::shell::has_command("clang++")) { - return "clang++"; + return mitama::success("clang++"); } #else else if (util::_shell::has_command("cl.exe")) { - return "cl.exe"; + return mitama::success("cl.exe"); } #endif else { - throw except::error( - "Environment variable \"CXX\" was not found.\n" - "Select the compiler and export it."); + return mitama::failure( + "Environment variable \"CXX\" was not found.\n" + "Select the compiler and export it." + ); } } } // end namespace diff --git a/include/poac/core/except.hpp b/include/poac/core/except.hpp deleted file mode 100644 index 3d872a281..000000000 --- a/include/poac/core/except.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef POAC_CORE_EXCEPT_HPP -#define POAC_CORE_EXCEPT_HPP - -#include -#include -#include - -namespace poac::core::except { - class error : public std::invalid_argument { - public: - explicit error(const std::string_view __s) - : invalid_argument(std::string(__s)) {} - - error() = delete; - error(const error&) = default; - error& operator=(const error&) = default; - error(error&&) = default; - error& operator=(error&&) = default; - ~error() noexcept override = default; - }; -} // end namespace -#endif // !POAC_CORE_EXCEPT_HPP diff --git a/include/poac/core/resolver.hpp b/include/poac/core/resolver.hpp index 902f9ff1c..ec47a6bfe 100644 --- a/include/poac/core/resolver.hpp +++ b/include/poac/core/resolver.hpp @@ -95,7 +95,7 @@ namespace poac::core::resolver { std::ofstream archive(archive_path); const auto [host, target] = util::net::parse_url(download_link); const util::net::requests requests{ host }; - requests.get(target, {}, std::move(archive)); + static_cast(requests.get(target, {}, std::move(archive))); return mitama::success(archive_path); } catch (...) { diff --git a/include/poac/util/misc.hpp b/include/poac/util/misc.hpp index 94c4766c4..ac2df591a 100644 --- a/include/poac/util/misc.hpp +++ b/include/poac/util/misc.hpp @@ -13,9 +13,7 @@ // external #include #include - -// internal -#include +#include namespace poac::util::misc { inline namespace path_literals { @@ -58,19 +56,18 @@ namespace poac::util::misc { // Inspired by https://stackoverflow.com/q/4891006 // Expand ~ to user home directory. - std::string expand_user() { + [[nodiscard]] mitama::result + expand_user() { auto home = dupenv("HOME"); if (home || (home = dupenv("USERPROFILE"))) { - return home.value(); + return mitama::success(home.value()); } else { const auto home_drive = dupenv("HOMEDRIVE"); const auto home_path = dupenv("HOMEPATH"); if (home_drive && home_path) { - return home_drive.value() + home_path.value(); + return mitama::success(home_drive.value() + home_path.value()); } - throw core::except::error( - "could not read environment variable" - ); + return mitama::failure("could not get home directory"); } } } // end namespace diff --git a/include/poac/util/net.hpp b/include/poac/util/net.hpp index bc21b86e7..7d1d8489a 100644 --- a/include/poac/util/net.hpp +++ b/include/poac/util/net.hpp @@ -37,7 +37,6 @@ // internal #include -#include #include #include #include @@ -268,7 +267,7 @@ namespace poac::util::net { typename ResponseBody, typename Request, typename Ofstream> - typename ResponseBody::value_type + [[nodiscard]] mitama::result request(Request&& req, Ofstream&& ofs) const { ssl_prepare(); write_request(req); @@ -288,7 +287,7 @@ namespace poac::util::net { std::ofstream>, http::vector_body, http::string_body>> - typename ResponseBody::value_type + [[nodiscard]] mitama::result get( const std::string_view target, const headers_t& headers={}, @@ -320,7 +319,7 @@ namespace poac::util::net { std::ofstream>, http::vector_body, http::string_body>> - typename ResponseBody::value_type + [[nodiscard]] mitama::result post( const std::string_view target, BodyType&& body, @@ -429,7 +428,7 @@ namespace poac::util::net { typename ResponseBody, typename Request, typename Ofstream> - typename ResponseBody::value_type + [[nodiscard]] mitama::result read_response(Request&& old_req, Ofstream&& ofs) const { // This buffer is used for reading and must be persisted boost::beast::flat_buffer buffer; @@ -439,9 +438,10 @@ namespace poac::util::net { http::read(*stream, buffer, res); // Handle HTTP status code return handle_status( - std::forward(old_req), - std::move(res), - std::forward(ofs)); + std::forward(old_req), + std::move(res), + std::forward(ofs) + ); } template < @@ -450,35 +450,33 @@ namespace poac::util::net { typename Response, typename Ofstream, typename ResponseBody = typename Response::body_type> - typename ResponseBody::value_type + [[nodiscard]] mitama::result handle_status(Request&& old_req, Response&& res, Ofstream&& ofs) const { close_stream(); switch (res.base().result_int() / 100) { case 2: - return parse_response( - std::forward(res), - std::forward(ofs)); + return mitama::success(parse_response( + std::forward(res), + std::forward(ofs) + )); case 3: return redirect( - std::forward(old_req), - std::forward(res), - std::forward(ofs)); + std::forward(old_req), + std::forward(res), + std::forward(ofs) + ); default: if constexpr (!std::is_same_v, std::ofstream>) { - throw core::except::error( - fmt::format( - "util::net received a bad response code: {}\n{}", - res.base().result_int(), res.body() - ) - ); + return mitama::failure(fmt::format( + "util::net received a bad response code: {}\n{}", + res.base().result_int(), res.body() + )); } else { - throw core::except::error( - fmt::format( - "util::net received a bad response code: {}", - res.base().result_int() - ) - ); + throw mitama::failure(fmt::format( + "util::net received a bad response code: {}", + res.base().result_int() + )); } } } @@ -524,7 +522,7 @@ namespace poac::util::net { typename Response, typename Ofstream, typename ResponseBody = typename Response::body_type> - typename ResponseBody::value_type + [[nodiscard]] mitama::result redirect(Request&& old_req, Response&& res, Ofstream&& ofs) const { const std::string new_location(res.base()["Location"]); const auto [new_host, new_target] = parse_url(new_location); @@ -537,7 +535,7 @@ namespace poac::util::net { } else if (method == http::verb::post) { return req.post(new_target, old_req.body(), {}, std::forward(ofs)); } else { // verb error - return {}; + return mitama::failure("[util::net::requests] unknown verb used"); } } @@ -593,15 +591,13 @@ namespace poac::util::net::api { headers.emplace("X-Algolia-API-Key", ALGOLIA_SEARCH_ONLY_KEY); headers.emplace("X-Algolia-Application-Id", ALGOLIA_APPLICATION_ID); - const auto response = request.post(ALGOLIA_SEARCH_INDEX_API, body, headers); + const auto response = MITAMA_TRY(request.post(ALGOLIA_SEARCH_INDEX_API, body, headers)); std::stringstream response_body; response_body << response.data(); boost::property_tree::ptree pt; boost::property_tree::json_parser::read_json(response_body, pt); return mitama::success(pt); - } catch (const core::except::error& e) { - return mitama::failure(e.what()); } catch (...) { return mitama::failure("unknown error caused when calling search api"); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 86010985a..2b0d9e905 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,5 @@ set(TEST_NAMES cfg - except meta misc net diff --git a/tests/except.cpp b/tests/except.cpp deleted file mode 100644 index 2d711debc..000000000 --- a/tests/except.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#define BOOST_TEST_MAIN -#include -#include -#include - -BOOST_AUTO_TEST_CASE( poac_core_except_error_test ) -{ - using poac::core::except::error; - - const std::string msg = "hoge"; - try { - throw error(msg); - } catch (const error& e) { - BOOST_CHECK(e.what() == msg); - } -} diff --git a/tests/standard.cpp b/tests/standard.cpp index ba0e2fdaf..93d0a5369 100644 --- a/tests/standard.cpp +++ b/tests/standard.cpp @@ -1,7 +1,6 @@ #define BOOST_TEST_MAIN #include #include -#include // inline std::string version_prefix(const bool& enable_gnu) noexcept BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_version_prefix_test ) @@ -15,7 +14,6 @@ BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_version_prefix_test ) BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_apple_llvm_convert_test ) { using poac::core::builder::standard::apple_llvm_convert; - using poac::core::except::error; BOOST_CHECK( apple_llvm_convert(98, false) == "-std=c++98" ); BOOST_CHECK( apple_llvm_convert(98, true) == "-std=gnu++98" ); @@ -32,53 +30,51 @@ BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_apple_llvm_convert_test ) BOOST_CHECK( apple_llvm_convert(17, false) == "-std=c++17" ); BOOST_CHECK( apple_llvm_convert(17, true) == "-std=gnu++17" ); - BOOST_CHECK_THROW( apple_llvm_convert(20, false), error ); - BOOST_CHECK_THROW( apple_llvm_convert(6, true), error ); + BOOST_CHECK( apple_llvm_convert(20, false).is_err() ); + BOOST_CHECK( apple_llvm_convert(6, true).is_err() ); } // std::string gcc_convert(const std::uint_fast8_t& cpp_version, const std::string& compiler_version, const bool& enable_gnu) BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_gcc_convert_test ) { using poac::core::builder::standard::gcc_convert; - using poac::core::except::error; BOOST_CHECK( gcc_convert(98, "1.0.0", false) == "" ); BOOST_CHECK( gcc_convert(98, "1.0.0", true) == "" ); - BOOST_CHECK_THROW( gcc_convert(3, "4.2", false), error ); + BOOST_CHECK( gcc_convert(3, "4.2", false).is_err() ); BOOST_CHECK( gcc_convert(3, "4.3", false) == "-std=c++0x" ); BOOST_CHECK( gcc_convert(3, "4.5", true) == "-std=gnu++0x" ); BOOST_CHECK( gcc_convert(3, "4.7", false) == "-std=c++11" ); BOOST_CHECK( gcc_convert(3, "8.0", true) == "-std=gnu++11" ); - BOOST_CHECK_THROW( gcc_convert(11, "4.2", false), error ); + BOOST_CHECK( gcc_convert(11, "4.2", false).is_err() ); BOOST_CHECK( gcc_convert(11, "4.3", false) == "-std=c++0x" ); BOOST_CHECK( gcc_convert(11, "4.5", true) == "-std=gnu++0x" ); BOOST_CHECK( gcc_convert(11, "4.7", false) == "-std=c++11" ); BOOST_CHECK( gcc_convert(11, "8.0", true) == "-std=gnu++11" ); - BOOST_CHECK_THROW( gcc_convert(14, "4.7", false), error ); + BOOST_CHECK( gcc_convert(14, "4.7", false).is_err() ); BOOST_CHECK( gcc_convert(14, "4.8", false) == "-std=c++1y" ); BOOST_CHECK( gcc_convert(14, "4.8.3", true) == "-std=gnu++1y" ); BOOST_CHECK( gcc_convert(14, "4.9", false) == "-std=c++14" ); BOOST_CHECK( gcc_convert(14, "8.0", true) == "-std=gnu++14" ); - BOOST_CHECK_THROW( gcc_convert(17, "4.9", false), error ); + BOOST_CHECK( gcc_convert(17, "4.9", false).is_err() ); BOOST_CHECK( gcc_convert(17, "5.0", false) == "-std=c++17" ); BOOST_CHECK( gcc_convert(17, "8.0", true) == "-std=gnu++17" ); - BOOST_CHECK_THROW( gcc_convert(20, "7", false), error ); + BOOST_CHECK( gcc_convert(20, "7", false).is_err() ); BOOST_CHECK( gcc_convert(20, "8.0", false) == "-std=c++2a" ); BOOST_CHECK( gcc_convert(20, "10.0", true) == "-std=gnu++2a" ); - BOOST_CHECK_THROW( gcc_convert(9, "1.0.0", false), error ); + BOOST_CHECK( gcc_convert(9, "1.0.0", false).is_err() ); } // std::string clang_convert(const std::uint_fast8_t& cpp_version, const std::string& compiler_version, const bool& enable_gnu) BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_clang_convert_test ) { using poac::core::builder::standard::clang_convert; - using poac::core::except::error; BOOST_CHECK( clang_convert(98, "1.0.0", false) == "" ); BOOST_CHECK( clang_convert(98, "1.0.0", true) == "" ); @@ -93,30 +89,29 @@ BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_clang_convert_test ) BOOST_CHECK( clang_convert(11, "7.0", false) == "-std=c++11" ); BOOST_CHECK( clang_convert(11, "7.0", true) == "-std=gnu++11" ); - BOOST_CHECK_THROW( clang_convert(14, "3.1", false), error ); + BOOST_CHECK( clang_convert(14, "3.1", false).is_err() ); BOOST_CHECK( clang_convert(14, "3.2", false) == "-std=c++1y" ); BOOST_CHECK( clang_convert(14, "3.4", true) == "-std=gnu++1y" ); BOOST_CHECK( clang_convert(14, "3.5", false) == "-std=c++14" ); BOOST_CHECK( clang_convert(14, "7.0", true) == "-std=gnu++14" ); - BOOST_CHECK_THROW( clang_convert(17, "3.4.0", false), error ); + BOOST_CHECK( clang_convert(17, "3.4.0", false).is_err() ); BOOST_CHECK( clang_convert(17, "3.5.0", false) == "-std=c++1z" ); BOOST_CHECK( clang_convert(17, "4.9.0", true) == "-std=gnu++1z" ); BOOST_CHECK( clang_convert(17, "5.0", false) == "-std=c++17" ); BOOST_CHECK( clang_convert(17, "7.0", true) == "-std=gnu++17" ); - BOOST_CHECK_THROW( clang_convert(20, "5.9.0", false), error ); + BOOST_CHECK( clang_convert(20, "5.9.0", false).is_err() ); BOOST_CHECK( clang_convert(20, "6.0", false) == "-std=c++2a" ); BOOST_CHECK( clang_convert(20, "7.0", true) == "-std=gnu++2a" ); - BOOST_CHECK_THROW( clang_convert(12, "1.0.0", false), error ); + BOOST_CHECK( clang_convert(12, "1.0.0", false).is_err() ); } // std::string icc_convert(const std::uint_fast8_t& cpp_version) BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_icc_convert_test ) { using poac::core::builder::standard::icc_convert; - using poac::core::except::error; BOOST_CHECK( icc_convert(98) == "" ); #ifndef _WIN32 @@ -130,21 +125,20 @@ BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_icc_convert_test ) BOOST_CHECK( icc_convert(14) == "/Qstd:c++14" ); BOOST_CHECK( icc_convert(17) == "/Qstd:c++17" ); #endif - BOOST_CHECK_THROW( icc_convert(20), error ); - BOOST_CHECK_THROW( icc_convert(15), error ); + BOOST_CHECK( icc_convert(20).is_err() ); + BOOST_CHECK( icc_convert(15).is_err() ); } // std::string msvc_convert(const std::uint_fast8_t& cpp_version) BOOST_AUTO_TEST_CASE( poac_core_builder_field_standard_msvc_convert_test ) { using poac::core::builder::standard::msvc_convert; - using poac::core::except::error; BOOST_CHECK( msvc_convert(98) == "" ); BOOST_CHECK( msvc_convert(3) == "" ); BOOST_CHECK( msvc_convert(11) == "" ); BOOST_CHECK( msvc_convert(14) == "/std:c++14" ); BOOST_CHECK( msvc_convert(17) == "/std:c++17" ); - BOOST_CHECK_THROW( msvc_convert(20), error ); - BOOST_CHECK_THROW( msvc_convert(18), error ); + BOOST_CHECK( msvc_convert(20).is_err() ); + BOOST_CHECK( msvc_convert(18).is_err() ); } From e61169599153df5b17972999beadac84f862db52 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Wed, 6 Jan 2021 20:35:26 +0900 Subject: [PATCH 06/32] Unify interface of new and init commands to Cargo --- include/poac/cmd/init.hpp | 4 ++-- include/poac/cmd/new.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/poac/cmd/init.hpp b/include/poac/cmd/init.hpp index fd9e7c990..62caad470 100644 --- a/include/poac/cmd/init.hpp +++ b/include/poac/cmd/init.hpp @@ -37,8 +37,8 @@ namespace poac::cmd::init { break; } PLOG_INFO << fmt::format( - "{}{} `{}` package", - "Created: "_green, + "{:>21}{} `{}` package", + "Created "_green, opts.type, package_name ); diff --git a/include/poac/cmd/new.hpp b/include/poac/cmd/new.hpp index c9537ecc6..1d9ae7fdb 100644 --- a/include/poac/cmd/new.hpp +++ b/include/poac/cmd/new.hpp @@ -145,8 +145,8 @@ namespace poac::cmd::_new { git2::repository().init(opts.package_name); PLOG_INFO << fmt::format( - "{}{} `{}` package", - "Created: "_green, + "{:>21}{} `{}` package", + "Created "_green, opts.type, opts.package_name ); From ac92aa02350c21d1e9e1b45ecea0ed287348c790 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Wed, 6 Jan 2021 20:37:20 +0900 Subject: [PATCH 07/32] Refactor cmd::init and cmd::new --- include/poac/cmd/init.hpp | 4 ++-- include/poac/cmd/new.hpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/poac/cmd/init.hpp b/include/poac/cmd/init.hpp index 62caad470..3f5ef556c 100644 --- a/include/poac/cmd/init.hpp +++ b/include/poac/cmd/init.hpp @@ -24,8 +24,6 @@ namespace poac::cmd::init { [[nodiscard]] mitama::result init(std::string_view package_name, init::Options&& opts) { - using termcolor2::color_literals::operator""_green; - PLOG_VERBOSE << "Creating ./poac.toml"; std::ofstream ofs_config("poac.toml"); switch (opts.type) { @@ -36,6 +34,8 @@ namespace poac::cmd::init { ofs_config << _new::files::poac_toml(package_name); break; } + + using termcolor2::color_literals::operator""_green; PLOG_INFO << fmt::format( "{:>21}{} `{}` package", "Created "_green, diff --git a/include/poac/cmd/new.hpp b/include/poac/cmd/new.hpp index 1d9ae7fdb..cd0847ecb 100644 --- a/include/poac/cmd/new.hpp +++ b/include/poac/cmd/new.hpp @@ -130,8 +130,6 @@ namespace poac::cmd::_new { [[nodiscard]] mitama::result _new(_new::Options&& opts) { - using termcolor2::color_literals::operator""_green; - std::ofstream ofs; for (auto&& [name, text] : create_template_files(opts)) { const std::string& file_path = (opts.package_name / name).string(); @@ -144,6 +142,7 @@ namespace poac::cmd::_new { ); git2::repository().init(opts.package_name); + using termcolor2::color_literals::operator""_green; PLOG_INFO << fmt::format( "{:>21}{} `{}` package", "Created "_green, From c459260dfa56c843c2d654278332185315f35557 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Wed, 6 Jan 2021 20:51:48 +0900 Subject: [PATCH 08/32] Create _bold_green user-defined literal --- include/poac/cmd/init.hpp | 7 ++-- include/poac/cmd/new.hpp | 7 ++-- include/poac/core/resolver.hpp | 9 ++--- .../poac/util/termcolor2/literals_extra.hpp | 35 +++++++++++++++++++ 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 include/poac/util/termcolor2/literals_extra.hpp diff --git a/include/poac/cmd/init.hpp b/include/poac/cmd/init.hpp index 3f5ef556c..db4e5361b 100644 --- a/include/poac/cmd/init.hpp +++ b/include/poac/cmd/init.hpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace poac::cmd::init { struct Options { @@ -35,10 +36,10 @@ namespace poac::cmd::init { break; } - using termcolor2::color_literals::operator""_green; + using termcolor2::color_literals::operator""_bold_green; PLOG_INFO << fmt::format( - "{:>21}{} `{}` package", - "Created "_green, + "{:>30}{} `{}` package", + "Created "_bold_green, opts.type, package_name ); diff --git a/include/poac/cmd/new.hpp b/include/poac/cmd/new.hpp index cd0847ecb..6ed393c08 100644 --- a/include/poac/cmd/new.hpp +++ b/include/poac/cmd/new.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace poac::cmd::_new { @@ -142,10 +143,10 @@ namespace poac::cmd::_new { ); git2::repository().init(opts.package_name); - using termcolor2::color_literals::operator""_green; + using termcolor2::color_literals::operator""_bold_green; PLOG_INFO << fmt::format( - "{:>21}{} `{}` package", - "Created "_green, + "{:>30}{} `{}` package", + "Created "_bold_green, opts.type, opts.package_name ); diff --git a/include/poac/core/resolver.hpp b/include/poac/core/resolver.hpp index 08267dff0..93c54175b 100644 --- a/include/poac/core/resolver.hpp +++ b/include/poac/core/resolver.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -111,9 +112,9 @@ namespace poac::core::resolver { MITAMA_TRY(util::archive::extract(installed_path, config::path::extract_dir)); MITAMA_TRY(rename_extracted_directory(package, extracted_directory_name)); - using termcolor2::color_literals::operator""_green; + using termcolor2::color_literals::operator""_bold_green; PLOG_INFO << fmt::format( - "{:>21} {} v{}", "Downloaded"_green, + "{:>30} {} v{}", "Downloaded"_bold_green, resolve::get_name(package), resolve::get_version(package) ); @@ -156,8 +157,8 @@ namespace poac::core::resolver { return mitama::success(); } - using termcolor2::color_literals::operator""_green; - PLOG_INFO << fmt::format("{:>21} packages ...", "Downloading"_green); + using termcolor2::color_literals::operator""_bold_green; + PLOG_INFO << fmt::format("{:>30} packages ...", "Downloading"_bold_green); try { std::filesystem::create_directories(config::path::cache_dir); } catch (...) { diff --git a/include/poac/util/termcolor2/literals_extra.hpp b/include/poac/util/termcolor2/literals_extra.hpp new file mode 100644 index 000000000..497d83e8e --- /dev/null +++ b/include/poac/util/termcolor2/literals_extra.hpp @@ -0,0 +1,35 @@ +#ifndef TERMCOLOR2_LITERALS_EXTRA_HPP +#define TERMCOLOR2_LITERALS_EXTRA_HPP + +#include // std::size_t +#include // std::basic_string +#include + +namespace termcolor2 { + inline namespace color_literals { + inline namespace foreground_literals { + inline std::basic_string + operator "" _bold_green(const char* str, std::size_t len) noexcept + { + return to_bold(to_green(str, len)); + } + inline std::basic_string + operator "" _bold_green(const wchar_t* str, std::size_t len) noexcept + { + return to_bold(to_green(str, len)); + } + inline std::basic_string + operator "" _bold_green(const char16_t* str, std::size_t len) noexcept + { + return to_bold(to_green(str, len)); + } + inline std::basic_string + operator "" _bold_green(const char32_t* str, std::size_t len) noexcept + { + return to_bold(to_green(str, len)); + } + } // end namespace foreground_literals + } // end namespace color_literals +} // end namespace termcolor2 + +#endif // !TERMCOLOR2_LITERALS_EXTRA_HPP From be16bf5bf1bdb4154b285fddb102ba8aaa6caa37 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Wed, 6 Jan 2021 21:03:37 +0900 Subject: [PATCH 09/32] Refactor termcolor2/literals_extra.hpp --- include/poac/cmd/init.hpp | 4 ++-- include/poac/cmd/new.hpp | 4 ++-- include/poac/core/resolver.hpp | 4 ++-- .../poac/util/termcolor2/literals_extra.hpp | 22 ++++++++++++++----- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/poac/cmd/init.hpp b/include/poac/cmd/init.hpp index db4e5361b..0823c7565 100644 --- a/include/poac/cmd/init.hpp +++ b/include/poac/cmd/init.hpp @@ -38,8 +38,8 @@ namespace poac::cmd::init { using termcolor2::color_literals::operator""_bold_green; PLOG_INFO << fmt::format( - "{:>30}{} `{}` package", - "Created "_bold_green, + "{:>25} {} `{}` package", + "Created"_bold_green, opts.type, package_name ); diff --git a/include/poac/cmd/new.hpp b/include/poac/cmd/new.hpp index 6ed393c08..415997a3c 100644 --- a/include/poac/cmd/new.hpp +++ b/include/poac/cmd/new.hpp @@ -145,8 +145,8 @@ namespace poac::cmd::_new { using termcolor2::color_literals::operator""_bold_green; PLOG_INFO << fmt::format( - "{:>30}{} `{}` package", - "Created "_bold_green, + "{:>25} {} `{}` package", + "Created"_bold_green, opts.type, opts.package_name ); diff --git a/include/poac/core/resolver.hpp b/include/poac/core/resolver.hpp index 93c54175b..caca07e58 100644 --- a/include/poac/core/resolver.hpp +++ b/include/poac/core/resolver.hpp @@ -114,7 +114,7 @@ namespace poac::core::resolver { using termcolor2::color_literals::operator""_bold_green; PLOG_INFO << fmt::format( - "{:>30} {} v{}", "Downloaded"_bold_green, + "{:>25} {} v{}", "Downloaded"_bold_green, resolve::get_name(package), resolve::get_version(package) ); @@ -158,7 +158,7 @@ namespace poac::core::resolver { } using termcolor2::color_literals::operator""_bold_green; - PLOG_INFO << fmt::format("{:>30} packages ...", "Downloading"_bold_green); + PLOG_INFO << fmt::format("{:>25} packages ...", "Downloading"_bold_green); try { std::filesystem::create_directories(config::path::cache_dir); } catch (...) { diff --git a/include/poac/util/termcolor2/literals_extra.hpp b/include/poac/util/termcolor2/literals_extra.hpp index 497d83e8e..84351de6f 100644 --- a/include/poac/util/termcolor2/literals_extra.hpp +++ b/include/poac/util/termcolor2/literals_extra.hpp @@ -3,7 +3,7 @@ #include // std::size_t #include // std::basic_string -#include +#include namespace termcolor2 { inline namespace color_literals { @@ -11,22 +11,34 @@ namespace termcolor2 { inline std::basic_string operator "" _bold_green(const char* str, std::size_t len) noexcept { - return to_bold(to_green(str, len)); + return bold_v().to_string() + + green_v().to_string() + + std::basic_string(str, len) + + reset_v().to_string(); } inline std::basic_string operator "" _bold_green(const wchar_t* str, std::size_t len) noexcept { - return to_bold(to_green(str, len)); + return bold_v().to_string() + + green_v().to_string() + + std::basic_string(str, len) + + reset_v().to_string(); } inline std::basic_string operator "" _bold_green(const char16_t* str, std::size_t len) noexcept { - return to_bold(to_green(str, len)); + return bold_v().to_string() + + green_v().to_string() + + std::basic_string(str, len) + + reset_v().to_string(); } inline std::basic_string operator "" _bold_green(const char32_t* str, std::size_t len) noexcept { - return to_bold(to_green(str, len)); + return bold_v().to_string() + + green_v().to_string() + + std::basic_string(str, len) + + reset_v().to_string(); } } // end namespace foreground_literals } // end namespace color_literals From 337d32b4d3c1afc53027b8148c14b2e060203421 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Wed, 6 Jan 2021 21:42:24 +0900 Subject: [PATCH 10/32] Remove macos-11.0 because it is broken frequently --- .github/workflows/macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index d9c839479..83526e36a 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ macos-10.15, macos-11.0 ] + os: [ macos-10.15 ] # macos-11.0 build_type: [ Debug, Release ] env: CACHE_KEY_PREFIX: ${{ matrix.os }}-${{ matrix.build_type }} From 34527e3080f935a4d413a9f3395b0874d6bd3a8e Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Thu, 7 Jan 2021 00:37:39 +0900 Subject: [PATCH 11/32] Improve util::pretty --- include/poac/util/net.hpp | 8 ++-- include/poac/util/pretty.hpp | 76 ++++++++++++++---------------------- tests/pretty.cpp | 34 ++++++---------- 3 files changed, 44 insertions(+), 74 deletions(-) diff --git a/include/poac/util/net.hpp b/include/poac/util/net.hpp index bc21b86e7..40592f589 100644 --- a/include/poac/util/net.hpp +++ b/include/poac/util/net.hpp @@ -67,13 +67,11 @@ namespace poac::util::net { if (now_count > max_count) { now_count = max_count; } - const auto [ parsed_max_byte, max_byte_unit ] = util::pretty::to_byte(max_count); - const auto [ parsed_now_byte, now_byte_unit ] = util::pretty::to_byte(now_count); return fmt::format( - FMT_STRING("{} {:.2f}{}/{:.2f}{}"), + FMT_STRING("{} {}/{}"), to_progress(max_count, now_count), - parsed_now_byte, now_byte_unit, - parsed_max_byte, max_byte_unit + util::pretty::to_byte(now_count), + util::pretty::to_byte(max_count) ); } diff --git a/include/poac/util/pretty.hpp b/include/poac/util/pretty.hpp index c991d42d0..80efcd66c 100644 --- a/include/poac/util/pretty.hpp +++ b/include/poac/util/pretty.hpp @@ -1,69 +1,53 @@ #ifndef POAC_UTIL_PRETTY_HPP #define POAC_UTIL_PRETTY_HPP +// std #include #include #include +// external +#include + namespace poac::util::pretty { std::string to_time(const std::string& s) { double total_seconds = std::stod(s); - if (total_seconds > 1.0) { - std::string res; - - const auto total_secs = static_cast(total_seconds); - const auto days = static_cast(total_secs / 60 / 60 / 24); - if (days > 0) { - res += std::to_string(days) + "d "; - } - const auto hours = static_cast((total_secs / 60 / 60) % 24); - if (hours > 0) { - res += std::to_string(hours) + "h "; - } - const auto minutes = static_cast((total_secs / 60) % 60); - if (minutes > 0) { - res += std::to_string(minutes) + "m "; - } - const auto seconds = static_cast(total_secs % 60); - res += std::to_string(seconds) + "s"; - - return res; - } - else { + if (total_seconds <= 1.0) { return s + "s"; } - } - std::pair - to_byte(const double b) { - // 1024 - const double kb = b / 1000.0; - if (kb < 1) { - return { b, "B" }; + std::string res; + const auto total_secs = static_cast(total_seconds); + if (const auto days = total_secs / 60 / 60 / 24; days > 0) { + res += std::to_string(days) + "d "; } - const double mb = kb / 1000.0; - if (mb < 1) { - return { kb, "KB" }; + if (const auto hours = (total_secs / 60 / 60) % 24; hours > 0) { + res += std::to_string(hours) + "h "; } - const double gb = mb / 1000.0; - if (gb < 1) { - return { mb, "MB" }; + if (const auto minutes = (total_secs / 60) % 60; minutes > 0) { + res += std::to_string(minutes) + "m "; } - const double tb = gb / 1000.0; - if (tb < 1) { - return { gb, "GB" }; - } - return { tb, "TB" }; + const auto seconds = total_secs % 60; + res += std::to_string(seconds) + "s"; + return res; + } + + inline const std::vector size_suffixes = { + "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" + }; + + std::string + to_byte(double bytes) { + int index = 0; + for (; bytes >= 1000.0; bytes /= 1024.0, ++index); + return fmt::format("{:.2f}{}", bytes, size_suffixes.at(index)); } // If string size is over specified number of characters and it can be clipped, // display an ellipsis (...). - std::string clip_string(const std::string& s, const std::size_t& n) { - if (s.size() <= n) { - return s; - } else { - return s.substr(0, n) + "..."; - } + inline std::string + clip_string(const std::string& s, const std::size_t& n) { + return s.size() <= n ? s : s.substr(0, n) + "..."; } } // end namespace #endif // !POAC_UTIL_PRETTY_HPP diff --git a/tests/pretty.cpp b/tests/pretty.cpp index 4204455fc..c6800fb0d 100644 --- a/tests/pretty.cpp +++ b/tests/pretty.cpp @@ -31,29 +31,17 @@ BOOST_AUTO_TEST_CASE( poac_util_pretty_to_byte_test1 ) using poac::util::pretty::to_byte; // Implicit conversion, float to int - std::pair temp = to_byte(12); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "12B" ); - temp = to_byte(1'000); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "1KB" ); - temp = to_byte(12'000); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "12KB" ); - temp = to_byte(1'000'000); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "1MB" ); - temp = to_byte(12'000'000); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "12MB" ); - temp = to_byte(1'000'000'000); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "1GB" ); - temp = to_byte(12'000'000'000); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "12GB" ); - temp = to_byte(1'000'000'000'000); - std::cout << temp.second << std::endl; - BOOST_CHECK( std::to_string(temp.first) + temp.second == "1TB" ); - temp = to_byte(12'000'000'000'000); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "12TB" ); - temp = to_byte(1'000'000'000'000'000); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "1000TB" ); - temp = to_byte(1'000'000'000'000'000'000); - BOOST_CHECK( std::to_string(temp.first) + temp.second == "1000000TB" ); + BOOST_CHECK( to_byte(12) == "12.00B" ); + BOOST_CHECK( to_byte(1'024) == "1.00KB" ); + BOOST_CHECK( to_byte(12'000) == "11.72KB" ); + BOOST_CHECK( to_byte(1'000'000) == "976.56KB" ); + BOOST_CHECK( to_byte(12'000'000) == "11.44MB" ); + BOOST_CHECK( to_byte(1'000'000'000) == "953.67MB" ); + BOOST_CHECK( to_byte(12'000'000'000) == "11.18GB" ); + BOOST_CHECK( to_byte(1'000'000'000'000) == "931.32GB" ); + BOOST_CHECK( to_byte(12'000'000'000'000) == "10.91TB" ); + BOOST_CHECK( to_byte(1'000'000'000'000'000) == "909.49TB" ); + BOOST_CHECK( to_byte(1'000'000'000'000'000'000) == "888.18PB" ); } // std::string clip_string(const std::string& s, const unsigned long& n) From efd0000e9af5341ec798d0fd6da4f8bc338727e3 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Thu, 7 Jan 2021 00:47:16 +0900 Subject: [PATCH 12/32] Refactor core::resolver::sat --- include/poac/core/resolver/sat.hpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/include/poac/core/resolver/sat.hpp b/include/poac/core/resolver/sat.hpp index d7879e8e9..3592d5592 100644 --- a/include/poac/core/resolver/sat.hpp +++ b/include/poac/core/resolver/sat.hpp @@ -160,19 +160,15 @@ namespace poac::core::resolver::sat { const int i = maximum_literal_number_index(clauses); // need to apply twice, once true, the other false for (int j = 0; j < 2; ++j) { - // copy the formula before recursing + // copy the formula before recursive circulation std::vector new_literals = literals; // if the number of literals with positive polarity are greater - if (calc_literal_polarity(clauses, i + 1) > 0) { - new_literals[i] = j; // positive - } else { - new_literals[i] = (j + 1) % 2; // negative - } + // cond ? positive : negative + new_literals[i] = calc_literal_polarity(clauses, i + 1) > 0 ? j : (j + 1) % 2; // apply the change to all the clauses - if ( - Status result = delete_set_literal(clauses, i, new_literals[i]); + if (Status result = delete_set_literal(clauses, i, new_literals[i]); result == Status::satisfied ) { return mitama::success(to_assignments(new_literals)); From 93049c4227ee2b64bfde2e78af6e32a8f8cd4569 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Thu, 7 Jan 2021 01:16:43 +0900 Subject: [PATCH 13/32] Improve usage of try/catch --- include/poac/core/resolver.hpp | 14 +++++++++++--- include/poac/util/net.hpp | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/poac/core/resolver.hpp b/include/poac/core/resolver.hpp index 09871e02b..3ef9007f1 100644 --- a/include/poac/core/resolver.hpp +++ b/include/poac/core/resolver.hpp @@ -98,6 +98,8 @@ namespace poac::core::resolver { static_cast(requests.get(target, {}, std::move(archive))); return mitama::success(archive_path); + } catch (const std::exception& e) { + return mitama::failure(e.what()); } catch (...) { return mitama::failure("fetching packages failed"); } @@ -160,8 +162,10 @@ namespace poac::core::resolver { PLOG_INFO << fmt::format("{:>21} packages ...", "Downloading"_green); try { std::filesystem::create_directories(config::path::cache_dir); - } catch (...) { - return mitama::failure("creating directories failed"); + } catch (const std::exception& e) { + return mitama::failure(fmt::format( + "creating directories failed with error:\n{}", e.what() + )); } return fetch(not_installed_deps); } @@ -186,8 +190,12 @@ namespace poac::core::resolver { } else { return resolve::backtrack_loop(duplicate_deps); } + } catch (const std::exception& e) { + return mitama::failure(fmt::format( + "resolving packages failed with error:\n{}", e.what() + )); } catch (...) { - return mitama::failure("resolving packages failed"); + return mitama::failure("resolving packages failed with unknown error"); } } diff --git a/include/poac/util/net.hpp b/include/poac/util/net.hpp index 7d1d8489a..7a26c521d 100644 --- a/include/poac/util/net.hpp +++ b/include/poac/util/net.hpp @@ -598,6 +598,8 @@ namespace poac::util::net::api { boost::property_tree::ptree pt; boost::property_tree::json_parser::read_json(response_body, pt); return mitama::success(pt); + } catch (const std::exception& e) { + return mitama::failure(e.what()); } catch (...) { return mitama::failure("unknown error caused when calling search api"); } From 905b2d5e6733d96694cb0fb9cee1201df4487dc9 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Thu, 7 Jan 2021 04:26:02 +0900 Subject: [PATCH 14/32] Unify format of util::pretty to Cargo --- include/poac/util/pretty.hpp | 2 +- tests/pretty.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/poac/util/pretty.hpp b/include/poac/util/pretty.hpp index 80efcd66c..2231c36b0 100644 --- a/include/poac/util/pretty.hpp +++ b/include/poac/util/pretty.hpp @@ -13,7 +13,7 @@ namespace poac::util::pretty { std::string to_time(const std::string& s) { double total_seconds = std::stod(s); if (total_seconds <= 1.0) { - return s + "s"; + return fmt::format("{:.2f}s", total_seconds); } std::string res; diff --git a/tests/pretty.cpp b/tests/pretty.cpp index c6800fb0d..f2234c2c2 100644 --- a/tests/pretty.cpp +++ b/tests/pretty.cpp @@ -10,7 +10,7 @@ BOOST_AUTO_TEST_CASE( poac_util_pretty_to_time_test1 ) { using poac::util::pretty::to_time; - BOOST_CHECK( to_time("0.5") == "0.5s" ); + BOOST_CHECK( to_time("0.5") == "0.50s" ); BOOST_CHECK( to_time("1.1") == "1s" ); BOOST_CHECK( to_time("60") == "1m 0s" ); BOOST_CHECK( to_time("60.1") == "1m 0s" ); From e488642bc2f89749fd901c14581deced9c2ba2e7 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Thu, 7 Jan 2021 04:27:04 +0900 Subject: [PATCH 15/32] Improve util::meta::time_to_string --- include/poac/util/meta.hpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/poac/util/meta.hpp b/include/poac/util/meta.hpp index 69af70e61..336079607 100644 --- a/include/poac/util/meta.hpp +++ b/include/poac/util/meta.hpp @@ -187,14 +187,9 @@ namespace poac::util::meta { ); } - template inline std::string - time_to_string(const std::chrono::time_point& time) { - return std::to_string( - std::chrono::duration_cast( - time.time_since_epoch() - ).count() - ); + time_to_string(const std::chrono::seconds& time) { + return std::to_string(time.count()); } // ref: https://qiita.com/rinse_/items/f00bb2a78d14c3c2f9fa From 833787a4d8e5f661975d9ae5c0f872ce2f74c59f Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Thu, 7 Jan 2021 04:29:07 +0900 Subject: [PATCH 16/32] Create util/execution_time.hpp --- include/poac/util.hpp | 1 + include/poac/util/execution_time.hpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 include/poac/util/execution_time.hpp diff --git a/include/poac/util.hpp b/include/poac/util.hpp index 6d591cada..47c98ebb6 100644 --- a/include/poac/util.hpp +++ b/include/poac/util.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/include/poac/util/execution_time.hpp b/include/poac/util/execution_time.hpp new file mode 100644 index 000000000..e44e2ee15 --- /dev/null +++ b/include/poac/util/execution_time.hpp @@ -0,0 +1,21 @@ +#ifndef POAC_UTIL_EXECUTION_TIME_HPP +#define POAC_UTIL_EXECUTION_TIME_HPP + +#include + +namespace poac::util { + class execution_time_t { + std::chrono::high_resolution_clock::time_point start; + + public: + execution_time_t() : start(std::chrono::high_resolution_clock::now()) {} + + std::chrono::seconds measure() { + return std::chrono::duration_cast( + std::chrono::high_resolution_clock::now() - start + ); + } + }; +} // end namespace + +#endif // POAC_UTIL_EXECUTION_TIME_HPP From 800193c1134b1c23c5c59d68a14fbbf2d4b923ff Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Thu, 7 Jan 2021 22:15:18 +0900 Subject: [PATCH 17/32] Create interface of build system --- include/poac/cmd/build.hpp | 10 ++++--- include/poac/core/builder/builder.hpp | 42 +++++++++++++++++++++++++++ include/poac/util/pretty.hpp | 12 ++++++-- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/include/poac/cmd/build.hpp b/include/poac/cmd/build.hpp index 8301a37ea..981f6738e 100644 --- a/include/poac/cmd/build.hpp +++ b/include/poac/cmd/build.hpp @@ -20,10 +20,12 @@ namespace poac::cmd::build { }; [[nodiscard]] mitama::result - build([[maybe_unused]] Options&& opts, const toml::value& config) { - [[maybe_unused]] const auto resolved_deps = MITAMA_TRY(core::resolver::install_deps(config)); -// [[maybe_unused]] const auto output_binary = MITAMA_TRY(core::builder::build(config, opts.mode, resolved_deps)); - return mitama::success(""); + build(Options&& opts, const toml::value& config) { + const auto resolved_deps = MITAMA_TRY(core::resolver::install_deps(config)); + const std::filesystem::path output_path = MITAMA_TRY( + core::builder::build(config, opts.mode, resolved_deps) + ); + return mitama::success(output_path); } [[nodiscard]] mitama::result diff --git a/include/poac/core/builder/builder.hpp b/include/poac/core/builder/builder.hpp index 684bb7d61..9c7eeb201 100644 --- a/include/poac/core/builder/builder.hpp +++ b/include/poac/core/builder/builder.hpp @@ -14,6 +14,15 @@ // external #include +#include +#include +#include + +// internal +#include +#include +#include +#include namespace poac::core::builder { enum class mode_t { @@ -41,6 +50,39 @@ namespace poac::core::builder { return fmt::format("-D{}=\\\"{}\\\"", key, std::forward(value)); } + using resolved_deps_t = + resolver::resolve::unique_deps_t; + + [[nodiscard]] mitama::result + build_impl(const toml::value&, const mode_t&, const resolved_deps_t&) { + return mitama::failure("build system is not implemented yet"); + } + + [[nodiscard]] mitama::result + build(const toml::value& config, const mode_t& mode, const resolved_deps_t& resolved_deps) { + using termcolor2::color_literals::operator""_bold_green; + PLOG_INFO << fmt::format( + "{:>25} {} v{} ({})", + "Compiling"_bold_green, + toml::find(config, "package", "name"), + toml::find(config, "package", "version"), + std::filesystem::current_path().string() + ); + + util::execution_time_t execution_time; + const std::filesystem::path output_path = MITAMA_TRY( + build_impl(config, mode, resolved_deps) + ); + + PLOG_INFO << fmt::format( + "{:>25} {} target(s) in {}", + "Finished"_bold_green, + mode, + util::pretty::to_time(execution_time.measure()) + ); + return mitama::success(output_path); + } + // struct Builder { // // Prohibit copy. // Builder(const Builder&) = delete; diff --git a/include/poac/util/pretty.hpp b/include/poac/util/pretty.hpp index 2231c36b0..cf66ed2b4 100644 --- a/include/poac/util/pretty.hpp +++ b/include/poac/util/pretty.hpp @@ -3,6 +3,7 @@ // std #include +#include #include #include @@ -10,8 +11,7 @@ #include namespace poac::util::pretty { - std::string to_time(const std::string& s) { - double total_seconds = std::stod(s); + std::string to_time(const double& total_seconds) { if (total_seconds <= 1.0) { return fmt::format("{:.2f}s", total_seconds); } @@ -32,6 +32,14 @@ namespace poac::util::pretty { return res; } + inline std::string to_time(const std::chrono::seconds& s) { + return to_time(s.count()); + } + + inline std::string to_time(const std::string& s) { + return to_time(std::stod(s)); + } + inline const std::vector size_suffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; From ba553a7381873f391c4d84bc81bbad6a0cc14011 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Thu, 7 Jan 2021 23:04:21 +0900 Subject: [PATCH 18/32] Refactor include/poac/util/pretty.hpp --- include/poac/util/pretty.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/poac/util/pretty.hpp b/include/poac/util/pretty.hpp index cf66ed2b4..09e2add25 100644 --- a/include/poac/util/pretty.hpp +++ b/include/poac/util/pretty.hpp @@ -2,6 +2,7 @@ #define POAC_UTIL_PRETTY_HPP // std +#include #include #include #include @@ -44,8 +45,7 @@ namespace poac::util::pretty { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; - std::string - to_byte(double bytes) { + std::string to_byte(double bytes) { int index = 0; for (; bytes >= 1000.0; bytes /= 1024.0, ++index); return fmt::format("{:.2f}{}", bytes, size_suffixes.at(index)); From 151e4e429eb3b10f197bc3200326d6a5b3d93715 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Feb 2021 05:40:59 +0000 Subject: [PATCH 19/32] Bump actions/upload-artifact from v2.2.1 to v2.2.2 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from v2.2.1 to v2.2.2. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v2.2.1...e448a9b857ee2131e752b06002bf0e093c65e571) Signed-off-by: dependabot[bot] --- .github/workflows/linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 429b01516..6828ffe6f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -161,7 +161,7 @@ jobs: working-directory: build - name: Upload pre-built binary - uses: actions/upload-artifact@v2.2.1 + uses: actions/upload-artifact@v2.2.2 if: matrix.build_type == 'Release' with: name: ${{ github.job }}-${{ matrix.compiler.pacakge }} From 2ff77e799e99a3b1f7eac0518f488e6c6647e9bd Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Sat, 13 Feb 2021 09:28:10 +0900 Subject: [PATCH 20/32] Add needed space in src/main.cpp --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a57b311e3..78cff2ef2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ no_such_command(const int& argc, char* argv[], const clipp::group& cli) { PLOG_ERROR << fmt::format( "{}: no such command: `{}`\n\n{}", error, - fmt::join(argv + 1, argv + argc," "), + fmt::join(argv + 1, argv + argc, " "), clipp::usage_lines(cli, "poac") ); return EXIT_FAILURE; From c1107041b951eaf088653a504dd9d2def39cf00c Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Sat, 13 Feb 2021 09:32:10 +0900 Subject: [PATCH 21/32] Remove Windows from supported OS temporarily --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4bdbda329..8382b205b 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,15 @@ By using poac, you can create a C++ project, build sources and execute an applic ## Supported Operating Systems -| Linux | macOS | Windows | -|:-----:|:-----:|:-------:| -|[![GitHub Actions Linux Build](https://github.com/poacpm/poac/workflows/Linux/badge.svg?branch=master)](https://github.com/poacpm/poac/actions?query=workflow%3A%22Linux%22)|[![GitHub Actions macOS Build](https://github.com/poacpm/poac/workflows/macOS/badge.svg?branch=master)](https://github.com/poacpm/poac/actions?query=workflow%3A%22macOS%22)|[![GitHub Actions Windows Build](https://github.com/poacpm/poac/workflows/Windows/badge.svg?branch=master)](https://github.com/poacpm/poac/actions?query=workflow%3A%22Windows%22)| +| Linux | macOS | +|:-----:|:-----:| +|[![GitHub Actions Linux Build](https://github.com/poacpm/poac/workflows/Linux/badge.svg?branch=master)](https://github.com/poacpm/poac/actions?query=workflow%3A%22Linux%22)|[![GitHub Actions macOS Build](https://github.com/poacpm/poac/workflows/macOS/badge.svg?branch=master)](https://github.com/poacpm/poac/actions?query=workflow%3A%22macOS%22)| + + From d2d2f4c8257942206dcb87e0cfcd9afd7e1ceafb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Mar 2021 05:46:31 +0000 Subject: [PATCH 22/32] Bump actions/cache from v2.1.3 to v2.1.4 Bumps [actions/cache](https://github.com/actions/cache) from v2.1.3 to v2.1.4. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.3...26968a09c0ea4f3e233fdddbafd1166051a095f6) Signed-off-by: dependabot[bot] --- .github/workflows/linux.yml | 8 ++++---- .github/workflows/macos.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 6828ffe6f..5199a842b 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -66,7 +66,7 @@ jobs: - name: Restore & Cache CMake build results if: matrix.build_type != 'Coverage' - uses: actions/cache@v2.1.3 + uses: actions/cache@v2.1.4 with: path: build key: ${{ env.CACHE_KEY_PREFIX }}-${{ hashFiles('CMakeLists.txt', 'cmake/*.cmake') }} @@ -77,7 +77,7 @@ jobs: - name: Restore & Cache openssl (${{ env.OPENSSL_VERSION }}) if: startsWith(matrix.compiler.cc, 'gcc') - uses: actions/cache@v2.1.3 + uses: actions/cache@v2.1.4 id: openssl-cache with: path: ${{ runner.temp }}/libs/openssl @@ -95,7 +95,7 @@ jobs: working-directory: ${{ runner.temp }} - name: Restore & Cache boost (${{ env.BOOST_VERSION }}) - uses: actions/cache@v2.1.3 + uses: actions/cache@v2.1.4 id: boost-cache with: path: ${{ runner.temp }}/libs/boost @@ -114,7 +114,7 @@ jobs: run: sudo apt-get install -y -qq libarchive-dev - name: Restore & Cache libgit2 (${{ env.LIBGIT2_VERSION }}) - uses: actions/cache@v2.1.3 + uses: actions/cache@v2.1.4 id: libgit2-cache with: path: ${{ runner.temp }}/libs/libgit2 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 83526e36a..3498de774 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -23,7 +23,7 @@ jobs: run: brew install libgit2 boost libarchive - name: Restore & Cache CMake build results - uses: actions/cache@v2.1.3 + uses: actions/cache@v2.1.4 with: path: build key: ${{ env.CACHE_KEY_PREFIX }}-${{ hashFiles('CMakeLists.txt', 'cmake/*.cmake') }} From 00651ee44fb6be0d581ec9b45c74e1032a4d0dd7 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Fri, 2 Apr 2021 05:13:55 +0900 Subject: [PATCH 23/32] Rename default branch master to main --- .githooks/pre-commit | 6 +++--- .github/disabled_workflows/linux.yml | 4 ++-- .github/workflows/linux.yml | 4 ++-- .github/workflows/macos.yml | 4 ++-- README.md | 16 ++++++++-------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 0ef40ce6e..a4acf03ba 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -21,10 +21,10 @@ allownonascii=$(git config --bool hooks.allownonascii) # Redirect output to stderr. exec 1>&2 -# Prevent committing to master branch -if test "$(git symbolic-ref HEAD | sed -e 's:^refs/heads/::')" = master; then +# Prevent committing to main branch +if test "$(git symbolic-ref HEAD | sed -e 's:^refs/heads/::')" = main; then cat <<\EOF -Error: Attempt to commit to master branch. +Error: Attempt to commit to main branch. If you want to commit new changes, you can create a new branch, checkout, and commit using: diff --git a/.github/disabled_workflows/linux.yml b/.github/disabled_workflows/linux.yml index 182d8b662..9f149cde2 100644 --- a/.github/disabled_workflows/linux.yml +++ b/.github/disabled_workflows/linux.yml @@ -2,9 +2,9 @@ name: Linux on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] env: OPENSSL_VERSION: 'OpenSSL_1_1_1h' BOOST_VERSION: 1.75.0 diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 5199a842b..738b9e3e2 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -2,9 +2,9 @@ name: Linux on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] env: OPENSSL_VERSION: 'OpenSSL_1_1_1h' BOOST_VERSION: 1.75.0 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 3498de774..08572c8ed 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -2,9 +2,9 @@ name: macOS on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] jobs: build: diff --git a/README.md b/README.md index 8382b205b..95093dc09 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -
poac
+
poac
## Description @@ -19,15 +19,15 @@ By using poac, you can create a C++ project, build sources and execute an applic | Linux | macOS | |:-----:|:-----:| -|[![GitHub Actions Linux Build](https://github.com/poacpm/poac/workflows/Linux/badge.svg?branch=master)](https://github.com/poacpm/poac/actions?query=workflow%3A%22Linux%22)|[![GitHub Actions macOS Build](https://github.com/poacpm/poac/workflows/macOS/badge.svg?branch=master)](https://github.com/poacpm/poac/actions?query=workflow%3A%22macOS%22)| +|[![GitHub Actions Linux Build](https://github.com/poacpm/poac/workflows/Linux/badge.svg?branch=main)](https://github.com/poacpm/poac/actions?query=workflow%3A%22Linux%22)|[![GitHub Actions macOS Build](https://github.com/poacpm/poac/workflows/macOS/badge.svg?branch=main)](https://github.com/poacpm/poac/actions?query=workflow%3A%22macOS%22)| - + Please see [1.1. Installation · The Poac Book](https://doc.poac.pm/en/getting-started/installation.html#supported-operating-systems) for more information about supported OS. @@ -36,13 +36,13 @@ Please see [1.1. Installation · The Poac Book](https://doc.poac.pm/en/getting-s * GitHub: [![GitHub Release Version](https://img.shields.io/github/release/poacpm/poac.svg?style=flat)](https://github.com/poacpm/poac/releases) [![Github All Releases](https://img.shields.io/github/downloads/poacpm/poac/total.svg)](https://github.com/poacpm/poac/releases) -[![GitHub License](https://img.shields.io/github/license/poacpm/poac.svg)](https://github.com/awslabs/aws-c-common/blob/master/LICENSE) +[![GitHub License](https://img.shields.io/github/license/poacpm/poac.svg)](https://github.com/awslabs/aws-c-common/blob/main/LICENSE) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fpoacpm%2Fpoac.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fpoacpm%2Fpoac?ref=badge_shield) * Code Coverage: [![Coverity Scan Build Status](https://scan.coverity.com/projects/17677/badge.svg)](https://scan.coverity.com/projects/poacpm-poac) -[![Coverage Status](https://coveralls.io/repos/github/poacpm/poac/badge.svg?branch=master)](https://coveralls.io/github/poacpm/poac?branch=master) -[![codecov](https://codecov.io/gh/poacpm/poac/branch/master/graph/badge.svg)](https://codecov.io/gh/poacpm/poac) +[![Coverage Status](https://coveralls.io/repos/github/poacpm/poac/badge.svg?branch=main)](https://coveralls.io/github/poacpm/poac?branch=main) +[![codecov](https://codecov.io/gh/poacpm/poac/branch/main/graph/badge.svg)](https://codecov.io/gh/poacpm/poac) * Code Quality: [![Codacy Badge](https://api.codacy.com/project/badge/Grade/4179a24c6e514bc0b3344f80bf64a40d)](https://app.codacy.com/app/matken11235/poac?utm_source=github.com&utm_medium=referral&utm_content=poacpm/poac&utm_campaign=Badge_Grade_Settings) @@ -118,7 +118,7 @@ You can also find the useful [architecture documentation](https://doc.poac.pm/en Poac is licensed under the terms of the Apache License version 2.0. -Please see [LICENSE](https://github.com/poacpm/poac/blob/master/LICENSE) for details. +Please see [LICENSE](https://github.com/poacpm/poac/blob/main/LICENSE) for details. [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fpoacpm%2Fpoac.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fpoacpm%2Fpoac?ref=badge_large) From 5d26a817b067d54b3cc44707f1cc508a58b8a85f Mon Sep 17 00:00:00 2001 From: I Date: Thu, 8 Apr 2021 23:25:53 +0900 Subject: [PATCH 24/32] kicking off the dirty database --- .github/workflows/linux.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 7292a8920..eddd73bad 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -61,6 +61,7 @@ jobs: - name: Install ${{ matrix.compiler.pacakge }} run: | + sudo apt-get -qq clean sudo apt-get -qq update sudo apt-get install -y -qq pkg-config cmake ${{ matrix.compiler.pacakge }} From a28cebd8342b1104e22921deb39b146c8c816edb Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Apr 2021 00:22:52 +0900 Subject: [PATCH 25/32] enable LTO by CMake manner --- cmake/ConfigRelease.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/ConfigRelease.cmake b/cmake/ConfigRelease.cmake index 15a1e90a6..2d2720609 100644 --- a/cmake/ConfigRelease.cmake +++ b/cmake/ConfigRelease.cmake @@ -4,7 +4,8 @@ if (APPLE) set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto -mtune=native -march=native") else () set(STATIC_LINK_FLAG "-static") # ref: https://stackoverflow.com/a/3801032 - set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto") # -mtune=powerpc64le -mcpu=powerpc64le + set(CMAKE_CXX_FLAGS_RELEASE "-O3") # -mtune=powerpc64le -mcpu=powerpc64le + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) endif () if (LINUX) set(Boost_USE_STATIC_LIBS ON) From e604d86876d3c1612ff3c4a1b7bd5bdff2088e7e Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Apr 2021 01:51:05 +0900 Subject: [PATCH 26/32] workaround for static link --- cmake/AddLibArchive.cmake | 11 +++++++++++ cmake/AddOpenSSL.cmake | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/cmake/AddLibArchive.cmake b/cmake/AddLibArchive.cmake index cef749c81..0b875107f 100644 --- a/cmake/AddLibArchive.cmake +++ b/cmake/AddLibArchive.cmake @@ -11,6 +11,17 @@ endif() find_package(LibArchive) if (LibArchive_FOUND) + if (STATIC_LINK_FLAG STREQUAL "-static" AND NOT APPLE AND ${LibArchive_LIBRARIES} MATCHES ".*\.so$") + unset(LibArchive_LIBRARIES) + unset(LibArchive_LIBRARY CACHE) + find_library(LibArchive_LIBRARY + NAMES libarchive.a) + mark_as_advanced(LibArchive_LIBRARY) + set(LibArchive_LIBRARIES ${LibArchive_LIBRARY}) + set_target_properties(LibArchive::LibArchive PROPERTIES + IMPORTED_LOCATION "${LibArchive_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LibArchive_INCLUDE_DIR}") + endif () message(CHECK_PASS "added") message(STATUS "LibArchive include directory is ... ${LibArchive_INCLUDE_DIR}") message(STATUS "LibArchive library is ... ${LibArchive_LIBRARIES}") diff --git a/cmake/AddOpenSSL.cmake b/cmake/AddOpenSSL.cmake index e6b145685..0c156d1cf 100644 --- a/cmake/AddOpenSSL.cmake +++ b/cmake/AddOpenSSL.cmake @@ -12,6 +12,14 @@ endif () find_package(OpenSSL REQUIRED) if (OPENSSL_FOUND) + if (STATIC_LINK_FLAG STREQUAL "-static" AND NOT APPLE) + foreach(x IN LISTS OPENSSL_LIBRARIES) + string(REGEX REPLACE "[.]so" ".a" x ${x}) + list(APPEND OPENSSL_STATIC_LIBRARIES ${x}) + endforeach() + set(OPENSSL_LIBRARIES ${OPENSSL_STATIC_LIBRARIES}) + unset(OPENSSL_STATIC_LIBRARIES) + endif () message(CHECK_PASS "added") if (LINUX) list(APPEND OPENSSL_LIBRARIES ssl crypto dl) From 0ef44ef9afc8d61877b22022951e743992dd9c2f Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Apr 2021 02:16:08 +0900 Subject: [PATCH 27/32] static link needs static libraries --- .github/workflows/linux.yml | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index eddd73bad..eb7ba8a53 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -114,14 +114,39 @@ jobs: - name: Install libarchive run: sudo apt-get install -y -qq libarchive-dev - - name: Restore & Cache libgit2 (${{ env.LIBGIT2_VERSION }}) + - name: Restore & Cache static libgit2 (${{ env.LIBGIT2_VERSION }}) uses: actions/cache@v2.1.4 - id: libgit2-cache + if: matrix.build_type == 'Release' + id: libgit2-static-cache + with: + path: ${{ runner.temp }}/libs/libgit2 + key: ${{ env.CACHE_KEY_PREFIX }}-libgit2-static-${{ env.LIBGIT2_VERSION }} + - name: Install libgit2 (${{ env.LIBGIT2_VERSION }}) as static + if: steps.libgit2-cache.outputs.cache-hit != 'true' && matrix.build_type == 'Release' + run: | + mkdir -p ${{ runner.temp }}/libs/libgit2 + git clone -q -b v${{ env.LIBGIT2_VERSION }} https://github.com/libgit2/libgit2.git + mkdir libgit2/build && cd libgit2/build + cmake .. \ + -DCMAKE_INSTALL_PREFIX=${{ runner.temp }}/libs/libgit2 \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_CLAR=OFF \ + -DCMAKE_C_FLAGS=-fPIC \ + -DREGEX_BACKEND=builtin + make + sudo make install + working-directory: ${{ runner.temp }} + + - name: Restore & Cache shared libgit2 (${{ env.LIBGIT2_VERSION }}) + uses: actions/cache@v2.1.4 + if: matrix.build_type != 'Release' + id: libgit2-shared-cache with: path: ${{ runner.temp }}/libs/libgit2 - key: ${{ env.CACHE_KEY_PREFIX }}-libgit2-${{ env.LIBGIT2_VERSION }} + key: ${{ env.CACHE_KEY_PREFIX }}-libgit2-shared-${{ env.LIBGIT2_VERSION }} - name: Install libgit2 (${{ env.LIBGIT2_VERSION }}) as shared - if: steps.libgit2-cache.outputs.cache-hit != 'true' + if: steps.libgit2-cache.outputs.cache-hit != 'true' && matrix.build_type != 'Release' run: | mkdir -p ${{ runner.temp }}/libs/libgit2 git clone -q -b v${{ env.LIBGIT2_VERSION }} https://github.com/libgit2/libgit2.git From fe19eeff930aa474822d43b7e082f8d4c5e52149 Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Apr 2021 03:38:00 +0900 Subject: [PATCH 28/32] add dependencies --- .github/workflows/linux.yml | 3 +++ cmake/AddLibArchive.cmake | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index eb7ba8a53..b7ccf367f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -111,6 +111,9 @@ jobs: sudo ./b2 link=static install -j2 --prefix=${{ runner.temp }}/libs/boost || exit 0 working-directory: ${{ runner.temp }} + - name: Install libacl + run: sudo apt-get install -y -qq libacl1-dev + - name: Install libarchive run: sudo apt-get install -y -qq libarchive-dev diff --git a/cmake/AddLibArchive.cmake b/cmake/AddLibArchive.cmake index 0b875107f..2012b37d9 100644 --- a/cmake/AddLibArchive.cmake +++ b/cmake/AddLibArchive.cmake @@ -28,6 +28,10 @@ if (LibArchive_FOUND) target_include_directories(${PROJECT_NAME} PRIVATE ${LibArchive_INCLUDE_DIR}) list(APPEND POAC_DEPENDENCIES ${LibArchive_LIBRARIES}) + if (STATIC_LINK_FLAG STREQUAL "-static" AND NOT APPLE) + list(APPEND POAC_DEPENDENCIES acl) + list(APPEND POAC_DEPENDENCIES z) + endif () else () message(CHECK_FAIL "not found") list(APPEND missingDependencies libarchive) From cb392fccacb3b3287a56ecfc4149697de56404fe Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Apr 2021 03:42:44 +0900 Subject: [PATCH 29/32] link libstdc++fs explicitly for old libstdc++ --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a08c0b5c..04cc52c86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,9 @@ target_include_directories(${PROJECT_NAME} PUBLIC include(cmake/PoacConfig.cmake) include(cmake/AddPoacDependencies.cmake) +if (NOT APPLE AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + list(APPEND POAC_DEPENDENCIES "-lstdc++fs") +endif () target_link_libraries( ${PROJECT_NAME} ${STATIC_LINK_FLAG} From 471ddceb755017fa09162d9d74b3e983e0aa9e1b Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Apr 2021 05:22:37 +0900 Subject: [PATCH 30/32] LINUX is not defined on default CMake --- cmake/AddOpenSSL.cmake | 2 +- cmake/ConfigRelease.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/AddOpenSSL.cmake b/cmake/AddOpenSSL.cmake index 0c156d1cf..7b1d7769a 100644 --- a/cmake/AddOpenSSL.cmake +++ b/cmake/AddOpenSSL.cmake @@ -21,7 +21,7 @@ if (OPENSSL_FOUND) unset(OPENSSL_STATIC_LIBRARIES) endif () message(CHECK_PASS "added") - if (LINUX) + if (UNIX AND NOT APPLE) list(APPEND OPENSSL_LIBRARIES ssl crypto dl) elseif (APPLE) list(APPEND OPENSSL_LIBRARIES dl) diff --git a/cmake/ConfigRelease.cmake b/cmake/ConfigRelease.cmake index 2d2720609..d43a11220 100644 --- a/cmake/ConfigRelease.cmake +++ b/cmake/ConfigRelease.cmake @@ -7,6 +7,6 @@ else () set(CMAKE_CXX_FLAGS_RELEASE "-O3") # -mtune=powerpc64le -mcpu=powerpc64le set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) endif () -if (LINUX) +if (UNIX AND NOT APPLE) set(Boost_USE_STATIC_LIBS ON) endif () From e679362f9c85589b7899bb5efa7f8a949afde73b Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Apr 2021 05:48:13 +0900 Subject: [PATCH 31/32] fix typo --- .github/workflows/linux.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index b7ccf367f..a3567f15e 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -20,50 +20,50 @@ jobs: compiler: - { cc: clang-7, cxx: clang++-7, - pacakge: clang-7, + package: clang-7, } - { cc: clang-8, cxx: clang++-8, - pacakge: clang-8, + package: clang-8, } - { cc: clang-9, cxx: clang++-9, - pacakge: clang-9, + package: clang-9, } - { cc: clang-10, cxx: clang++-10, - pacakge: clang-10, + package: clang-10, } - { cc: gcc-8, cxx: g++-8, - pacakge: g++-8, + package: g++-8, } - { cc: gcc-9, cxx: g++-9, - pacakge: g++-9, + package: g++-9, } - { cc: gcc-10, cxx: g++-10, - pacakge: g++-10, + package: g++-10, } include: - build_type: Coverage compiler: { cc: gcc-10, cxx: g++-10, - pacakge: g++-10, + package: g++-10, } env: CC: ${{ matrix.compiler.cc }} CXX: ${{ matrix.compiler.cxx }} - CACHE_KEY_PREFIX: ${{ github.job }}-${{ matrix.compiler.pacakge }}-${{ matrix.build_type }} + CACHE_KEY_PREFIX: ${{ github.job }}-${{ matrix.compiler.package }}-${{ matrix.build_type }} steps: - uses: actions/checkout@v2.3.4 - - name: Install ${{ matrix.compiler.pacakge }} + - name: Install ${{ matrix.compiler.package }} run: | sudo apt-get -qq clean sudo apt-get -qq update - sudo apt-get install -y -qq pkg-config cmake ${{ matrix.compiler.pacakge }} + sudo apt-get install -y -qq pkg-config cmake ${{ matrix.compiler.package }} - name: Restore & Cache CMake build results if: matrix.build_type != 'Coverage' @@ -193,7 +193,7 @@ jobs: uses: actions/upload-artifact@v2.2.2 if: matrix.build_type == 'Release' with: - name: ${{ github.job }}-${{ matrix.compiler.pacakge }} + name: ${{ github.job }}-${{ matrix.compiler.package }} path: poac - uses: actions/setup-python@v2.2.1 From 69958135aaa8fd853bb6f7a739ebc39a712db407 Mon Sep 17 00:00:00 2001 From: I Date: Fri, 9 Apr 2021 05:51:40 +0900 Subject: [PATCH 32/32] install lld and use it for ThinLTO --- .github/workflows/linux.yml | 12 ++++++++++-- cmake/AddLibArchive.cmake | 4 ++-- cmake/AddOpenSSL.cmake | 2 +- cmake/ConfigRelease.cmake | 11 ++++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index a3567f15e..003cafb4f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -21,36 +21,44 @@ jobs: - { cc: clang-7, cxx: clang++-7, package: clang-7, + subpackage: lld-7, } - { cc: clang-8, cxx: clang++-8, package: clang-8, + subpackage: lld-8, } - { cc: clang-9, cxx: clang++-9, package: clang-9, + subpackage: lld-9, } - { cc: clang-10, cxx: clang++-10, package: clang-10, + subpackage: lld-10, } - { cc: gcc-8, cxx: g++-8, package: g++-8, + subpackage: binutils, } - { cc: gcc-9, cxx: g++-9, package: g++-9, + subpackage: binutils, } - { cc: gcc-10, cxx: g++-10, package: g++-10, + subpackage: binutils, } include: - build_type: Coverage compiler: { cc: gcc-10, cxx: g++-10, package: g++-10, + subpackage: binutils, } env: CC: ${{ matrix.compiler.cc }} @@ -59,11 +67,11 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - - name: Install ${{ matrix.compiler.package }} + - name: Install ${{ matrix.compiler.package }} and ${{ matrix.compiler.subpackage }} run: | sudo apt-get -qq clean sudo apt-get -qq update - sudo apt-get install -y -qq pkg-config cmake ${{ matrix.compiler.package }} + sudo apt-get install -y -qq pkg-config cmake ${{ matrix.compiler.package }} ${{ matrix.compiler.subpackage }} - name: Restore & Cache CMake build results if: matrix.build_type != 'Coverage' diff --git a/cmake/AddLibArchive.cmake b/cmake/AddLibArchive.cmake index 2012b37d9..dd3561e91 100644 --- a/cmake/AddLibArchive.cmake +++ b/cmake/AddLibArchive.cmake @@ -11,7 +11,7 @@ endif() find_package(LibArchive) if (LibArchive_FOUND) - if (STATIC_LINK_FLAG STREQUAL "-static" AND NOT APPLE AND ${LibArchive_LIBRARIES} MATCHES ".*\.so$") + if (STATIC_LINK_FLAG MATCHES "(^-static )|( -static )|(^-static$)|( -static$)" AND NOT APPLE AND ${LibArchive_LIBRARIES} MATCHES ".*\.so$") unset(LibArchive_LIBRARIES) unset(LibArchive_LIBRARY CACHE) find_library(LibArchive_LIBRARY @@ -28,7 +28,7 @@ if (LibArchive_FOUND) target_include_directories(${PROJECT_NAME} PRIVATE ${LibArchive_INCLUDE_DIR}) list(APPEND POAC_DEPENDENCIES ${LibArchive_LIBRARIES}) - if (STATIC_LINK_FLAG STREQUAL "-static" AND NOT APPLE) + if (STATIC_LINK_FLAG MATCHES "(^-static )|( -static )|(^-static$)|( -static$)" AND NOT APPLE) list(APPEND POAC_DEPENDENCIES acl) list(APPEND POAC_DEPENDENCIES z) endif () diff --git a/cmake/AddOpenSSL.cmake b/cmake/AddOpenSSL.cmake index 7b1d7769a..6b237ff65 100644 --- a/cmake/AddOpenSSL.cmake +++ b/cmake/AddOpenSSL.cmake @@ -12,7 +12,7 @@ endif () find_package(OpenSSL REQUIRED) if (OPENSSL_FOUND) - if (STATIC_LINK_FLAG STREQUAL "-static" AND NOT APPLE) + if (STATIC_LINK_FLAG MATCHES "(^-static )|( -static )|(^-static$)|( -static$)" AND NOT APPLE) foreach(x IN LISTS OPENSSL_LIBRARIES) string(REGEX REPLACE "[.]so" ".a" x ${x}) list(APPEND OPENSSL_STATIC_LIBRARIES ${x}) diff --git a/cmake/ConfigRelease.cmake b/cmake/ConfigRelease.cmake index d43a11220..70bf8cbc3 100644 --- a/cmake/ConfigRelease.cmake +++ b/cmake/ConfigRelease.cmake @@ -3,7 +3,16 @@ include_guard(GLOBAL) if (APPLE) set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto -mtune=native -march=native") else () - set(STATIC_LINK_FLAG "-static") # ref: https://stackoverflow.com/a/3801032 + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if (${CMAKE_CXX_COMPILER} MATCHES "-[0-9]+$") + string(REGEX REPLACE [[.*clang\+\+(-[0-9]+)$]] [[lld\1]] LD ${CMAKE_CXX_COMPILER}) + set(STATIC_LINK_FLAG "-static -fuse-ld=${LD}") + else () + set(STATIC_LINK_FLAG "-static -fuse-ld=lld") + endif () + else () + set(STATIC_LINK_FLAG "-static") # ref: https://stackoverflow.com/a/3801032 + endif () set(CMAKE_CXX_FLAGS_RELEASE "-O3") # -mtune=powerpc64le -mcpu=powerpc64le set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) endif ()