Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactorenv.h free functions to staticProject class#201

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
coder137 merged 11 commits intomainfromstatic_project_class
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes fromall 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
3 changes: 1 addition & 2 deletionsbootstrap/main.buildcc.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,8 +44,7 @@ int main(int argc, char **argv) {
BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain();

BuildBuildCC buildcc(
reg, toolchain,
TargetEnv(env::get_project_root_dir(), env::get_project_build_dir()));
reg, toolchain, TargetEnv(Project::GetRootDir(), Project::GetBuildDir()));
buildcc.Setup(custom_toolchain_arg.state);

const auto &buildcc_lib = buildcc.GetBuildcc();
Expand Down
4 changes: 2 additions & 2 deletionsbuildcc/lib/args/src/register.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,8 +119,8 @@ void Register::BuildStoreTask(const std::string &unique_id,
void Register::Initialize() { Env(); }

void Register::Env() {
env::init(fs::current_path() / args_.GetProjectRootDir(),
fs::current_path() / args_.GetProjectBuildDir());
Project::Init(fs::current_path() / args_.GetProjectRootDir(),
fs::current_path() / args_.GetProjectBuildDir());
env::set_log_level(args_.GetLogLevel());
}

Expand Down
2 changes: 1 addition & 1 deletionbuildcc/lib/args/test/test_persistent_storage.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,6 +55,6 @@ TEST(PersistentStorageTestGroup, NullptrDelete) {
}

int main(int ac, char **av) {
buildcc::env::init(fs::current_path(), fs::current_path());
buildcc::Project::Init(fs::current_path(), fs::current_path());
return CommandLineTestRunner::RunAllTests(ac, av);
}
28 changes: 14 additions & 14 deletionsbuildcc/lib/args/test/test_register.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,7 +99,7 @@ TEST(RegisterTestGroup, Register_Build) {
CHECK_TRUE(args.Clean());

// Make dummy toolchain and target
buildcc::env::init(fs::current_path(), fs::current_path());
buildcc::Project::Init(fs::current_path(), fs::current_path());
buildcc::Toolchain toolchain(buildcc::ToolchainId::Gcc, "", "", "", "", "",
"");
buildcc::BaseTarget target("dummyT", buildcc::TargetType::Executable,
Expand All@@ -122,7 +122,7 @@ TEST(RegisterTestGroup, Register_Build) {
state, [](buildcc::BaseTarget &target) { (void)target; }, target);
}

buildcc::env::deinit();
buildcc::Project::Deinit();
mock().checkExpectations();
}

Expand All@@ -147,7 +147,7 @@ TEST(RegisterTestGroup, Register_NoBuildAndDep) {
CHECK_TRUE(args.Clean());

// Make dummy toolchain and target
buildcc::env::init(fs::current_path(), fs::current_path());
buildcc::Project::Init(fs::current_path(), fs::current_path());
buildcc::Toolchain toolchain(buildcc::ToolchainId::Gcc, "", "", "", "", "",
"");
buildcc::BaseTarget target("dummyT", buildcc::TargetType::Executable,
Expand DownExpand Up@@ -206,7 +206,7 @@ TEST(RegisterTestGroup, Register_NoBuildAndDep) {
reg.Dep(target, dependency);
}

buildcc::env::deinit();
buildcc::Project::Deinit();
mock().checkExpectations();
}

Expand All@@ -231,7 +231,7 @@ TEST(RegisterTestGroup, Register_BuildAndDep) {
CHECK_TRUE(args.Clean());

// Make dummy toolchain and target
buildcc::env::init(fs::current_path(), fs::current_path());
buildcc::Project::Init(fs::current_path(), fs::current_path());
buildcc::Toolchain toolchain(buildcc::ToolchainId::Gcc, "", "", "", "", "",
"");
buildcc::BaseTarget target("dummyT", buildcc::TargetType::Executable,
Expand DownExpand Up@@ -301,7 +301,7 @@ TEST(RegisterTestGroup, Register_BuildAndDep) {
reg.Dep(target, dependency);
}

buildcc::env::deinit();
buildcc::Project::Deinit();
mock().checkExpectations();
}

Expand All@@ -326,7 +326,7 @@ TEST(RegisterTestGroup, Register_DepDuplicate) {
CHECK_TRUE(args.Clean());

// Make dummy toolchain and target
buildcc::env::init(fs::current_path(), fs::current_path());
buildcc::Project::Init(fs::current_path(), fs::current_path());
buildcc::Toolchain toolchain(buildcc::ToolchainId::Gcc, "", "", "", "", "",
"");
buildcc::BaseTarget target("dummyT", buildcc::TargetType::Executable,
Expand DownExpand Up@@ -377,7 +377,7 @@ TEST(RegisterTestGroup, Register_DepDuplicate) {
CHECK_THROWS(std::exception, reg.Dep(target, dependency2));
}

buildcc::env::deinit();
buildcc::Project::Deinit();
mock().checkExpectations();
}

Expand All@@ -402,7 +402,7 @@ TEST(RegisterTestGroup, Register_DepCyclic) {
CHECK_TRUE(args.Clean());

// Make dummy toolchain and target
buildcc::env::init(fs::current_path(), fs::current_path());
buildcc::Project::Init(fs::current_path(), fs::current_path());
buildcc::Toolchain toolchain(buildcc::ToolchainId::Gcc, "", "", "", "", "",
"");
buildcc::BaseTarget target("dummyT", buildcc::TargetType::Executable,
Expand DownExpand Up@@ -452,7 +452,7 @@ TEST(RegisterTestGroup, Register_DepCyclic) {
CHECK_THROWS(std::exception, reg.Dep(dependency2, target));
}

buildcc::env::deinit();
buildcc::Project::Deinit();
mock().checkExpectations();
}

Expand All@@ -478,7 +478,7 @@ TEST(RegisterTestGroup, Register_Test) {
CHECK_TRUE(args.Clean());

// Make dummy toolchain and target
buildcc::env::init(fs::current_path(), fs::current_path());
buildcc::Project::Init(fs::current_path(), fs::current_path());
buildcc::Toolchain toolchain(buildcc::ToolchainId::Gcc, "", "", "", "", "",
"");
buildcc::BaseTarget target("dummyT", buildcc::TargetType::Executable,
Expand DownExpand Up@@ -537,7 +537,7 @@ TEST(RegisterTestGroup, Register_Test) {
reg.RunTest();
}

buildcc::env::deinit();
buildcc::Project::Deinit();
mock().checkExpectations();
}

Expand All@@ -563,7 +563,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
CHECK_TRUE(args.Clean());

// Make dummy toolchain and target
buildcc::env::init(fs::current_path(), fs::current_path());
buildcc::Project::Init(fs::current_path(), fs::current_path());
buildcc::Toolchain toolchain(buildcc::ToolchainId::Gcc, "", "", "", "", "",
"");
buildcc::BaseTarget target("dummyT", buildcc::TargetType::Executable,
Expand DownExpand Up@@ -676,7 +676,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
CHECK_THROWS(std::exception, reg.RunTest());
}

buildcc::env::deinit();
buildcc::Project::Deinit();
mock().checkExpectations();
}

Expand Down
4 changes: 4 additions & 0 deletionsbuildcc/lib/env/CMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,6 +26,9 @@ if (${TESTING})
target_link_options(mock_env PUBLIC ${TEST_LINK_FLAGS} ${BUILD_LINK_FLAGS})

# Tests
add_executable(test_static_project test/test_static_project.cpp)
target_link_libraries(test_static_project PRIVATE mock_env)

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

Expand All@@ -35,6 +38,7 @@ if (${TESTING})
add_executable(test_command test/test_command.cpp)
target_link_libraries(test_command PRIVATE mock_env)

add_test(NAME test_static_project COMMAND test_static_project)
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)
Expand Down
30 changes: 16 additions & 14 deletionsbuildcc/lib/env/include/env/env.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,22 +23,24 @@

namespace fs = std::filesystem;

namespace buildcc::env {
namespace buildcc {

/**
* @brief Initialize project environment
*
* @param project_root_dir Root directory for source files
* @param project_build_dir Directory for intermediate build files
*/
void init(const fs::path &project_root_dir, const fs::path &project_build_dir);
void deinit();
class Project {
public:
static void Init(const fs::path &project_root_dir,
const fs::path &project_build_dir);
static void Deinit();

static bool IsInit();
static const fs::path &GetRootDir();
static const fs::path &GetBuildDir();

// Getters
bool is_init();
const fs::path &get_project_root_dir();
const fs::path &get_project_build_dir();
private:
static bool &GetStaticInit();
static fs::path &GetStaticRootDir();
static fs::path &GetStaticBuildDir();
};

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

#endif
59 changes: 33 additions & 26 deletionsbuildcc/lib/env/src/env.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,38 +17,45 @@
#include "env/env.h"
#include "env/logging.h"

namespace {
namespacebuildcc{

fs::path root_dir_{""};
fs::path build_dir_{""};
bool init_ = false;

} // namespace

namespace buildcc::env {

void init(const fs::path &project_root_dir, const fs::path &project_build_dir) {
void Project::Init(const fs::path &project_root_dir,
const fs::path &project_build_dir) {
// State
root_dir_ = project_root_dir;
build_dir_ = project_build_dir;
root_dir_.make_preferred();
build_dir_.make_preferred();
fs::path root_dir = project_root_dir;
fs::path build_dir = project_build_dir;
root_dir.make_preferred();
build_dir.make_preferred();

init_ = true;
GetStaticRootDir() = root_dir;
GetStaticBuildDir() = build_dir;
GetStaticInit() = true;

// Logging
set_log_pattern("%^[%l]%$ %v");
set_log_level(LogLevel::Info);
env::set_log_pattern("%^[%l]%$ %v");
env::set_log_level(env::LogLevel::Info);
}

void deinit() {
root_dir_ = "";
build_dir_ = "";
init_ = false;
void Project::Deinit() {
GetStaticRootDir() = "";
GetStaticBuildDir() = "";
GetStaticInit() = false;
}

bool is_init(void) { return init_; }
const fs::path &get_project_root_dir() { return root_dir_; }
const fs::path &get_project_build_dir() { return build_dir_; }
bool Project::IsInit() { return GetStaticInit(); }
const fs::path &Project::GetRootDir() { return GetStaticRootDir(); }
const fs::path &Project::GetBuildDir() { return GetStaticBuildDir(); }

bool &Project::GetStaticInit() {
static bool is_init = false;
return is_init;
}
fs::path &Project::GetStaticRootDir() {
static fs::path root_dir = "";
return root_dir;
}
fs::path &Project::GetStaticBuildDir() {
static fs::path build_dir = "";
return build_dir;
}

} // namespace buildcc::env
} // namespace buildcc
28 changes: 28 additions & 0 deletionsbuildcc/lib/env/test/test_static_project.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
#include "env/env.h"

// NOTE, Make sure all these includes are AFTER the system and header includes
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/MemoryLeakDetectorNewMacros.h"
#include "CppUTest/TestHarness.h"
#include "CppUTest/Utest.h"

// clang-format off
TEST_GROUP(StaticProjectTestGroup)
{
void setup() {
}
};
// clang-format on

TEST(StaticProjectTestGroup, ProjectInitialized) {
CHECK_FALSE(buildcc::Project::IsInit());
buildcc::Project::Init(fs::current_path(), fs::current_path());
CHECK_TRUE(buildcc::Project::IsInit());
buildcc::Project::Deinit();
CHECK_FALSE(buildcc::Project::IsInit());
}

int main(int ac, char **av) {
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
return CommandLineTestRunner::RunAllTests(ac, av);
}
11 changes: 5 additions & 6 deletionsbuildcc/lib/target/include/target/common/target_env.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,14 +35,14 @@ class TargetEnv {
* @brief Change the relative root path for a particular Generator / Target
*
* Absolute root now changes to
* `env::get_project_root_dir() / target_relative_to_env_root`
* `Project::GetRootDir() / target_relative_to_env_root`
*
* Absolute build dir remains the same.
*
* Can be used implicitly
*
* @param target_relative_to_env_root Change root dir with respect to
*env::get_project_root_dir()
*Project::GetRootDir()
*/
TargetEnv(const char *target_relative_to_env_root)
: TargetEnv(fs::path(target_relative_to_env_root)) {}
Expand All@@ -53,12 +53,11 @@ class TargetEnv {
* Only explicit usage allowed
*
* @param target_relative_to_env_root Change root dir with respect to
*env::get_project_root_dir()
*Project::GetRootDir()
*/
explicit TargetEnv(const fs::path &target_relative_to_env_root)
: target_root_dir_(env::get_project_root_dir() /
target_relative_to_env_root),
target_build_dir_(env::get_project_build_dir()), relative_(true) {}
: target_root_dir_(Project::GetRootDir() / target_relative_to_env_root),
target_build_dir_(Project::GetBuildDir()), relative_(true) {}

/**
* @brief Change the absolute root and build path for a particular Generator /
Expand Down
4 changes: 2 additions & 2 deletionsbuildcc/lib/target/src/generator/generator.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,8 +79,8 @@ Generator::GetValueByIdentifier(const std::string &file_identifier) const {
void Generator::Initialize() {
// Checks
env::assert_fatal(
env::is_init(),
"Environment is not initialized. Use the buildcc::env::init API");
Project::IsInit(),
"Environment is not initialized. Use the buildcc::Project::Init API");

//
fs::create_directories(generator_build_dir_);
Expand Down
4 changes: 2 additions & 2 deletionsbuildcc/lib/target/src/generator/task.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,14 +79,14 @@ void Generator::GenerateTask() {
// Graph Generation
for (const auto &i : user_.inputs) {
std::string name =
fmt::format("{}", i.lexically_relative(env::get_project_root_dir()));
fmt::format("{}", i.lexically_relative(Project::GetRootDir()));
tf::Task task = subflow.placeholder().name(name);
task.precede(command_task);
}

for (const auto &o : user_.outputs) {
std::string name =
fmt::format("{}", o.lexically_relative(env::get_project_root_dir()));
fmt::format("{}", o.lexically_relative(Project::GetRootDir()));
tf::Task task = subflow.placeholder().name(name);
task.succeed(command_task);
}
Expand Down
4 changes: 2 additions & 2 deletionsbuildcc/lib/target/src/target/friend/compile_object.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,9 +82,9 @@ CompileObject::GetObjectData(const fs::path &absolute_source) const {
// PRIVATE

// NOTE: If RELATIVE TargetEnv supplied
// {target_root_dir} => `env::get_project_root_dir()` /
// {target_root_dir} => `Project::GetRootDir()` /
// `target_relative_to_root`
// {target_build_dir} => `env::get_project_build_dir()` / `toolchain.GetName()`
// {target_build_dir} => `Project::GetBuildDir()` / `toolchain.GetName()`
// / `name`

// Scenarios
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp