Skip to content

Commit 6fec1da

Browse files
authored
[Architecture] Shift the Command module inside the global environment (#170)
1 parent 4f5b154 commit 6fec1da

39 files changed

+271
-337
lines changed

bootstrap/src/build_buildcc.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
5353
target.AddIncludeDir("lib/env/include");
5454
target.GlobHeaders("lib/env/include/env");
5555

56-
// COMMAND
57-
target.GlobSources("lib/command/src");
58-
target.AddIncludeDir("lib/command/include");
59-
target.GlobHeaders("lib/command/include/command");
60-
6156
// TOOLCHAIN
6257
target.AddIncludeDir("lib/toolchain/include");
6358
target.GlobHeaders("lib/toolchain/include/toolchain");

buildcc/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ endif()
3434
# Environment
3535
add_subdirectory(lib/env)
3636

37-
#
38-
add_subdirectory(lib/command)
39-
4037
# Toolchain
4138
add_subdirectory(lib/toolchain)
4239
add_subdirectory(toolchains)

buildcc/buildcc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
#include "env/host_os.h"
2727
#include "env/host_compiler.h"
2828
#include "env/util.h"
29-
30-
//
31-
#include "command/command.h"
29+
#include "env/command.h"
3230

3331
// Base
3432
#include "toolchain/toolchain.h"

buildcc/lib/args/src/register.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void Register::Env() {
129129
void TestInfo::TestRunner() const {
130130
env::log_info(__FUNCTION__,
131131
fmt::format("Testing \'{}\'", target_.GetUniqueId()));
132-
Command command;
132+
env::Command command;
133133
command.AddDefaultArguments({
134134
{"executable", fmt::format("{}", target_.GetTargetPath())},
135135
});
@@ -173,8 +173,8 @@ void TestInfo::TestRunner() const {
173173
};
174174

175175
const bool success =
176-
Command::Execute(test_command, config_.GetWorkingDirectory(),
177-
redirect_stdout, redirect_stderr);
176+
env::Command::Execute(test_command, config_.GetWorkingDirectory(),
177+
redirect_stdout, redirect_stderr);
178178
env::assert_fatal(success,
179179
fmt::format("Could not run {}", target_.GetUniqueId()));
180180

buildcc/lib/args/src/tasks.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "args/register.h"
1818
#include "env/logging.h"
19+
#include "env/util.h"
1920

2021
namespace buildcc {
2122

@@ -33,6 +34,8 @@ void Register::RunBuild() {
3334
executor_.num_workers()));
3435
executor_.run(build_tf_);
3536
executor_.wait_for_all();
37+
env::assert_fatal(env::get_task_state() == env::TaskState::SUCCESS,
38+
"Task state is not successful!");
3639
}
3740

3841
void Register::RunTest() {

buildcc/lib/args/test/test_register.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ TEST(RegisterTestGroup, Register_Test) {
535535

536536
std::vector<std::string> stdout_data;
537537
std::vector<std::string> stderr_data;
538-
buildcc::m::CommandExpect_Execute(1, true, &stdout_data, &stderr_data);
538+
buildcc::env::m::CommandExpect_Execute(1, true, &stdout_data, &stderr_data);
539539
reg.RunTest();
540540
}
541541

@@ -588,7 +588,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
588588
{}, {},
589589
buildcc::TestOutput(buildcc::TestOutput::Type::DefaultBehaviour)));
590590

591-
buildcc::m::CommandExpect_Execute(1, true);
591+
buildcc::env::m::CommandExpect_Execute(1, true);
592592
reg.RunTest();
593593
}
594594

@@ -606,7 +606,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
606606
buildcc::TestOutput(buildcc::TestOutput::Type::TestPrintOnStderr)));
607607

608608
std::vector<std::string> stderr_data;
609-
buildcc::m::CommandExpect_Execute(1, true, nullptr, &stderr_data);
609+
buildcc::env::m::CommandExpect_Execute(1, true, nullptr, &stderr_data);
610610
reg.RunTest();
611611
}
612612

@@ -624,7 +624,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
624624
buildcc::TestOutput(buildcc::TestOutput::Type::TestPrintOnStdout)));
625625

