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 from1 commit
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
PrevPrevious commit
NextNext commit
Replaced env:: env.h with Project static class
  • Loading branch information
@coder137
coder137 committedMar 27, 2022
commit89590f4a3181e7957a3bb214a1ab16623c653bee
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
28 changes: 14 additions & 14 deletionsbuildcc/lib/env/include/env/env.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,22 +43,22 @@ class Project {

} // namespace buildcc

namespace buildcc::env {
//namespace buildcc::env {

/**
* @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();
// /**
// * @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();

// Getters
bool is_init();
const fs::path &get_project_root_dir();
const fs::path &get_project_build_dir();
////Getters
//bool is_init();
//const fs::path &get_project_root_dir();
//const fs::path &get_project_build_dir();

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

#endif
56 changes: 27 additions & 29 deletionsbuildcc/lib/env/src/env.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,20 +17,18 @@
#include "env/env.h"
#include "env/logging.h"

namespace {
//namespace {

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

} // namespace
//} // namespace

namespace buildcc {

void Project::Init(const fs::path &project_root_dir,
const fs::path &project_build_dir) {
// env::init(project_root_dir, project_build_dir);

// State
fs::path root_dir = project_root_dir;
fs::path build_dir = project_build_dir;
Expand All@@ -46,7 +44,6 @@ void Project::Init(const fs::path &project_root_dir,
env::set_log_level(env::LogLevel::Info);
}
void Project::Deinit() {
// env::deinit();
GetStaticRootDir() = "";
GetStaticBuildDir() = "";
GetStaticInit() = false;
Expand All@@ -71,30 +68,31 @@ fs::path &Project::GetStaticBuildDir() {

} // namespace buildcc

namespace buildcc::env {
//namespace buildcc::env {

void 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();
// void 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();

init_ = true;
// init_ = true;

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

void deinit() {
root_dir_ = "";
build_dir_ = "";
init_ = false;
}
//void deinit() {
// root_dir_ = "";
// build_dir_ = "";
// init_ = 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 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_; }

} // namespace buildcc::env
//} // namespace buildcc::env
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
6 changes: 3 additions & 3 deletionsbuildcc/lib/target/src/target/target.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,15 +49,15 @@ namespace buildcc {
void Target::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");
env::assert_fatal(IsValidTargetType(type_), "Invalid Target Type");
fs::create_directories(GetTargetBuildDir());

// String updates
unique_id_ = fmt::format("[{}] {}", toolchain_.GetName(), name_);
std::string path = fmt::format(
"{}", GetTargetPath().lexically_relative(env::get_project_build_dir()));
"{}", GetTargetPath().lexically_relative(Project::GetBuildDir()));
tf_.name(path);
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp