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 7e662cc56..003cafb4f 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
@@ -20,52 +20,62 @@ jobs:
compiler:
- {
cc: clang-7, cxx: clang++-7,
- pacakge: clang-7,
+ package: clang-7,
+ subpackage: lld-7,
}
- {
cc: clang-8, cxx: clang++-8,
- pacakge: clang-8,
+ package: clang-8,
+ subpackage: lld-8,
}
- {
cc: clang-9, cxx: clang++-9,
- pacakge: clang-9,
+ package: clang-9,
+ subpackage: lld-9,
}
- {
cc: clang-10, cxx: clang++-10,
- pacakge: clang-10,
+ package: clang-10,
+ subpackage: lld-10,
}
- {
cc: gcc-8, cxx: g++-8,
- pacakge: g++-8,
+ package: g++-8,
+ subpackage: binutils,
}
- {
cc: gcc-9, cxx: g++-9,
- pacakge: g++-9,
+ package: g++-9,
+ subpackage: binutils,
}
- {
cc: gcc-10, cxx: g++-10,
- pacakge: g++-10,
+ package: g++-10,
+ subpackage: binutils,
}
include:
- build_type: Coverage
compiler: {
cc: gcc-10, cxx: g++-10,
- pacakge: g++-10,
+ package: g++-10,
+ subpackage: binutils,
}
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 }} 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.pacakge }}
+ sudo apt-get install -y -qq pkg-config cmake ${{ matrix.compiler.package }} ${{ matrix.compiler.subpackage }}
- name: Restore & Cache CMake build results
- uses: actions/cache@v2.1.3
+ if: matrix.build_type != 'Coverage'
+ uses: actions/cache@v2.1.4
with:
path: build
key: ${{ env.CACHE_KEY_PREFIX }}-${{ hashFiles('CMakeLists.txt', 'cmake/*.cmake') }}
@@ -76,7 +86,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
@@ -94,7 +104,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
@@ -109,17 +119,45 @@ 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
- - name: Restore & Cache libgit2 (${{ env.LIBGIT2_VERSION }})
- uses: actions/cache@v2.1.3
- id: libgit2-cache
+ - name: Restore & Cache static libgit2 (${{ env.LIBGIT2_VERSION }})
+ uses: actions/cache@v2.1.4
+ 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
@@ -160,10 +198,10 @@ 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 }}
+ name: ${{ github.job }}-${{ matrix.compiler.package }}
path: poac
- uses: actions/setup-python@v2.2.1
diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml
index d9c839479..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:
@@ -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 }}
@@ -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') }}
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}
diff --git a/README.md b/README.md
index 4bdbda329..95093dc09 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-
![poac](https://github.com/poacpm/design/raw/master/images/logo.svg)
+![poac](https://github.com/poacpm/design/raw/main/images/logo.svg)
## Description
@@ -17,11 +17,17 @@ 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=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.
@@ -30,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)
@@ -112,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)
diff --git a/cmake/AddLibArchive.cmake b/cmake/AddLibArchive.cmake
index cef749c81..dd3561e91 100644
--- a/cmake/AddLibArchive.cmake
+++ b/cmake/AddLibArchive.cmake
@@ -11,12 +11,27 @@ endif()
find_package(LibArchive)
if (LibArchive_FOUND)
+ 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
+ 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}")
target_include_directories(${PROJECT_NAME} PRIVATE ${LibArchive_INCLUDE_DIR})
list(APPEND POAC_DEPENDENCIES ${LibArchive_LIBRARIES})
+ if (STATIC_LINK_FLAG MATCHES "(^-static )|( -static )|(^-static$)|( -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)
diff --git a/cmake/AddOpenSSL.cmake b/cmake/AddOpenSSL.cmake
index e6b145685..6b237ff65 100644
--- a/cmake/AddOpenSSL.cmake
+++ b/cmake/AddOpenSSL.cmake
@@ -12,8 +12,16 @@ endif ()
find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
+ 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})
+ endforeach()
+ set(OPENSSL_LIBRARIES ${OPENSSL_STATIC_LIBRARIES})
+ 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 15a1e90a6..70bf8cbc3 100644
--- a/cmake/ConfigRelease.cmake
+++ b/cmake/ConfigRelease.cmake
@@ -3,9 +3,19 @@ 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
- set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto") # -mtune=powerpc64le -mcpu=powerpc64le
+ 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 ()
-if (LINUX)
+if (UNIX AND NOT APPLE)
set(Boost_USE_STATIC_LIBS ON)
endif ()
diff --git a/include/poac/cmd/build.hpp b/include/poac/cmd/build.hpp
index 0def93251..981f6738e 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,24 @@
namespace poac::cmd::build {
struct Options {
- core::builder::Mode mode;
+ core::builder::mode_t mode;
};
- [[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();
+ [[nodiscard]] mitama::result
+ 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
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/cmd/init.hpp b/include/poac/cmd/init.hpp
index fd9e7c990..0823c7565 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 {
@@ -24,8 +25,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,9 +35,11 @@ namespace poac::cmd::init {
ofs_config << _new::files::poac_toml(package_name);
break;
}
+
+ using termcolor2::color_literals::operator""_bold_green;
PLOG_INFO << fmt::format(
- "{}{} `{}` package",
- "Created: "_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 c9537ecc6..415997a3c 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 {
@@ -130,8 +131,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,9 +143,10 @@ namespace poac::cmd::_new {
);
git2::repository().init(opts.package_name);
+ using termcolor2::color_literals::operator""_bold_green;
PLOG_INFO << fmt::format(
- "{}{} `{}` package",
- "Created: "_green,
+ "{:>25} {} `{}` package",
+ "Created"_bold_green,
opts.type,
opts.package_name
);
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/builder.hpp b/include/poac/core/builder/builder.hpp
index 431b352dc..9c7eeb201 100644
--- a/include/poac/core/builder/builder.hpp
+++ b/include/poac/core/builder/builder.hpp
@@ -1,52 +1,86 @@
#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
+#include
+#include
+#include
+
+// internal
+#include
+#include
+#include
+#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"(\")";
+ template
+ std::string make_definition(std::string_view key, T&& value) {
+ 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");
}
- 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());
+
+ [[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 {
@@ -179,8 +213,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/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 58368b611..beeb96de0 100644
--- a/include/poac/core/resolver.hpp
+++ b/include/poac/core/resolver.hpp
@@ -23,6 +23,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -95,9 +96,11 @@ 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 (const std::exception& e) {
+ return mitama::failure(e.what());
} catch (...) {
return mitama::failure("fetching packages failed");
}
@@ -111,9 +114,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,
+ "{:>25} {} v{}", "Downloaded"_bold_green,
resolve::get_name(package),
resolve::get_version(package)
);
@@ -156,12 +159,14 @@ 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("{:>25} packages ...", "Downloading"_bold_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,10 +191,12 @@ namespace poac::core::resolver {
} else {
return resolve::backtrack_loop(duplicate_deps);
}
- } catch (const core::except::error& e) {
- return mitama::failure(e.what());
+ } 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");
}
}
@@ -209,15 +216,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/include/poac/core/resolver/resolve.hpp b/include/poac/core/resolver/resolve.hpp
index 8db516f99..0c33e2fad 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,14 +21,18 @@
#include
#include
#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
#include
#include
#include
// internal
#include
-#include
#include
#include
#include
@@ -129,20 +134,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 +200,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 +228,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 +257,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 +285,29 @@ 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 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(
+ 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);
}
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) {
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));
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
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
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..315c97d05 100644
--- a/include/poac/util/net.hpp
+++ b/include/poac/util/net.hpp
@@ -37,7 +37,6 @@
// internal
#include
-#include
#include
#include
#include
@@ -67,13 +66,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)
);
}
@@ -268,7 +265,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 +285,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 +317,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 +426,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 +436,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 +448,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 +520,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 +533,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,14 +589,14 @@ 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) {
+ } catch (const std::exception& e) {
return mitama::failure(e.what());
} catch (...) {
return mitama::failure("unknown error caused when calling search api");
diff --git a/include/poac/util/pretty.hpp b/include/poac/util/pretty.hpp
index c991d42d0..09e2add25 100644
--- a/include/poac/util/pretty.hpp
+++ b/include/poac/util/pretty.hpp
@@ -1,69 +1,61 @@
#ifndef POAC_UTIL_PRETTY_HPP
#define POAC_UTIL_PRETTY_HPP
+// std
+#include
#include
+#include
#include
#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";
+// external
+#include
- return res;
- }
- else {
- return s + "s";
+namespace poac::util::pretty {
+ std::string to_time(const double& total_seconds) {
+ if (total_seconds <= 1.0) {
+ return fmt::format("{:.2f}s", total_seconds);
}
- }
- std::pair
- to_byte(const double b) {
- // 1024
- const double kb = b / 1000.0;
- if (kb < 1) {
- return { b, "B" };
- }
- const double mb = kb / 1000.0;
- if (mb < 1) {
- return { kb, "KB" };
+ 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 gb = mb / 1000.0;
- if (gb < 1) {
- return { mb, "MB" };
+ if (const auto hours = (total_secs / 60 / 60) % 24; hours > 0) {
+ res += std::to_string(hours) + "h ";
}
- const double tb = gb / 1000.0;
- if (tb < 1) {
- return { gb, "GB" };
+ if (const auto minutes = (total_secs / 60) % 60; minutes > 0) {
+ res += std::to_string(minutes) + "m ";
}
- return { tb, "TB" };
+ const auto seconds = total_secs % 60;
+ res += std::to_string(seconds) + "s";
+ 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"
+ };
+
+ 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/include/poac/util/termcolor2/literals_extra.hpp b/include/poac/util/termcolor2/literals_extra.hpp
new file mode 100644
index 000000000..84351de6f
--- /dev/null
+++ b/include/poac/util/termcolor2/literals_extra.hpp
@@ -0,0 +1,47 @@
+#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 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 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 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 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
+} // end namespace termcolor2
+
+#endif // !TERMCOLOR2_LITERALS_EXTRA_HPP
diff --git a/src/main.cpp b/src/main.cpp
index 3164d941b..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;
@@ -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")
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/pretty.cpp b/tests/pretty.cpp
index 4204455fc..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" );
@@ -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)
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() );
}