626626
std::vector<std::string> stdout_data;
627-
buildcc::m::CommandExpect_Execute(1, true, &stdout_data, nullptr);
627+
buildcc::env::m::CommandExpect_Execute(1, true, &stdout_data, nullptr);
628628
reg.RunTest();
629629
}
630630

@@ -643,7 +643,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
643643

644644
std::vector<std::string> stdout_data;
645645
std::vector<std::string> stderr_data;
646-
buildcc::m::CommandExpect_Execute(1, true, &stdout_data, &stderr_data);
646+
buildcc::env::m::CommandExpect_Execute(1, true, &stdout_data, &stderr_data);
647647
reg.RunTest();
648648
}
649649

@@ -660,7 +660,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
660660
buildcc::TestOutput(buildcc::TestOutput::Type::UserRedirect,
661661
nullptr, nullptr)));
662662

663-
buildcc::m::CommandExpect_Execute(1, true);
663+
buildcc::env::m::CommandExpect_Execute(1, true);
664664
reg.RunTest();
665665
}
666666

@@ -684,7 +684,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
684684

685685
int main(int ac, char **av) {
686686
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
687-
buildcc::m::VectorStringCopier copier;
687+
buildcc::env::m::VectorStringCopier copier;
688688
mock().installCopier(TEST_VECTOR_STRING_TYPE, copier);
689689
return CommandLineTestRunner::RunAllTests(ac, av);
690690
}

buildcc/lib/command/CMakeLists.txt

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

buildcc/lib/env/CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ if (${TESTING})
66

