From 0102a4a322123e3a3cd4eaec7b78973b7c1c5589 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 04:11:43 -0800 Subject: [PATCH 1/6] Update lib_api --- buildcc/lib/target/include/target/api/lib_api.h | 4 +++- buildcc/lib/target/src/api/lib_api.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/buildcc/lib/target/include/target/api/lib_api.h b/buildcc/lib/target/include/target/api/lib_api.h index 1566bf10..c787a4bb 100644 --- a/buildcc/lib/target/include/target/api/lib_api.h +++ b/buildcc/lib/target/include/target/api/lib_api.h @@ -24,6 +24,8 @@ namespace fs = std::filesystem; namespace buildcc::base { +class Target; + // Requires // - TargetStorer // - TargetState @@ -31,7 +33,7 @@ namespace buildcc::base { // T::GetTargetPath template class LibApi { public: - void AddLibDep(const T &lib_dep); + void AddLibDep(const Target &lib_dep); void AddLibDep(const std::string &lib_dep); void AddLibDir(const fs::path &relative_lib_dir); diff --git a/buildcc/lib/target/src/api/lib_api.cpp b/buildcc/lib/target/src/api/lib_api.cpp index e8e1bfaa..290f93b8 100644 --- a/buildcc/lib/target/src/api/lib_api.cpp +++ b/buildcc/lib/target/src/api/lib_api.cpp @@ -36,7 +36,7 @@ void LibApi::AddLibDirAbsolute(const fs::path &absolute_lib_dir) { t.storer_.current_lib_dirs.insert(absolute_lib_dir); } -template void LibApi::AddLibDep(const T &lib_dep) { +template void LibApi::AddLibDep(const Target &lib_dep) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); From f151f650ca647b22bbe49e6ecf6efadeb8e4c602 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 18:44:13 -0800 Subject: [PATCH 2/6] Added PchAPI --- buildcc/lib/target/cmake/mock_target.cmake | 1 + buildcc/lib/target/cmake/target.cmake | 2 + .../lib/target/include/target/api/pch_api.h | 35 ++++++++++++++ buildcc/lib/target/src/api/pch_api.cpp | 48 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 buildcc/lib/target/include/target/api/pch_api.h create mode 100644 buildcc/lib/target/src/api/pch_api.cpp diff --git a/buildcc/lib/target/cmake/mock_target.cmake b/buildcc/lib/target/cmake/mock_target.cmake index 36c6ebc9..c0a5b143 100644 --- a/buildcc/lib/target/cmake/mock_target.cmake +++ b/buildcc/lib/target/cmake/mock_target.cmake @@ -11,6 +11,7 @@ add_library(mock_target STATIC src/api/source_api.cpp src/api/include_api.cpp src/api/lib_api.cpp + src/api/pch_api.cpp # Generator src/generator/generator_loader.cpp diff --git a/buildcc/lib/target/cmake/target.cmake b/buildcc/lib/target/cmake/target.cmake index 7ee43969..c6b12559 100644 --- a/buildcc/lib/target/cmake/target.cmake +++ b/buildcc/lib/target/cmake/target.cmake @@ -22,10 +22,12 @@ set(TARGET_SRCS src/api/source_api.cpp src/api/include_api.cpp src/api/lib_api.cpp + src/api/pch_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 # Generator src/generator/generator_loader.cpp diff --git a/buildcc/lib/target/include/target/api/pch_api.h b/buildcc/lib/target/include/target/api/pch_api.h new file mode 100644 index 00000000..9a67d395 --- /dev/null +++ b/buildcc/lib/target/include/target/api/pch_api.h @@ -0,0 +1,35 @@ +/* + * 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_PCH_API_H_ +#define TARGET_API_PCH_API_H_ + +#include + +namespace fs = std::filesystem; + +namespace buildcc::base { + +template class PchApi { +public: + void AddPch(const fs::path &relative_filename, + const fs::path &relative_to_target_path = ""); + void AddPchAbsolute(const fs::path &absolute_filepath); +}; + +} // namespace buildcc::base + +#endif \ No newline at end of file diff --git a/buildcc/lib/target/src/api/pch_api.cpp b/buildcc/lib/target/src/api/pch_api.cpp new file mode 100644 index 00000000..e439259e --- /dev/null +++ b/buildcc/lib/target/src/api/pch_api.cpp @@ -0,0 +1,48 @@ +/* + * 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/pch_api.h" + +#include "target/target.h" + +namespace buildcc::base { + +template +void PchApi::AddPchAbsolute(const fs::path &absolute_filepath) { + T &t = static_cast(*this); + + t.state_.ExpectsUnlock(); + t.config_.ExpectsValidHeader(absolute_filepath); + + const fs::path absolute_pch = fs::path(absolute_filepath).make_preferred(); + t.storer_.current_pch_files.user.insert(absolute_pch); +} + +template +void PchApi::AddPch(const fs::path &relative_filename, + const fs::path &relative_to_target_path) { + T &t = static_cast(*this); + + // Compute the absolute source path + fs::path absolute_pch = + t.env_.GetTargetRootDir() / relative_to_target_path / relative_filename; + + AddPchAbsolute(absolute_pch); +} + +template class PchApi; + +} // namespace buildcc::base \ No newline at end of file From fc03480f8a0da459bf9172a09e2e1dce1a006e56 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 18:44:21 -0800 Subject: [PATCH 3/6] Update target.h --- buildcc/lib/target/include/target/target.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index 1124e39d..dcd2a9e5 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -40,6 +40,7 @@ #include "target/api/copy_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 @@ -71,7 +72,8 @@ class Target : public BuilderInterface, public CopyApi, public SourceApi, public IncludeApi, - public LibApi { + public LibApi, + public PchApi { public: explicit Target(const std::string &name, TargetType type, @@ -93,11 +95,6 @@ class Target : public BuilderInterface, // Setters - // PCH - void AddPch(const fs::path &relative_filename, - const fs::path &relative_to_target_path = ""); - void AddPchAbsolute(const fs::path &absolute_filepath); - // * Flags void AddPreprocessorFlag(const std::string &flag); void AddCommonCompileFlag(const std::string &flag); @@ -231,6 +228,7 @@ class Target : public BuilderInterface, friend class SourceApi; friend class IncludeApi; friend class LibApi; + friend class PchApi; private: void Initialize(); From d0d4f5d7c13c4044b08ad458e63b216004f7ea0d Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 18:45:25 -0800 Subject: [PATCH 4/6] Removed pch.cpp --- buildcc/lib/target/cmake/mock_target.cmake | 1 - buildcc/lib/target/cmake/target.cmake | 1 - buildcc/lib/target/src/target/pch.cpp | 42 ---------------------- 3 files changed, 44 deletions(-) delete mode 100644 buildcc/lib/target/src/target/pch.cpp diff --git a/buildcc/lib/target/cmake/mock_target.cmake b/buildcc/lib/target/cmake/mock_target.cmake index c0a5b143..2080d12e 100644 --- a/buildcc/lib/target/cmake/mock_target.cmake +++ b/buildcc/lib/target/cmake/mock_target.cmake @@ -32,7 +32,6 @@ add_library(mock_target STATIC src/target/target_loader.cpp src/target/target_storer.cpp - src/target/pch.cpp src/target/flags.cpp src/target/additional_deps.cpp diff --git a/buildcc/lib/target/cmake/target.cmake b/buildcc/lib/target/cmake/target.cmake index c6b12559..34cd5646 100644 --- a/buildcc/lib/target/cmake/target.cmake +++ b/buildcc/lib/target/cmake/target.cmake @@ -54,7 +54,6 @@ set(TARGET_SRCS include/target/target_storer.h include/target/target.h - src/target/pch.cpp src/target/flags.cpp src/target/additional_deps.cpp diff --git a/buildcc/lib/target/src/target/pch.cpp b/buildcc/lib/target/src/target/pch.cpp deleted file mode 100644 index 4683e513..00000000 --- a/buildcc/lib/target/src/target/pch.cpp +++ /dev/null @@ -1,42 +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::AddPchAbsolute(const fs::path &absolute_filepath) { - state_.ExpectsUnlock(); - env::assert_fatal(config_.IsValidHeader(absolute_filepath), - fmt::format("{} does not have a valid header extension", - absolute_filepath)); - - const fs::path absolute_pch = fs::path(absolute_filepath).make_preferred(); - storer_.current_pch_files.user.insert(absolute_pch); -} - -void Target::AddPch(const fs::path &relative_filename, - const fs::path &relative_to_target_path) { - env::log_trace(name_, __FUNCTION__); - - // Compute the absolute source path - fs::path absolute_pch = - GetTargetRootDir() / relative_to_target_path / relative_filename; - - AddPchAbsolute(absolute_pch); -} - -} // namespace buildcc::base From 8feff41452f682ca0d43085fedd0837f6490248e Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 18:45:31 -0800 Subject: [PATCH 5/6] Update README.md --- buildcc/lib/target/src/target/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/buildcc/lib/target/src/target/README.md b/buildcc/lib/target/src/target/README.md index 3633ab0f..27f90dba 100644 --- a/buildcc/lib/target/src/target/README.md +++ b/buildcc/lib/target/src/target/README.md @@ -24,7 +24,8 @@ Check the `include/target/api` and `src/api` folder - `include_api` - [x] Lib and Lib Dir - `lib_api` -- [ ] PCH +- [x] PCH + - `pch_api` - [ ] Flags - [ ] Rebuild Deps - [ ] Getters @@ -32,8 +33,6 @@ Check the `include/target/api` and `src/api` folder ## Inputs to Target -- [x] `pch.cpp` - - Precompile Header files - [x] `flags.cpp` - PreprocessorFlags - CommonCompileFlags From 960053d937c201ce8c044ece6aa587b2c486f730 Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 17 Nov 2021 18:46:20 -0800 Subject: [PATCH 6/6] Update pch_api.h --- buildcc/lib/target/include/target/api/pch_api.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/buildcc/lib/target/include/target/api/pch_api.h b/buildcc/lib/target/include/target/api/pch_api.h index 9a67d395..345574b0 100644 --- a/buildcc/lib/target/include/target/api/pch_api.h +++ b/buildcc/lib/target/include/target/api/pch_api.h @@ -23,6 +23,11 @@ namespace fs = std::filesystem; namespace buildcc::base { +// Requires +// - TargetStorer +// - TargetState +// - TargetConfig +// - TargetEnv template class PchApi { public: void AddPch(const fs::path &relative_filename,