Skip to content

[Architecture] Shift the Command module inside the global environment #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions bootstrap/src/build_buildcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
target.AddIncludeDir("lib/env/include");
target.GlobHeaders("lib/env/include/env");

// COMMAND
target.GlobSources("lib/command/src");
target.AddIncludeDir("lib/command/include");
target.GlobHeaders("lib/command/include/command");

// TOOLCHAIN
target.AddIncludeDir("lib/toolchain/include");
target.GlobHeaders("lib/toolchain/include/toolchain");
Expand Down
3 changes: 0 additions & 3 deletions buildcc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ endif()
# Environment
add_subdirectory(lib/env)

#
add_subdirectory(lib/command)

# Toolchain
add_subdirectory(lib/toolchain)
add_subdirectory(toolchains)
Expand Down
4 changes: 1 addition & 3 deletions buildcc/buildcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#include "env/host_os.h"
#include "env/host_compiler.h"
#include "env/util.h"

//
#include "command/command.h"
#include "env/command.h"

// Base
#include "toolchain/toolchain.h"
Expand Down
6 changes: 3 additions & 3 deletions buildcc/lib/args/src/register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void Register::Env() {
void TestInfo::TestRunner() const {
env::log_info(__FUNCTION__,
fmt::format("Testing \'{}\'", target_.GetUniqueId()));
Command command;
env::Command command;
command.AddDefaultArguments({
{"executable", fmt::format("{}", target_.GetTargetPath())},
});
Expand Down Expand Up @@ -173,8 +173,8 @@ void TestInfo::TestRunner() const {
};

const bool success =
Command::Execute(test_command, config_.GetWorkingDirectory(),
redirect_stdout, redirect_stderr);
env::Command::Execute(test_command, config_.GetWorkingDirectory(),
redirect_stdout, redirect_stderr);
env::assert_fatal(success,
fmt::format("Could not run {}", target_.GetUniqueId()));

Expand Down
3 changes: 3 additions & 0 deletions buildcc/lib/args/src/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "args/register.h"
#include "env/logging.h"
#include "env/util.h"

namespace buildcc {

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

void Register::RunTest() {
Expand Down
14 changes: 7 additions & 7 deletions buildcc/lib/args/test/test_register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ TEST(RegisterTestGroup, Register_Test) {

std::vector<std::string> stdout_data;
std::vector<std::string> stderr_data;
buildcc::m::CommandExpect_Execute(1, true, &stdout_data, &stderr_data);
buildcc::env::m::CommandExpect_Execute(1, true, &stdout_data, &stderr_data);
reg.RunTest();
}

Expand Down Expand Up @@ -588,7 +588,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
{}, {},
buildcc::TestOutput(buildcc::TestOutput::Type::DefaultBehaviour)));

buildcc::m::CommandExpect_Execute(1, true);
buildcc::env::m::CommandExpect_Execute(1, true);
reg.RunTest();
}

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

std::vector<std::string> stderr_data;
buildcc::m::CommandExpect_Execute(1, true, nullptr, &stderr_data);
buildcc::env::m::CommandExpect_Execute(1, true, nullptr, &stderr_data);
reg.RunTest();
}

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

std::vector<std::string> stdout_data;
buildcc::m::CommandExpect_Execute(1, true, &stdout_data, nullptr);
buildcc::env::m::CommandExpect_Execute(1, true, &stdout_data, nullptr);
reg.RunTest();
}

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

std::vector<std::string> stdout_data;
std::vector<std::string> stderr_data;
buildcc::m::CommandExpect_Execute(1, true, &stdout_data, &stderr_data);
buildcc::env::m::CommandExpect_Execute(1, true, &stdout_data, &stderr_data);
reg.RunTest();
}

Expand All @@ -660,7 +660,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
buildcc::TestOutput(buildcc::TestOutput::Type::UserRedirect,
nullptr, nullptr)));

buildcc::m::CommandExpect_Execute(1, true);
buildcc::env::m::CommandExpect_Execute(1, true);
reg.RunTest();
}

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

int main(int ac, char **av) {
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
buildcc::m::VectorStringCopier copier;
buildcc::env::m::VectorStringCopier copier;
mock().installCopier(TEST_VECTOR_STRING_TYPE, copier);
return CommandLineTestRunner::RunAllTests(ac, av);
}
68 changes: 0 additions & 68 deletions buildcc/lib/command/CMakeLists.txt

This file was deleted.

21 changes: 16 additions & 5 deletions buildcc/lib/env/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ if (${TESTING})

src/env.cpp
src/task_state.cpp

