Skip to content

Commit ed1fe29

Browse files
committed
got rid of outdated tests
* replaced `tl::expected` with `Err` where ever possible * removed `.gitattributes`
1 parent 0fc3264 commit ed1fe29

File tree

27 files changed

+72
-448
lines changed

27 files changed

+72
-448
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
This file was deleted.

deps/spdlog/3335c380a08c5e0f5117a66622df6afdb3d74959/muuk.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ git = 'https://github.com/fmtlib/fmt.git'
88
muuk_path = 'deps/fmt/muuk.toml'
99
revision = '577fd3be883accf8629423ed77fcca8a24bccee2'
1010
version = '577fd3be883accf8629423ed77fcca8a24bccee2'
11-
features = ['use_std2_fmt']
1211

1312
[library]
1413
cflags = ["-DSPDLOG_COMPILED_LIB", "-DSPDLOG_FMT_EXTERNAL"]

include/base_config.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ struct BaseFields {
217217
}
218218

219219
std::filesystem::path full_path = std::filesystem::path(base_path) / file_path;
220-
temp_sources.emplace_back(util::file_system::to_linux_path(full_path.lexically_normal().string()), extracted_cflags);
220+
temp_sources.emplace_back(
221+
util::file_system::to_linux_path(full_path.lexically_normal().string()),
222+
extracted_cflags);
221223
}
222224

223225
return temp_sources;

include/muuk.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#include <string>
66
#include <vector>
77

8-
#include <tl/expected.hpp>
9-
108
#include "compiler.hpp"
119
#include "rustify.hpp"
1210

include/rustify.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ inline constexpr auto Err(const std::string& msg) {
2424
}
2525

2626
inline constexpr auto Err(std::string_view msg) {
27-
return tl::unexpected(std::string(msg));
27+
return Err(std::string(msg));
2828
}
2929

3030
inline constexpr auto Err(const char* msg) {
31-
return tl::unexpected(std::string(msg));
31+
return Err(std::string(msg));
3232
}
3333

3434
template <typename T>
3535
inline constexpr auto Err(Result<T> result) {
36-
return tl::unexpected(result.error());
36+
return Err(result.error());
3737
}
3838

3939
template <typename... Args>
4040
inline constexpr auto Err(fmt::format_string<Args...> fmt_str, Args&&... args) {
41-
return tl::unexpected(fmt::format(fmt_str, std::forward<Args>(args)...));
41+
return Err(fmt::format(fmt_str, std::forward<Args>(args)...));
4242
}
4343

