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

Commit70ca258

Browse files
authored
Refactorenv.h free functions to staticProject class (#201)
1 parenta3d2c7f commit70ca258

File tree

60 files changed

+277
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+277
-179
lines changed

‎bootstrap/main.buildcc.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ int main(int argc, char **argv) {
4444
BaseToolchain toolchain = custom_toolchain_arg.ConstructToolchain();
4545

4646
BuildBuildCCbuildcc(
47-
reg, toolchain,
48-
TargetEnv(env::get_project_root_dir(),env::get_project_build_dir()));
47+
reg, toolchain,TargetEnv(Project::GetRootDir(),Project::GetBuildDir()));
4948
buildcc.Setup(custom_toolchain_arg.state);
5049

5150
constauto &buildcc_lib = buildcc.GetBuildcc();

‎buildcc/lib/args/src/register.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ void Register::BuildStoreTask(const std::string &unique_id,
119119
voidRegister::Initialize() {Env(); }
120120

121121
voidRegister::Env() {
122-
env::init(fs::current_path() / args_.GetProjectRootDir(),
123-
fs::current_path() / args_.GetProjectBuildDir());
122+
Project::Init(fs::current_path() / args_.GetProjectRootDir(),
123+
fs::current_path() / args_.GetProjectBuildDir());
124124
env::set_log_level(args_.GetLogLevel());
125125
}
126126

‎buildcc/lib/args/test/test_persistent_storage.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ TEST(PersistentStorageTestGroup, NullptrDelete) {
5555
}
5656

5757
intmain(int ac,char **av) {
58-
buildcc::env::init(fs::current_path(),fs::current_path());
58+
buildcc::Project::Init(fs::current_path(),fs::current_path());
5959
returnCommandLineTestRunner::RunAllTests(ac, av);
6060
}

‎buildcc/lib/args/test/test_register.cpp‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ TEST(RegisterTestGroup, Register_Build) {
9999
CHECK_TRUE(args.Clean());
100100

101101
// Make dummy toolchain and target
102-
buildcc::env::init(fs::current_path(),fs::current_path());
102+
buildcc::Project::Init(fs::current_path(),fs::current_path());
103103
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
104104
"");
105105
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
@@ -122,7 +122,7 @@ TEST(RegisterTestGroup, Register_Build) {
122122
state, [](buildcc::BaseTarget &target) { (void)target; }, target);
123123
}
124124

125-
buildcc::env::deinit();
125+
buildcc::Project::Deinit();
126126
mock().checkExpectations();
127127
}
128128

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

149149
// Make dummy toolchain and target
150-
buildcc::env::init(fs::current_path(),fs::current_path());
150+
buildcc::Project::Init(fs::current_path(),fs::current_path());
151151
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
152152
"");
153153
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
@@ -206,7 +206,7 @@ TEST(RegisterTestGroup, Register_NoBuildAndDep) {
206206
reg.Dep(target, dependency);
207207
}
208208

209-
buildcc::env::deinit();
209+
buildcc::Project::Deinit();
210210
mock().checkExpectations();
211211
}
212212

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

233233
// Make dummy toolchain and target
234-
buildcc::env::init(fs::current_path(),fs::current_path());
234+
buildcc::Project::Init(fs::current_path(),fs::current_path());
235235
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
236236
"");
237237
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
@@ -301,7 +301,7 @@ TEST(RegisterTestGroup, Register_BuildAndDep) {
301301
reg.Dep(target, dependency);
302302
}
303303

304-
buildcc::env::deinit();
304+
buildcc::Project::Deinit();
305305
mock().checkExpectations();
306306
}
307307

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

328328
// Make dummy toolchain and target
329-
buildcc::env::init(fs::current_path(),fs::current_path());
329+
buildcc::Project::Init(fs::current_path(),fs::current_path());
330330
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
331331
"");
332332
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
@@ -377,7 +377,7 @@ TEST(RegisterTestGroup, Register_DepDuplicate) {
377377
CHECK_THROWS(std::exception, reg.Dep(target, dependency2));
378378
}
379379

380-
buildcc::env::deinit();
380+
buildcc::Project::Deinit();
381381
mock().checkExpectations();
382382
}
383383

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

404404
// Make dummy toolchain and target
405-
buildcc::env::init(fs::current_path(),fs::current_path());
405+
buildcc::Project::Init(fs::current_path(),fs::current_path());
406406
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
407407
"");
408408
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
@@ -452,7 +452,7 @@ TEST(RegisterTestGroup, Register_DepCyclic) {
452452
CHECK_THROWS(std::exception, reg.Dep(dependency2, target));
453453
}
454454