src/command.cpp
mock/execute.cpp
)
target_include_directories(mock_env PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/mock/include
)
target_link_libraries(mock_env PUBLIC
fmt::fmt-header-only
Expand All @@ -28,8 +32,12 @@ if (${TESTING})
add_executable(test_task_state test/test_task_state.cpp)
target_link_libraries(test_task_state PRIVATE mock_env)

add_executable(test_command test/test_command.cpp)
target_link_libraries(test_command PRIVATE mock_env)

add_test(NAME test_env_util COMMAND test_env_util)
add_test(NAME test_task_state COMMAND test_task_state)
add_test(NAME test_command COMMAND test_command)
endif()

set(ENV_SRCS
Expand All @@ -48,6 +56,10 @@ set(ENV_SRCS

src/task_state.cpp
include/env/task_state.h

src/command.cpp
src/execute.cpp
include/env/command.h
)

if(${BUILDCC_BUILD_AS_SINGLE_LIB})
Expand All @@ -74,15 +86,14 @@ if(${BUILDCC_BUILD_AS_INTERFACE})
target_link_options(env PRIVATE ${BUILD_LINK_FLAGS})
target_link_libraries(env PRIVATE
spdlog::spdlog_header_only
tiny-process-library::tiny-process-library
)
endif()

# Env install
if (${BUILDCC_INSTALL})
if (${BUILDCC_INSTALL})
if (${BUILDCC_BUILD_AS_INTERFACE})
install(TARGETS env DESTINATION lib EXPORT envConfig)
install(EXPORT envConfig DESTINATION "${BUILDCC_INSTALL_LIB_PREFIX}/env")
endif()
endif()

if (${BUILDCC_INSTALL})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION "${BUILDCC_INSTALL_HEADER_PREFIX}")
endif()
3 changes: 2 additions & 1 deletion buildcc/lib/env/include/env/assert_fatal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace buildcc::env {
/**
* @brief Compile time expr asserts fatally when false
*/
template <bool expr> inline void assert_fatal(const char *message) {
template <bool expr>
inline void assert_fatal([[maybe_unused]] const char *message) {
if constexpr (!expr) {
env::log_critical("assert", message);
assert_handle_fatal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

#ifndef COMMAND_COMMAND_H_
#define COMMAND_COMMAND_H_
#ifndef ENV_COMMAND_H_
#define ENV_COMMAND_H_

#include <filesystem>
#include <optional>
Expand All @@ -25,7 +25,7 @@

namespace fs = std::filesystem;

namespace buildcc {
namespace buildcc::env {

class Command {
public:
Expand Down Expand Up @@ -82,6 +82,6 @@ class Command {
std::unordered_map<std::string, std::string> default_values_;
};

} // namespace buildcc
} // namespace buildcc::env

#endif
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "command/command.h"
#include "env/command.h"

#include "expect_command.h"

#include "CppUTestExt/MockSupport.h"

namespace buildcc {
namespace buildcc::env {

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

} // namespace m

} // namespace buildcc
} // namespace buildcc::env
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#ifndef COMMAND_MOCK_EXPECT_COMMAND_H_
#define COMMAND_MOCK_EXPECT_COMMAND_H_
#ifndef ENV_MOCK_EXPECT_COMMAND_H_
#define ENV_MOCK_EXPECT_COMMAND_H_

#include <string>
#include <vector>

constexpr const char *const TEST_VECTOR_STRING_TYPE = "vector_string";

namespace buildcc::m {
namespace buildcc::env::m {

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

} // namespace buildcc::m
} // namespace buildcc::env::m

#endif
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef COMMAND_MOCK_MOCK_COMMAND_COPIER_H_
#define COMMAND_MOCK_MOCK_COMMAND_COPIER_H_
#ifndef ENV_MOCK_MOCK_COMMAND_COPIER_H_
#define ENV_MOCK_MOCK_COMMAND_COPIER_H_

#include <string>
#include <vector>

#include "CppUTestExt/MockSupport.h"

namespace buildcc::m {
namespace buildcc::env::m {

class VectorStringCopier : public MockNamedValueCopier {
public:
Expand All @@ -23,6 +23,6 @@ class VectorStringCopier : public MockNamedValueCopier {
}
};

} // namespace buildcc::m
} // namespace buildcc::env::m

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "command/command.h"
#include "env/command.h"

#include <algorithm>

Expand All @@ -24,7 +24,7 @@
#include "env/assert_fatal.h"
#include "env/logging.h"

namespace buildcc {
namespace buildcc::env {

void Command::AddDefaultArgument(const std::string &key,
const std::string &value) {
Expand Down Expand Up @@ -64,4 +64,4 @@ std::string Command::Construct(
return fmt::vformat(pattern, store);
}

} // namespace buildcc
} // namespace buildcc::env
Loading