4444
struct PanicException : public std::exception {
@@ -55,15 +55,15 @@ struct PanicException : public std::exception {
5555
template <typename T>
5656
inline auto Try(Result<T>&& exp) -> Result<T> {
5757
if (!exp)
58-
return tl::unexpected(exp.error());
58+
return Err(exp.error());
5959
return std::move(*exp);
6060
}
6161

6262
// Specialization for void type
6363
template <>
6464
inline auto Try<void>(Result<void>&& exp) -> Result<void> {
6565
if (!exp)
66-
return tl::unexpected(exp.error());
66+
return Err(exp.error());
6767
return {}; // Return an empty Result<void> (equivalent to Ok())
6868
}
6969

include/try_expected.hpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,12 @@
1212

1313
#pragma once
1414

15-
// Detect whether we are compiling with GCC/Clang for statement expressions
16-
#if defined(__GNUC__) || defined(__clang__)
17-
#define TRY_HAS_STATEMENT_EXPR 1
18-
#else
19-
#define TRY_HAS_STATEMENT_EXPR 0
20-
#endif
21-
2215
#include <tl/expected.hpp>
2316

24-
#if TRY_HAS_STATEMENT_EXPR
25-
#else
26-
#include <type_traits>
27-
#include <utility>
28-
#endif
29-
30-
// Basic TRY macro using statement expressions (non-portable)
31-
#if TRY_HAS_STATEMENT_EXPR
32-
#define TRY(expr) \
33-
({ \
34-
auto _try_result = (expr); \
35-
if (!_try_result) \
36-
return tl::unexpected(_try_result.error()); \
37-
std::move(*_try_result); \
38-
})
39-
#else
40-
// Portable version using lambda
41-
#define TRY(expr) \
42-
([&]() -> decltype(auto) { \
43-
auto _try_result = (expr); \
44-
if (!_try_result) \
45-
return tl::unexpected(_try_result.error()); \
46-
return std::move(*_try_result); \
47-
}())
48-
#endif
49-
5017
// TRYV: use when expr returns std::expected<void, E>
5118
#define TRYV(expr) \
5219
do { \
5320
auto _try_result = (expr); \
5421
if (!_try_result) \
5522
return tl::unexpected(_try_result.error()); \
5623
} while (0)
57-
58-
// TRY_OR: custom error handling function/lambda
59-
#define TRY_OR(expr, handler) \
60-
([&]() -> decltype(auto) { \
61-
auto _try_result = (expr); \
62-
if (!_try_result) \
63-
return (handler)(_try_result.error()); \
64-
return std::move(*_try_result); \
65-
}())
66-
67-
// TRYV_OR: custom error handler for void-returning std::expected
68-
#define TRYV_OR(expr, handler) \
69-
do { \
70-
auto _try_result = (expr); \
71-
if (!_try_result) \
72-
return (handler)(_try_result.error()); \
73-
} while (0)

muuk.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ sources = ['test/internal/muuk_test.cpp']
5959
[build.test.dependencies]
6060
googletest = { git = 'https://github.com/google/googletest.git', version = '3fbe4db9a39291ae8d7a9c5f1d75896bb4c5a18f' }
6161

62-
[build.test_util]
63-
profile = ['debug']
64-
sources = ['test/internal/test_util.cpp']
65-
66-
[build.test_util.dependencies]
67-
googletest = { git = 'https://github.com/google/googletest.git', version = '3fbe4db9a39291ae8d7a9c5f1d75896bb4c5a18f' }
68-
6962
[platform.windows]
7063
cflags = []
7164

src/lockgen/muuklockgen.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
#include <fmt/core.h>
77
#include <fmt/ranges.h>
8-
#include <glob/glob.hpp>
9-
#include <tl/expected.hpp>
108
#include <toml.hpp>
119

1210
#include "buildconfig.h"
@@ -273,11 +271,9 @@ Result<void> MuukLockGenerator::load() {
273271
base_package_dep.version = base_package_version;
274272

275273
// Resolve dependencies for the base package
276-
auto result_base_pkg = resolve_dependencies(
274+
TRYV(resolve_dependencies(
277275
base_package_name,
278-
base_package_version);
279-
if (!result_base_pkg)
280-
return Err(result_base_pkg);
276+
base_package_version));
281277

282278
muuk::logger::info("Resolving dependencies for build packages...");
283279
for (const auto& [build_name, build] : builds_) {

src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <argparse/argparse.hpp>
77
#include <fmt/ostream.h>
88
#include <nlohmann/json.hpp>
9-
#include <tl/expected.hpp>
109

1110
#include "buildconfig.h"
1211
#include "commands/add.hpp"

src/muukbuilder.cpp

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
#include "buildparser.hpp"
1010
#include "commands/build.hpp"
1111
#include "compiler.hpp"
12+
#include "error_codes.hpp"
1213
#include "logger.hpp"
1314
#include "muuk_parser.hpp"
1415
#include "muuklockgen.hpp"
1516
#include "rustify.hpp"
17+
#include "try_expected.hpp"
1618
#include "util.hpp"
1719

1820
namespace fs = std::filesystem;
@@ -89,29 +91,34 @@ namespace muuk {
8991
Result<void> add_script(const std::string& profile, const std::string& build_name) {
9092
(void)build_name;
9193

92-
auto result = muuk::parse_muuk_file("muuk.toml", false);
94+
auto result = muuk::parse_muuk_file(
95+
"muuk.toml",
96+
false,
97+
false);
9398
if (!result)
94-
return tl::unexpected("Failed to parse muuk.toml: " + result.error());
99+
return Err(result.error());
95100

96101
toml::value config = result.value();
97102

98-
std::string executable_name = "muuk";
99103
#ifdef _WIN32
100-
std::string executable_path = "build/" + profile + "/" + executable_name + ".exe";
104+
std::string executable_path = "build/"
105+
+ profile + "/" + build_name
106+
+ "/" + build_name + ".exe";
101107
#else
102-
std::string executable_path = "./build/" + profile + "/" + executable_name;
108+
std::string executable_path = "./build/"
109+
+ profile + "/" + build_name
110+
+ "/" + build_name + ".exe";
103111
#endif
104112

105113
if (!config.contains("scripts") || !config["scripts"].is_table()) {
106114
config["scripts"] = toml::table {};
107115
}
108116

109-
config["scripts"].as_table()["run"] = toml::value(executable_path);
117+
config["scripts"].as_table()[build_name] = toml::value(executable_path);
110118

111119
std::ofstream out("muuk.toml");
112-
if (!out) {
113-
return tl::unexpected("Failed to open muuk.toml for writing.");
114-
}
120+
if (!out)
121+
return make_error<EC::FileNotFound>("muuk.toml");
115122
out << toml::format(config);
116123

117124
muuk::logger::info("Successfully added run script to 'muuk.toml': {}", executable_path);
@@ -128,15 +135,21 @@ namespace muuk {
128135

129136
Result<void> build(std::string& target_build, const std::string& compiler, const std::string& profile, const toml::value& config) {
130137

138+
auto muuk_result = parse_muuk_file(
139+
"muuk.toml",
140+
false,
141+
true);
142+
if (!muuk_result)
143+
return Err(muuk_result);
144+
145+
auto muuk_file = muuk_result.value();
146+
147+
// TODO: Pass the config to the lock generator
131148
auto lock_generator_ = MuukLockGenerator::create("./");
132149
if (!lock_generator_)
133150
return Err(lock_generator_.error());
134151

135-
auto lock_file_result = lock_generator_->generate_cache(MUUK_CACHE_FILE);
136-
if (!lock_file_result)
137-
return Err(lock_file_result.error());
138-
139-
spdlog::default_logger()->flush();
152+
TRYV(lock_generator_->generate_cache(MUUK_CACHE_FILE));
140153

141154
auto compiler_result = compiler.empty()
142155
? detect_default_compiler()
@@ -151,24 +164,28 @@ namespace muuk {
151164

152165
auto profile_result = select_profile(profile, config);
153166
if (!profile_result)
154-
return tl::unexpected(profile_result.error());
155-
156-
std::string selected_profile = profile_result.value();
167+
return Err(profile_result);
168+
auto selected_profile = profile_result.value();
157169

158170
auto build_manager = std::make_unique<BuildManager>();
159171

160-
auto parse_result = parse(
172+
// TODO: IMPLEMENT
173+
// if (muuk_file.contains("build")) {
174+
// const auto& builds = muuk_file["build"].as_table();
175+
// for (const auto& [build_name, _] : builds) {
176+
// muuk::logger::info("Adding script for build target '{}'", build_name);
177+
// TRYV(add_script(selected_profile, build_name));
178+
// }
179+
// }
180+
181+
TRYV(parse(
161182
*build_manager,
162183
selected_compiler,
163184
fs::path("build") / selected_profile,
164-
selected_profile);
165-
166-
if (!parse_result) {
167-
return Err(parse_result.error());
168-
}
185+
selected_profile));
169186

170187
NinjaBackend build_backend(
171-
*build_manager, // ← Reuse external BuildManager
188+
*build_manager,
172189
selected_compiler,
173190
selected_archiver,
174191
selected_linker);
@@ -179,7 +196,12 @@ namespace muuk {
179196
build_backend.generate_build_file(target_build, selected_profile);
180197

181198
execute_build(selected_profile);
182-
generate_compile_commands(*build_manager, selected_profile, selected_compiler, selected_archiver, selected_linker);
199+
generate_compile_commands(
200+
*build_manager,
201+
selected_profile,
202+
selected_compiler,
203+
selected_archiver,
204+
selected_linker);
183205

184206
return {};
185207
}

0 commit comments

Comments
 (0)