From 2a083fab09f4b50810910728da0b1e64f6bfda3e Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 22:57:06 -0800 Subject: [PATCH 1/3] Added crtp deps api Removed additional deps --- buildcc/lib/target/cmake/mock_target.cmake | 3 +- buildcc/lib/target/cmake/target.cmake | 4 +- .../lib/target/include/target/api/deps_api.h | 40 +++++++++++++ buildcc/lib/target/src/api/deps_api.cpp | 56 +++++++++++++++++++ .../lib/target/src/target/additional_deps.cpp | 39 ------------- 5 files changed, 99 insertions(+), 43 deletions(-) create mode 100644 buildcc/lib/target/include/target/api/deps_api.h create mode 100644 buildcc/lib/target/src/api/deps_api.cpp delete mode 100644 buildcc/lib/target/src/target/additional_deps.cpp diff --git a/buildcc/lib/target/cmake/mock_target.cmake b/buildcc/lib/target/cmake/mock_target.cmake index b450aa4d..96d037c9 100644 --- a/buildcc/lib/target/cmake/mock_target.cmake +++ b/buildcc/lib/target/cmake/mock_target.cmake @@ -13,6 +13,7 @@ add_library(mock_target STATIC src/api/lib_api.cpp src/api/pch_api.cpp src/api/flag_api.cpp + src/api/deps_api.cpp # Generator src/generator/generator_loader.cpp @@ -33,8 +34,6 @@ add_library(mock_target STATIC src/target/target_loader.cpp src/target/target_storer.cpp - src/target/additional_deps.cpp - src/target/build.cpp # Target mocks diff --git a/buildcc/lib/target/cmake/target.cmake b/buildcc/lib/target/cmake/target.cmake index eaae6721..16b3c190 100644 --- a/buildcc/lib/target/cmake/target.cmake +++ b/buildcc/lib/target/cmake/target.cmake @@ -24,12 +24,14 @@ set(TARGET_SRCS 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 include/target/api/pch_api.h include/target/api/flag_api.h + include/target/api/deps_api.h # Generator src/generator/generator_loader.cpp @@ -56,8 +58,6 @@ set(TARGET_SRCS include/target/target_storer.h include/target/target.h - src/target/additional_deps.cpp - src/target/recheck_states.cpp src/target/build.cpp diff --git a/buildcc/lib/target/include/target/api/deps_api.h b/buildcc/lib/target/include/target/api/deps_api.h new file mode 100644 index 00000000..2fd4e7cb --- /dev/null +++ b/buildcc/lib/target/include/target/api/deps_api.h @@ -0,0 +1,40 @@ +/* + * 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_DEPS_API_H_ +#define TARGET_API_DEPS_API_H_ + +#include + +namespace fs = std::filesystem; + +namespace buildcc::base { + +// Requires +// - TargetStorer +// - TargetState +// - TargetEnv +template class DepsApi { +public: + void AddCompileDependency(const fs::path &relative_path); + void AddCompileDependencyAbsolute(const fs::path &absolute_path); + void AddLinkDependency(const fs::path &relative_path); + void AddLinkDependencyAbsolute(const fs::path &absolute_path); +}; + +} // namespace buildcc::base + +#endif diff --git a/buildcc/lib/target/src/api/deps_api.cpp b/buildcc/lib/target/src/api/deps_api.cpp new file mode 100644 index 00000000..ff6b51d4 --- /dev/null +++ b/buildcc/lib/target/src/api/deps_api.cpp @@ -0,0 +1,56 @@ +/* + * 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/deps_api.h" + +#include "target/target.h" + +namespace buildcc::base { + +template +void DepsApi::AddCompileDependencyAbsolute(const fs::path &absolute_path) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_compile_dependencies.user.insert(absolute_path); +} +template +void DepsApi::AddLinkDependencyAbsolute(const fs::path &absolute_path) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.storer_.current_link_dependencies.user.insert(absolute_path); +} + +template +void DepsApi::AddCompileDependency(const fs::path &relative_path) { + T &t = static_cast(*this); + + fs::path absolute_path = t.env_.GetTargetRootDir() / relative_path; + AddCompileDependencyAbsolute(absolute_path); +} + +template +void DepsApi::AddLinkDependency(const fs::path &relative_path) { + T &t = static_cast(*this); + + fs::path absolute_path = t.env_.GetTargetRootDir() / relative_path; + AddLinkDependencyAbsolute(absolute_path); +} + +template class DepsApi; + +} // namespace buildcc::base diff --git a/buildcc/lib/target/src/target/additional_deps.cpp b/buildcc/lib/target/src/target/additional_deps.cpp deleted file mode 100644 index 79579e2f..00000000 --- a/buildcc/lib/target/src/target/additional_deps.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/target.h" - -namespace buildcc::base { - -void Target::AddCompileDependencyAbsolute(const fs::path &absolute_path) { - state_.ExpectsUnlock(); - storer_.current_compile_dependencies.user.insert(absolute_path); -} -void Target::AddLinkDependencyAbsolute(const fs::path &absolute_path) { - state_.ExpectsUnlock(); - storer_.current_link_dependencies.user.insert(absolute_path); -} - -void Target::AddCompileDependency(const fs::path &relative_path) { - fs::path absolute_path = GetTargetRootDir() / relative_path; - AddCompileDependencyAbsolute(absolute_path); -} -void Target::AddLinkDependency(const fs::path &relative_path) { - fs::path absolute_path = GetTargetRootDir() / relative_path; - AddLinkDependencyAbsolute(absolute_path); -} - -} // namespace buildcc::base From 4a6a77341a1a097f54fea5bf8ac8428340a9bd27 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 22:57:21 -0800 Subject: [PATCH 2/3] Update flag_api.h --- buildcc/lib/target/include/target/api/flag_api.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/buildcc/lib/target/include/target/api/flag_api.h b/buildcc/lib/target/include/target/api/flag_api.h index 576a7159..3591ecf8 100644 --- a/buildcc/lib/target/include/target/api/flag_api.h +++ b/buildcc/lib/target/include/target/api/flag_api.h @@ -21,6 +21,9 @@ namespace buildcc::base { +// Requires +// - TargetStorer +// - TargetState template class FlagApi { public: void AddPreprocessorFlag(const std::string &flag); From 7c96b92d3be946e4d8086572d94df0e72f6e1dad Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 22:57:28 -0800 Subject: [PATCH 3/3] Update target.h --- buildcc/lib/target/include/target/target.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index 3473fefc..f01786bc 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -38,6 +38,7 @@ // 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" @@ -75,7 +76,8 @@ class Target : public BuilderInterface, public IncludeApi, public LibApi, public PchApi, - public FlagApi { + public FlagApi, + public DepsApi { public: explicit Target(const std::string &name, TargetType type, @@ -95,14 +97,6 @@ class Target : public BuilderInterface, // Builders void Build() override; - // Setters - - // * Rebuild - void AddCompileDependency(const fs::path &relative_path); - void AddCompileDependencyAbsolute(const fs::path &absolute_path); - void AddLinkDependency(const fs::path &relative_path); - void AddLinkDependencyAbsolute(const fs::path &absolute_path); - // TODO, Add more setters // @@ -222,6 +216,7 @@ class Target : public BuilderInterface, friend class LibApi; friend class PchApi; friend class FlagApi; + friend class DepsApi; private: void Initialize();