Skip to content

Commit ee2664b

Browse files
author
xwei19
committed
Make task build:all runnable
1 parent 8243ff7 commit ee2664b

10 files changed

Lines changed: 208 additions & 75 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ if(BUILD_TESTING AND YSTDLIB_CPP_BUILD_TESTING)
5353
set(YSTDLIB_CPP_ENABLE_TESTS ON)
5454
endif()
5555

56-
find_package(outcome REQUIRED)
57-
if(outcome_FOUND)
58-
message(STATUS "Found outcome.")
59-
else()
60-
message(FATAL_ERROR "Could not find libraries for outcome.")
61-
endif()
62-
6356
if(YSTDLIB_CPP_ENABLE_TESTS)
6457
find_package(Catch2 3.8.0 REQUIRED)
6558
if(Catch2_FOUND)

src/ystdlib/error_handling/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ cpp_library(
66
TraceableException.hpp
77
Result.hpp
88
utils.hpp
9-
PUBLIC_LINK_LIBRARIES
10-
outcome::hl
119
TESTS_SOURCES
1210
test/constants.hpp
1311
test/test_ErrorCode.cpp

src/ystdlib/error_handling/Result.hpp

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
#include <system_error>
55

6-
#include <outcome/config.hpp>
7-
#include <outcome/std_result.hpp>
8-
#include <outcome/success_failure.hpp>
9-
#include <outcome/try.hpp>
6+
#include <boost/outcome/config.hpp>
7+
#include <boost/outcome/std_result.hpp>
8+
#include <boost/outcome/success_failure.hpp>
9+
#include <boost/outcome/try.hpp>
1010

1111
namespace ystdlib::error_handling {
1212
/**
@@ -20,34 +20,16 @@ namespace ystdlib::error_handling {
2020
* @tparam ErrorType The type used to represent errors.
2121
*/
2222
template <typename ReturnType, typename ErrorType = std::error_code>
23-
using Result = OUTCOME_V2_NAMESPACE::std_result<ReturnType, ErrorType>;
23+
using Result = BOOST_OUTCOME_V2_NAMESPACE::std_result<ReturnType, ErrorType>;
2424

2525
/**
2626
* @return A value indicating successful completion of a function that returns a void result (i.e.,
2727
* `Result<void, E>`).
2828
*/
29-
[[nodiscard]] inline auto success() -> OUTCOME_V2_NAMESPACE::success_type<void> {
30-
return OUTCOME_V2_NAMESPACE::success();
29+
[[nodiscard]] inline auto success() -> BOOST_OUTCOME_V2_NAMESPACE::success_type<void> {
30+
return BOOST_OUTCOME_V2_NAMESPACE::success();
3131
}
3232

33-
/**
34-
* A function-style macro that emulates Rust’s try (`?`) operator for error propagation.
35-
*
36-
* @param expr An expression that evaluates to a `Result` object.
37-
*
38-
* Behavior:
39-
* - If `expr` represents an error (i.e., `expr.has_error()` returns true), the macro performs an
40-
* early return from the enclosing function with the contained error.
41-
* - Otherwise, it unwraps and yields the successful value as an rvalue reference (`expr.value()`).
42-
*
43-
* NOTE: This macro is only supported on GCC and Clang due to reliance on compiler-specific
44-
* extensions.
45-
*/
46-
#ifdef OUTCOME_TRYX
47-
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
48-
#define YSTDLIB_ERROR_HANDLING_TRYX(expr) OUTCOME_TRYX(expr)
49-
#endif
50-
5133
/**
5234
* A function-style macro for propagating errors from expressions that evaluate to a void result
5335
* (`Result<void, E>`).
@@ -60,7 +42,7 @@ using Result = OUTCOME_V2_NAMESPACE::std_result<ReturnType, ErrorType>;
6042
* - Otherwise, execution continues normally.
6143
*/
6244
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
63-
#define YSTDLIB_ERROR_HANDLING_TRYV(expr) OUTCOME_TRYV(expr)
45+
#define YSTDLIB_ERROR_HANDLING_TRY(expr) BOOST_OUTCOME_TRY(expr)
6446
} // namespace ystdlib::error_handling
6547

6648
#endif // YSTDLIB_ERROR_HANDLING_RESULT_HPP

src/ystdlib/error_handling/test/test_Result.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TEST_CASE("test_result_void", "[error_handling][Result]") {
5050

5151
TEST_CASE("test_result_void_in_main", "[error_handling][Result]") {
5252
auto main_func = [&](bool is_error) -> Result<void> {
53-
YSTDLIB_ERROR_HANDLING_TRYV(cVoidFunc(is_error));
53+
YSTDLIB_ERROR_HANDLING_TRY(cVoidFunc(is_error));
5454
return success();
5555
};
5656
auto const main_no_error{main_func(false)};
@@ -74,7 +74,7 @@ TEST_CASE("test_result_int", "[error_handling][Result]") {
7474

7575
TEST_CASE("test_result_int_in_main", "[error_handling][Result]") {
7676
auto main_func = [&](bool is_error) -> Result<void> {
77-
YSTDLIB_ERROR_HANDLING_TRYV(cIntFunc(is_error));
77+
YSTDLIB_ERROR_HANDLING_TRY(cIntFunc(is_error));
7878
return success();
7979
};
8080
auto const main_no_error{main_func(false)};
@@ -88,7 +88,8 @@ TEST_CASE("test_result_int_in_main", "[error_handling][Result]") {
8888

8989
TEST_CASE("test_result_int_propagate", "[error_handling][Result]") {
9090
auto main_func = [&](bool is_error) -> Result<int> {
91-
return YSTDLIB_ERROR_HANDLING_TRYX(cIntFunc(is_error));
91+
YSTDLIB_ERROR_HANDLING_TRY(cIntFunc(is_error));
92+
return success();
9293
};
9394
auto const main_no_error{main_func(false)};
9495
REQUIRE_FALSE(main_no_error.has_error());
@@ -112,7 +113,7 @@ TEST_CASE("test_result_unique_ptr", "[error_handling][Result]") {
112113

113114
TEST_CASE("test_result_unique_ptr_in_main", "[error_handling][Result]") {
114115
auto main_func = [&](bool is_error) -> Result<void> {
115-
YSTDLIB_ERROR_HANDLING_TRYV(cUniquePtrFunc(is_error));
116+
YSTDLIB_ERROR_HANDLING_TRY(cUniquePtrFunc(is_error));
116117
return success();
117118
};
118119
auto const main_no_error{main_func(false)};
@@ -126,7 +127,8 @@ TEST_CASE("test_result_unique_ptr_in_main", "[error_handling][Result]") {
126127

127128
TEST_CASE("test_result_unique_ptr_propagate", "[error_handling][Result]") {
128129
auto main_func = [&](bool is_error) -> Result<std::unique_ptr<int>> {
129-
return YSTDLIB_ERROR_HANDLING_TRYX(cUniquePtrFunc(is_error));
130+
YSTDLIB_ERROR_HANDLING_TRY(cUniquePtrFunc(is_error));
131+
return success();
130132
};
131133
auto const main_no_error{main_func(false)};
132134
REQUIRE_FALSE(main_no_error.has_error());

taskfile.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ includes:
44
build: "./taskfiles/build.yaml"
55
deps: "./taskfiles/deps.yaml"
66
lint: "./taskfiles/lint.yaml"
7-
utils: "tools/yscope-dev-utils/taskfiles/utils.yaml"
7+
utils: "tools/yscope-dev-utils/exports/taskfiles/utils/utils.yaml"
88

99
vars:
1010
G_BUILD_DIR: "{{.ROOT_DIR}}/build"

taskfiles/build.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ tasks:
1010
deps:
1111
- "init"
1212
cmds:
13-
- task: ":utils:cmake-build"
13+
- task: ":utils:cmake:build"
1414
vars:
1515
BUILD_DIR: "{{.G_BUILD_DIR}}"
1616

@@ -21,7 +21,7 @@ tasks:
2121
deps:
2222
- "init"
2323
cmds:
24-
- task: ":utils:cmake-build"
24+
- task: ":utils:cmake:build"
2525
vars:
2626
BUILD_DIR: "{{.G_BUILD_DIR}}"
2727
TARGETS:
@@ -49,7 +49,7 @@ tasks:
4949
clean:
5050
desc: "Removes all built artifacts."
5151
deps:
52-
- task: ":utils:cmake-clean"
52+
- task: ":utils:cmake:clean"
5353
vars:
5454
BUILD_DIR: "{{.G_BUILD_DIR}}"
5555

@@ -59,7 +59,7 @@ tasks:
5959
- ":deps:install-all"
6060
run: "once"
6161
cmds:
62-
- task: ":utils:cmake-generate"
62+
- task: ":utils:cmake:generate"
6363
vars:
6464
BUILD_DIR: "{{.G_BUILD_DIR}}"
6565
SOURCE_DIR: "{{.ROOT_DIR}}"

taskfiles/deps.yaml

Lines changed: 163 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ version: "3"
33
vars:
44
G_CATCH2_LIB_NAME: "Catch2"
55
G_CATCH2_WORK_DIR: "{{.G_DEPS_DIR}}/{{.G_CATCH2_LIB_NAME}}"
6-
G_OUTCOME_LIB_NAME: "outcome"
7-
G_OUTCOME_WORK_DIR: "{{.G_DEPS_DIR}}/{{.G_OUTCOME_LIB_NAME}}"
86
G_QUICKCPPLIB_LIB_NAME: "quickcpplib"
97
G_QUICKCPPLIB_WORK_DIR: "{{.G_DEPS_DIR}}/{{.G_QUICKCPPLIB_LIB_NAME}}"
108

@@ -26,8 +24,8 @@ tasks:
2624
install-all-run:
2725
internal: true
2826
deps:
27+
- "install-boost"
2928
- "install-Catch2"
30-
- "install-outcome"
3129

3230
install-all-finish:
3331
internal: true
@@ -58,12 +56,12 @@ tasks:
5856
internal: true
5957
run: "once"
6058
cmds:
61-
- task: ":utils:cmake-install-remote-tar"
59+
- task: ":utils:cmake:install-remote-tar"
6260
vars:
63-
NAME: "{{.G_CATCH2_LIB_NAME}}"
61+
CMAKE_PACKAGE_NAME: "{{.G_CATCH2_LIB_NAME}}"
6462
WORK_DIR: "{{.G_CATCH2_WORK_DIR}}"
65-
FILE_SHA256: "1ab2de20460d4641553addfdfe6acd4109d871d5531f8f519a52ea4926303087"
66-
URL: "https://github.com/catchorg/Catch2/archive/refs/tags/v3.8.0.tar.gz"
63+
TAR_SHA256: "1ab2de20460d4641553addfdfe6acd4109d871d5531f8f519a52ea4926303087"
64+
TAR_URL: "https://github.com/catchorg/Catch2/archive/refs/tags/v3.8.0.tar.gz"
6765
- task: "add-package-root-to-cmake-settings"
6866
vars:
6967
NAME: "{{.G_CATCH2_LIB_NAME}}"
@@ -86,5 +84,162 @@ tasks:
8684
- "process"
8785
- "program_options"
8886
- "regex"
89-
- "system"
87+
- "system"
88+
89+
# Runs the bootstrap.sh generate step in the given source directory. Boost only supports
90+
# in-source generation and building.
91+
#
92+
# @param {string} SOURCE_DIR Project source directory.
93+
# @param {string} INSTALL_PREFIX Path prefix of where the project should be installed.
94+
# @param {string[]} TARGETS Target libraries to build.
95+
# @param {string[]} [EXTRA_ARGS] Any additional arguments to pass to the generate command.
96+
boost-generate:
97+
internal: true
98+
dir: "{{.SOURCE_DIR}}"
99+
cmds:
100+
- >-
101+
./bootstrap.sh
102+
--prefix="{{.INSTALL_PREFIX}}"
103+
--exec-prefix="{{.INSTALL_PREFIX}}"
104+
--with-libraries={{(join "," .TARGETS)}}
105+
{{- range .EXTRA_ARGS}}
106+
"{{.}}"
107+
{{- end}}
108+
109+
# Runs the b2 build step for boost. The caller must have previously called `generate` on
110+
# `SOURCE_DIR` for this task to succeed.
111+
#
112+
# @param {string} SOURCE_DIR Directory containing the boost source.
113+
# @param {string[]} [EXTRA_ARGS] Any additional arguments to pass to the build command.
114+
# @param {int} [JOBS] The maximum number of concurrent processes to use when building. If
115+
# omitted, the b2 default number is used. Before 1.76.0, the number was 1. Since 1.76.0, the
116+
# default is the number of cores.
117+
boost-build:
118+
internal: true
119+
dir: "{{.SOURCE_DIR}}"
120+
cmds:
121+
- >-
122+
./b2
123+
{{- range .EXTRA_ARGS}}
124+
"{{.}}"
125+
{{- end}}
126+
{{- if .JOBS}}
127+
"-j{{.JOBS}}"
128+
{{- end}}
129+
130+
# Runs the b2 install step for boost. The caller must have previously called `build` on
131+
# `SOURCE_DIR` for this task to succeed. If `CMAKE_SETTINGS_DIR` is set, a settings file will be
132+
# created in that directory, containing a `boost_ROOT` CMake variable that points to
133+
# `INSTALL_PREFIX`.
134+
#
135+
# @param {string} SOURCE_DIR Directory containing the boost source.
136+
# @param {string} INSTALL_PREFIX Path prefix of where the project should be installed.
137+
# @param {string} [CMAKE_SETTINGS_DIR] If set, the directory where the project's CMake settings
138+
# file should be stored.
139+
# @param {string[]} [EXTRA_ARGS] Any additional arguments to pass to the install command.
140+
boost-install:
141+
internal: true
142+
dir: "{{.SOURCE_DIR}}"
143+
cmds:
144+
- >-
145+
./b2
146+
install
147+
{{- range .EXTRA_ARGS}}
148+
"{{.}}"
149+
{{- end}}
150+
- >-
151+
{{- if .CMAKE_SETTINGS_DIR}}
152+
echo "set(BOOST_ROOT
153+
\"{{.INSTALL_PREFIX}}\"
154+
CACHE PATH
155+
\"Package root for boost.\"
156+
)" >> "{{.CMAKE_SETTINGS_DIR}}/boost.cmake"
157+
{{- end}}
158+
159+
# Downloads boost from `URL` and installs boost.
160+
#
161+
# General parameters
162+
# @param {string} [WORK_DIR={{.TASK_DIR}}] Base directory to store the install and src
163+
# directories inside.
164+
# @param {string} [SOURCE_DIR={{.WORK_DIR}}/boost-src] Directory in which to extract the tar
165+
# file.
166+
#
167+
# Download parameters
168+
# @param {string} FILE_SHA256 Content hash to verify the downloaded tar file against.
169+
# @param {string} URL
170+
#
171+
# Boost generate parameters
172+
# @param {string} [INSTALL_PREFIX={{.WORK_DIR}}/boost-install] Path prefix of where the project
173+
# should be installed.
174+
# @param {string[]} TARGETS Target libraries to build.
175+
# @param {string[]} [GEN_ARGS] Any additional arguments to pass to the generate command.
176+
#
177+
# Boost build parameters
178+
# @param {int} [JOBS] The maximum number of concurrent processes to use when building. If
179+
# omitted, the b2 default number is used. Before 1.76.0, the number was 1. Since 1.76.0, the
180+
# default is the number of cores.
181+
# @param {string[]} [BUILD_ARGS] Any additional arguments to pass to the build command.
182+
#
183+
# Boost install parameters
184+
# @param {string[]} [INSTALL_ARGS] Any additional arguments to pass to the install command.
185+
# @param {string} [CMAKE_SETTINGS_DIR] If set, the directory where the project's CMake settings
186+
# file should be stored.
187+
boost-download-and-install:
188+
internal: true
189+
label: "{{.TASK}}:{{.URL}}-{{.INSTALL_PREFIX}}"
190+
vars:
191+
# General parameters
192+
WORK_DIR: >-
193+
{{default .ROOT_DIR .WORK_DIR}}
194+
SOURCE_DIR: >-
195+
{{default (printf "%s/boost-src" .WORK_DIR) .SOURCE_DIR}}
196+
197+
# Boost generate parameters
198+
INSTALL_PREFIX: >-
199+
{{default (printf "%s/boost-install" .WORK_DIR) .INSTALL_PREFIX}}
200+
TARGETS:
201+
ref: "default (list) .TARGETS"
202+
GEN_ARGS:
203+
ref: "default (list) .GEN_ARGS"
90204

205+
# Boost build parameters
206+
BUILD_ARGS:
207+
ref: "default (list) .BUILD_ARGS"
208+
JOBS: >-
209+
{{default "" .JOBS}}
210+
211+
# Boost install parameters
212+
INSTALL_ARGS:
213+
ref: "default (list) .INSTALL_ARGS"
214+
CMAKE_SETTINGS_DIR: >-
215+
{{default "" .CMAKE_SETTINGS_DIR}}
216+
requires:
217+
vars: ["FILE_SHA256", "URL"]
218+
deps:
219+
- task: ":utils:remote:download-and-extract-tar"
220+
vars:
221+
FILE_SHA256: "{{.FILE_SHA256}}"
222+
OUTPUT_DIR: "{{.SOURCE_DIR}}"
223+
URL: "{{.URL}}"
224+
cmds:
225+
- task: "boost-generate"
226+
vars:
227+
SOURCE_DIR: "{{.SOURCE_DIR}}"
228+
INSTALL_PREFIX: "{{.INSTALL_PREFIX}}"
229+
TARGETS:
230+
ref: ".TARGETS"
231+
EXTRA_ARGS:
232+
ref: ".GEN_ARGS"
233+
- task: "boost-build"
234+
vars:
235+
SOURCE_DIR: "{{.SOURCE_DIR}}"
236+
JOBS: "{{.JOBS}}"
237+
EXTRA_ARGS:
238+
ref: ".BUILD_ARGS"
239+
- task: "boost-install"
240+
vars:
241+
SOURCE_DIR: "{{.SOURCE_DIR}}"
242+
INSTALL_PREFIX: "{{.INSTALL_PREFIX}}"
243+
CMAKE_SETTINGS_DIR: "{{.CMAKE_SETTINGS_DIR}}"
244+
EXTRA_ARGS:
245+
ref: ".INSTALL_ARGS"

0 commit comments

Comments
 (0)