From 9445750b48aada142dddedb2d0aeb37621941660 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Mon, 21 Feb 2022 15:09:59 -0800 Subject: [PATCH 1/7] Update target_state.h --- buildcc/lib/target/include/target/common/target_state.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/buildcc/lib/target/include/target/common/target_state.h b/buildcc/lib/target/include/target/common/target_state.h index 3afc766f..89e95785 100644 --- a/buildcc/lib/target/include/target/common/target_state.h +++ b/buildcc/lib/target/include/target/common/target_state.h @@ -29,12 +29,6 @@ namespace buildcc { struct TargetState { void SetSourceState(FileExt file_extension); void SetPch(); - void SetLock(); - - void ExpectsUnlock() const; - void ExpectsLock() const; - // TODO, IsLocked - bool ContainsPch() const { return contains_pch_; } // TODO, Make these private getters @@ -42,7 +36,6 @@ struct TargetState { bool contains_c{false}; bool contains_cpp{false}; bool build{false}; - bool lock{false}; private: bool contains_pch_{false}; From 8d5765a647f84db7b9dfbdc65ad9cba8f9d4675e Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Mon, 21 Feb 2022 15:11:19 -0800 Subject: [PATCH 2/7] Create function_lock.h --- .../include/target/common/function_lock.h | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 buildcc/lib/target/include/target/common/function_lock.h diff --git a/buildcc/lib/target/include/target/common/function_lock.h b/buildcc/lib/target/include/target/common/function_lock.h new file mode 100644 index 00000000..3f15bddf --- /dev/null +++ b/buildcc/lib/target/include/target/common/function_lock.h @@ -0,0 +1,48 @@ +/* + * Copyright 2021-2022 Niket Naidu. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TARGET_COMMON_FUNCTION_LOCK_H_ +#define TARGET_COMMON_FUNCTION_LOCK_H_ + +#include + +#include "fmt/format.h" + +#include "env/assert_fatal.h" + +namespace buildcc { + +class FunctionLock { +public: + void Lock() { lock_ = true; } + void Unlock() { lock_ = false; } + bool IsLocked() const { return lock_; } + void ExpectsUnlock(std::string_view tag) const { + env::assert_fatal(!lock_, + fmt::format("Cannot use {} when lock == true", tag)); + } + void ExpectsLock(std::string_view tag) const { + env::assert_fatal(lock_, + fmt::format("Cannot use {} when lock == false", tag)); + } + +private: + bool lock_{false}; +}; + +} // namespace buildcc + +#endif From c9e412f33e9bf7ace68726bf70323d98dab858a2 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Mon, 21 Feb 2022 15:11:29 -0800 Subject: [PATCH 3/7] Update target.h --- buildcc/lib/target/include/target/target.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index a9540a14..ed72277f 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -75,8 +75,6 @@ class Target : public internal::BuilderInterface, env.GetTargetBuildDir() / toolchain.GetName() / name), config), name_(name), type_(type), - // toolchain_(toolchain), - // loader_(name, env_.GetTargetBuildDir()), serialization_(env_.GetTargetBuildDir() / fmt::format("{}.bin", name)), compile_pch_(*this), compile_object_(*this), link_target_(*this) { Initialize(); @@ -141,7 +139,6 @@ class Target : public internal::BuilderInterface, private: std::string name_; TargetType type_; - // const Toolchain &toolchain_; internal::TargetSerialization serialization_; // Friend classes From 8ce626095d8ba827d06b2a2bfa3e94d9d019e09f Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Mon, 21 Feb 2022 15:12:04 -0800 Subject: [PATCH 4/7] Updated files with FunctionLock --- buildcc/lib/target/include/target/target_info.h | 2 ++ buildcc/lib/target/src/api/deps_api.cpp | 4 ++-- buildcc/lib/target/src/api/flag_api.cpp | 16 ++++++++-------- buildcc/lib/target/src/api/include_api.cpp | 4 ++-- buildcc/lib/target/src/api/lib_api.cpp | 6 +++--- buildcc/lib/target/src/api/pch_api.cpp | 2 +- buildcc/lib/target/src/api/source_api.cpp | 2 +- buildcc/lib/target/src/api/sync_api.cpp | 4 ++-- buildcc/lib/target/src/api/target_getter.cpp | 6 +++--- .../lib/target/src/api/target_info_getter.cpp | 2 +- buildcc/lib/target/src/target/build.cpp | 4 ++-- 11 files changed, 27 insertions(+), 25 deletions(-) diff --git a/buildcc/lib/target/include/target/target_info.h b/buildcc/lib/target/include/target/target_info.h index fb795161..98115a51 100644 --- a/buildcc/lib/target/include/target/target_info.h +++ b/buildcc/lib/target/include/target/target_info.h @@ -21,6 +21,7 @@ #include "toolchain/toolchain.h" +#include "target/common/function_lock.h" #include "target/common/target_config.h" #include "target/common/target_env.h" #include "target/common/target_state.h" @@ -88,6 +89,7 @@ class TargetInfo : public internal::SourceApi, UserTargetSchema user_; + FunctionLock lock_; TargetState state_; }; diff --git a/buildcc/lib/target/src/api/deps_api.cpp b/buildcc/lib/target/src/api/deps_api.cpp index 8cbee764..18a7c820 100644 --- a/buildcc/lib/target/src/api/deps_api.cpp +++ b/buildcc/lib/target/src/api/deps_api.cpp @@ -24,14 +24,14 @@ template void DepsApi::AddCompileDependencyAbsolute(const fs::path &absolute_path) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.compile_dependencies.insert(absolute_path); } template void DepsApi::AddLinkDependencyAbsolute(const fs::path &absolute_path) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.link_dependencies.insert(absolute_path); } diff --git a/buildcc/lib/target/src/api/flag_api.cpp b/buildcc/lib/target/src/api/flag_api.cpp index 99a9f294..856b46bb 100644 --- a/buildcc/lib/target/src/api/flag_api.cpp +++ b/buildcc/lib/target/src/api/flag_api.cpp @@ -24,55 +24,55 @@ template void FlagApi::AddPreprocessorFlag(const std::string &flag) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.preprocessor_flags.insert(flag); } template void FlagApi::AddCommonCompileFlag(const std::string &flag) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.common_compile_flags.insert(flag); } template void FlagApi::AddPchCompileFlag(const std::string &flag) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.pch_compile_flags.insert(flag); } template void FlagApi::AddPchObjectFlag(const std::string &flag) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.pch_object_flags.insert(flag); } template void FlagApi::AddAsmCompileFlag(const std::string &flag) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.asm_compile_flags.insert(flag); } template void FlagApi::AddCCompileFlag(const std::string &flag) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.c_compile_flags.insert(flag); } template void FlagApi::AddCppCompileFlag(const std::string &flag) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.cpp_compile_flags.insert(flag); } template void FlagApi::AddLinkFlag(const std::string &flag) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.link_flags.insert(flag); } diff --git a/buildcc/lib/target/src/api/include_api.cpp b/buildcc/lib/target/src/api/include_api.cpp index 49ca6241..66baa44e 100644 --- a/buildcc/lib/target/src/api/include_api.cpp +++ b/buildcc/lib/target/src/api/include_api.cpp @@ -24,7 +24,7 @@ template void IncludeApi::AddHeaderAbsolute(const fs::path &absolute_filepath) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.toolchain_.GetConfig().ExpectsValidHeader(absolute_filepath); t.user_.headers.insert(absolute_filepath); } @@ -74,7 +74,7 @@ void IncludeApi::AddIncludeDirAbsolute(const fs::path &absolute_include_dir, bool glob_headers) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.include_dirs.insert(absolute_include_dir); if (glob_headers) { diff --git a/buildcc/lib/target/src/api/lib_api.cpp b/buildcc/lib/target/src/api/lib_api.cpp index 16eb85a8..aa15898a 100644 --- a/buildcc/lib/target/src/api/lib_api.cpp +++ b/buildcc/lib/target/src/api/lib_api.cpp @@ -25,7 +25,7 @@ template void LibApi::AddLibDirAbsolute(const fs::path &absolute_lib_dir) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.lib_dirs.insert(absolute_lib_dir); } @@ -40,14 +40,14 @@ void LibApi::AddLibDir(const fs::path &relative_lib_dir) { template void LibApi::AddLibDep(const BaseTarget &lib_dep) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.libs.push_back(lib_dep.GetTargetPath()); } template void LibApi::AddLibDep(const std::string &lib_dep) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.user_.external_libs.push_back(lib_dep); } diff --git a/buildcc/lib/target/src/api/pch_api.cpp b/buildcc/lib/target/src/api/pch_api.cpp index c0695342..35fc16bf 100644 --- a/buildcc/lib/target/src/api/pch_api.cpp +++ b/buildcc/lib/target/src/api/pch_api.cpp @@ -24,7 +24,7 @@ template void PchApi::AddPchAbsolute(const fs::path &absolute_filepath) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.toolchain_.GetConfig().ExpectsValidHeader(absolute_filepath); const fs::path absolute_pch = fs::path(absolute_filepath).make_preferred(); diff --git a/buildcc/lib/target/src/api/source_api.cpp b/buildcc/lib/target/src/api/source_api.cpp index cc47cda3..99676c15 100644 --- a/buildcc/lib/target/src/api/source_api.cpp +++ b/buildcc/lib/target/src/api/source_api.cpp @@ -24,7 +24,7 @@ template void SourceApi::AddSourceAbsolute(const fs::path &absolute_source) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); t.toolchain_.GetConfig().ExpectsValidSource(absolute_source); t.user_.sources.emplace(fs::path(absolute_source).make_preferred()); } diff --git a/buildcc/lib/target/src/api/sync_api.cpp b/buildcc/lib/target/src/api/sync_api.cpp index 261eca24..e947fb56 100644 --- a/buildcc/lib/target/src/api/sync_api.cpp +++ b/buildcc/lib/target/src/api/sync_api.cpp @@ -41,7 +41,7 @@ template void SyncApi::SpecializedCopy(TargetType target, std::initializer_list options) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); for (const SyncOption o : options) { switch (o) { case SyncOption::PreprocessorFlags: @@ -122,7 +122,7 @@ template void SyncApi::SpecializedInsert(TargetType target, std::initializer_list options) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); + t.lock_.ExpectsUnlock(__FUNCTION__); for (const SyncOption o : options) { switch (o) { case SyncOption::PreprocessorFlags: diff --git a/buildcc/lib/target/src/api/target_getter.cpp b/buildcc/lib/target/src/api/target_getter.cpp index e49e30ef..0c490c25 100644 --- a/buildcc/lib/target/src/api/target_getter.cpp +++ b/buildcc/lib/target/src/api/target_getter.cpp @@ -69,7 +69,7 @@ const std::string & TargetGetter::GetCompileCommand(const fs::path &source) const { const T &t = static_cast(*this); - t.state_.ExpectsLock(); + t.lock_.ExpectsLock(__FUNCTION__); return t.compile_object_.GetObjectData(source).command; } @@ -77,14 +77,14 @@ template const std::string &TargetGetter::GetLinkCommand() const { const T &t = static_cast(*this); - t.state_.ExpectsLock(); + t.lock_.ExpectsLock(__FUNCTION__); return t.link_target_.GetCommand(); } template tf::Taskflow &TargetGetter::GetTaskflow() { T &t = static_cast(*this); - t.state_.ExpectsLock(); + t.lock_.ExpectsLock(__FUNCTION__); return t.tf_; } diff --git a/buildcc/lib/target/src/api/target_info_getter.cpp b/buildcc/lib/target/src/api/target_info_getter.cpp index 488818a7..e61def04 100644 --- a/buildcc/lib/target/src/api/target_info_getter.cpp +++ b/buildcc/lib/target/src/api/target_info_getter.cpp @@ -36,7 +36,7 @@ template bool TargetInfoGetter::IsBuilt() const { template bool TargetInfoGetter::IsLocked() const { const T &t = static_cast(*this); - return t.state_.lock; + return t.lock_.IsLocked(); } // Target Env diff --git a/buildcc/lib/target/src/target/build.cpp b/buildcc/lib/target/src/target/build.cpp index 7d00cd19..02263c0f 100644 --- a/buildcc/lib/target/src/target/build.cpp +++ b/buildcc/lib/target/src/target/build.cpp @@ -54,8 +54,8 @@ namespace buildcc { void Target::Build() { env::log_trace(name_, __FUNCTION__); - state_.ExpectsUnlock(); - state_.SetLock(); + lock_.ExpectsUnlock(__FUNCTION__); + lock_.Lock(); // PCH state if (!user_.pchs.empty()) { From d8153106ba3514a26be5d152c42af54e466befd8 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Mon, 21 Feb 2022 15:12:17 -0800 Subject: [PATCH 5/7] Update target_state.cpp --- buildcc/lib/target/src/common/target_state.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/buildcc/lib/target/src/common/target_state.cpp b/buildcc/lib/target/src/common/target_state.cpp index 95a8a022..9e8da200 100644 --- a/buildcc/lib/target/src/common/target_state.cpp +++ b/buildcc/lib/target/src/common/target_state.cpp @@ -40,14 +40,4 @@ void TargetState::SetSourceState(FileExt file_extension) { void TargetState::SetPch() { contains_pch_ = true; } -void TargetState::SetLock() { lock = true; } - -void TargetState::ExpectsUnlock() const { - env::assert_fatal(!lock, "Cannot use this function when lock == true"); -} - -void TargetState::ExpectsLock() const { - env::assert_fatal(lock, "Cannot use this function when lock == false"); -} - } // namespace buildcc From 8ac3a146f26facf31e62148e1d131e8403858b57 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Mon, 21 Feb 2022 15:28:55 -0800 Subject: [PATCH 6/7] Updated target_state to private variable fields --- .../include/target/common/target_state.h | 22 +++++++++---------- .../lib/target/src/api/target_info_getter.cpp | 2 +- .../lib/target/src/common/target_state.cpp | 8 ++++--- .../target/src/target/friend/compile_pch.cpp | 6 ++--- buildcc/lib/target/src/target/tasks.cpp | 2 +- .../target/test/target/test_target_state.cpp | 12 +++++----- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/buildcc/lib/target/include/target/common/target_state.h b/buildcc/lib/target/include/target/common/target_state.h index 89e95785..4790951a 100644 --- a/buildcc/lib/target/include/target/common/target_state.h +++ b/buildcc/lib/target/include/target/common/target_state.h @@ -21,24 +21,24 @@ namespace buildcc { -// TODO, Seperate TargetState into lock_ and other internal boolean variables -// NOTE, This is because apart from lock_ every other parameter is updated -// during `Target::Build` -// TargetInfo does not have a `Build` method, it is only meant to hold -// information struct TargetState { + void BuildCompleted(); void SetSourceState(FileExt file_extension); void SetPch(); - bool ContainsPch() const { return contains_pch_; } - // TODO, Make these private getters - bool contains_asm{false}; - bool contains_c{false}; - bool contains_cpp{false}; - bool build{false}; + bool IsBuilt() const { return build_; } + bool ContainsPch() const { return contains_pch_; } + bool ContainsAsm() const { return contains_asm_; } + bool ContainsC() const { return contains_c_; } + bool ContainsCpp() const { return contains_cpp_; } private: + bool build_{false}; + bool contains_pch_{false}; + bool contains_asm_{false}; + bool contains_c_{false}; + bool contains_cpp_{false}; }; } // namespace buildcc diff --git a/buildcc/lib/target/src/api/target_info_getter.cpp b/buildcc/lib/target/src/api/target_info_getter.cpp index e61def04..7efdc88a 100644 --- a/buildcc/lib/target/src/api/target_info_getter.cpp +++ b/buildcc/lib/target/src/api/target_info_getter.cpp @@ -30,7 +30,7 @@ template const TargetState &TargetInfoGetter::GetState() const { template bool TargetInfoGetter::IsBuilt() const { const T &t = static_cast(*this); - return t.state_.build; + return t.state_.IsBuilt(); } template bool TargetInfoGetter::IsLocked() const { diff --git a/buildcc/lib/target/src/common/target_state.cpp b/buildcc/lib/target/src/common/target_state.cpp index 9e8da200..da61c03c 100644 --- a/buildcc/lib/target/src/common/target_state.cpp +++ b/buildcc/lib/target/src/common/target_state.cpp @@ -20,16 +20,18 @@ namespace buildcc { +void TargetState::BuildCompleted() { build_ = true; } + void TargetState::SetSourceState(FileExt file_extension) { switch (file_extension) { case FileExt::Asm: - contains_asm = true; + contains_asm_ = true; break; case FileExt::C: - contains_c = true; + contains_c_ = true; break; case FileExt::Cpp: - contains_cpp = true; + contains_cpp_ = true; break; case FileExt::Header: case FileExt::Invalid: diff --git a/buildcc/lib/target/src/target/friend/compile_pch.cpp b/buildcc/lib/target/src/target/friend/compile_pch.cpp index 312b8b7c..83e7cf62 100644 --- a/buildcc/lib/target/src/target/friend/compile_pch.cpp +++ b/buildcc/lib/target/src/target/friend/compile_pch.cpp @@ -64,7 +64,7 @@ namespace buildcc::internal { // PUBLIC void CompilePch::CacheCompileCommand() { - source_path_ = ConstructSourcePath(target_.GetState().contains_cpp); + source_path_ = ConstructSourcePath(target_.GetState().ContainsCpp()); command_ = ConstructCompileCommand(); } @@ -138,12 +138,12 @@ fs::path CompilePch::ConstructObjectPath() const { } std::string CompilePch::ConstructCompileCommand() const { - std::string compiler = target_.GetState().contains_cpp + std::string compiler = target_.GetState().ContainsCpp() ? target_.GetToolchain().GetCppCompiler() : target_.GetToolchain().GetCCompiler(); compiler = fmt::format("{}", fs::path(compiler)); const FileExt file_ext_type = - target_.GetState().contains_cpp ? FileExt::Cpp : FileExt::C; + target_.GetState().ContainsCpp() ? FileExt::Cpp : FileExt::C; const std::string compile_flags = target_.SelectCompileFlags(file_ext_type).value_or(""); const std::string pch_compile_path = fmt::format("{}", compile_path_); diff --git a/buildcc/lib/target/src/target/tasks.cpp b/buildcc/lib/target/src/target/tasks.cpp index 94b81ec7..0efb6e54 100644 --- a/buildcc/lib/target/src/target/tasks.cpp +++ b/buildcc/lib/target/src/target/tasks.cpp @@ -173,7 +173,7 @@ void Target::EndTask() { serialization_.UpdateStore(user_); env::assert_throw(serialization_.StoreToFile(), fmt::format("Store failed for {}", GetName())); - state_.build = true; + state_.BuildCompleted(); } catch (...) { SetTaskStateFailure(); } diff --git a/buildcc/lib/target/test/target/test_target_state.cpp b/buildcc/lib/target/test/target/test_target_state.cpp index f3af3363..20c5344e 100644 --- a/buildcc/lib/target/test/target/test_target_state.cpp +++ b/buildcc/lib/target/test/target/test_target_state.cpp @@ -16,17 +16,17 @@ TEST_GROUP(TargetStateTestGroup) TEST(TargetStateTestGroup, SetSourceState) { buildcc::TargetState target_state; - CHECK_FALSE(target_state.contains_c); + CHECK_FALSE(target_state.ContainsC()); target_state.SetSourceState(buildcc::FileExt::C); - CHECK_TRUE(target_state.contains_c); + CHECK_TRUE(target_state.ContainsC()); - CHECK_FALSE(target_state.contains_cpp); + CHECK_FALSE(target_state.ContainsCpp()); target_state.SetSourceState(buildcc::FileExt::Cpp); - CHECK_TRUE(target_state.contains_cpp); + CHECK_TRUE(target_state.ContainsCpp()); - CHECK_FALSE(target_state.contains_asm); + CHECK_FALSE(target_state.ContainsAsm()); target_state.SetSourceState(buildcc::FileExt::Asm); - CHECK_TRUE(target_state.contains_asm); + CHECK_TRUE(target_state.ContainsAsm()); // Ignored target_state.SetSourceState(buildcc::FileExt::Header); From a897d2c7c626b8cd372f51beb73633209cc09b63 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Mon, 21 Feb 2022 15:50:02 -0800 Subject: [PATCH 7/7] Updated TargetState naming --- .../lib/target/include/target/common/target_state.h | 4 ++-- buildcc/lib/target/src/common/target_state.cpp | 4 ++-- buildcc/lib/target/src/target/build.cpp | 4 ++-- buildcc/lib/target/test/target/test_target_state.cpp | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/buildcc/lib/target/include/target/common/target_state.h b/buildcc/lib/target/include/target/common/target_state.h index 4790951a..bd211456 100644 --- a/buildcc/lib/target/include/target/common/target_state.h +++ b/buildcc/lib/target/include/target/common/target_state.h @@ -23,8 +23,8 @@ namespace buildcc { struct TargetState { void BuildCompleted(); - void SetSourceState(FileExt file_extension); - void SetPch(); + void SourceDetected(FileExt file_extension); + void PchDetected(); bool IsBuilt() const { return build_; } bool ContainsPch() const { return contains_pch_; } diff --git a/buildcc/lib/target/src/common/target_state.cpp b/buildcc/lib/target/src/common/target_state.cpp index da61c03c..a8e5cc65 100644 --- a/buildcc/lib/target/src/common/target_state.cpp +++ b/buildcc/lib/target/src/common/target_state.cpp @@ -22,7 +22,7 @@ namespace buildcc { void TargetState::BuildCompleted() { build_ = true; } -void TargetState::SetSourceState(FileExt file_extension) { +void TargetState::SourceDetected(FileExt file_extension) { switch (file_extension) { case FileExt::Asm: contains_asm_ = true; @@ -40,6 +40,6 @@ void TargetState::SetSourceState(FileExt file_extension) { } } -void TargetState::SetPch() { contains_pch_ = true; } +void TargetState::PchDetected() { contains_pch_ = true; } } // namespace buildcc diff --git a/buildcc/lib/target/src/target/build.cpp b/buildcc/lib/target/src/target/build.cpp index 02263c0f..7435e7a5 100644 --- a/buildcc/lib/target/src/target/build.cpp +++ b/buildcc/lib/target/src/target/build.cpp @@ -59,14 +59,14 @@ void Target::Build() { // PCH state if (!user_.pchs.empty()) { - state_.SetPch(); + state_.PchDetected(); } // Source - Object relation // Source state for (const auto &abs_source : user_.sources) { // Set state - state_.SetSourceState(toolchain_.GetConfig().GetFileExt(abs_source)); + state_.SourceDetected(toolchain_.GetConfig().GetFileExt(abs_source)); // Relate input source with output object compile_object_.AddObjectData(abs_source); diff --git a/buildcc/lib/target/test/target/test_target_state.cpp b/buildcc/lib/target/test/target/test_target_state.cpp index 20c5344e..ec8806c9 100644 --- a/buildcc/lib/target/test/target/test_target_state.cpp +++ b/buildcc/lib/target/test/target/test_target_state.cpp @@ -17,20 +17,20 @@ TEST(TargetStateTestGroup, SetSourceState) { buildcc::TargetState target_state; CHECK_FALSE(target_state.ContainsC()); - target_state.SetSourceState(buildcc::FileExt::C); + target_state.SourceDetected(buildcc::FileExt::C); CHECK_TRUE(target_state.ContainsC()); CHECK_FALSE(target_state.ContainsCpp()); - target_state.SetSourceState(buildcc::FileExt::Cpp); + target_state.SourceDetected(buildcc::FileExt::Cpp); CHECK_TRUE(target_state.ContainsCpp()); CHECK_FALSE(target_state.ContainsAsm()); - target_state.SetSourceState(buildcc::FileExt::Asm); + target_state.SourceDetected(buildcc::FileExt::Asm); CHECK_TRUE(target_state.ContainsAsm()); // Ignored - target_state.SetSourceState(buildcc::FileExt::Header); - target_state.SetSourceState(buildcc::FileExt::Invalid); + target_state.SourceDetected(buildcc::FileExt::Header); + target_state.SourceDetected(buildcc::FileExt::Invalid); } int main(int ac, char **av) {