From 77dce84bb7bbf0c2b8edd67c1baee91238d95c8b Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 00:56:06 -0800 Subject: [PATCH 01/10] Update target_state.h --- buildcc/lib/target/include/target/common/target_state.h | 1 + 1 file changed, 1 insertion(+) diff --git a/buildcc/lib/target/include/target/common/target_state.h b/buildcc/lib/target/include/target/common/target_state.h index 92f1ba18..2b75d084 100644 --- a/buildcc/lib/target/include/target/common/target_state.h +++ b/buildcc/lib/target/include/target/common/target_state.h @@ -21,6 +21,7 @@ namespace buildcc::base { +// TODO, Seperate TargetState into lock_ and other internal boolean variables struct TargetState { void SetSourceState(TargetFileExt file_extension); void SetPch(); From 4f36e72329223ae72f929b48c5e57a875cfdc44f Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 01:19:56 -0800 Subject: [PATCH 02/10] Updated apis to target_info - Added Target Info class --- .../lib/target/include/target/target_info.h | 68 +++++++++++++++++++ buildcc/lib/target/src/api/copy_api.cpp | 8 +-- buildcc/lib/target/src/api/deps_api.cpp | 4 +- buildcc/lib/target/src/api/flag_api.cpp | 4 +- buildcc/lib/target/src/api/include_api.cpp | 4 +- buildcc/lib/target/src/api/lib_api.cpp | 3 +- buildcc/lib/target/src/api/pch_api.cpp | 4 +- buildcc/lib/target/src/api/source_api.cpp | 4 +- 8 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 buildcc/lib/target/include/target/target_info.h diff --git a/buildcc/lib/target/include/target/target_info.h b/buildcc/lib/target/include/target/target_info.h new file mode 100644 index 00000000..65b77d95 --- /dev/null +++ b/buildcc/lib/target/include/target/target_info.h @@ -0,0 +1,68 @@ +/* + * Copyright 2021 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_TARGET_INFO_H_ +#define TARGET_TARGET_INFO_H_ + +#include + +#include "target/common/target_config.h" +#include "target/common/target_env.h" +#include "target/common/target_state.h" +#include "target/target_storer.h" + +#include "target/api/copy_api.h" +#include "target/api/deps_api.h" +#include "target/api/flag_api.h" +#include "target/api/include_api.h" +#include "target/api/lib_api.h" +#include "target/api/pch_api.h" +#include "target/api/source_api.h" + +namespace buildcc::base { + +// +class TargetInfo : public SourceApi, + public IncludeApi, + public LibApi, + public PchApi, + public FlagApi, + public DepsApi, + public CopyApi { +public: + TargetInfo(const TargetEnv &env, const TargetConfig &config = TargetConfig()) + : env_(env), config_(config) {} + +private: + friend class SourceApi; + friend class IncludeApi; + friend class LibApi; + friend class PchApi; + friend class FlagApi; + friend class DepsApi; + friend class CopyApi; + +protected: + TargetEnv env_; + TargetConfig config_; + + internal::TargetStorer storer_; + TargetState state_; +}; + +} // namespace buildcc::base + +#endif diff --git a/buildcc/lib/target/src/api/copy_api.cpp b/buildcc/lib/target/src/api/copy_api.cpp index b3dfbddf..cbdd8108 100644 --- a/buildcc/lib/target/src/api/copy_api.cpp +++ b/buildcc/lib/target/src/api/copy_api.cpp @@ -16,7 +16,7 @@ #include "target/api/copy_api.h" -#include "target/target.h" +#include "target/target_info.h" namespace buildcc::base { @@ -24,13 +24,13 @@ template void CopyApi::Copy(const T &target, std::initializer_list options) { env::log_trace(__FUNCTION__, "Copy by const ref"); - SpecializedCopy(target, options); + SpecializedCopy(target, options); } template void CopyApi::Copy(T &&target, std::initializer_list options) { env::log_trace(__FUNCTION__, "Copy by move"); - SpecializedCopy(std::move(target), options); + SpecializedCopy(std::move(target), options); } // template @@ -116,6 +116,6 @@ void CopyApi::SpecializedCopy(TargetType target, } } -template class CopyApi; +template class CopyApi; } // namespace buildcc::base diff --git a/buildcc/lib/target/src/api/deps_api.cpp b/buildcc/lib/target/src/api/deps_api.cpp index ff6b51d4..f0c85a91 100644 --- a/buildcc/lib/target/src/api/deps_api.cpp +++ b/buildcc/lib/target/src/api/deps_api.cpp @@ -16,7 +16,7 @@ #include "target/api/deps_api.h" -#include "target/target.h" +#include "target/target_info.h" namespace buildcc::base { @@ -51,6 +51,6 @@ void DepsApi::AddLinkDependency(const fs::path &relative_path) { AddLinkDependencyAbsolute(absolute_path); } -template class DepsApi; +template class DepsApi; } // namespace buildcc::base diff --git a/buildcc/lib/target/src/api/flag_api.cpp b/buildcc/lib/target/src/api/flag_api.cpp index 0609ee47..7145f54b 100644 --- a/buildcc/lib/target/src/api/flag_api.cpp +++ b/buildcc/lib/target/src/api/flag_api.cpp @@ -16,7 +16,7 @@ #include "target/api/flag_api.h" -#include "target/target.h" +#include "target/target_info.h" namespace buildcc::base { @@ -76,6 +76,6 @@ template void FlagApi::AddLinkFlag(const std::string &flag) { t.storer_.current_link_flags.insert(flag); } -template class FlagApi; +template class FlagApi; } // namespace buildcc::base diff --git a/buildcc/lib/target/src/api/include_api.cpp b/buildcc/lib/target/src/api/include_api.cpp index 9833f5ab..2b66eb19 100644 --- a/buildcc/lib/target/src/api/include_api.cpp +++ b/buildcc/lib/target/src/api/include_api.cpp @@ -16,7 +16,7 @@ #include "target/api/include_api.h" -#include "target/target.h" +#include "target/target_info.h" namespace buildcc::base { @@ -83,6 +83,6 @@ void IncludeApi::AddIncludeDirAbsolute(const fs::path &absolute_include_dir, } } -template class IncludeApi; +template class IncludeApi; } // namespace buildcc::base diff --git a/buildcc/lib/target/src/api/lib_api.cpp b/buildcc/lib/target/src/api/lib_api.cpp index 290f93b8..5fcd05d5 100644 --- a/buildcc/lib/target/src/api/lib_api.cpp +++ b/buildcc/lib/target/src/api/lib_api.cpp @@ -17,6 +17,7 @@ #include "target/api/lib_api.h" #include "target/target.h" +#include "target/target_info.h" namespace buildcc::base { @@ -50,6 +51,6 @@ template void LibApi::AddLibDep(const std::string &lib_dep) { t.storer_.current_external_lib_deps.insert(lib_dep); } -template class LibApi; +template class LibApi; } // namespace buildcc::base diff --git a/buildcc/lib/target/src/api/pch_api.cpp b/buildcc/lib/target/src/api/pch_api.cpp index 115e2d6f..58692067 100644 --- a/buildcc/lib/target/src/api/pch_api.cpp +++ b/buildcc/lib/target/src/api/pch_api.cpp @@ -16,7 +16,7 @@ #include "target/api/pch_api.h" -#include "target/target.h" +#include "target/target_info.h" namespace buildcc::base { @@ -43,6 +43,6 @@ void PchApi::AddPch(const fs::path &relative_filename, AddPchAbsolute(absolute_pch); } -template class PchApi; +template class PchApi; } // namespace buildcc::base diff --git a/buildcc/lib/target/src/api/source_api.cpp b/buildcc/lib/target/src/api/source_api.cpp index 4e407a1e..154c1fda 100644 --- a/buildcc/lib/target/src/api/source_api.cpp +++ b/buildcc/lib/target/src/api/source_api.cpp @@ -16,7 +16,7 @@ #include "target/api/source_api.h" -#include "target/target.h" +#include "target/target_info.h" namespace buildcc::base { @@ -67,6 +67,6 @@ void SourceApi::GlobSources(const fs::path &relative_to_target_path) { } // -template class SourceApi; +template class SourceApi; } // namespace buildcc::base From 14c5e81b65e08e793be8f54a9949f74d39fc800c Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 01:21:04 -0800 Subject: [PATCH 03/10] Update target.h --- buildcc/lib/target/include/target/target.h | 49 +++++++--------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index f01786bc..bedb0778 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -30,21 +30,12 @@ // Interface #include "target/builder_interface.h" +// API +#include "target/target_info.h" + // Common -#include "target/common/target_config.h" -#include "target/common/target_env.h" -#include "target/common/target_state.h" #include "target/common/target_type.h" -// API -#include "target/api/copy_api.h" -#include "target/api/deps_api.h" -#include "target/api/flag_api.h" -#include "target/api/include_api.h" -#include "target/api/lib_api.h" -#include "target/api/pch_api.h" -#include "target/api/source_api.h" - // Friend #include "target/friend/compile_object.h" #include "target/friend/compile_pch.h" @@ -70,22 +61,17 @@ namespace buildcc::base { // of the inheritance pattern // NOTE, base::Target is meant to be a blank slate which can be customized by // the specialized target-toolchain classes -class Target : public BuilderInterface, - public CopyApi, - public SourceApi, - public IncludeApi, - public LibApi, - public PchApi, - public FlagApi, - public DepsApi { +class Target : public BuilderInterface, public TargetInfo { public: explicit Target(const std::string &name, TargetType type, const Toolchain &toolchain, const TargetEnv &env, - const TargetConfig &config = {}) - : name_(name), type_(type), toolchain_(toolchain), config_(config), - env_(env.GetTargetRootDir(), - env.GetTargetBuildDir() / toolchain.GetName() / name), + const TargetConfig &config = TargetConfig()) + : TargetInfo( + TargetEnv(env.GetTargetRootDir(), + env.GetTargetBuildDir() / toolchain.GetName() / name), + config), + name_(name), type_(type), toolchain_(toolchain), loader_(name, env_.GetTargetBuildDir()), compile_pch_(*this), compile_object_(*this), link_target_(*this) { Initialize(); @@ -99,10 +85,6 @@ class Target : public BuilderInterface, // TODO, Add more setters - // - std::optional SelectCompileFlags(TargetFileExt ext) const; - std::optional SelectCompiler(TargetFileExt ext) const; - // Getters (GENERIC) // Target state @@ -221,6 +203,10 @@ class Target : public BuilderInterface, private: void Initialize(); + // + std::optional SelectCompileFlags(TargetFileExt ext) const; + std::optional SelectCompiler(TargetFileExt ext) const; + // Recompilation checks void RecheckPaths(const internal::path_unordered_set &previous_path, const internal::path_unordered_set ¤t_path); @@ -250,12 +236,9 @@ class Target : public BuilderInterface, void TaskDeps(); private: - // Constructor defined std::string name_; TargetType type_; const Toolchain &toolchain_; - TargetConfig config_; - TargetEnv env_; internal::TargetLoader loader_; // Friend @@ -263,9 +246,7 @@ class Target : public BuilderInterface, CompileObject compile_object_; LinkTarget link_target_; - // Used for serialization - internal::TargetStorer storer_; - TargetState state_; + // Command command_; tf::Taskflow tf_; }; From 4e6ae70c3c75b318d4bfbe0e2bb7b0842f8f3f99 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 01:49:45 -0800 Subject: [PATCH 04/10] Update target_info.h --- buildcc/lib/target/include/target/target_info.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/buildcc/lib/target/include/target/target_info.h b/buildcc/lib/target/include/target/target_info.h index 65b77d95..1db81677 100644 --- a/buildcc/lib/target/include/target/target_info.h +++ b/buildcc/lib/target/include/target/target_info.h @@ -65,4 +65,10 @@ class TargetInfo : public SourceApi, } // namespace buildcc::base +namespace buildcc { + +typedef base::TargetInfo TargetInfo; + +} + #endif From 851a21ad1626b6030aa51cf3116083b60e7cc3e7 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 02:34:20 -0800 Subject: [PATCH 05/10] Added target_info_getter --- buildcc/lib/target/cmake/mock_target.cmake | 6 +- buildcc/lib/target/cmake/target.cmake | 8 +- .../include/target/api/target_info_getter.h | 49 ++++++ .../lib/target/src/api/target_info_getter.cpp | 161 ++++++++++++++++++ 4 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 buildcc/lib/target/include/target/api/target_info_getter.h create mode 100644 buildcc/lib/target/src/api/target_info_getter.cpp diff --git a/buildcc/lib/target/cmake/mock_target.cmake b/buildcc/lib/target/cmake/mock_target.cmake index 96d037c9..a622254b 100644 --- a/buildcc/lib/target/cmake/mock_target.cmake +++ b/buildcc/lib/target/cmake/mock_target.cmake @@ -7,7 +7,6 @@ add_library(mock_target STATIC src/common/target_state.cpp # API - src/api/copy_api.cpp src/api/source_api.cpp src/api/include_api.cpp src/api/lib_api.cpp @@ -15,6 +14,11 @@ add_library(mock_target STATIC src/api/flag_api.cpp src/api/deps_api.cpp + src/api/copy_api.cpp + + src/api/target_info_getter.cpp + + # Generator src/generator/generator_loader.cpp src/generator/generator_storer.cpp diff --git a/buildcc/lib/target/cmake/target.cmake b/buildcc/lib/target/cmake/target.cmake index 16b3c190..6510e998 100644 --- a/buildcc/lib/target/cmake/target.cmake +++ b/buildcc/lib/target/cmake/target.cmake @@ -18,14 +18,12 @@ set(TARGET_SRCS include/target/common/target_type.h # API - src/api/copy_api.cpp src/api/source_api.cpp src/api/include_api.cpp src/api/lib_api.cpp src/api/pch_api.cpp src/api/flag_api.cpp src/api/deps_api.cpp - include/target/api/copy_api.h include/target/api/source_api.h include/target/api/include_api.h include/target/api/lib_api.h @@ -33,6 +31,12 @@ set(TARGET_SRCS include/target/api/flag_api.h include/target/api/deps_api.h + src/api/copy_api.cpp + include/target/api/copy_api.h + + src/api/target_info_getter.cpp + include/target/api/target_info_getter.h + # Generator src/generator/generator_loader.cpp src/generator/generator_storer.cpp diff --git a/buildcc/lib/target/include/target/api/target_info_getter.h b/buildcc/lib/target/include/target/api/target_info_getter.h new file mode 100644 index 00000000..fec99c6d --- /dev/null +++ b/buildcc/lib/target/include/target/api/target_info_getter.h @@ -0,0 +1,49 @@ +/* + * Copyright 2021 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_API_TARGET_INFO_GETTER_H_ +#define TARGET_API_TARGET_INFO_GETTER_H_ + +#include "target/path.h" + +namespace buildcc::base { + +// Requires +// - TargetStorer +template class TargetInfoGetter { +public: + const internal::fs_unordered_set &GetCurrentSourceFiles() const; + const internal::fs_unordered_set &GetCurrentHeaderFiles() const; + const internal::fs_unordered_set &GetCurrentPchFiles() const; + const internal::fs_unordered_set &GetTargetLibDeps() const; + const std::unordered_set &GetCurrentExternalLibDeps() const; + const internal::fs_unordered_set &GetCurrentIncludeDirs() const; + const internal::fs_unordered_set &GetCurrentLibDirs() const; + const std::unordered_set &GetCurrentPreprocessorFlags() const; + const std::unordered_set &GetCurrentCommonCompileFlags() const; + const std::unordered_set &GetCurrentPchCompileFlags() const; + const std::unordered_set &GetCurrentPchObjectFlags() const; + const std::unordered_set &GetCurrentAsmCompileFlags() const; + const std::unordered_set &GetCurrentCCompileFlags() const; + const std::unordered_set &GetCurrentCppCompileFlags() const; + const std::unordered_set &GetCurrentLinkFlags() const; + const internal::fs_unordered_set &GetCurrentCompileDependencies() const; + const internal::fs_unordered_set &GetCurrentLinkDependencies() const; +}; + +} // namespace buildcc::base + +#endif diff --git a/buildcc/lib/target/src/api/target_info_getter.cpp b/buildcc/lib/target/src/api/target_info_getter.cpp new file mode 100644 index 00000000..b3ceeb76 --- /dev/null +++ b/buildcc/lib/target/src/api/target_info_getter.cpp @@ -0,0 +1,161 @@ +/* + * Copyright 2021 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. + */ + +#include "target/api/target_info_getter.h" + +#include "target/target_info.h" + +namespace buildcc::base { + +template +const internal::fs_unordered_set & +TargetInfoGetter::GetCurrentSourceFiles() const { + const T &t = static_cast(*this); + + return t.storer_.current_source_files.user; +} + +template +const internal::fs_unordered_set & +TargetInfoGetter::GetCurrentHeaderFiles() const { + const T &t = static_cast(*this); + + return t.storer_.current_header_files.user; +} + +template +const internal::fs_unordered_set & +TargetInfoGetter::GetCurrentPchFiles() const { + const T &t = static_cast(*this); + + return t.storer_.current_pch_files.user; +} + +template +const internal::fs_unordered_set & +TargetInfoGetter::GetTargetLibDeps() const { + const T &t = static_cast(*this); + + return t.storer_.current_lib_deps.user; +} + +template +const std::unordered_set & +TargetInfoGetter::GetCurrentExternalLibDeps() const { + const T &t = static_cast(*this); + + return t.storer_.current_external_lib_deps; +} + +template +const internal::fs_unordered_set & +TargetInfoGetter::GetCurrentIncludeDirs() const { + const T &t = static_cast(*this); + + return t.storer_.current_include_dirs; +} + +template +const internal::fs_unordered_set & +TargetInfoGetter::GetCurrentLibDirs() const { + const T &t = static_cast(*this); + + return t.storer_.current_lib_dirs; +} + +template +const std::unordered_set & +TargetInfoGetter::GetCurrentPreprocessorFlags() const { + const T &t = static_cast(*this); + + return t.storer_.current_preprocessor_flags; +} + +template +const std::unordered_set & +TargetInfoGetter::GetCurrentCommonCompileFlags() const { + const T &t = static_cast(*this); + + return t.storer_.current_common_compile_flags; +} + +template +const std::unordered_set & +TargetInfoGetter::GetCurrentPchCompileFlags() const { + const T &t = static_cast(*this); + + return t.storer_.current_pch_compile_flags; +} + +template +const std::unordered_set & +TargetInfoGetter::GetCurrentPchObjectFlags() const { + const T &t = static_cast(*this); + + return t.storer_.current_pch_object_flags; +} + +template +const std::unordered_set & +TargetInfoGetter::GetCurrentAsmCompileFlags() const { + const T &t = static_cast(*this); + + return t.storer_.current_asm_compile_flags; +} + +template +const std::unordered_set & +TargetInfoGetter::GetCurrentCCompileFlags() const { + const T &t = static_cast(*this); + + return t.storer_.current_c_compile_flags; +} + +template +const std::unordered_set & +TargetInfoGetter::GetCurrentCppCompileFlags() const { + const T &t = static_cast(*this); + + return t.storer_.current_cpp_compile_flags; +} + +template +const std::unordered_set & +TargetInfoGetter::GetCurrentLinkFlags() const { + const T &t = static_cast(*this); + + return t.storer_.current_link_flags; +} + +template +const internal::fs_unordered_set & +TargetInfoGetter::GetCurrentCompileDependencies() const { + const T &t = static_cast(*this); + + return t.storer_.current_compile_dependencies.user; +} + +template +const internal::fs_unordered_set & +TargetInfoGetter::GetCurrentLinkDependencies() const { + const T &t = static_cast(*this); + + return t.storer_.current_link_dependencies.user; +} + +template class TargetInfoGetter; + +} // namespace buildcc::base From 06dc739ccc62abf289e300d418c5676dced1bad0 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 02:34:46 -0800 Subject: [PATCH 06/10] Updated target_info and target with TargetInfoGetter CRTP --- buildcc/lib/target/include/target/target.h | 55 ------------------- .../lib/target/include/target/target_info.h | 12 +++- 2 files changed, 11 insertions(+), 56 deletions(-) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index bedb0778..afcd1b12 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -83,12 +83,8 @@ class Target : public BuilderInterface, public TargetInfo { // Builders void Build() override; - // TODO, Add more setters - // Getters (GENERIC) - // Target state - // Set during first build or rebuild // lock == true after Build is called const TargetState &GetState() const { return state_; } @@ -117,57 +113,6 @@ class Target : public BuilderInterface, public TargetInfo { const TargetConfig &GetConfig() const { return config_; } // - const internal::fs_unordered_set &GetCurrentSourceFiles() const { - return storer_.current_source_files.user; - } - const internal::fs_unordered_set &GetCurrentHeaderFiles() const { - return storer_.current_header_files.user; - } - const internal::fs_unordered_set &GetCurrentPchFiles() const { - return storer_.current_pch_files.user; - } - const internal::fs_unordered_set &GetTargetLibDeps() const { - return storer_.current_lib_deps.user; - } - const std::unordered_set &GetCurrentExternalLibDeps() const { - return storer_.current_external_lib_deps; - } - const internal::fs_unordered_set &GetCurrentIncludeDirs() const { - return storer_.current_include_dirs; - } - const internal::fs_unordered_set &GetCurrentLibDirs() const { - return storer_.current_lib_dirs; - } - const std::unordered_set &GetCurrentPreprocessorFlags() const { - return storer_.current_preprocessor_flags; - } - const std::unordered_set &GetCurrentCommonCompileFlags() const { - return storer_.current_common_compile_flags; - } - const std::unordered_set &GetCurrentPchCompileFlags() const { - return storer_.current_pch_compile_flags; - } - const std::unordered_set &GetCurrentPchObjectFlags() const { - return storer_.current_pch_object_flags; - } - const std::unordered_set &GetCurrentAsmCompileFlags() const { - return storer_.current_asm_compile_flags; - } - const std::unordered_set &GetCurrentCCompileFlags() const { - return storer_.current_c_compile_flags; - } - const std::unordered_set &GetCurrentCppCompileFlags() const { - return storer_.current_cpp_compile_flags; - } - const std::unordered_set &GetCurrentLinkFlags() const { - return storer_.current_link_flags; - } - const internal::fs_unordered_set &GetCurrentCompileDependencies() const { - return storer_.current_compile_dependencies.user; - } - const internal::fs_unordered_set &GetCurrentLinkDependencies() const { - return storer_.current_link_dependencies.user; - } // Getters (state_.ExpectsLock) diff --git a/buildcc/lib/target/include/target/target_info.h b/buildcc/lib/target/include/target/target_info.h index 1db81677..bdf889bd 100644 --- a/buildcc/lib/target/include/target/target_info.h +++ b/buildcc/lib/target/include/target/target_info.h @@ -30,8 +30,11 @@ #include "target/api/include_api.h" #include "target/api/lib_api.h" #include "target/api/pch_api.h" + #include "target/api/source_api.h" +#include "target/api/target_info_getter.h" + namespace buildcc::base { // @@ -41,20 +44,27 @@ class TargetInfo : public SourceApi, public PchApi, public FlagApi, public DepsApi, - public CopyApi { + public CopyApi, + public TargetInfoGetter { public: TargetInfo(const TargetEnv &env, const TargetConfig &config = TargetConfig()) : env_(env), config_(config) {} private: + // Inputs friend class SourceApi; friend class IncludeApi; friend class LibApi; friend class PchApi; friend class FlagApi; friend class DepsApi; + + // Feature friend class CopyApi; + // Getters + friend class TargetInfoGetter; + protected: TargetEnv env_; TargetConfig config_; From 13016999e41497f832a70d3db3c7a75aed317992 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 03:57:44 -0800 Subject: [PATCH 07/10] Added Target State to Target Info getters --- .../include/target/api/target_info_getter.h | 9 +++++++++ buildcc/lib/target/include/target/target.h | 8 -------- .../lib/target/src/api/target_info_getter.cpp | 20 +++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/buildcc/lib/target/include/target/api/target_info_getter.h b/buildcc/lib/target/include/target/api/target_info_getter.h index fec99c6d..0fb85adf 100644 --- a/buildcc/lib/target/include/target/api/target_info_getter.h +++ b/buildcc/lib/target/include/target/api/target_info_getter.h @@ -19,12 +19,21 @@ #include "target/path.h" +#include "target/common/target_state.h" + namespace buildcc::base { // Requires // - TargetStorer +// - TargetState template class TargetInfoGetter { public: + // Target State + const TargetState &GetState() const; + bool GetBuildState() const; + bool GetLockState() const; + + // Target Storere const internal::fs_unordered_set &GetCurrentSourceFiles() const; const internal::fs_unordered_set &GetCurrentHeaderFiles() const; const internal::fs_unordered_set &GetCurrentPchFiles() const; diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index afcd1b12..67803252 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -77,7 +77,6 @@ class Target : public BuilderInterface, public TargetInfo { Initialize(); } virtual ~Target() {} - Target(const Target &target) = delete; // Builders @@ -85,15 +84,8 @@ class Target : public BuilderInterface, public TargetInfo { // Getters (GENERIC) - // Set during first build or rebuild - // lock == true after Build is called - const TargetState &GetState() const { return state_; } - bool GetBuildState() const { return state_.build; } - bool GetLockState() const { return state_.lock; } - // NOTE, We are constructing the path fs::path GetBinaryPath() const { return loader_.GetBinaryPath(); } - const fs::path &GetTargetPath() const { return link_target_.GetOutput(); } const fs::path &GetPchHeaderPath() const { return compile_pch_.GetHeaderPath(); diff --git a/buildcc/lib/target/src/api/target_info_getter.cpp b/buildcc/lib/target/src/api/target_info_getter.cpp index b3ceeb76..dce1457d 100644 --- a/buildcc/lib/target/src/api/target_info_getter.cpp +++ b/buildcc/lib/target/src/api/target_info_getter.cpp @@ -20,6 +20,26 @@ namespace buildcc::base { +// Target State +template const TargetState &TargetInfoGetter::GetState() const { + const T &t = static_cast(*this); + + return t.state_; +} + +template bool TargetInfoGetter::GetBuildState() const { + const T &t = static_cast(*this); + + return t.state_.build; +} + +template bool TargetInfoGetter::GetLockState() const { + const T &t = static_cast(*this); + + return t.state_.lock; +} + +// Target Storer template const internal::fs_unordered_set & TargetInfoGetter::GetCurrentSourceFiles() const { From be4e3f8ee3aaa406f52e8d419d57eafcbe929010 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 03:58:06 -0800 Subject: [PATCH 08/10] Update target_info_getter.h --- buildcc/lib/target/include/target/api/target_info_getter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildcc/lib/target/include/target/api/target_info_getter.h b/buildcc/lib/target/include/target/api/target_info_getter.h index 0fb85adf..38e910d6 100644 --- a/buildcc/lib/target/include/target/api/target_info_getter.h +++ b/buildcc/lib/target/include/target/api/target_info_getter.h @@ -33,7 +33,7 @@ template class TargetInfoGetter { bool GetBuildState() const; bool GetLockState() const; - // Target Storere + // Target Storer const internal::fs_unordered_set &GetCurrentSourceFiles() const; const internal::fs_unordered_set &GetCurrentHeaderFiles() const; const internal::fs_unordered_set &GetCurrentPchFiles() const; From e3fb12c08e7bf1ab6204b3df2c2474705d9b4806 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 04:02:38 -0800 Subject: [PATCH 09/10] Shifted env and config to target_info_getter class --- .../include/target/api/target_info_getter.h | 10 ++++++++ buildcc/lib/target/include/target/target.h | 3 --- .../lib/target/src/api/target_info_getter.cpp | 23 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/buildcc/lib/target/include/target/api/target_info_getter.h b/buildcc/lib/target/include/target/api/target_info_getter.h index 38e910d6..c3db01d4 100644 --- a/buildcc/lib/target/include/target/api/target_info_getter.h +++ b/buildcc/lib/target/include/target/api/target_info_getter.h @@ -19,6 +19,7 @@ #include "target/path.h" +#include "target/common/target_config.h" #include "target/common/target_state.h" namespace buildcc::base { @@ -26,6 +27,8 @@ namespace buildcc::base { // Requires // - TargetStorer // - TargetState +// - TargetEnv +// - TargetConfig template class TargetInfoGetter { public: // Target State @@ -33,6 +36,13 @@ template class TargetInfoGetter { bool GetBuildState() const; bool GetLockState() const; + // Target Env + const fs::path &GetTargetRootDir() const; + const fs::path &GetTargetBuildDir() const; + + // Target Config + const TargetConfig &GetConfig() const; + // Target Storer const internal::fs_unordered_set &GetCurrentSourceFiles() const; const internal::fs_unordered_set &GetCurrentHeaderFiles() const; diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index 67803252..6c9e5b09 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -100,9 +100,6 @@ class Target : public BuilderInterface, public TargetInfo { const std::string &GetName() const { return name_; } const Toolchain &GetToolchain() const { return toolchain_; } TargetType GetType() const { return type_; } - const fs::path &GetTargetRootDir() const { return env_.GetTargetRootDir(); } - const fs::path &GetTargetBuildDir() const { return env_.GetTargetBuildDir(); } - const TargetConfig &GetConfig() const { return config_; } // diff --git a/buildcc/lib/target/src/api/target_info_getter.cpp b/buildcc/lib/target/src/api/target_info_getter.cpp index dce1457d..66c7381e 100644 --- a/buildcc/lib/target/src/api/target_info_getter.cpp +++ b/buildcc/lib/target/src/api/target_info_getter.cpp @@ -39,6 +39,29 @@ template bool TargetInfoGetter::GetLockState() const { return t.state_.lock; } +// Target Env +template +const fs::path &TargetInfoGetter::GetTargetRootDir() const { + const T &t = static_cast(*this); + + return t.env_.GetTargetRootDir(); +} + +template +const fs::path &TargetInfoGetter::GetTargetBuildDir() const { + const T &t = static_cast(*this); + + return t.env_.GetTargetBuildDir(); +} + +// Target Config +template +const TargetConfig &TargetInfoGetter::GetConfig() const { + const T &t = static_cast(*this); + + return t.config_; +} + // Target Storer template const internal::fs_unordered_set & From fa3811d439fe794bd5bf81e43b592187ea5e7eda Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Thu, 18 Nov 2021 04:18:35 -0800 Subject: [PATCH 10/10] Minor updates --- .../lib/target/include/target/common/target_state.h | 11 +++++------ buildcc/lib/target/include/target/target.h | 9 +++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/buildcc/lib/target/include/target/common/target_state.h b/buildcc/lib/target/include/target/common/target_state.h index 2b75d084..49affaba 100644 --- a/buildcc/lib/target/include/target/common/target_state.h +++ b/buildcc/lib/target/include/target/common/target_state.h @@ -22,6 +22,10 @@ namespace buildcc::base { // 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 SetSourceState(TargetFileExt file_extension); void SetPch(); @@ -29,14 +33,9 @@ struct TargetState { void ExpectsUnlock() const; void ExpectsLock() const; + // TODO, IsLocked bool ContainsPch() const { return contains_pch_; } - // TODO, ContainsAsm - // TODO, ContainsC - // TODO, ContainsCpp - - // TODO, IsLocked - // TODO, IsBuilt // TODO, Make these private getters bool contains_asm{false}; diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index 6c9e5b09..98a4548d 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -155,7 +155,10 @@ class Target : public BuilderInterface, public TargetInfo { // Fbs bool Store() override; - // Callbacks + // Tasks + void TaskDeps(); + + // Callbacks for unit tests void SourceRemoved(); void SourceAdded(); void SourceUpdated(); @@ -167,15 +170,13 @@ class Target : public BuilderInterface, public TargetInfo { void FlagChanged(); void ExternalLibChanged(); - void TaskDeps(); - private: std::string name_; TargetType type_; const Toolchain &toolchain_; internal::TargetLoader loader_; - // Friend + // Friend classes CompilePch compile_pch_; CompileObject compile_object_; LinkTarget link_target_;