77
src/env.cpp
88
src/task_state.cpp
9+
10+
src/command.cpp
11+
mock/execute.cpp
912
)
1013
target_include_directories(mock_env PUBLIC
1114
${CMAKE_CURRENT_SOURCE_DIR}/include
15+
${CMAKE_CURRENT_SOURCE_DIR}/mock/include
1216
)
1317
target_link_libraries(mock_env PUBLIC
1418
fmt::fmt-header-only
@@ -28,8 +32,12 @@ if (${TESTING})
2832
add_executable(test_task_state test/test_task_state.cpp)
2933
target_link_libraries(test_task_state PRIVATE mock_env)
3034

35+
add_executable(test_command test/test_command.cpp)
36+
target_link_libraries(test_command PRIVATE mock_env)
37+
3138
add_test(NAME test_env_util COMMAND test_env_util)
3239
add_test(NAME test_task_state COMMAND test_task_state)
40+
add_test(NAME test_command COMMAND test_command)
3341
endif()
3442

3543
set(ENV_SRCS
@@ -48,6 +56,10 @@ set(ENV_SRCS
4856

4957
src/task_state.cpp
5058
include/env/task_state.h
59+
60+
src/command.cpp
61+
src/execute.cpp
62+
include/env/command.h
5163
)
5264

5365
if(${BUILDCC_BUILD_AS_SINGLE_LIB})
@@ -74,15 +86,14 @@ if(${BUILDCC_BUILD_AS_INTERFACE})
7486
target_link_options(env PRIVATE ${BUILD_LINK_FLAGS})
7587
target_link_libraries(env PRIVATE
7688
spdlog::spdlog_header_only
89+
tiny-process-library::tiny-process-library
7790
)
91+
endif()
7892

79-
# Env install
80-
if (${BUILDCC_INSTALL})
93+
if (${BUILDCC_INSTALL})
94+
if (${BUILDCC_BUILD_AS_INTERFACE})
8195
install(TARGETS env DESTINATION lib EXPORT envConfig)
8296
install(EXPORT envConfig DESTINATION "${BUILDCC_INSTALL_LIB_PREFIX}/env")
8397
endif()
84-
endif()
85-
86-
if (${BUILDCC_INSTALL})
8798
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION "${BUILDCC_INSTALL_HEADER_PREFIX}")
8899
endif()

buildcc/lib/env/include/env/assert_fatal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ namespace buildcc::env {
3232
/**
3333
* @brief Compile time expr asserts fatally when false
3434
*/
35-
template <bool expr> inline void assert_fatal(const char *message) {
35+
template <bool expr>
36+
inline void assert_fatal([[maybe_unused]] const char *message) {
3637
if constexpr (!expr) {
3738
env::log_critical("assert", message);
3839
assert_handle_fatal();

buildcc/lib/command/include/command/command.h renamed to buildcc/lib/env/include/env/command.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef COMMAND_COMMAND_H_
18-
#define COMMAND_COMMAND_H_
17+
#ifndef ENV_COMMAND_H_
18+
#define ENV_COMMAND_H_
1919

2020
#include <filesystem>
2121
#include <optional>
@@ -25,7 +25,7 @@
2525

2626
namespace fs = std::filesystem;
2727

28-
namespace buildcc {
28+
namespace buildcc::env {
2929

3030
class Command {
3131
public:
@@ -82,6 +82,6 @@ class Command {
8282
std::unordered_map<std::string, std::string> default_values_;
8383
};
8484

85-
} // namespace buildcc
85+
} // namespace buildcc::env
8686

8787
#endif

buildcc/lib/command/mock/execute.cpp renamed to buildcc/lib/env/mock/execute.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "command/command.h"
1+
#include "env/command.h"
22

33
#include "expect_command.h"
44

55
#include "CppUTestExt/MockSupport.h"
66

7-
namespace buildcc {
7+
namespace buildcc::env {
88

99
static constexpr const char *const EXECUTE_FUNCTION = "execute";
1010
static constexpr const char *const STDOUT_DATA_STRING = "stdout_data";
@@ -48,4 +48,4 @@ void CommandExpect_Execute(unsigned int calls, bool expectation,
4848

4949
} // namespace m
5050

51-
} // namespace buildcc
51+
} // namespace buildcc::env
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#ifndef COMMAND_MOCK_EXPECT_COMMAND_H_
2-
#define COMMAND_MOCK_EXPECT_COMMAND_H_
1+
#ifndef ENV_MOCK_EXPECT_COMMAND_H_
2+
#define ENV_MOCK_EXPECT_COMMAND_H_
33

44
#include <string>
55
#include <vector>
66

77
constexpr const char *const TEST_VECTOR_STRING_TYPE = "vector_string";
88

9-
namespace buildcc::m {
9+
namespace buildcc::env::m {
1010

1111
void CommandExpect_Execute(unsigned int calls, bool expectation,
1212
std::vector<std::string> *stdout_data = nullptr,
1313
std::vector<std::string> *stderr_data = nullptr);
1414

15-
} // namespace buildcc::m
15+
} // namespace buildcc::env::m
1616

1717
#endif

buildcc/lib/command/mock/mock_command_copier.h renamed to buildcc/lib/env/mock/include/mock_command_copier.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#ifndef COMMAND_MOCK_MOCK_COMMAND_COPIER_H_
2-
#define COMMAND_MOCK_MOCK_COMMAND_COPIER_H_
1+
#ifndef ENV_MOCK_MOCK_COMMAND_COPIER_H_
2+
#define ENV_MOCK_MOCK_COMMAND_COPIER_H_
33

44
#include <string>
55
#include <vector>
66

77
#include "CppUTestExt/MockSupport.h"
88

9-
namespace buildcc::m {
9+
namespace buildcc::env::m {
1010

1111
class VectorStringCopier : public MockNamedValueCopier {
1212
public:
@@ -23,6 +23,6 @@ class VectorStringCopier : public MockNamedValueCopier {
2323
}
2424
};
2525

26-
} // namespace buildcc::m
26+
} // namespace buildcc::env::m
2727

2828
#endif

buildcc/lib/command/src/command.cpp renamed to buildcc/lib/env/src/command.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "command/command.h"
17+
#include "env/command.h"
1818

1919
#include <algorithm>
2020

@@ -24,7 +24,7 @@
2424
#include "env/assert_fatal.h"
2525
#include "env/logging.h"
2626

27-
namespace buildcc {
27+
namespace buildcc::env {
2828

2929
void Command::AddDefaultArgument(const std::string &key,
3030
const std::string &value) {
@@ -64,4 +64,4 @@ std::string Command::Construct(
6464
return fmt::vformat(pattern, store);
6565
}
6666

67-
} // namespace buildcc
67+
} // namespace buildcc::env

0 commit comments

Comments
 (0)