455-
buildcc::env::deinit();
455+
buildcc::Project::Deinit();
456456
mock().checkExpectations();
457457
}
458458

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

480480
// Make dummy toolchain and target
481-
buildcc::env::init(fs::current_path(),fs::current_path());
481+
buildcc::Project::Init(fs::current_path(),fs::current_path());
482482
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
483483
"");
484484
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
@@ -537,7 +537,7 @@ TEST(RegisterTestGroup, Register_Test) {
537537
reg.RunTest();
538538
}
539539

540-
buildcc::env::deinit();
540+
buildcc::Project::Deinit();
541541
mock().checkExpectations();
542542
}
543543

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

565565
// Make dummy toolchain and target
566-
buildcc::env::init(fs::current_path(),fs::current_path());
566+
buildcc::Project::Init(fs::current_path(),fs::current_path());
567567
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
568568
"");
569569
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
@@ -676,7 +676,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
676676
CHECK_THROWS(std::exception, reg.RunTest());
677677
}
678678

679-
buildcc::env::deinit();
679+
buildcc::Project::Deinit();
680680
mock().checkExpectations();
681681
}
682682

‎buildcc/lib/env/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ if (${TESTING})
2626
target_link_options(mock_envPUBLIC${TEST_LINK_FLAGS}${BUILD_LINK_FLAGS})
2727

2828
# Tests
29+
add_executable(test_static_projecttest/test_static_project.cpp)
30+
target_link_libraries(test_static_projectPRIVATE mock_env)
31+
2932
add_executable(test_env_utiltest/test_env_util.cpp)
3033
target_link_libraries(test_env_utilPRIVATE mock_env)
3134

@@ -35,6 +38,7 @@ if (${TESTING})
3538
add_executable(test_commandtest/test_command.cpp)
3639
target_link_libraries(test_commandPRIVATE mock_env)
3740

41+
add_test(NAME test_static_projectCOMMAND test_static_project)
3842
add_test(NAME test_env_utilCOMMAND test_env_util)
3943
add_test(NAME test_task_stateCOMMAND test_task_state)
4044
add_test(NAME test_commandCOMMAND test_command)

‎buildcc/lib/env/include/env/env.h‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@
2323

2424
namespacefs= std::filesystem;
2525

26-
namespacebuildcc::env {
26+
namespacebuildcc {
2727

28-
/**
29-
* @brief Initialize project environment
30-
*
31-
* @param project_root_dir Root directory for source files
32-
* @param project_build_dir Directory for intermediate build files
33-
*/
34-
voidinit(const fs::path &project_root_dir,const fs::path &project_build_dir);
35-
voiddeinit();
28+
classProject {
29+
public:
30+
staticvoidInit(const fs::path &project_root_dir,
31+
const fs::path &project_build_dir);
32+
staticvoidDeinit();
33+
34+
staticboolIsInit();
35+
staticconst fs::path &GetRootDir();
36+
staticconst fs::path &GetBuildDir();
3637

37-
// Getters
38-
boolis_init();
39-
const fs::path &get_project_root_dir();
40-
const fs::path &get_project_build_dir();
38+
private:
39+
staticbool &GetStaticInit();
40+
static fs::path &GetStaticRootDir();
41+
static fs::path &GetStaticBuildDir();
42+
};
4143

42-
}// namespace buildcc::env
44+
}// namespace buildcc
4345

4446
#endif

‎buildcc/lib/env/src/env.cpp‎

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,45 @@
1717
#include"env/env.h"
1818
#include"env/logging.h"
1919

20-
namespace {
20+
namespacebuildcc{
2121

22-
fs::path root_dir_{""};
23-
fs::path build_dir_{""};
24-
bool init_ =false;
25-
26-
}// namespace
27-
28-
namespacebuildcc::env {
29-
30-
voidinit(const fs::path &project_root_dir,const fs::path &project_build_dir) {
22+
voidProject::Init(const fs::path &project_root_dir,
23+
const fs::path &project_build_dir) {
3124
// State
32-
root_dir_ = project_root_dir;
33-
build_dir_ = project_build_dir;
34-
root_dir_.make_preferred();
35-
build_dir_.make_preferred();
25+
fs::path root_dir = project_root_dir;
26+
fs::path build_dir = project_build_dir;
27+
root_dir.make_preferred();
28+
build_dir.make_preferred();
3629

37-
init_ =true;
30+
GetStaticRootDir() = root_dir;
31+
GetStaticBuildDir() = build_dir;
32+
GetStaticInit() =true;
3833

3934
// Logging
40-
set_log_pattern("%^[%l]%$ %v");
41-
set_log_level(LogLevel::Info);
35+
env::set_log_pattern("%^[%l]%$ %v");
36+
env::set_log_level(env::LogLevel::Info);
4237
}
43-
44-
voiddeinit() {
45-
root_dir_ ="";
46-
build_dir_ ="";
47-
init_ =false;
38+
voidProject::Deinit() {
39+
GetStaticRootDir() ="";
40+
GetStaticBuildDir() ="";
41+
GetStaticInit() =false;
4842
}
4943

50-
boolis_init(void) {return init_; }
51-
const fs::path &get_project_root_dir() {return root_dir_; }
52-
const fs::path &get_project_build_dir() {return build_dir_; }
44+
boolProject::IsInit() {returnGetStaticInit(); }
45+
const fs::path &Project::GetRootDir() {returnGetStaticRootDir(); }
46+
const fs::path &Project::GetBuildDir() {returnGetStaticBuildDir(); }
47+
48+
bool &Project::GetStaticInit() {
49+
staticbool is_init =false;
50+
return is_init;
51+
}
52+
fs::path &Project::GetStaticRootDir() {
53+
static fs::path root_dir ="";
54+
return root_dir;
55+
}
56+
fs::path &Project::GetStaticBuildDir() {
57+
static fs::path build_dir ="";
58+
return build_dir;
59+
}
5360

54-
}// namespace buildcc::env
61+
}// namespace buildcc
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include"env/env.h"
2+
3+
// NOTE, Make sure all these includes are AFTER the system and header includes
4+
#include"CppUTest/CommandLineTestRunner.h"
5+
#include"CppUTest/MemoryLeakDetectorNewMacros.h"
6+
#include"CppUTest/TestHarness.h"
7+
#include"CppUTest/Utest.h"
8+
9+
// clang-format off
10+
TEST_GROUP(StaticProjectTestGroup)
11+
{
12+
voidsetup() {
13+
}
14+
};
15+
// clang-format on
16+
17+
TEST(StaticProjectTestGroup, ProjectInitialized) {
18+
CHECK_FALSE(buildcc::Project::IsInit());
19+
buildcc::Project::Init(fs::current_path(),fs::current_path());
20+
CHECK_TRUE(buildcc::Project::IsInit());
21+
buildcc::Project::Deinit();
22+
CHECK_FALSE(buildcc::Project::IsInit());
23+
}
24+
25+
intmain(int ac,char **av) {
26+
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
27+
returnCommandLineTestRunner::RunAllTests(ac, av);
28+
}

‎buildcc/lib/target/include/target/common/target_env.h‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class TargetEnv {
3535
* @brief Change the relative root path for a particular Generator / Target
3636
*
3737
* Absolute root now changes to
38-
* `env::get_project_root_dir() / target_relative_to_env_root`
38+
* `Project::GetRootDir() / target_relative_to_env_root`
3939
*
4040
* Absolute build dir remains the same.
4141
*
4242
* Can be used implicitly
4343
*
4444
* @param target_relative_to_env_root Change root dir with respect to
45-
*env::get_project_root_dir()
45+
*Project::GetRootDir()
4646
*/
4747
TargetEnv(constchar *target_relative_to_env_root)
4848
: TargetEnv(fs::path(target_relative_to_env_root)) {}
@@ -53,12 +53,11 @@ class TargetEnv {
5353
* Only explicit usage allowed
5454
*
5555
* @param target_relative_to_env_root Change root dir with respect to
56-
*env::get_project_root_dir()
56+
*Project::GetRootDir()
5757
*/
5858
explicitTargetEnv(const fs::path &target_relative_to_env_root)
59-
: target_root_dir_(env::get_project_root_dir() /
60-
target_relative_to_env_root),
61-
target_build_dir_(env::get_project_build_dir()), relative_(true) {}
59+
: target_root_dir_(Project::GetRootDir() / target_relative_to_env_root),
60+
target_build_dir_(Project::GetBuildDir()), relative_(true) {}
6261

6362
/**
6463
* @brief Change the absolute root and build path for a particular Generator /

‎buildcc/lib/target/src/generator/generator.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ Generator::GetValueByIdentifier(const std::string &file_identifier) const {
7979
voidGenerator::Initialize() {
8080
// Checks
8181
env::assert_fatal(
82-
env::is_init(),
83-
"Environment is not initialized. Use the buildcc::env::init API");
82+
Project::IsInit(),
83+
"Environment is not initialized. Use the buildcc::Project::Init API");
8484

8585
//
8686
fs::create_directories(generator_build_dir_);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp