From bcaa8b4e29ffe97296fe811e5a61286d3b8160fb Mon Sep 17 00:00:00 2001 From: coder137 Date: Sat, 5 Feb 2022 20:38:59 -0800 Subject: [PATCH 01/19] Updated header include in toolchain_setup.cpp --- buildexe/src/toolchain_setup.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildexe/src/toolchain_setup.cpp b/buildexe/src/toolchain_setup.cpp index e9bfe0e1..198bf40d 100644 --- a/buildexe/src/toolchain_setup.cpp +++ b/buildexe/src/toolchain_setup.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "buildexe/toolchain_setup.h" + namespace { constexpr const char *const kTag = "BuildExe"; From 5d63b5125b14b31f4029d3035f6432ff75460225 Mon Sep 17 00:00:00 2001 From: coder137 Date: Mon, 7 Feb 2022 03:04:18 -0800 Subject: [PATCH 02/19] Added serialization interface --- .../interface/serialization_interface.h | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 buildcc/lib/target/include/target/interface/serialization_interface.h diff --git a/buildcc/lib/target/include/target/interface/serialization_interface.h b/buildcc/lib/target/include/target/interface/serialization_interface.h new file mode 100644 index 00000000..819d4121 --- /dev/null +++ b/buildcc/lib/target/include/target/interface/serialization_interface.h @@ -0,0 +1,71 @@ +/* + * 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. + */ + +#include + +#include "env/assert_fatal.h" +#include "env/util.h" + +#include "target/common/path.h" + +namespace fs = std::filesystem; + +namespace buildcc::internal { + +class SerializationInterface { +public: + SerializationInterface(const fs::path serialized_file) + : serialized_file_(serialized_file) {} + virtual ~SerializationInterface() {} + + bool LoadFromFile() { + std::string buffer; + + // Read from serialized file + bool is_loaded = + env::load_file(path_as_string(serialized_file_).c_str(), true, &buffer); + if (!is_loaded) { + return false; + } + + // Verify serialized data as per schema + if (!Verify(buffer)) { + return false; + } + + // Load serialized data as C++ data + loaded_ = Load(buffer); + return loaded_; + } + + bool StoreToFile() { return Store(serialized_file_); } + + const fs::path &GetSerializedFile() const noexcept { + return serialized_file_; + } + bool IsLoaded() const noexcept { return loaded_; } + +private: + virtual bool Verify(const std::string &serialized_data) = 0; + virtual bool Load(const std::string &serialized_data) = 0; + virtual bool Store(const fs::path &absolute_serialized_file) = 0; + +private: + fs::path serialized_file_; + bool loaded_{false}; +}; + +} // namespace buildcc::internal From 12242f2536bb115fe42934926d47d80ed849e983 Mon Sep 17 00:00:00 2001 From: coder137 Date: Mon, 7 Feb 2022 03:05:04 -0800 Subject: [PATCH 03/19] Added generator_serialization interface - Contains cmake updates --- .../lib/target/cmake/common_target_src.cmake | 6 +- .../serialization/generator_serialization.h | 59 ++++++++++++++ .../src/generator/generator_serialization.cpp | 77 +++++++++++++++++++ 3 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 buildcc/lib/target/include/target/serialization/generator_serialization.h create mode 100644 buildcc/lib/target/src/generator/generator_serialization.cpp diff --git a/buildcc/lib/target/cmake/common_target_src.cmake b/buildcc/lib/target/cmake/common_target_src.cmake index 5a662c46..c13e6db3 100644 --- a/buildcc/lib/target/cmake/common_target_src.cmake +++ b/buildcc/lib/target/cmake/common_target_src.cmake @@ -2,6 +2,7 @@ set(COMMON_TARGET_SRCS # Interfaces include/target/interface/loader_interface.h include/target/interface/builder_interface.h + include/target/interface/serialization_interface.h # Common src/common/target_config.cpp @@ -40,9 +41,8 @@ set(COMMON_TARGET_SRCS include/target/api/target_getter.h # Base Generator - src/generator/generator_loader.cpp - src/generator/generator_storer.cpp - include/target/base/generator_loader.h + src/generator/generator_serialization.cpp + include/target/serialization/generator_serialization.h # Generator src/generator/generator.cpp diff --git a/buildcc/lib/target/include/target/serialization/generator_serialization.h b/buildcc/lib/target/include/target/serialization/generator_serialization.h new file mode 100644 index 00000000..e78f1678 --- /dev/null +++ b/buildcc/lib/target/include/target/serialization/generator_serialization.h @@ -0,0 +1,59 @@ +/* + * 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. + */ + +#include "target/interface/serialization_interface.h" + +#include +#include +#include + +#include "target/common/path.h" + +namespace buildcc::internal { + +struct GeneratorSchema { + std::string name; + path_unordered_set internal_inputs; + fs_unordered_set outputs; + std::vector commands; +}; + +class GeneratorSerialization : public SerializationInterface { +public: + GeneratorSerialization(const fs::path &serialized_file) + : SerializationInterface(serialized_file) {} + + void UpdateStore(const GeneratorSchema &store); + + const path_unordered_set &GetLoadInputs() const { + return load_.internal_inputs; + } + const fs_unordered_set &GetLoadOutputs() const { return load_.outputs; } + const std::vector &GetLoadCommands() const { + return load_.commands; + } + +private: + bool Verify(const std::string &serialized_data) override; + bool Load(const std::string &serialized_data) override; + bool Store(const fs::path &absolute_serialized_file) override; + +private: + GeneratorSchema load_; + GeneratorSchema store_; +}; + +} // namespace buildcc::internal diff --git a/buildcc/lib/target/src/generator/generator_serialization.cpp b/buildcc/lib/target/src/generator/generator_serialization.cpp new file mode 100644 index 00000000..d85cb0d0 --- /dev/null +++ b/buildcc/lib/target/src/generator/generator_serialization.cpp @@ -0,0 +1,77 @@ +/* + * 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. + */ + +#include "target/serialization/generator_serialization.h" + +// Third party +#include "flatbuffers/flatbuffers.h" + +// Private +#include "target/private/schema_util.h" + +// Schema generated +#include "generator_generated.h" + +namespace buildcc::internal { + +// PUBLIC + +void GeneratorSerialization::UpdateStore(const GeneratorSchema &store) { + store_ = store; +} + +// PRIVATE + +bool GeneratorSerialization::Verify(const std::string &serialized_data) { + flatbuffers::Verifier verifier((const uint8_t *)serialized_data.c_str(), + serialized_data.length()); + return fbs::VerifyGeneratorBuffer(verifier); +} + +bool GeneratorSerialization::Load(const std::string &serialized_data) { + const auto *generator = + fbs::GetGenerator((const void *)serialized_data.c_str()); + if (generator == nullptr) { + return false; + } + + extract_path(generator->inputs(), load_.internal_inputs); + extract(generator->outputs(), load_.outputs); + extract(generator->commands(), load_.commands); + return true; +} + +bool GeneratorSerialization::Store(const fs::path &absolute_serialized_file) { + flatbuffers::FlatBufferBuilder builder; + + auto fbs_input_files = + internal::create_fbs_vector_path(builder, store_.internal_inputs); + auto fbs_output_files = + internal::create_fbs_vector_string(builder, store_.outputs); + auto fbs_commands = + internal::create_fbs_vector_string(builder, store_.commands); + + auto fbs_generator = + fbs::CreateGeneratorDirect(builder, store_.name.c_str(), &fbs_input_files, + &fbs_output_files, &fbs_commands); + fbs::FinishGeneratorBuffer(builder, fbs_generator); + + return env::save_file(path_as_string(absolute_serialized_file).c_str(), + (const char *)builder.GetBufferPointer(), + builder.GetSize(), true); +} + +} // namespace buildcc::internal From 8259f1e587daa3de45149ef8cd4e1ca79e591d5c Mon Sep 17 00:00:00 2001 From: coder137 Date: Mon, 7 Feb 2022 03:05:42 -0800 Subject: [PATCH 04/19] Added path_schema_convert free functions --- .../lib/target/include/target/common/path.h | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/buildcc/lib/target/include/target/common/path.h b/buildcc/lib/target/include/target/common/path.h index faa6e0f8..7b8f131b 100644 --- a/buildcc/lib/target/include/target/common/path.h +++ b/buildcc/lib/target/include/target/common/path.h @@ -142,6 +142,25 @@ class PathHash { typedef std::unordered_set path_unordered_set; typedef std::unordered_set fs_unordered_set; +inline path_unordered_set +path_schema_convert(const fs_unordered_set &path_set, + const std::function &cb) { + path_unordered_set internal_path_set; + for (const auto &p : path_set) { + internal_path_set.insert(cb(p)); + } + return internal_path_set; +} + +inline fs_unordered_set +path_schema_convert(const path_unordered_set &internal_path_set) { + fs_unordered_set path_set; + for (const auto &p : internal_path_set) { + path_set.insert(p.GetPathname()); + } + return path_set; +} + // * Relation between // - internal timestamp verified files (Path + Timestamp) // - user facing file paths (Only Path) @@ -152,12 +171,11 @@ typedef std::unordered_set fs_unordered_set; // We must only verify the File timestamp AFTER dependent Generator(s) / // Target(s) have been built // ? Why not do everything inside path_unordered_set? -// Users might want to query just the `fs_unordered_set` instead of the entire -// internal::path_unordered_set (The timestamp is internal information that the -// user does not need) -// In this case we opt for runtime (speed) optimization instead of memory -// optimization by caching the `user` information and `internal` information -// together +// Users might want to query just the `fs_unordered_set` instead of the +// entire internal::path_unordered_set (The timestamp is internal +// information that the user does not need) In this case we opt for runtime +// (speed) optimization instead of memory optimization by caching the `user` +// information and `internal` information together struct RelationalPathFiles { RelationalPathFiles() {} RelationalPathFiles(const path_unordered_set &i, const fs_unordered_set &u) @@ -173,9 +191,7 @@ struct RelationalPathFiles { } done_once = true; - for (const auto &p : user) { - internal.emplace(Path::CreateExistingPath(p)); - } + internal = path_schema_convert(user, Path::CreateExistingPath); } public: From e0e77ea8085982559df09772e0ac42aec6b974fd Mon Sep 17 00:00:00 2001 From: coder137 Date: Mon, 7 Feb 2022 03:06:10 -0800 Subject: [PATCH 05/19] Updated generator with new schema --- buildcc/lib/target/include/target/generator.h | 19 ++++++----- .../lib/target/src/generator/generator.cpp | 32 +++++++++++++------ .../target/src/generator/generator_storer.cpp | 27 +--------------- buildcc/lib/target/src/generator/task.cpp | 20 ++++++------ 4 files changed, 45 insertions(+), 53 deletions(-) diff --git a/buildcc/lib/target/include/target/generator.h b/buildcc/lib/target/include/target/generator.h index 0a9b463b..fa6d25f6 100644 --- a/buildcc/lib/target/include/target/generator.h +++ b/buildcc/lib/target/include/target/generator.h @@ -33,6 +33,7 @@ #include "target/interface/builder_interface.h" #include "target/base/generator_loader.h" +#include "target/serialization/generator_serialization.h" #include "target/common/path.h" #include "target/common/target_env.h" @@ -45,7 +46,8 @@ class Generator : public internal::BuilderInterface { bool parallel = false) : name_(name), generator_root_dir_(env.GetTargetRootDir()), generator_build_dir_(env.GetTargetBuildDir() / name), - loader_(name, generator_build_dir_), parallel_(parallel) { + serialization_(generator_build_dir_ / fmt::format("{}.bin", name)), + parallel_(parallel) { Initialize(); } virtual ~Generator() {} @@ -101,7 +103,9 @@ class Generator : public internal::BuilderInterface { void Build() override; // Getter - const fs::path &GetBinaryPath() const { return loader_.GetBinaryPath(); } + const fs::path &GetBinaryPath() const { + return serialization_.GetSerializedFile(); + } tf::Taskflow &GetTaskflow() { return tf_; } const std::string &GetName() const { return name_; } @@ -117,7 +121,7 @@ class Generator : public internal::BuilderInterface { void Convert(); void BuildGenerate(); - bool Store() override; + bool Store() override { return false; } // Recheck states void InputRemoved(); @@ -132,13 +136,12 @@ class Generator : public internal::BuilderInterface { std::string name_; fs::path generator_root_dir_; fs::path generator_build_dir_; - internal::GeneratorLoader loader_; + internal::GeneratorSerialization serialization_; + bool parallel_{false}; // Serialization - internal::RelationalPathFiles current_input_files_; - fs_unordered_set current_output_files_; - std::vector current_commands_; - bool parallel_{false}; + fs_unordered_set user_inputs_; + internal::GeneratorSchema user_; // Internal std::mutex task_state_mutex_; diff --git a/buildcc/lib/target/src/generator/generator.cpp b/buildcc/lib/target/src/generator/generator.cpp index caa2ada9..df7ea4b8 100644 --- a/buildcc/lib/target/src/generator/generator.cpp +++ b/buildcc/lib/target/src/generator/generator.cpp @@ -33,7 +33,7 @@ void Generator::AddInput(const std::string &absolute_input_pattern, command_.Construct(absolute_input_pattern); const auto absolute_input_path = internal::Path::CreateNewPath(absolute_input_string); - current_input_files_.user.insert(absolute_input_path.GetPathname()); + user_inputs_.insert(absolute_input_path.GetPathname()); if (identifier != nullptr) { command_.AddDefaultArgument(identifier, @@ -47,7 +47,7 @@ void Generator::AddOutput(const std::string &absolute_output_pattern, command_.Construct(absolute_output_pattern); const auto absolute_output_path = internal::Path::CreateNewPath(absolute_output_string); - current_output_files_.insert(absolute_output_path.GetPathname()); + user_.outputs.insert(absolute_output_path.GetPathname()); if (identifier != nullptr) { command_.AddDefaultArgument(identifier, @@ -60,11 +60,12 @@ void Generator::AddCommand( const std::unordered_map &arguments) { std::string constructed_command = command_.Construct(command_pattern, arguments); - current_commands_.emplace_back(std::move(constructed_command)); + user_.commands.emplace_back(std::move(constructed_command)); } void Generator::Build() { - (void)loader_.Load(); + // (void)loader_.Load(); + (void)serialization_.LoadFromFile(); GenerateTask(); } @@ -94,19 +95,32 @@ void Generator::Initialize() { tf_.name(name_); } -void Generator::Convert() { current_input_files_.Convert(); } +void Generator::Convert() { + user_.internal_inputs = internal::path_schema_convert( + user_inputs_, internal::Path::CreateExistingPath); +} void Generator::BuildGenerate() { - if (!loader_.IsLoaded()) { + // if (!loader_.IsLoaded()) { + if (!serialization_.IsLoaded()) { dirty_ = true; } else { + // RecheckPaths( + // loader_.GetLoadedInputFiles(), current_input_files_.internal, + // [&]() { InputRemoved(); }, [&]() { InputAdded(); }, + // [&]() { InputUpdated(); }); + // RecheckChanged(loader_.GetLoadedOutputFiles(), current_output_files_, + // [&]() { OutputChanged(); }); + // RecheckChanged(loader_.GetLoadedCommands(), current_commands_, + // [&]() { CommandChanged(); }); + RecheckPaths( - loader_.GetLoadedInputFiles(), current_input_files_.internal, + serialization_.GetLoadInputs(), user_.internal_inputs, [&]() { InputRemoved(); }, [&]() { InputAdded(); }, [&]() { InputUpdated(); }); - RecheckChanged(loader_.GetLoadedOutputFiles(), current_output_files_, + RecheckChanged(serialization_.GetLoadOutputs(), user_.outputs, [&]() { OutputChanged(); }); - RecheckChanged(loader_.GetLoadedCommands(), current_commands_, + RecheckChanged(serialization_.GetLoadCommands(), user_.commands, [&]() { CommandChanged(); }); } } diff --git a/buildcc/lib/target/src/generator/generator_storer.cpp b/buildcc/lib/target/src/generator/generator_storer.cpp index a652e5ff..2ba589e7 100644 --- a/buildcc/lib/target/src/generator/generator_storer.cpp +++ b/buildcc/lib/target/src/generator/generator_storer.cpp @@ -25,29 +25,4 @@ namespace fbs = schema::internal; -namespace buildcc { - -bool Generator::Store() { - env::log_trace(name_, __FUNCTION__); - - flatbuffers::FlatBufferBuilder builder; - - auto fbs_input_files = - internal::create_fbs_vector_path(builder, current_input_files_.internal); - auto fbs_output_files = - internal::create_fbs_vector_string(builder, current_output_files_); - auto fbs_commands = - internal::create_fbs_vector_string(builder, current_commands_); - - auto fbs_generator = - fbs::CreateGeneratorDirect(builder, name_.c_str(), &fbs_input_files, - &fbs_output_files, &fbs_commands); - fbs::FinishGeneratorBuffer(builder, fbs_generator); - - const fs::path file_path = GetBinaryPath(); - return env::save_file(path_as_string(file_path).c_str(), - (const char *)builder.GetBufferPointer(), - builder.GetSize(), true); -} - -} // namespace buildcc +namespace buildcc {} // namespace buildcc diff --git a/buildcc/lib/target/src/generator/task.cpp b/buildcc/lib/target/src/generator/task.cpp index 8ee2fb8c..1845a58f 100644 --- a/buildcc/lib/target/src/generator/task.cpp +++ b/buildcc/lib/target/src/generator/task.cpp @@ -62,11 +62,11 @@ void Generator::GenerateTask() { tf::Task command_task; if (dirty_) { if (parallel_) { - command_task = subflow.for_each(current_commands_.cbegin(), - current_commands_.cend(), run_command); + command_task = subflow.for_each(user_.commands.cbegin(), + user_.commands.cend(), run_command); } else { command_task = subflow.emplace([&, run_command]() { - for (const auto &command : current_commands_) { + for (const auto &command : user_.commands) { run_command(command); } }); @@ -77,14 +77,14 @@ void Generator::GenerateTask() { command_task.name(kCommandTaskName); // Graph Generation - for (const auto &i : current_input_files_.user) { + for (const auto &i : user_inputs_) { std::string name = fmt::format("{}", i.lexically_relative(env::get_project_root_dir())); tf::Task task = subflow.placeholder().name(name); task.precede(command_task); } - for (const auto &o : current_output_files_) { + for (const auto &o : user_.outputs) { std::string name = fmt::format("{}", o.lexically_relative(env::get_project_root_dir())); tf::Task task = subflow.placeholder().name(name); @@ -103,15 +103,15 @@ void Generator::GenerateTask() { if (task_state_ == env::TaskState::SUCCESS) { if (dirty_) { try { - env::assert_throw(Store(), fmt::format("Store failed for {}", name_)); + serialization_.UpdateStore(user_); + env::assert_throw(serialization_.StoreToFile(), + fmt::format("Store failed for {}", name_)); } catch (...) { task_state_ = env::TaskState::FAILURE; } } - } - - // Update Env task state when NOT SUCCESS only - if (task_state_ != env::TaskState::SUCCESS) { + } else { + // not SUCCESS state env::set_task_state(task_state_); } }); From db0dcbe7d1c1ee0171c0da8ff32f9a079863d32f Mon Sep 17 00:00:00 2001 From: coder137 Date: Mon, 7 Feb 2022 03:17:28 -0800 Subject: [PATCH 06/19] Updated ifdefs --- .../include/target/interface/serialization_interface.h | 5 +++++ .../include/target/serialization/generator_serialization.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/buildcc/lib/target/include/target/interface/serialization_interface.h b/buildcc/lib/target/include/target/interface/serialization_interface.h index 819d4121..7cb71a70 100644 --- a/buildcc/lib/target/include/target/interface/serialization_interface.h +++ b/buildcc/lib/target/include/target/interface/serialization_interface.h @@ -14,6 +14,9 @@ * limitations under the License. */ +#ifndef TARGET_INTERFACE_SERIALIZATION_INTERFACE_H_ +#define TARGET_INTERFACE_SERIALIZATION_INTERFACE_H_ + #include #include "env/assert_fatal.h" @@ -69,3 +72,5 @@ class SerializationInterface { }; } // namespace buildcc::internal + +#endif diff --git a/buildcc/lib/target/include/target/serialization/generator_serialization.h b/buildcc/lib/target/include/target/serialization/generator_serialization.h index e78f1678..c4d5877e 100644 --- a/buildcc/lib/target/include/target/serialization/generator_serialization.h +++ b/buildcc/lib/target/include/target/serialization/generator_serialization.h @@ -14,6 +14,9 @@ * limitations under the License. */ +#ifndef TARGET_SERIALIZATION_GENERATOR_SERIALIZATION_H_ +#define TARGET_SERIALIZATION_GENERATOR_SERIALIZATION_H_ + #include "target/interface/serialization_interface.h" #include @@ -57,3 +60,5 @@ class GeneratorSerialization : public SerializationInterface { }; } // namespace buildcc::internal + +#endif From 61fb3159c64512ab41de914f2fbb455fbaffe0d3 Mon Sep 17 00:00:00 2001 From: coder137 Date: Mon, 7 Feb 2022 19:51:10 -0800 Subject: [PATCH 07/19] Minor generator updates --- buildcc/lib/target/include/target/generator.h | 8 ++++++-- .../serialization/generator_serialization.h | 2 +- buildcc/lib/target/src/generator/generator.cpp | 15 ++------------- .../src/generator/generator_serialization.cpp | 6 ------ buildcc/lib/target/src/generator/task.cpp | 2 +- 5 files changed, 10 insertions(+), 23 deletions(-) diff --git a/buildcc/lib/target/include/target/generator.h b/buildcc/lib/target/include/target/generator.h index fa6d25f6..6abcfe6d 100644 --- a/buildcc/lib/target/include/target/generator.h +++ b/buildcc/lib/target/include/target/generator.h @@ -40,6 +40,10 @@ namespace buildcc { +struct UserGeneratorSchema : public internal::GeneratorSchema { + fs_unordered_set inputs; +}; + class Generator : public internal::BuilderInterface { public: Generator(const std::string &name, const TargetEnv &env, @@ -121,6 +125,7 @@ class Generator : public internal::BuilderInterface { void Convert(); void BuildGenerate(); + // TODO, Remove this later bool Store() override { return false; } // Recheck states @@ -140,8 +145,7 @@ class Generator : public internal::BuilderInterface { bool parallel_{false}; // Serialization - fs_unordered_set user_inputs_; - internal::GeneratorSchema user_; + UserGeneratorSchema user_; // Internal std::mutex task_state_mutex_; diff --git a/buildcc/lib/target/include/target/serialization/generator_serialization.h b/buildcc/lib/target/include/target/serialization/generator_serialization.h index c4d5877e..45ad10d6 100644 --- a/buildcc/lib/target/include/target/serialization/generator_serialization.h +++ b/buildcc/lib/target/include/target/serialization/generator_serialization.h @@ -39,7 +39,7 @@ class GeneratorSerialization : public SerializationInterface { GeneratorSerialization(const fs::path &serialized_file) : SerializationInterface(serialized_file) {} - void UpdateStore(const GeneratorSchema &store); + void UpdateStore(const GeneratorSchema &store) { store_ = store; } const path_unordered_set &GetLoadInputs() const { return load_.internal_inputs; diff --git a/buildcc/lib/target/src/generator/generator.cpp b/buildcc/lib/target/src/generator/generator.cpp index df7ea4b8..dbe63e63 100644 --- a/buildcc/lib/target/src/generator/generator.cpp +++ b/buildcc/lib/target/src/generator/generator.cpp @@ -33,7 +33,7 @@ void Generator::AddInput(const std::string &absolute_input_pattern, command_.Construct(absolute_input_pattern); const auto absolute_input_path = internal::Path::CreateNewPath(absolute_input_string); - user_inputs_.insert(absolute_input_path.GetPathname()); + user_.inputs.insert(absolute_input_path.GetPathname()); if (identifier != nullptr) { command_.AddDefaultArgument(identifier, @@ -64,7 +64,6 @@ void Generator::AddCommand( } void Generator::Build() { - // (void)loader_.Load(); (void)serialization_.LoadFromFile(); GenerateTask(); @@ -97,23 +96,13 @@ void Generator::Initialize() { void Generator::Convert() { user_.internal_inputs = internal::path_schema_convert( - user_inputs_, internal::Path::CreateExistingPath); + user_.inputs, internal::Path::CreateExistingPath); } void Generator::BuildGenerate() { - // if (!loader_.IsLoaded()) { if (!serialization_.IsLoaded()) { dirty_ = true; } else { - // RecheckPaths( - // loader_.GetLoadedInputFiles(), current_input_files_.internal, - // [&]() { InputRemoved(); }, [&]() { InputAdded(); }, - // [&]() { InputUpdated(); }); - // RecheckChanged(loader_.GetLoadedOutputFiles(), current_output_files_, - // [&]() { OutputChanged(); }); - // RecheckChanged(loader_.GetLoadedCommands(), current_commands_, - // [&]() { CommandChanged(); }); - RecheckPaths( serialization_.GetLoadInputs(), user_.internal_inputs, [&]() { InputRemoved(); }, [&]() { InputAdded(); }, diff --git a/buildcc/lib/target/src/generator/generator_serialization.cpp b/buildcc/lib/target/src/generator/generator_serialization.cpp index d85cb0d0..855aae04 100644 --- a/buildcc/lib/target/src/generator/generator_serialization.cpp +++ b/buildcc/lib/target/src/generator/generator_serialization.cpp @@ -27,12 +27,6 @@ namespace buildcc::internal { -// PUBLIC - -void GeneratorSerialization::UpdateStore(const GeneratorSchema &store) { - store_ = store; -} - // PRIVATE bool GeneratorSerialization::Verify(const std::string &serialized_data) { diff --git a/buildcc/lib/target/src/generator/task.cpp b/buildcc/lib/target/src/generator/task.cpp index 1845a58f..c4118114 100644 --- a/buildcc/lib/target/src/generator/task.cpp +++ b/buildcc/lib/target/src/generator/task.cpp @@ -77,7 +77,7 @@ void Generator::GenerateTask() { command_task.name(kCommandTaskName); // Graph Generation - for (const auto &i : user_inputs_) { + for (const auto &i : user_.inputs) { std::string name = fmt::format("{}", i.lexically_relative(env::get_project_root_dir())); tf::Task task = subflow.placeholder().name(name); From 10ae232e0a07f4b144fc18d700b11ca1ad7198db Mon Sep 17 00:00:00 2001 From: coder137 Date: Tue, 8 Feb 2022 19:23:39 -0800 Subject: [PATCH 08/19] Updated generator serialization --- .../target/serialization/generator_serialization.h | 10 ++-------- buildcc/lib/target/src/generator/generator.cpp | 6 +++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/buildcc/lib/target/include/target/serialization/generator_serialization.h b/buildcc/lib/target/include/target/serialization/generator_serialization.h index 45ad10d6..dfe9553f 100644 --- a/buildcc/lib/target/include/target/serialization/generator_serialization.h +++ b/buildcc/lib/target/include/target/serialization/generator_serialization.h @@ -40,14 +40,8 @@ class GeneratorSerialization : public SerializationInterface { : SerializationInterface(serialized_file) {} void UpdateStore(const GeneratorSchema &store) { store_ = store; } - - const path_unordered_set &GetLoadInputs() const { - return load_.internal_inputs; - } - const fs_unordered_set &GetLoadOutputs() const { return load_.outputs; } - const std::vector &GetLoadCommands() const { - return load_.commands; - } + const GeneratorSchema &GetLoad() const { return load_; } + const GeneratorSchema &GetStore() const { return store_; } private: bool Verify(const std::string &serialized_data) override; diff --git a/buildcc/lib/target/src/generator/generator.cpp b/buildcc/lib/target/src/generator/generator.cpp index dbe63e63..bd935db3 100644 --- a/buildcc/lib/target/src/generator/generator.cpp +++ b/buildcc/lib/target/src/generator/generator.cpp @@ -104,12 +104,12 @@ void Generator::BuildGenerate() { dirty_ = true; } else { RecheckPaths( - serialization_.GetLoadInputs(), user_.internal_inputs, + serialization_.GetLoad().internal_inputs, user_.internal_inputs, [&]() { InputRemoved(); }, [&]() { InputAdded(); }, [&]() { InputUpdated(); }); - RecheckChanged(serialization_.GetLoadOutputs(), user_.outputs, + RecheckChanged(serialization_.GetLoad().outputs, user_.outputs, [&]() { OutputChanged(); }); - RecheckChanged(serialization_.GetLoadCommands(), user_.commands, + RecheckChanged(serialization_.GetLoad().commands, user_.commands, [&]() { CommandChanged(); }); } } From 90c1c5fb4db5629caa8647db92f094b60d9e7889 Mon Sep 17 00:00:00 2001 From: coder137 Date: Wed, 9 Feb 2022 20:09:51 -0800 Subject: [PATCH 09/19] Added target serialization changes --- .../lib/target/cmake/common_target_src.cmake | 6 +- .../target/include/target/api/recheck_api.h | 78 ++++++++ .../lib/target/include/target/common/path.h | 14 +- .../include/target/private/schema_util.h | 23 ++- .../serialization/target_serialization.h | 85 ++++++++ buildcc/lib/target/include/target/target.h | 20 +- .../lib/target/include/target/target_info.h | 20 +- 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 | 16 +- buildcc/lib/target/src/api/pch_api.cpp | 2 +- buildcc/lib/target/src/api/source_api.cpp | 3 +- buildcc/lib/target/src/api/sync_api.cpp | 181 +++++++----------- buildcc/lib/target/src/api/target_getter.cpp | 2 +- .../lib/target/src/api/target_info_getter.cpp | 34 ++-- buildcc/lib/target/src/target/build.cpp | 6 +- .../src/target/friend/compile_object.cpp | 75 ++++---- .../target/src/target/friend/compile_pch.cpp | 51 ++--- .../target/src/target/friend/link_target.cpp | 60 +++--- buildcc/lib/target/src/target/target.cpp | 4 +- .../src/target/target_serialization.cpp | 153 +++++++++++++++ .../lib/target/src/target/target_storer.cpp | 76 +------- buildcc/lib/target/src/target/tasks.cpp | 21 +- 24 files changed, 597 insertions(+), 357 deletions(-) create mode 100644 buildcc/lib/target/include/target/api/recheck_api.h create mode 100644 buildcc/lib/target/include/target/serialization/target_serialization.h create mode 100644 buildcc/lib/target/src/target/target_serialization.cpp diff --git a/buildcc/lib/target/cmake/common_target_src.cmake b/buildcc/lib/target/cmake/common_target_src.cmake index c13e6db3..a8cd30ee 100644 --- a/buildcc/lib/target/cmake/common_target_src.cmake +++ b/buildcc/lib/target/cmake/common_target_src.cmake @@ -57,10 +57,8 @@ set(COMMON_TARGET_SRCS include/target/friend/link_target.h # Base Target - src/target/target_loader.cpp - src/target/target_storer.cpp - include/target/base/target_loader.h - include/target/base/target_storer.h + src/target/target_serialization.cpp + include/target/serialization/target_serialization.h # Target src/target/target.cpp diff --git a/buildcc/lib/target/include/target/api/recheck_api.h b/buildcc/lib/target/include/target/api/recheck_api.h new file mode 100644 index 00000000..2090acf2 --- /dev/null +++ b/buildcc/lib/target/include/target/api/recheck_api.h @@ -0,0 +1,78 @@ +/* + * 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_API_RECHECK_API_H_ +#define TARGET_API_RECHECK_API_H_ + +#include "target/common/path.h" + +namespace buildcc::internal { + +template +inline bool recheck_changed(const T &previous, const T ¤t) { + bool changed = false; + if (previous != current) { + changed = true; + } + return changed; +} + +enum class PathChanged { + kPathNotChanged, + kPathRemoved, + kPathAdded, + kPathUpdated +}; + +inline PathChanged +recheck_path_changed(const path_unordered_set &previous_path, + const path_unordered_set ¤t_path) { + // * Old path is removed + PathChanged path_changed = kPathNotChanged; + const bool removed = std::any_of( + previous_path.begin(), previous_path.end(), [&](const internal::Path &p) { + return current_path.find(p) == current_path.end(); + }); + if (removed) { + path_changed = kPathRemoved; + } + (void)std::any_of(current_path.cbegin(), current_path.cend(), + [&](const internal::Path &p) -> bool { + bool changed = false; + const auto find = previous_path.find(p); + const bool added_cond = (find == previous_path.end()); + if (added_cond) { + changed = true; + path_changed = kPathAdded; + } else { + const bool updated_cond = + (p.GetLastWriteTimestamp() > + find->GetLastWriteTimestamp()); + if (updated_cond) { + changed = true; + path_changed = kPathUpdated; + } else { + changed = false; + } + } + return changed; + }); + return path_changed; +} + +}; // namespace buildcc::internal + +#endif diff --git a/buildcc/lib/target/include/target/common/path.h b/buildcc/lib/target/include/target/common/path.h index 7b8f131b..38b864a8 100644 --- a/buildcc/lib/target/include/target/common/path.h +++ b/buildcc/lib/target/include/target/common/path.h @@ -142,9 +142,21 @@ class PathHash { typedef std::unordered_set path_unordered_set; typedef std::unordered_set fs_unordered_set; +inline std::vector +path_schema_convert(const std::vector &path_list, + const std::function &cb = + Path::CreateExistingPath) { + std::vector internal_path_list; + for (const auto &p : path_list) { + internal_path_list.push_back(cb(p)); + } + return internal_path_list; +} + inline path_unordered_set path_schema_convert(const fs_unordered_set &path_set, - const std::function &cb) { + const std::function &cb = + Path::CreateExistingPath) { path_unordered_set internal_path_set; for (const auto &p : path_set) { internal_path_set.insert(cb(p)); diff --git a/buildcc/lib/target/include/target/private/schema_util.h b/buildcc/lib/target/include/target/private/schema_util.h index d962e83e..b0ad689b 100644 --- a/buildcc/lib/target/include/target/private/schema_util.h +++ b/buildcc/lib/target/include/target/private/schema_util.h @@ -32,14 +32,28 @@ namespace buildcc::internal { inline void extract_path( const flatbuffers::Vector> *fbs_paths, - buildcc::internal::path_unordered_set &out) { + path_unordered_set &out) { if (fbs_paths == nullptr) { return; } for (auto iter = fbs_paths->begin(); iter != fbs_paths->end(); iter++) { - out.insert(buildcc::internal::Path::CreateNewPath( - iter->pathname()->c_str(), iter->last_write_timestamp())); + out.insert(Path::CreateNewPath(iter->pathname()->c_str(), + iter->last_write_timestamp())); + } +} + +inline void extract_path( + const flatbuffers::Vector> + *fbs_paths, + std::vector &out) { + if (fbs_paths == nullptr) { + return; + } + + for (auto iter = fbs_paths->begin(); iter != fbs_paths->end(); iter++) { + out.push_back(Path::CreateNewPath(iter->pathname()->c_str(), + iter->last_write_timestamp())); } } @@ -86,9 +100,10 @@ extract(const flatbuffers::Vector> // Create APIs for STORE +template inline std::vector> create_fbs_vector_path(flatbuffers::FlatBufferBuilder &builder, - const buildcc::internal::path_unordered_set &pathlist) { + const T &pathlist) { std::vector> paths; for (const auto &p : pathlist) { auto fbs_file = fbs::CreatePathDirect(builder, p.GetPathAsString().c_str(), diff --git a/buildcc/lib/target/include/target/serialization/target_serialization.h b/buildcc/lib/target/include/target/serialization/target_serialization.h new file mode 100644 index 00000000..c8e6b882 --- /dev/null +++ b/buildcc/lib/target/include/target/serialization/target_serialization.h @@ -0,0 +1,85 @@ +/* + * 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_SERIALIZATION_TARGET_SERIALIZATION_H_ +#define TARGET_SERIALIZATION_TARGET_SERIALIZATION_H_ + +#include "target/interface/serialization_interface.h" + +#include + +#include "target/common/path.h" +#include "target/common/target_type.h" + +namespace buildcc::internal { + +struct TargetSchema { + std::string name; + TargetType type; + + path_unordered_set internal_sources; + path_unordered_set internal_headers; + path_unordered_set internal_pchs; + std::vector internal_libs; + std::vector external_libs; + + fs_unordered_set include_dirs; + fs_unordered_set lib_dirs; + + std::unordered_set preprocessor_flags; + std::unordered_set common_compile_flags; + std::unordered_set pch_compile_flags; + std::unordered_set pch_object_flags; + std::unordered_set asm_compile_flags; + std::unordered_set c_compile_flags; + std::unordered_set cpp_compile_flags; + std::unordered_set link_flags; + + path_unordered_set internal_compile_dependencies; + path_unordered_set internal_link_dependencies; + + bool pch_compiled{false}; + bool target_linked{false}; +}; + +class TargetSerialization : public SerializationInterface { +public: + TargetSerialization(const fs::path &serialized_file) + : SerializationInterface(serialized_file) {} + + void UpdatePchCompiled(const TargetSchema &store); + void UpdateTargetCompiled(); + void AddSource(const internal::Path &source); + void UpdateStore(const TargetSchema &store); + + const TargetSchema &GetLoad() const { return load_; } + const TargetSchema &GetStore() const { return store_; } + +private: + bool Verify(const std::string &serialized_data) override; + bool Load(const std::string &serialized_data) override; + bool Store(const fs::path &absolute_serialized_file) override; + +private: + TargetSchema load_; + TargetSchema store_; + + std::mutex add_source_mutex; +}; + +} // namespace buildcc::internal + +#endif diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index edcad7e7..ab0a55dc 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -47,6 +47,8 @@ #include "target/base/target_storer.h" #include "target/common/path.h" +#include "target/serialization/target_serialization.h" + // Env #include "env/env.h" #include "env/task_state.h" @@ -75,8 +77,9 @@ class Target : public internal::BuilderInterface, 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) { + // loader_(name, env_.GetTargetBuildDir()), + serialization_(env_.GetTargetBuildDir() / fmt::format("{}.bin", name)), + compile_pch_(*this), compile_object_(*this), link_target_(*this) { Initialize(); } virtual ~Target() {} @@ -109,12 +112,12 @@ class Target : public internal::BuilderInterface, const fs_unordered_set ¤t_dirs); void RecheckFlags(const std::unordered_set &previous_flags, const std::unordered_set ¤t_flags); - void RecheckExternalLib( - const std::unordered_set &previous_external_libs, - const std::unordered_set ¤t_external_libs); + void + RecheckExternalLib(const std::vector &previous_external_libs, + const std::vector ¤t_external_libs); // Fbs - bool Store() override; + bool Store() override { return false; } // Tasks void SetTaskStateFailure(); @@ -143,7 +146,8 @@ class Target : public internal::BuilderInterface, std::string name_; TargetType type_; const Toolchain &toolchain_; - internal::TargetLoader loader_; + // internal::TargetLoader loader_; + internal::TargetSerialization serialization_; // Friend classes internal::CompilePch compile_pch_; @@ -158,7 +162,7 @@ class Target : public internal::BuilderInterface, env::TaskState task_state_{env::TaskState::SUCCESS}; std::mutex compiled_source_files_mutex_; - internal::path_unordered_set compiled_source_files_; + // internal::path_unordered_set compiled_source_files_; // env::Command command_; diff --git a/buildcc/lib/target/include/target/target_info.h b/buildcc/lib/target/include/target/target_info.h index 022df822..b05cff85 100644 --- a/buildcc/lib/target/include/target/target_info.h +++ b/buildcc/lib/target/include/target/target_info.h @@ -29,14 +29,25 @@ #include "target/api/include_api.h" #include "target/api/lib_api.h" #include "target/api/pch_api.h" -#include "target/api/sync_api.h" - #include "target/api/source_api.h" - +#include "target/api/sync_api.h" #include "target/api/target_info_getter.h" +#include "target/serialization/target_serialization.h" + namespace buildcc { +struct UserTargetSchema : public internal::TargetSchema { + fs_unordered_set sources; + fs_unordered_set headers; + fs_unordered_set pchs; + + std::vector libs; + + fs_unordered_set compile_dependencies; + fs_unordered_set link_dependencies; +}; + // NOTE: BaseTarget info is meant to hold information that is common to // multiple targets // It is also meant to be used in situations where we do not need to build @@ -72,7 +83,8 @@ class TargetInfo : public internal::SourceApi, TargetEnv env_; TargetConfig config_; - internal::TargetStorer storer_; + UserTargetSchema user_; + TargetState state_; }; diff --git a/buildcc/lib/target/src/api/deps_api.cpp b/buildcc/lib/target/src/api/deps_api.cpp index 63e59647..8cbee764 100644 --- a/buildcc/lib/target/src/api/deps_api.cpp +++ b/buildcc/lib/target/src/api/deps_api.cpp @@ -25,14 +25,14 @@ 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); + 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.storer_.current_link_dependencies.user.insert(absolute_path); + t.user_.link_dependencies.insert(absolute_path); } template diff --git a/buildcc/lib/target/src/api/flag_api.cpp b/buildcc/lib/target/src/api/flag_api.cpp index abcfbcf7..99a9f294 100644 --- a/buildcc/lib/target/src/api/flag_api.cpp +++ b/buildcc/lib/target/src/api/flag_api.cpp @@ -25,55 +25,55 @@ void FlagApi::AddPreprocessorFlag(const std::string &flag) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_preprocessor_flags.insert(flag); + t.user_.preprocessor_flags.insert(flag); } template void FlagApi::AddCommonCompileFlag(const std::string &flag) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_common_compile_flags.insert(flag); + t.user_.common_compile_flags.insert(flag); } template void FlagApi::AddPchCompileFlag(const std::string &flag) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_pch_compile_flags.insert(flag); + t.user_.pch_compile_flags.insert(flag); } template void FlagApi::AddPchObjectFlag(const std::string &flag) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_pch_object_flags.insert(flag); + t.user_.pch_object_flags.insert(flag); } template void FlagApi::AddAsmCompileFlag(const std::string &flag) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_asm_compile_flags.insert(flag); + t.user_.asm_compile_flags.insert(flag); } template void FlagApi::AddCCompileFlag(const std::string &flag) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_c_compile_flags.insert(flag); + t.user_.c_compile_flags.insert(flag); } template void FlagApi::AddCppCompileFlag(const std::string &flag) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_cpp_compile_flags.insert(flag); + t.user_.cpp_compile_flags.insert(flag); } template void FlagApi::AddLinkFlag(const std::string &flag) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_link_flags.insert(flag); + t.user_.link_flags.insert(flag); } template class FlagApi; diff --git a/buildcc/lib/target/src/api/include_api.cpp b/buildcc/lib/target/src/api/include_api.cpp index bb9aa1b1..a1716935 100644 --- a/buildcc/lib/target/src/api/include_api.cpp +++ b/buildcc/lib/target/src/api/include_api.cpp @@ -26,7 +26,7 @@ void IncludeApi::AddHeaderAbsolute(const fs::path &absolute_filepath) { t.state_.ExpectsUnlock(); t.config_.ExpectsValidHeader(absolute_filepath); - t.storer_.current_header_files.user.insert(absolute_filepath); + t.user_.headers.insert(absolute_filepath); } template @@ -75,7 +75,7 @@ void IncludeApi::AddIncludeDirAbsolute(const fs::path &absolute_include_dir, T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_include_dirs.insert(absolute_include_dir); + t.user_.include_dirs.insert(absolute_include_dir); if (glob_headers) { GlobHeadersAbsolute(absolute_include_dir); diff --git a/buildcc/lib/target/src/api/lib_api.cpp b/buildcc/lib/target/src/api/lib_api.cpp index 0814927c..16eb85a8 100644 --- a/buildcc/lib/target/src/api/lib_api.cpp +++ b/buildcc/lib/target/src/api/lib_api.cpp @@ -22,33 +22,33 @@ namespace buildcc::internal { template -void LibApi::AddLibDir(const fs::path &relative_lib_dir) { +void LibApi::AddLibDirAbsolute(const fs::path &absolute_lib_dir) { T &t = static_cast(*this); - fs::path final_lib_dir = t.env_.GetTargetRootDir() / relative_lib_dir; - AddLibDirAbsolute(final_lib_dir); + t.state_.ExpectsUnlock(); + t.user_.lib_dirs.insert(absolute_lib_dir); } template -void LibApi::AddLibDirAbsolute(const fs::path &absolute_lib_dir) { +void LibApi::AddLibDir(const fs::path &relative_lib_dir) { T &t = static_cast(*this); - t.state_.ExpectsUnlock(); - t.storer_.current_lib_dirs.insert(absolute_lib_dir); + fs::path final_lib_dir = t.env_.GetTargetRootDir() / relative_lib_dir; + AddLibDirAbsolute(final_lib_dir); } template void LibApi::AddLibDep(const BaseTarget &lib_dep) { T &t = static_cast(*this); t.state_.ExpectsUnlock(); - t.storer_.current_user_lib_deps.push_back(lib_dep.GetTargetPath()); + 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.storer_.current_user_external_lib_deps.push_back(lib_dep); + t.user_.external_libs.push_back(lib_dep); } template class LibApi; diff --git a/buildcc/lib/target/src/api/pch_api.cpp b/buildcc/lib/target/src/api/pch_api.cpp index 885c5469..60d3745e 100644 --- a/buildcc/lib/target/src/api/pch_api.cpp +++ b/buildcc/lib/target/src/api/pch_api.cpp @@ -28,7 +28,7 @@ void PchApi::AddPchAbsolute(const fs::path &absolute_filepath) { 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); + t.user_.pchs.insert(absolute_pch); } template diff --git a/buildcc/lib/target/src/api/source_api.cpp b/buildcc/lib/target/src/api/source_api.cpp index cce228df..78d260a9 100644 --- a/buildcc/lib/target/src/api/source_api.cpp +++ b/buildcc/lib/target/src/api/source_api.cpp @@ -26,8 +26,7 @@ void SourceApi::AddSourceAbsolute(const fs::path &absolute_source) { t.state_.ExpectsUnlock(); t.config_.ExpectsValidSource(absolute_source); - t.storer_.current_source_files.user.emplace( - fs::path(absolute_source).make_preferred()); + t.user_.sources.emplace(fs::path(absolute_source).make_preferred()); } template diff --git a/buildcc/lib/target/src/api/sync_api.cpp b/buildcc/lib/target/src/api/sync_api.cpp index d5efc349..261eca24 100644 --- a/buildcc/lib/target/src/api/sync_api.cpp +++ b/buildcc/lib/target/src/api/sync_api.cpp @@ -45,71 +45,57 @@ void SyncApi::SpecializedCopy(TargetType target, for (const SyncOption o : options) { switch (o) { case SyncOption::PreprocessorFlags: - t.storer_.current_preprocessor_flags = - std::move(target.storer_.current_preprocessor_flags); + t.user_.preprocessor_flags = std::move(target.user_.preprocessor_flags); break; case SyncOption::CommonCompileFlags: - t.storer_.current_common_compile_flags = - std::move(target.storer_.current_common_compile_flags); + t.user_.common_compile_flags = + std::move(target.user_.common_compile_flags); break; case SyncOption::PchCompileFlags: - t.storer_.current_pch_compile_flags = - std::move(target.storer_.current_pch_compile_flags); + t.user_.pch_compile_flags = std::move(target.user_.pch_compile_flags); break; case SyncOption::PchObjectFlags: - t.storer_.current_pch_object_flags = - std::move(target.storer_.current_pch_object_flags); + t.user_.pch_object_flags = std::move(target.user_.pch_object_flags); break; case SyncOption::AsmCompileFlags: - t.storer_.current_asm_compile_flags = - std::move(target.storer_.current_asm_compile_flags); + t.user_.asm_compile_flags = std::move(target.user_.asm_compile_flags); break; case SyncOption::CCompileFlags: - t.storer_.current_c_compile_flags = - std::move(target.storer_.current_c_compile_flags); + t.user_.c_compile_flags = std::move(target.user_.c_compile_flags); break; case SyncOption::CppCompileFlags: - t.storer_.current_cpp_compile_flags = - std::move(target.storer_.current_cpp_compile_flags); + t.user_.cpp_compile_flags = std::move(target.user_.cpp_compile_flags); break; case SyncOption::LinkFlags: - t.storer_.current_link_flags = - std::move(target.storer_.current_link_flags); + t.user_.link_flags = std::move(target.user_.link_flags); break; case SyncOption::CompileDependencies: - t.storer_.current_compile_dependencies.user = - std::move(target.storer_.current_compile_dependencies.user); + t.user_.compile_dependencies = + std::move(target.user_.compile_dependencies); break; case SyncOption::LinkDependencies: - t.storer_.current_link_dependencies.user = - std::move(target.storer_.current_link_dependencies.user); + t.user_.link_dependencies = std::move(target.user_.link_dependencies); break; case SyncOption::SourceFiles: - t.storer_.current_source_files.user = - std::move(target.storer_.current_source_files.user); + t.user_.sources = std::move(target.user_.sources); break; case SyncOption::HeaderFiles: - t.storer_.current_header_files.user = - std::move(target.storer_.current_header_files.user); + t.user_.headers = std::move(target.user_.headers); break; case SyncOption::PchFiles: - t.storer_.current_pch_files.user = - std::move(target.storer_.current_pch_files.user); + t.user_.pchs = std::move(target.user_.pchs); break; case SyncOption::LibDeps: - t.storer_.current_user_lib_deps = - std::move(target.storer_.current_user_lib_deps); + t.user_.libs = std::move(target.user_.libs); break; case SyncOption::IncludeDirs: - t.storer_.current_include_dirs = - std::move(target.storer_.current_include_dirs); + t.user_.include_dirs = std::move(target.user_.include_dirs); break; case SyncOption::LibDirs: - t.storer_.current_lib_dirs = std::move(target.storer_.current_lib_dirs); + t.user_.lib_dirs = std::move(target.user_.lib_dirs); break; case SyncOption::ExternalLibDeps: - t.storer_.current_user_external_lib_deps = - std::move(target.storer_.current_user_external_lib_deps); + t.user_.external_libs = std::move(target.user_.external_libs); break; default: env::assert_fatal("Invalid Option added"); @@ -140,116 +126,89 @@ void SyncApi::SpecializedInsert(TargetType target, for (const SyncOption o : options) { switch (o) { case SyncOption::PreprocessorFlags: - t.storer_.current_preprocessor_flags.insert( - std::make_move_iterator( - target.storer_.current_preprocessor_flags.begin()), - std::make_move_iterator( - target.storer_.current_preprocessor_flags.end())); + t.user_.preprocessor_flags.insert( + std::make_move_iterator(target.user_.preprocessor_flags.begin()), + std::make_move_iterator(target.user_.preprocessor_flags.end())); break; case SyncOption::CommonCompileFlags: - t.storer_.current_common_compile_flags.insert( - std::make_move_iterator( - target.storer_.current_common_compile_flags.begin()), - std::make_move_iterator( - target.storer_.current_common_compile_flags.end())); + t.user_.common_compile_flags.insert( + std::make_move_iterator(target.user_.common_compile_flags.begin()), + std::make_move_iterator(target.user_.common_compile_flags.end())); break; case SyncOption::PchCompileFlags: - t.storer_.current_pch_compile_flags.insert( - std::make_move_iterator( - target.storer_.current_pch_compile_flags.begin()), - std::make_move_iterator( - target.storer_.current_pch_compile_flags.end())); + t.user_.pch_compile_flags.insert( + std::make_move_iterator(target.user_.pch_compile_flags.begin()), + std::make_move_iterator(target.user_.pch_compile_flags.end())); break; case SyncOption::PchObjectFlags: - t.storer_.current_pch_object_flags.insert( - std::make_move_iterator( - target.storer_.current_pch_object_flags.begin()), - std::make_move_iterator( - target.storer_.current_pch_object_flags.end())); + t.user_.pch_object_flags.insert( + std::make_move_iterator(target.user_.pch_object_flags.begin()), + std::make_move_iterator(target.user_.pch_object_flags.end())); break; case SyncOption::AsmCompileFlags: - t.storer_.current_asm_compile_flags.insert( - std::make_move_iterator( - target.storer_.current_asm_compile_flags.begin()), - std::make_move_iterator( - target.storer_.current_asm_compile_flags.end())); + t.user_.asm_compile_flags.insert( + std::make_move_iterator(target.user_.asm_compile_flags.begin()), + std::make_move_iterator(target.user_.asm_compile_flags.end())); break; case SyncOption::CCompileFlags: - t.storer_.current_c_compile_flags.insert( - std::make_move_iterator( - target.storer_.current_c_compile_flags.begin()), - std::make_move_iterator( - target.storer_.current_c_compile_flags.end())); + t.user_.c_compile_flags.insert( + std::make_move_iterator(target.user_.c_compile_flags.begin()), + std::make_move_iterator(target.user_.c_compile_flags.end())); break; case SyncOption::CppCompileFlags: - t.storer_.current_cpp_compile_flags.insert( - std::make_move_iterator( - target.storer_.current_cpp_compile_flags.begin()), - std::make_move_iterator( - target.storer_.current_cpp_compile_flags.end())); + t.user_.cpp_compile_flags.insert( + std::make_move_iterator(target.user_.cpp_compile_flags.begin()), + std::make_move_iterator(target.user_.cpp_compile_flags.end())); break; case SyncOption::LinkFlags: - t.storer_.current_link_flags.insert( - std::make_move_iterator(target.storer_.current_link_flags.begin()), - std::make_move_iterator(target.storer_.current_link_flags.end())); + t.user_.link_flags.insert( + std::make_move_iterator(target.user_.link_flags.begin()), + std::make_move_iterator(target.user_.link_flags.end())); break; case SyncOption::CompileDependencies: - t.storer_.current_compile_dependencies.user.insert( - std::make_move_iterator( - target.storer_.current_compile_dependencies.user.begin()), - std::make_move_iterator( - target.storer_.current_compile_dependencies.user.end())); + t.user_.compile_dependencies.insert( + std::make_move_iterator(target.user_.compile_dependencies.begin()), + std::make_move_iterator(target.user_.compile_dependencies.end())); break; case SyncOption::LinkDependencies: - t.storer_.current_link_dependencies.user.insert( - std::make_move_iterator( - target.storer_.current_link_dependencies.user.begin()), - std::make_move_iterator( - target.storer_.current_link_dependencies.user.end())); + t.user_.link_dependencies.insert( + std::make_move_iterator(target.user_.link_dependencies.begin()), + std::make_move_iterator(target.user_.link_dependencies.end())); break; case SyncOption::SourceFiles: - t.storer_.current_source_files.user.insert( - std::make_move_iterator( - target.storer_.current_source_files.user.begin()), - std::make_move_iterator( - target.storer_.current_source_files.user.end())); + t.user_.sources.insert( + std::make_move_iterator(target.user_.sources.begin()), + std::make_move_iterator(target.user_.sources.end())); break; case SyncOption::HeaderFiles: - t.storer_.current_header_files.user.insert( - std::make_move_iterator( - target.storer_.current_header_files.user.begin()), - std::make_move_iterator( - target.storer_.current_header_files.user.end())); + t.user_.headers.insert( + std::make_move_iterator(target.user_.headers.begin()), + std::make_move_iterator(target.user_.headers.end())); break; case SyncOption::PchFiles: - t.storer_.current_pch_files.user.insert( - std::make_move_iterator( - target.storer_.current_pch_files.user.begin()), - std::make_move_iterator(target.storer_.current_pch_files.user.end())); + t.user_.pchs.insert(std::make_move_iterator(target.user_.pchs.begin()), + std::make_move_iterator(target.user_.pchs.end())); break; case SyncOption::LibDeps: - t.storer_.current_user_lib_deps.insert( - t.storer_.current_user_lib_deps.end(), - std::make_move_iterator(target.storer_.current_user_lib_deps.begin()), - std::make_move_iterator(target.storer_.current_user_lib_deps.end())); + t.user_.libs.insert(t.user_.libs.end(), + std::make_move_iterator(target.user_.libs.begin()), + std::make_move_iterator(target.user_.libs.end())); break; case SyncOption::IncludeDirs: - t.storer_.current_include_dirs.insert( - std::make_move_iterator(target.storer_.current_include_dirs.begin()), - std::make_move_iterator(target.storer_.current_include_dirs.end())); + t.user_.include_dirs.insert( + std::make_move_iterator(target.user_.include_dirs.begin()), + std::make_move_iterator(target.user_.include_dirs.end())); break; case SyncOption::LibDirs: - t.storer_.current_lib_dirs.insert( - std::make_move_iterator(target.storer_.current_lib_dirs.begin()), - std::make_move_iterator(target.storer_.current_lib_dirs.end())); + t.user_.lib_dirs.insert( + std::make_move_iterator(target.user_.lib_dirs.begin()), + std::make_move_iterator(target.user_.lib_dirs.end())); break; case SyncOption::ExternalLibDeps: - t.storer_.current_user_external_lib_deps.insert( - t.storer_.current_user_external_lib_deps.end(), - std::make_move_iterator( - target.storer_.current_user_external_lib_deps.begin()), - std::make_move_iterator( - target.storer_.current_user_external_lib_deps.end())); + t.user_.external_libs.insert( + t.user_.external_libs.end(), + std::make_move_iterator(target.user_.external_libs.begin()), + std::make_move_iterator(target.user_.external_libs.end())); break; default: env::assert_fatal("Invalid Option added"); diff --git a/buildcc/lib/target/src/api/target_getter.cpp b/buildcc/lib/target/src/api/target_getter.cpp index 83cad46e..e49e30ef 100644 --- a/buildcc/lib/target/src/api/target_getter.cpp +++ b/buildcc/lib/target/src/api/target_getter.cpp @@ -23,7 +23,7 @@ namespace buildcc::internal { template const fs::path &TargetGetter::GetBinaryPath() const { const T &t = static_cast(*this); - return t.loader_.GetBinaryPath(); + return t.serialization_.GetSerializedFile(); } template const fs::path &TargetGetter::GetTargetPath() const { diff --git a/buildcc/lib/target/src/api/target_info_getter.cpp b/buildcc/lib/target/src/api/target_info_getter.cpp index 10b18a2f..488818a7 100644 --- a/buildcc/lib/target/src/api/target_info_getter.cpp +++ b/buildcc/lib/target/src/api/target_info_getter.cpp @@ -67,28 +67,28 @@ template const fs_unordered_set &TargetInfoGetter::GetSourceFiles() const { const T &t = static_cast(*this); - return t.storer_.current_source_files.user; + return t.user_.sources; } template const fs_unordered_set &TargetInfoGetter::GetHeaderFiles() const { const T &t = static_cast(*this); - return t.storer_.current_header_files.user; + return t.user_.headers; } template const fs_unordered_set &TargetInfoGetter::GetPchFiles() const { const T &t = static_cast(*this); - return t.storer_.current_pch_files.user; + return t.user_.pchs; } template const std::vector &TargetInfoGetter::GetLibDeps() const { const T &t = static_cast(*this); - return t.storer_.current_user_lib_deps; + return t.user_.libs; } template @@ -96,21 +96,21 @@ const std::vector & TargetInfoGetter::GetExternalLibDeps() const { const T &t = static_cast(*this); - return t.storer_.current_user_external_lib_deps; + return t.user_.external_libs; } template const fs_unordered_set &TargetInfoGetter::GetIncludeDirs() const { const T &t = static_cast(*this); - return t.storer_.current_include_dirs; + return t.user_.include_dirs; } template const fs_unordered_set &TargetInfoGetter::GetLibDirs() const { const T &t = static_cast(*this); - return t.storer_.current_lib_dirs; + return t.user_.lib_dirs; } template @@ -118,7 +118,7 @@ const std::unordered_set & TargetInfoGetter::GetPreprocessorFlags() const { const T &t = static_cast(*this); - return t.storer_.current_preprocessor_flags; + return t.user_.preprocessor_flags; } template @@ -126,7 +126,7 @@ const std::unordered_set & TargetInfoGetter::GetCommonCompileFlags() const { const T &t = static_cast(*this); - return t.storer_.current_common_compile_flags; + return t.user_.common_compile_flags; } template @@ -134,7 +134,7 @@ const std::unordered_set & TargetInfoGetter::GetPchCompileFlags() const { const T &t = static_cast(*this); - return t.storer_.current_pch_compile_flags; + return t.user_.pch_compile_flags; } template @@ -142,7 +142,7 @@ const std::unordered_set & TargetInfoGetter::GetPchObjectFlags() const { const T &t = static_cast(*this); - return t.storer_.current_pch_object_flags; + return t.user_.pch_object_flags; } template @@ -150,7 +150,7 @@ const std::unordered_set & TargetInfoGetter::GetAsmCompileFlags() const { const T &t = static_cast(*this); - return t.storer_.current_asm_compile_flags; + return t.user_.asm_compile_flags; } template @@ -158,7 +158,7 @@ const std::unordered_set & TargetInfoGetter::GetCCompileFlags() const { const T &t = static_cast(*this); - return t.storer_.current_c_compile_flags; + return t.user_.c_compile_flags; } template @@ -166,7 +166,7 @@ const std::unordered_set & TargetInfoGetter::GetCppCompileFlags() const { const T &t = static_cast(*this); - return t.storer_.current_cpp_compile_flags; + return t.user_.cpp_compile_flags; } template @@ -174,21 +174,21 @@ const std::unordered_set & TargetInfoGetter::GetLinkFlags() const { const T &t = static_cast(*this); - return t.storer_.current_link_flags; + return t.user_.link_flags; } template const fs_unordered_set &TargetInfoGetter::GetCompileDependencies() const { const T &t = static_cast(*this); - return t.storer_.current_compile_dependencies.user; + return t.user_.compile_dependencies; } template const fs_unordered_set &TargetInfoGetter::GetLinkDependencies() const { const T &t = static_cast(*this); - return t.storer_.current_link_dependencies.user; + return t.user_.link_dependencies; } template class TargetInfoGetter; diff --git a/buildcc/lib/target/src/target/build.cpp b/buildcc/lib/target/src/target/build.cpp index 82e00a53..4e9de6c6 100644 --- a/buildcc/lib/target/src/target/build.cpp +++ b/buildcc/lib/target/src/target/build.cpp @@ -58,13 +58,13 @@ void Target::Build() { state_.SetLock(); // PCH state - if (!storer_.current_pch_files.user.empty()) { + if (!user_.pchs.empty()) { state_.SetPch(); } // Source - Object relation // Source state - for (const auto &abs_source : storer_.current_source_files.user) { + for (const auto &abs_source : user_.sources) { // Set state state_.SetSourceState(config_.GetFileExt(abs_source)); @@ -94,7 +94,7 @@ void Target::Build() { }); // Load the serialized file - (void)loader_.Load(); + (void)serialization_.LoadFromFile(); // Target State Tasks StartTask(); diff --git a/buildcc/lib/target/src/target/friend/compile_object.cpp b/buildcc/lib/target/src/target/friend/compile_object.cpp index a2c418f7..846108df 100644 --- a/buildcc/lib/target/src/target/friend/compile_object.cpp +++ b/buildcc/lib/target/src/target/friend/compile_object.cpp @@ -165,30 +165,31 @@ void CompileObject::BuildObjectCompile( std::vector &dummy_source_files) { PreObjectCompile(); - const auto &loader = target_.loader_; - const auto &storer = target_.storer_; + const auto &serialization = target_.serialization_; + const auto &load_target_schema = serialization.GetLoad(); + const auto &user_target_schema = target_.user_; - if (!loader.IsLoaded()) { + if (!serialization.IsLoaded()) { target_.dirty_ = true; } else { - target_.RecheckFlags(loader.GetLoadedPreprocessorFlags(), - target_.GetPreprocessorFlags()); - target_.RecheckFlags(loader.GetLoadedCommonCompileFlags(), - target_.GetCommonCompileFlags()); - target_.RecheckFlags(loader.GetLoadedPchObjectFlags(), - target_.GetPchObjectFlags()); - target_.RecheckFlags(loader.GetLoadedAsmCompileFlags(), - target_.GetAsmCompileFlags()); - target_.RecheckFlags(loader.GetLoadedCCompileFlags(), - target_.GetCCompileFlags()); - target_.RecheckFlags(loader.GetLoadedCppCompileFlags(), - target_.GetCppCompileFlags()); - target_.RecheckDirs(loader.GetLoadedIncludeDirs(), - target_.GetIncludeDirs()); - target_.RecheckPaths(loader.GetLoadedHeaders(), - storer.current_header_files.internal); - target_.RecheckPaths(loader.GetLoadedCompileDependencies(), - storer.current_compile_dependencies.internal); + target_.RecheckFlags(load_target_schema.preprocessor_flags, + user_target_schema.preprocessor_flags); + target_.RecheckFlags(load_target_schema.common_compile_flags, + user_target_schema.common_compile_flags); + target_.RecheckFlags(load_target_schema.pch_object_flags, + user_target_schema.pch_object_flags); + target_.RecheckFlags(load_target_schema.asm_compile_flags, + user_target_schema.asm_compile_flags); + target_.RecheckFlags(load_target_schema.c_compile_flags, + user_target_schema.c_compile_flags); + target_.RecheckFlags(load_target_schema.cpp_compile_flags, + user_target_schema.cpp_compile_flags); + target_.RecheckDirs(load_target_schema.include_dirs, + user_target_schema.include_dirs); + target_.RecheckPaths(load_target_schema.internal_headers, + user_target_schema.internal_headers); + target_.RecheckPaths(load_target_schema.internal_compile_dependencies, + user_target_schema.internal_compile_dependencies); } if (target_.dirty_) { @@ -199,39 +200,41 @@ void CompileObject::BuildObjectCompile( } void CompileObject::PreObjectCompile() { - auto &storer = target_.storer_; + auto &target_user_schema = target_.user_; // Convert user_source_files to current_source_files - storer.current_source_files.Convert(); + target_user_schema.internal_sources = + internal::path_schema_convert(target_user_schema.sources); // Convert user_header_files to current_header_files - storer.current_header_files.Convert(); + target_user_schema.internal_headers = + internal::path_schema_convert(target_user_schema.headers); // Convert user_compile_dependencies to current_compile_dependencies - storer.current_compile_dependencies.Convert(); + target_user_schema.internal_compile_dependencies = + internal::path_schema_convert(target_user_schema.compile_dependencies); } void CompileObject::CompileSources(std::vector &source_files) { - const auto &storer = target_.storer_; + const auto &target_user_schema = target_.user_; source_files = - std::vector(storer.current_source_files.internal.begin(), - storer.current_source_files.internal.end()); + std::vector(target_user_schema.internal_sources.begin(), + target_user_schema.internal_sources.end()); } void CompileObject::RecompileSources( std::vector &source_files, std::vector &dummy_source_files) { - const auto &loader = target_.loader_; - const auto &storer = target_.storer_; - - const auto &previous_source_files = loader.GetLoadedSources(); + const auto &serialization = target_.serialization_; + const auto &user_target_schema = target_.user_; + const auto &previous_source_files = serialization.GetLoad().internal_sources; // * Cannot find previous source in current source files const bool is_source_removed = std::any_of(previous_source_files.begin(), previous_source_files.end(), [&](const internal::Path &p) { - return storer.current_source_files.internal.find(p) == - storer.current_source_files.internal.end(); + return user_target_schema.internal_sources.find(p) == + user_target_schema.internal_sources.end(); }); if (is_source_removed) { @@ -239,9 +242,7 @@ void CompileObject::RecompileSources( target_.SourceRemoved(); } - for (const auto ¤t_file : storer.current_source_files.internal) { - // const auto ¤t_source = current_file.GetPathname(); - + for (const auto ¤t_file : user_target_schema.internal_sources) { // Find current_file in the loaded sources auto iter = previous_source_files.find(current_file); diff --git a/buildcc/lib/target/src/target/friend/compile_pch.cpp b/buildcc/lib/target/src/target/friend/compile_pch.cpp index 2d4057ba..115138ab 100644 --- a/buildcc/lib/target/src/target/friend/compile_pch.cpp +++ b/buildcc/lib/target/src/target/friend/compile_pch.cpp @@ -73,29 +73,31 @@ void CompilePch::CacheCompileCommand() { void CompilePch::BuildCompile() { PreCompile(); - const auto &loader = target_.loader_; + const auto &serialization = target_.serialization_; + const auto &load_target_schema = serialization.GetLoad(); + const auto &user_target_schema = target_.user_; - if (!loader.IsLoaded()) { + if (!serialization.IsLoaded()) { target_.dirty_ = true; } else { - target_.RecheckFlags(loader.GetLoadedPreprocessorFlags(), - target_.GetPreprocessorFlags()); - target_.RecheckFlags(loader.GetLoadedCommonCompileFlags(), - target_.GetCommonCompileFlags()); - target_.RecheckFlags(loader.GetLoadedCCompileFlags(), - target_.GetCCompileFlags()); - target_.RecheckFlags(loader.GetLoadedCppCompileFlags(), - target_.GetCppCompileFlags()); - target_.RecheckDirs(loader.GetLoadedIncludeDirs(), - target_.GetIncludeDirs()); - target_.RecheckPaths(loader.GetLoadedHeaders(), - target_.storer_.current_header_files.internal); - - target_.RecheckFlags(loader.GetLoadedPchCompileFlags(), - target_.GetPchCompileFlags()); - target_.RecheckPaths(loader.GetLoadedPchs(), - target_.storer_.current_pch_files.internal); - if (!loader.GetLoadedPchCompiled()) { + target_.RecheckFlags(load_target_schema.preprocessor_flags, + user_target_schema.preprocessor_flags); + target_.RecheckFlags(load_target_schema.common_compile_flags, + user_target_schema.common_compile_flags); + target_.RecheckFlags(load_target_schema.c_compile_flags, + user_target_schema.c_compile_flags); + target_.RecheckFlags(load_target_schema.cpp_compile_flags, + user_target_schema.cpp_compile_flags); + target_.RecheckDirs(load_target_schema.include_dirs, + user_target_schema.include_dirs); + target_.RecheckPaths(load_target_schema.internal_headers, + user_target_schema.internal_headers); + + target_.RecheckFlags(load_target_schema.pch_compile_flags, + user_target_schema.pch_compile_flags); + target_.RecheckPaths(load_target_schema.internal_pchs, + user_target_schema.internal_pchs); + if (!load_target_schema.pch_compiled) { target_.dirty_ = true; } } @@ -110,7 +112,6 @@ void CompilePch::BuildCompile() { } bool success = env::Command::Execute(command_); env::assert_throw(success, "Failed to compile pch"); - target_.storer_.pch_compiled = true; } } @@ -158,9 +159,13 @@ std::string CompilePch::ConstructCompileCommand() const { } void CompilePch::PreCompile() { - target_.storer_.current_header_files.Convert(); + auto &target_user_schema = target_.user_; - target_.storer_.current_pch_files.Convert(); + target_user_schema.internal_headers = + internal::path_schema_convert(target_user_schema.headers); + + target_user_schema.internal_pchs = + internal::path_schema_convert(target_user_schema.pchs); } } // namespace buildcc::internal diff --git a/buildcc/lib/target/src/target/friend/link_target.cpp b/buildcc/lib/target/src/target/friend/link_target.cpp index 42b4208d..2c6fd30e 100644 --- a/buildcc/lib/target/src/target/friend/link_target.cpp +++ b/buildcc/lib/target/src/target/friend/link_target.cpp @@ -34,18 +34,15 @@ void LinkTarget::CacheLinkCommand() { internal::aggregate(target_.compile_object_.GetCompiledSources()); const std::string output_target = fmt::format("{}", output_); - - const auto &storer = target_.storer_; + const auto &target_user_schema = target_.user_; command_ = target_.command_.Construct( target_.config_.link_command, { {kOutput, output_target}, {kCompiledSources, aggregated_compiled_sources}, - // NOTE, This needs to be ORDERED {kLibDeps, - fmt::format( - "{} {}", internal::aggregate(storer.current_user_lib_deps), - internal::aggregate(storer.current_user_external_lib_deps))}, + fmt::format("{} {}", internal::aggregate(target_user_schema.libs), + internal::aggregate(target_user_schema.external_libs))}, }); } @@ -60,40 +57,41 @@ fs::path LinkTarget::ConstructOutputPath() const { } void LinkTarget::PreLink() { - auto &storer = target_.storer_; - - for (const auto &p : storer.current_user_lib_deps) { - storer.current_internal_lib_deps.emplace( - internal::Path::CreateExistingPath(p)); - } + auto &target_user_schema = target_.user_; - storer.current_internal_external_lib_deps.insert( - storer.current_user_external_lib_deps.begin(), - storer.current_user_external_lib_deps.end()); + target_user_schema.internal_libs = + path_schema_convert(target_user_schema.libs); - storer.current_link_dependencies.Convert(); + target_user_schema.internal_link_dependencies = + path_schema_convert(target_user_schema.link_dependencies); } void LinkTarget::BuildLink() { PreLink(); - const auto &loader = target_.loader_; - const auto &storer = target_.storer_; + const auto &serialization = target_.serialization_; + const auto &target_load_schema = serialization.GetLoad(); + const auto &target_user_schema = target_.user_; - if (!loader.IsLoaded()) { + if (!serialization.IsLoaded()) { target_.dirty_ = true; } else { - target_.RecheckFlags(loader.GetLoadedLinkFlags(), target_.GetLinkFlags()); - target_.RecheckDirs(loader.GetLoadedLibDirs(), target_.GetLibDirs()); - target_.RecheckExternalLib(loader.GetLoadedExternalLibDeps(), - storer.current_internal_external_lib_deps); - target_.RecheckPaths(loader.GetLoadedLinkDependencies(), - storer.current_link_dependencies.internal); - - // NOTE, This needs to be UNORDERED - target_.RecheckPaths(loader.GetLoadedLibDeps(), - storer.current_internal_lib_deps); - if (!loader.GetLoadedTargetLinked()) { + target_.RecheckFlags(target_load_schema.link_flags, + target_user_schema.link_flags); + target_.RecheckDirs(target_load_schema.lib_dirs, + target_user_schema.lib_dirs); + target_.RecheckExternalLib(target_load_schema.external_libs, + target_user_schema.external_libs); + target_.RecheckPaths(target_load_schema.internal_link_dependencies, + target_user_schema.internal_link_dependencies); + path_unordered_set target_loaded_libs( + target_load_schema.internal_libs.begin(), + target_load_schema.internal_libs.end()); + path_unordered_set target_user_libs( + target_user_schema.internal_libs.begin(), + target_user_schema.internal_libs.end()); + target_.RecheckPaths(target_loaded_libs, target_user_libs); + if (!target_load_schema.target_linked) { target_.dirty_ = true; } } @@ -101,7 +99,7 @@ void LinkTarget::BuildLink() { if (target_.dirty_) { bool success = env::Command::Execute(command_); env::assert_throw(success, "Failed to link target"); - target_.storer_.target_linked = true; + target_.serialization_.UpdateTargetCompiled(); } } diff --git a/buildcc/lib/target/src/target/target.cpp b/buildcc/lib/target/src/target/target.cpp index fe069f31..571cd9a4 100644 --- a/buildcc/lib/target/src/target/target.cpp +++ b/buildcc/lib/target/src/target/target.cpp @@ -83,8 +83,8 @@ void Target::RecheckFlags( } void Target::RecheckExternalLib( - const std::unordered_set &previous_external_libs, - const std::unordered_set ¤t_external_libs) { + const std::vector &previous_external_libs, + const std::vector ¤t_external_libs) { RecheckChanged(previous_external_libs, current_external_libs, std::bind(&Target::ExternalLibChanged, this)); } diff --git a/buildcc/lib/target/src/target/target_serialization.cpp b/buildcc/lib/target/src/target/target_serialization.cpp new file mode 100644 index 00000000..b965ae56 --- /dev/null +++ b/buildcc/lib/target/src/target/target_serialization.cpp @@ -0,0 +1,153 @@ +/* + * 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. + */ + +#include "target/serialization/target_serialization.h" + +// Third party +#include "flatbuffers/flatbuffers.h" + +// Private +#include "target/private/schema_util.h" + +// Schema generated +#include "target_generated.h" + +namespace buildcc::internal { + +// PUBLIC +void TargetSerialization::UpdatePchCompiled(const TargetSchema &store) { + store_.internal_pchs = store.internal_pchs; + store_.pch_compiled = true; +} +void TargetSerialization::AddSource(const internal::Path &source) { + std::lock_guard guard(add_source_mutex); + store_.internal_sources.insert(source); +} + +void TargetSerialization::UpdateTargetCompiled() { + store_.target_linked = true; +} + +void TargetSerialization::UpdateStore(const TargetSchema &store) { + TargetSchema temp = store; + temp.internal_pchs = store_.internal_pchs; + temp.pch_compiled = store_.pch_compiled; + temp.internal_sources = store_.internal_sources; + temp.target_linked = store_.target_linked; + store_ = std::move(temp); +} + +// PRIVATE +bool TargetSerialization::Verify(const std::string &serialized_data) { + flatbuffers::Verifier verifier((const uint8_t *)serialized_data.c_str(), + serialized_data.length()); + return fbs::VerifyTargetBuffer(verifier); +} + +bool TargetSerialization::Load(const std::string &serialized_data) { + const auto *target = fbs::GetTarget((const void *)serialized_data.c_str()); + if (target == nullptr) { + return false; + } + + extract_path(target->source_files(), load_.internal_sources); + extract_path(target->header_files(), load_.internal_headers); + extract_path(target->pch_files(), load_.internal_pchs); + extract_path(target->lib_deps(), load_.internal_libs); + + extract(target->external_lib_deps(), load_.external_libs); + + extract(target->include_dirs(), load_.include_dirs); + extract(target->lib_dirs(), load_.lib_dirs); + + extract(target->preprocessor_flags(), load_.preprocessor_flags); + extract(target->common_compile_flags(), load_.common_compile_flags); + extract(target->pch_compile_flags(), load_.pch_compile_flags); + extract(target->pch_object_flags(), load_.pch_object_flags); + extract(target->asm_compile_flags(), load_.asm_compile_flags); + extract(target->c_compile_flags(), load_.c_compile_flags); + extract(target->cpp_compile_flags(), load_.cpp_compile_flags); + extract(target->link_flags(), load_.link_flags); + + extract_path(target->compile_dependencies(), + load_.internal_compile_dependencies); + extract_path(target->link_dependencies(), load_.internal_link_dependencies); + + load_.pch_compiled = target->pch_compiled(); + load_.target_linked = target->target_linked(); + return true; +} + +bool TargetSerialization::Store(const fs::path &absolute_serialized_file) { + flatbuffers::FlatBufferBuilder builder; + + auto fbs_target_type = (fbs::TargetType)store_.type; + + auto fbs_source_files = + internal::create_fbs_vector_path(builder, store_.internal_sources); + auto fbs_header_files = + internal::create_fbs_vector_path(builder, store_.internal_headers); + auto fbs_pch_files = + internal::create_fbs_vector_path(builder, store_.internal_pchs); + + auto fbs_lib_deps = + internal::create_fbs_vector_path(builder, store_.internal_libs); + auto fbs_external_lib_deps = + internal::create_fbs_vector_string(builder, store_.external_libs); + + auto fbs_include_dirs = + internal::create_fbs_vector_string(builder, store_.include_dirs); + auto fbs_lib_dirs = + internal::create_fbs_vector_string(builder, store_.lib_dirs); + + auto fbs_preprocessor_flags = + internal::create_fbs_vector_string(builder, store_.preprocessor_flags); + auto fbs_common_compile_flags = + internal::create_fbs_vector_string(builder, store_.common_compile_flags); + auto fbs_pch_compile_flags = + internal::create_fbs_vector_string(builder, store_.pch_compile_flags); + auto fbs_pch_object_flags = + internal::create_fbs_vector_string(builder, store_.pch_object_flags); + auto fbs_asm_compile_flags = + internal::create_fbs_vector_string(builder, store_.asm_compile_flags); + auto fbs_c_compile_flags = + internal::create_fbs_vector_string(builder, store_.c_compile_flags); + auto fbs_cpp_compile_flags = + internal::create_fbs_vector_string(builder, store_.cpp_compile_flags); + auto fbs_link_flags = + internal::create_fbs_vector_string(builder, store_.link_flags); + + auto fbs_compile_dependencies = internal::create_fbs_vector_path( + builder, store_.internal_compile_dependencies); + auto fbs_link_dependencies = internal::create_fbs_vector_path( + builder, store_.internal_link_dependencies); + + auto fbs_target = fbs::CreateTargetDirect( + builder, store_.name.c_str(), fbs_target_type, &fbs_source_files, + &fbs_header_files, &fbs_pch_files, &fbs_lib_deps, &fbs_external_lib_deps, + &fbs_include_dirs, &fbs_lib_dirs, &fbs_preprocessor_flags, + &fbs_common_compile_flags, &fbs_pch_compile_flags, &fbs_pch_object_flags, + &fbs_asm_compile_flags, &fbs_c_compile_flags, &fbs_cpp_compile_flags, + &fbs_link_flags, &fbs_compile_dependencies, &fbs_link_dependencies, + store_.pch_compiled, store_.target_linked); + fbs::FinishTargetBuffer(builder, fbs_target); + + return env::save_file(path_as_string(absolute_serialized_file).c_str(), + (const char *)builder.GetBufferPointer(), + builder.GetSize(), true); +} + +} // namespace buildcc::internal diff --git a/buildcc/lib/target/src/target/target_storer.cpp b/buildcc/lib/target/src/target/target_storer.cpp index 65793748..f1a17c82 100644 --- a/buildcc/lib/target/src/target/target_storer.cpp +++ b/buildcc/lib/target/src/target/target_storer.cpp @@ -27,78 +27,6 @@ namespace fbs = schema::internal; -namespace { +namespace {} // namespace -fbs::TargetType CreateFbsTargetType(buildcc::TargetType type) { - return (fbs::TargetType)type; -} - -} // namespace - -namespace buildcc { - -bool Target::Store() { - env::log_trace(name_, __FUNCTION__); - - flatbuffers::FlatBufferBuilder builder; - - auto fbs_target_type = CreateFbsTargetType(type_); - - auto fbs_source_files = internal::create_fbs_vector_path( - builder, storer_.current_source_files.internal); - auto fbs_header_files = internal::create_fbs_vector_path( - builder, storer_.current_header_files.internal); - auto fbs_pch_files = internal::create_fbs_vector_path( - builder, storer_.current_pch_files.internal); - // NOTE, This can be UNORDERED - auto fbs_lib_deps = internal::create_fbs_vector_path( - builder, storer_.current_internal_lib_deps); - - // NOTE, This can be UNORDERED - auto fbs_external_lib_deps = internal::create_fbs_vector_string( - builder, storer_.current_internal_external_lib_deps); - - auto fbs_include_dirs = - internal::create_fbs_vector_string(builder, storer_.current_include_dirs); - auto fbs_lib_dirs = - internal::create_fbs_vector_string(builder, storer_.current_lib_dirs); - - auto fbs_preprocessor_flags = internal::create_fbs_vector_string( - builder, storer_.current_preprocessor_flags); - auto fbs_common_compile_flags = internal::create_fbs_vector_string( - builder, storer_.current_common_compile_flags); - auto fbs_pch_compile_flags = internal::create_fbs_vector_string( - builder, storer_.current_pch_compile_flags); - auto fbs_pch_object_flags = internal::create_fbs_vector_string( - builder, storer_.current_pch_object_flags); - auto fbs_asm_compile_flags = internal::create_fbs_vector_string( - builder, storer_.current_asm_compile_flags); - auto fbs_c_compile_flags = internal::create_fbs_vector_string( - builder, storer_.current_c_compile_flags); - auto fbs_cpp_compile_flags = internal::create_fbs_vector_string( - builder, storer_.current_cpp_compile_flags); - auto fbs_link_flags = - internal::create_fbs_vector_string(builder, storer_.current_link_flags); - - auto fbs_compile_dependencies = internal::create_fbs_vector_path( - builder, storer_.current_compile_dependencies.internal); - auto fbs_link_dependencies = internal::create_fbs_vector_path( - builder, storer_.current_link_dependencies.internal); - - auto fbs_target = fbs::CreateTargetDirect( - builder, name_.c_str(), fbs_target_type, &fbs_source_files, - &fbs_header_files, &fbs_pch_files, &fbs_lib_deps, &fbs_external_lib_deps, - &fbs_include_dirs, &fbs_lib_dirs, &fbs_preprocessor_flags, - &fbs_common_compile_flags, &fbs_pch_compile_flags, &fbs_pch_object_flags, - &fbs_asm_compile_flags, &fbs_c_compile_flags, &fbs_cpp_compile_flags, - &fbs_link_flags, &fbs_compile_dependencies, &fbs_link_dependencies, - storer_.pch_compiled, storer_.target_linked); - fbs::FinishTargetBuffer(builder, fbs_target); - - auto file_path = GetBinaryPath(); - return env::save_file(path_as_string(file_path).c_str(), - (const char *)builder.GetBufferPointer(), - builder.GetSize(), true); -} - -} // namespace buildcc +namespace buildcc {} // namespace buildcc diff --git a/buildcc/lib/target/src/target/tasks.cpp b/buildcc/lib/target/src/target/tasks.cpp index 772d31e9..94b81ec7 100644 --- a/buildcc/lib/target/src/target/tasks.cpp +++ b/buildcc/lib/target/src/target/tasks.cpp @@ -80,6 +80,7 @@ void CompilePch::Task() { task_ = target_.tf_.emplace([&](tf::Subflow &subflow) { try { BuildCompile(); + target_.serialization_.UpdatePchCompiled(target_.user_); } catch (...) { target_.SetTaskStateFailure(); } @@ -111,9 +112,9 @@ void CompileObject::Task() { try { BuildObjectCompile(selected_source_files, selected_dummy_source_files); - target_.compiled_source_files_.clear(); - target_.compiled_source_files_.insert(selected_dummy_source_files.begin(), - selected_dummy_source_files.end()); + for (const auto &piter : selected_dummy_source_files) { + target_.serialization_.AddSource(piter); + } for (const auto &s : selected_source_files) { std::string name = fmt::format("{}", s.GetPathname().lexically_relative( @@ -124,17 +125,9 @@ void CompileObject::Task() { bool success = env::Command::Execute( GetObjectData(s.GetPathname()).command); env::assert_throw(success, "Could not compile source"); - - // NOTE, If conmpilation is successful we update the source - // files - std::lock_guard guard( - target_.compiled_source_files_mutex_); - target_.compiled_source_files_.insert(s); + target_.serialization_.AddSource(s); } catch (...) { target_.SetTaskStateFailure(); - - // NOTE, If compilation fails, we do not need to update the - // source files } }) .name(name); @@ -177,8 +170,8 @@ void Target::EndTask() { target_end_task_ = tf_.emplace([&]() { if (dirty_) { try { - storer_.current_source_files.internal = compiled_source_files_; - env::assert_throw(Store(), + serialization_.UpdateStore(user_); + env::assert_throw(serialization_.StoreToFile(), fmt::format("Store failed for {}", GetName())); state_.build = true; } catch (...) { From 7c00284f8a9d55ffd5d64919e58fab3fcf3b0864 Mon Sep 17 00:00:00 2001 From: coder137 Date: Wed, 9 Feb 2022 20:10:13 -0800 Subject: [PATCH 10/19] Updated unit tests with Target serialization --- .../test/target/test_target_external_lib.cpp | 21 +++--- .../target/test_target_failure_states.cpp | 1 + .../target/test/target/test_target_flags.cpp | 44 +++++++----- .../test/target/test_target_include_dir.cpp | 71 ++++++++++--------- .../test/target/test_target_lib_dep.cpp | 12 ++-- .../target/test/target/test_target_source.cpp | 28 ++++---- 6 files changed, 98 insertions(+), 79 deletions(-) diff --git a/buildcc/lib/target/test/target/test_target_external_lib.cpp b/buildcc/lib/target/test/target/test_target_external_lib.cpp index 8500de88..72e7dcdf 100644 --- a/buildcc/lib/target/test/target/test_target_external_lib.cpp +++ b/buildcc/lib/target/test/target/test_target_external_lib.cpp @@ -7,7 +7,7 @@ #include "target/target.h" -#include "target/base/target_loader.h" +#include "target/serialization/target_serialization.h" #include #include @@ -53,12 +53,12 @@ TEST(TargetTestExternalLib, TestAddLibDir) { mock().checkExpectations(); // Verify binary - buildcc::internal::TargetLoader loader(EXENAME, exe.GetTargetBuildDir()); - bool loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + exe.GetTargetBuildDir() / (std::string(EXENAME) + ".bin")); + bool loaded = serialization.LoadFromFile(); CHECK_TRUE(loaded); - - CHECK_EQUAL(loader.GetLoadedLibDirs().size(), 1); - CHECK_EQUAL(loader.GetLoadedExternalLibDeps().size(), 0); + CHECK_EQUAL(serialization.GetLoad().lib_dirs.size(), 1); + CHECK_EQUAL(serialization.GetLoad().external_libs.size(), 0); } TEST(TargetTestExternalLib, TestAddExternalLibDep_Simple) { @@ -81,12 +81,13 @@ TEST(TargetTestExternalLib, TestAddExternalLibDep_Simple) { mock().checkExpectations(); // Verify binary - buildcc::internal::TargetLoader loader(EXENAME, exe.GetTargetBuildDir()); - bool loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + exe.GetTargetBuildDir() / (std::string(EXENAME) + ".bin")); + bool loaded = serialization.LoadFromFile(); CHECK_TRUE(loaded); - CHECK_EQUAL(loader.GetLoadedLibDirs().size(), 1); - CHECK_EQUAL(loader.GetLoadedExternalLibDeps().size(), 1); + CHECK_EQUAL(serialization.GetLoad().lib_dirs.size(), 1); + CHECK_EQUAL(serialization.GetLoad().external_libs.size(), 1); } TEST(TargetTestExternalLib, TestAddExternalLibDep_RebuildChanged) { diff --git a/buildcc/lib/target/test/target/test_target_failure_states.cpp b/buildcc/lib/target/test/target/test_target_failure_states.cpp index 4b9bac5a..bfe00ed9 100644 --- a/buildcc/lib/target/test/target/test_target_failure_states.cpp +++ b/buildcc/lib/target/test/target/test_target_failure_states.cpp @@ -193,6 +193,7 @@ TEST(TargetTestFailureStates, CompilePchFailure_Rebuild) { target.AddPch("include/include_header.h"); target.Build(); + buildcc::m::TargetExpect_PathAdded(1, &target); buildcc::env::m::CommandExpect_Execute(1, true); // PCH compile buildcc::env::m::CommandExpect_Execute(1, true); // Object compile buildcc::env::m::CommandExpect_Execute(1, true); // Link target diff --git a/buildcc/lib/target/test/target/test_target_flags.cpp b/buildcc/lib/target/test/target/test_target_flags.cpp index 8b6cb218..21acef59 100644 --- a/buildcc/lib/target/test/target/test_target_flags.cpp +++ b/buildcc/lib/target/test/target/test_target_flags.cpp @@ -8,7 +8,7 @@ #include "env/env.h" // -#include "target/base/target_loader.h" +#include "target/serialization/target_serialization.h" // Third Party @@ -62,11 +62,12 @@ TEST(TargetTestPreprocessorFlagGroup, Target_AddPreprocessorFlag) { mock().checkExpectations(); // Verify binary - buildcc::internal::TargetLoader loader(NAME, simple.GetTargetBuildDir()); - bool loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + simple.GetTargetBuildDir() / (std::string(NAME) + ".bin")); + bool loaded = serialization.LoadFromFile(); CHECK_TRUE(loaded); - CHECK_EQUAL(loader.GetLoadedPreprocessorFlags().size(), 1); + CHECK_EQUAL(serialization.GetLoad().preprocessor_flags.size(), 1); } TEST(TargetTestPreprocessorFlagGroup, Target_ChangedPreprocessorFlag) { @@ -160,11 +161,12 @@ TEST(TargetTestCommonCompileFlagsGroup, Target_AddCommonCompileFlag) { mock().checkExpectations(); // Verify binary - buildcc::internal::TargetLoader loader(NAME, simple.GetTargetBuildDir()); - bool loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + simple.GetTargetBuildDir() / (std::string(NAME) + ".bin")); + bool loaded = serialization.LoadFromFile(); CHECK_TRUE(loaded); - CHECK_EQUAL(loader.GetLoadedCommonCompileFlags().size(), 2); + CHECK_EQUAL(serialization.GetLoad().common_compile_flags.size(), 2); } TEST(TargetTestCommonCompileFlagsGroup, Target_ChangedCommonCompileFlag) { @@ -274,11 +276,12 @@ TEST(TargetTestAsmCompileFlagGroup, Target_AddCompileFlag) { mock().checkExpectations(); // Verify binary - buildcc::internal::TargetLoader loader(NAME, simple.GetTargetBuildDir()); - bool loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + simple.GetTargetBuildDir() / (std::string(NAME) + ".bin")); + bool loaded = serialization.LoadFromFile(); CHECK_TRUE(loaded); - CHECK_EQUAL(loader.GetLoadedAsmCompileFlags().size(), 2); + CHECK_EQUAL(serialization.GetLoad().asm_compile_flags.size(), 2); } TEST(TargetTestAsmCompileFlagGroup, Target_ChangedCompileFlag) { @@ -388,11 +391,12 @@ TEST(TargetTestCCompileFlagsGroup, Target_AddCompileFlag) { mock().checkExpectations(); // Verify binary - buildcc::internal::TargetLoader loader(NAME, simple.GetTargetBuildDir()); - bool loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + simple.GetTargetBuildDir() / (std::string(NAME) + ".bin")); + bool loaded = serialization.LoadFromFile(); CHECK_TRUE(loaded); - CHECK_EQUAL(loader.GetLoadedCCompileFlags().size(), 1); + CHECK_EQUAL(serialization.GetLoad().c_compile_flags.size(), 1); } TEST(TargetTestCCompileFlagsGroup, Target_ChangedCompileFlag) { @@ -485,11 +489,12 @@ TEST(TargetTestCppCompileFlagsGroup, Target_AddCompileFlag) { mock().checkExpectations(); // Verify binary - buildcc::internal::TargetLoader loader(NAME, simple.GetTargetBuildDir()); - bool loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + simple.GetTargetBuildDir() / (std::string(NAME) + ".bin")); + bool loaded = serialization.LoadFromFile(); CHECK_TRUE(loaded); - CHECK_EQUAL(loader.GetLoadedCppCompileFlags().size(), 1); + CHECK_EQUAL(serialization.GetLoad().cpp_compile_flags.size(), 1); } TEST(TargetTestCppCompileFlagsGroup, Target_ChangedCompileFlag) { @@ -582,11 +587,12 @@ TEST(TargetTestLinkFlagsGroup, Target_AddLinkFlag) { mock().checkExpectations(); // Verify binary - buildcc::internal::TargetLoader loader(NAME, simple.GetTargetBuildDir()); - bool loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + simple.GetTargetBuildDir() / (std::string(NAME) + ".bin")); + bool loaded = serialization.LoadFromFile(); CHECK_TRUE(loaded); - CHECK_EQUAL(loader.GetLoadedLinkFlags().size(), 1); + CHECK_EQUAL(serialization.GetLoad().link_flags.size(), 1); } TEST(TargetTestLinkFlagsGroup, Target_ChangedLinkFlag) { diff --git a/buildcc/lib/target/test/target/test_target_include_dir.cpp b/buildcc/lib/target/test/target/test_target_include_dir.cpp index 2a65112a..323a6935 100644 --- a/buildcc/lib/target/test/target/test_target_include_dir.cpp +++ b/buildcc/lib/target/test/target/test_target_include_dir.cpp @@ -114,11 +114,12 @@ TEST(TargetTestIncludeDirGroup, TargetBuildIncludeDir) { include_compile.Build(); buildcc::m::TargetRunner(include_compile); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - const auto &loaded_sources = loader.GetLoadedSources(); - const auto &loaded_dirs = loader.GetLoadedIncludeDirs(); + const auto &loaded_sources = serialization.GetLoad().internal_sources; + const auto &loaded_dirs = serialization.GetLoad().include_dirs; CHECK_EQUAL(loaded_sources.size(), 2); CHECK_EQUAL(loaded_dirs.size(), 1); @@ -146,11 +147,12 @@ TEST(TargetTestIncludeDirGroup, TargetBuildIncludeDir) { include_compile.Build(); buildcc::m::TargetRunner(include_compile); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - const auto &loaded_sources = loader.GetLoadedSources(); - const auto &loaded_dirs = loader.GetLoadedIncludeDirs(); + const auto &loaded_sources = serialization.GetLoad().internal_sources; + const auto &loaded_dirs = serialization.GetLoad().include_dirs; CHECK_EQUAL(loaded_sources.size(), 2); CHECK_EQUAL(loaded_dirs.size(), 2); @@ -175,11 +177,12 @@ TEST(TargetTestIncludeDirGroup, TargetBuildIncludeDir) { include_compile.Build(); buildcc::m::TargetRunner(include_compile); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - const auto &loaded_sources = loader.GetLoadedSources(); - const auto &loaded_dirs = loader.GetLoadedIncludeDirs(); + const auto &loaded_sources = serialization.GetLoad().internal_sources; + const auto &loaded_dirs = serialization.GetLoad().include_dirs; CHECK_EQUAL(loaded_sources.size(), 2); CHECK_EQUAL(loaded_dirs.size(), 1); @@ -228,12 +231,13 @@ TEST(TargetTestIncludeDirGroup, TargetBuildHeaderFile) { add_header.Build(); buildcc::m::TargetRunner(add_header); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - CHECK_EQUAL(loader.GetLoadedSources().size(), 2); - CHECK_EQUAL(loader.GetLoadedIncludeDirs().size(), 1); - CHECK_EQUAL(loader.GetLoadedHeaders().size(), 0); + CHECK_EQUAL(serialization.GetLoad().internal_sources.size(), 2); + CHECK_EQUAL(serialization.GetLoad().include_dirs.size(), 1); + CHECK_EQUAL(serialization.GetLoad().internal_headers.size(), 0); } // Add header @@ -251,12 +255,13 @@ TEST(TargetTestIncludeDirGroup, TargetBuildHeaderFile) { add_header.Build(); buildcc::m::TargetRunner(add_header); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - CHECK_EQUAL(loader.GetLoadedSources().size(), 2); - CHECK_EQUAL(loader.GetLoadedIncludeDirs().size(), 1); - CHECK_EQUAL(loader.GetLoadedHeaders().size(), 1); + CHECK_EQUAL(serialization.GetLoad().internal_sources.size(), 2); + CHECK_EQUAL(serialization.GetLoad().include_dirs.size(), 1); + CHECK_EQUAL(serialization.GetLoad().internal_headers.size(), 1); } // Update header @@ -280,12 +285,13 @@ TEST(TargetTestIncludeDirGroup, TargetBuildHeaderFile) { add_header.Build(); buildcc::m::TargetRunner(add_header); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - CHECK_EQUAL(loader.GetLoadedSources().size(), 2); - CHECK_EQUAL(loader.GetLoadedIncludeDirs().size(), 1); - CHECK_EQUAL(loader.GetLoadedHeaders().size(), 1); + CHECK_EQUAL(serialization.GetLoad().internal_sources.size(), 2); + CHECK_EQUAL(serialization.GetLoad().include_dirs.size(), 1); + CHECK_EQUAL(serialization.GetLoad().internal_headers.size(), 1); } // Remove header @@ -302,12 +308,13 @@ TEST(TargetTestIncludeDirGroup, TargetBuildHeaderFile) { add_header.Build(); buildcc::m::TargetRunner(add_header); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - CHECK_EQUAL(loader.GetLoadedSources().size(), 2); - CHECK_EQUAL(loader.GetLoadedIncludeDirs().size(), 1); - CHECK_EQUAL(loader.GetLoadedHeaders().size(), 0); + CHECK_EQUAL(serialization.GetLoad().internal_sources.size(), 2); + CHECK_EQUAL(serialization.GetLoad().include_dirs.size(), 1); + CHECK_EQUAL(serialization.GetLoad().internal_headers.size(), 0); } mock().checkExpectations(); diff --git a/buildcc/lib/target/test/target/test_target_lib_dep.cpp b/buildcc/lib/target/test/target/test_target_lib_dep.cpp index 4d2cf140..f9ff8faf 100644 --- a/buildcc/lib/target/test/target/test_target_lib_dep.cpp +++ b/buildcc/lib/target/test/target/test_target_lib_dep.cpp @@ -9,7 +9,7 @@ #include "target/target.h" // -#include "target/base/target_loader.h" +#include "target/serialization/target_serialization.h" #include #include @@ -54,13 +54,13 @@ TEST(TargetTestLibDep, StaticLibrary_SimpleBuildTest) { mock().checkExpectations(); // Verify binary - buildcc::internal::TargetLoader loader(STATIC_NAME, - foolib.GetTargetBuildDir()); - bool loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + foolib.GetTargetBuildDir() / (std::string(STATIC_NAME) + ".bin")); + bool loaded = serialization.LoadFromFile(); CHECK_TRUE(loaded); - CHECK_EQUAL(loader.GetLoadedSources().size(), 1); - CHECK_EQUAL(loader.GetLoadedIncludeDirs().size(), 1); + CHECK_EQUAL(serialization.GetLoad().internal_sources.size(), 1); + CHECK_EQUAL(serialization.GetLoad().include_dirs.size(), 1); } TEST(TargetTestLibDep, TargetDep_RebuildTest) { diff --git a/buildcc/lib/target/test/target/test_target_source.cpp b/buildcc/lib/target/test/target/test_target_source.cpp index c68f6ea4..13d3974f 100644 --- a/buildcc/lib/target/test/target/test_target_source.cpp +++ b/buildcc/lib/target/test/target/test_target_source.cpp @@ -107,11 +107,12 @@ TEST(TargetTestSourceGroup, Target_Build_SourceCompile) { mock().checkExpectations(); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - const auto &loaded_sources = loader.GetLoadedSources(); + const auto &loaded_sources = serialization.GetLoad().internal_sources; CHECK_EQUAL(loaded_sources.size(), 1); auto dummy_file = buildcc::internal::Path::CreateExistingPath( (source_path / DUMMY_MAIN).make_preferred().string()); @@ -150,11 +151,12 @@ TEST(TargetTestSourceGroup, Target_Build_SourceRecompile) { simple.Build(); buildcc::m::TargetRunner(simple); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - const auto &loaded_sources = loader.GetLoadedSources(); + const auto &loaded_sources = serialization.GetLoad().internal_sources; CHECK_EQUAL(loaded_sources.size(), 2); CHECK_FALSE(loaded_sources.find(dummy_c_file) == loaded_sources.end()); @@ -181,11 +183,12 @@ TEST(TargetTestSourceGroup, Target_Build_SourceRecompile) { simple.Build(); buildcc::m::TargetRunner(simple); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - const auto &loaded_sources = loader.GetLoadedSources(); + const auto &loaded_sources = serialization.GetLoad().internal_sources; CHECK_EQUAL(loaded_sources.size(), 2); CHECK_FALSE(loaded_sources.find(dummy_cpp_file) == loaded_sources.end()); CHECK_FALSE(loaded_sources.find(new_source_file) == loaded_sources.end()); @@ -211,11 +214,12 @@ TEST(TargetTestSourceGroup, Target_Build_SourceRecompile) { simple.Build(); buildcc::m::TargetRunner(simple); - buildcc::internal::TargetLoader loader(NAME, intermediate_path); - bool is_loaded = loader.Load(); + buildcc::internal::TargetSerialization serialization( + intermediate_path / (std::string(NAME) + ".bin")); + bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); - const auto &loaded_sources = loader.GetLoadedSources(); + const auto &loaded_sources = serialization.GetLoad().internal_sources; CHECK_EQUAL(loaded_sources.size(), 2); CHECK_FALSE(loaded_sources.find(dummy_cpp_file) == loaded_sources.end()); CHECK_FALSE(loaded_sources.find(new_source_file) == loaded_sources.end()); From 34b552f87c8dfa6bccc506bda8b0eb9e322fa234 Mon Sep 17 00:00:00 2001 From: coder137 Date: Wed, 9 Feb 2022 20:54:43 -0800 Subject: [PATCH 11/19] Removed loader and storer srcs and includes --- .../include/target/base/generator_loader.h | 67 -------- .../include/target/base/target_loader.h | 145 ------------------ .../include/target/base/target_storer.h | 60 -------- buildcc/lib/target/include/target/generator.h | 1 - buildcc/lib/target/include/target/target.h | 7 - .../lib/target/include/target/target_info.h | 1 - .../target/src/generator/generator_loader.cpp | 57 ------- .../target/src/generator/generator_storer.cpp | 28 ---- .../lib/target/src/target/target_loader.cpp | 83 ---------- .../lib/target/src/target/target_storer.cpp | 32 ---- 10 files changed, 481 deletions(-) delete mode 100644 buildcc/lib/target/include/target/base/generator_loader.h delete mode 100644 buildcc/lib/target/include/target/base/target_loader.h delete mode 100644 buildcc/lib/target/include/target/base/target_storer.h delete mode 100644 buildcc/lib/target/src/generator/generator_loader.cpp delete mode 100644 buildcc/lib/target/src/generator/generator_storer.cpp delete mode 100644 buildcc/lib/target/src/target/target_loader.cpp delete mode 100644 buildcc/lib/target/src/target/target_storer.cpp diff --git a/buildcc/lib/target/include/target/base/generator_loader.h b/buildcc/lib/target/include/target/base/generator_loader.h deleted file mode 100644 index a3bc0e85..00000000 --- a/buildcc/lib/target/include/target/base/generator_loader.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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_BASE_GENERATOR_LOADER_H_ -#define TARGET_BASE_GENERATOR_LOADER_H_ - -#include "target/interface/loader_interface.h" - -#include -#include -#include - -#include "fmt/format.h" - -#include "target/common/path.h" - -namespace buildcc::internal { - -class GeneratorLoader : public LoaderInterface { -public: - GeneratorLoader(const std::string &name, const fs::path &absolute_path) - : name_(name), path_(absolute_path) { - binary_path_ = absolute_path / fmt::format("{}.bin", name); - } - - GeneratorLoader(const GeneratorLoader &loader) = delete; - - bool Load() override; - - // Getters - const internal::path_unordered_set &GetLoadedInputFiles() const noexcept { - return loaded_input_files_; - } - - const fs_unordered_set &GetLoadedOutputFiles() const noexcept { - return loaded_output_files_; - } - - const std::vector &GetLoadedCommands() const noexcept { - return loaded_commands_; - } - -private: - std::string name_; - fs::path path_; - - internal::path_unordered_set loaded_input_files_; - fs_unordered_set loaded_output_files_; - std::vector loaded_commands_; -}; - -} // namespace buildcc::internal - -#endif diff --git a/buildcc/lib/target/include/target/base/target_loader.h b/buildcc/lib/target/include/target/base/target_loader.h deleted file mode 100644 index 9bf1161f..00000000 --- a/buildcc/lib/target/include/target/base/target_loader.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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_BASE_TARGET_LOADER_H_ -#define TARGET_BASE_TARGET_LOADER_H_ - -#include "target/interface/loader_interface.h" - -#include -#include - -#include "fmt/format.h" - -#include "target/common/path.h" - -namespace buildcc::internal { - -class TargetLoader : public LoaderInterface { -public: - explicit TargetLoader(const std::string &name, const fs::path &relative_path) - : name_(name), relative_path_(relative_path) { - binary_path_ = relative_path / fmt::format("{}.bin", name); - Initialize(); - } - - TargetLoader(const TargetLoader &loader) = delete; - -public: - bool Load() override; - - // Getters - const path_unordered_set &GetLoadedSources() const noexcept { - return loaded_sources_; - } - const path_unordered_set &GetLoadedHeaders() const noexcept { - return loaded_headers_; - } - const path_unordered_set &GetLoadedPchs() const noexcept { - return loaded_pchs_; - } - const path_unordered_set &GetLoadedLibDeps() const noexcept { - return loaded_lib_deps_; - } - const std::unordered_set & - GetLoadedExternalLibDeps() const noexcept { - return loaded_external_lib_dirs_; - } - - const fs_unordered_set &GetLoadedIncludeDirs() const noexcept { - return loaded_include_dirs_; - } - const fs_unordered_set &GetLoadedLibDirs() const noexcept { - return loaded_lib_dirs_; - } - const std::unordered_set & - GetLoadedPreprocessorFlags() const noexcept { - return loaded_preprocessor_flags_; - } - const std::unordered_set & - GetLoadedCommonCompileFlags() const noexcept { - return loaded_common_compile_flags_; - } - const std::unordered_set & - GetLoadedPchCompileFlags() const noexcept { - return loaded_pch_compile_flags_; - } - const std::unordered_set & - GetLoadedPchObjectFlags() const noexcept { - return loaded_pch_object_flags_; - } - const std::unordered_set & - GetLoadedAsmCompileFlags() const noexcept { - return loaded_asm_compile_flags_; - } - const std::unordered_set & - GetLoadedCCompileFlags() const noexcept { - return loaded_c_compile_flags_; - } - const std::unordered_set & - GetLoadedCppCompileFlags() const noexcept { - return loaded_cpp_compile_flags_; - } - const std::unordered_set &GetLoadedLinkFlags() const noexcept { - return loaded_link_flags_; - } - - const path_unordered_set &GetLoadedCompileDependencies() const noexcept { - return loaded_compile_dependencies_; - } - const path_unordered_set &GetLoadedLinkDependencies() const noexcept { - return loaded_link_dependencies_; - } - - bool GetLoadedPchCompiled() const noexcept { return loaded_pch_compiled_; } - bool GetLoadedTargetLinked() const noexcept { return loaded_target_linked_; } - -private: - void Initialize(); - -private: - std::string name_; - fs::path relative_path_; - - path_unordered_set loaded_sources_; - path_unordered_set loaded_headers_; - path_unordered_set loaded_pchs_; - path_unordered_set loaded_lib_deps_; - - std::unordered_set loaded_external_lib_dirs_; - - fs_unordered_set loaded_include_dirs_; - fs_unordered_set loaded_lib_dirs_; - - std::unordered_set loaded_preprocessor_flags_; - std::unordered_set loaded_common_compile_flags_; - std::unordered_set loaded_pch_compile_flags_; - std::unordered_set loaded_pch_object_flags_; - std::unordered_set loaded_asm_compile_flags_; - std::unordered_set loaded_c_compile_flags_; - std::unordered_set loaded_cpp_compile_flags_; - std::unordered_set loaded_link_flags_; - - path_unordered_set loaded_compile_dependencies_; - path_unordered_set loaded_link_dependencies_; - - bool loaded_pch_compiled_{false}; - bool loaded_target_linked_{false}; -}; - -} // namespace buildcc::internal - -#endif diff --git a/buildcc/lib/target/include/target/base/target_storer.h b/buildcc/lib/target/include/target/base/target_storer.h deleted file mode 100644 index c8cceea6..00000000 --- a/buildcc/lib/target/include/target/base/target_storer.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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_BASE_TARGET_STORER_H_ -#define TARGET_BASE_TARGET_STORER_H_ - -#include - -#include "target/common/path.h" - -namespace buildcc::internal { - -struct TargetStorer { - internal::RelationalPathFiles current_source_files; - internal::RelationalPathFiles current_header_files; - internal::RelationalPathFiles current_pch_files; - - // NOTE, Order matters (BuildCC takes care of the order here) - std::vector current_user_lib_deps; - internal::path_unordered_set current_internal_lib_deps; - - fs_unordered_set current_include_dirs; - fs_unordered_set current_lib_dirs; - - // NOTE, Order matters (user takes care of the order here) - std::vector current_user_external_lib_deps; - std::unordered_set current_internal_external_lib_deps; - - std::unordered_set current_preprocessor_flags; - std::unordered_set current_common_compile_flags; - std::unordered_set current_pch_compile_flags; - std::unordered_set current_pch_object_flags; - std::unordered_set current_asm_compile_flags; - std::unordered_set current_c_compile_flags; - std::unordered_set current_cpp_compile_flags; - std::unordered_set current_link_flags; - - internal::RelationalPathFiles current_compile_dependencies; - internal::RelationalPathFiles current_link_dependencies; - - bool pch_compiled{false}; - bool target_linked{false}; -}; - -} // namespace buildcc::internal - -#endif diff --git a/buildcc/lib/target/include/target/generator.h b/buildcc/lib/target/include/target/generator.h index 6abcfe6d..949e9fcd 100644 --- a/buildcc/lib/target/include/target/generator.h +++ b/buildcc/lib/target/include/target/generator.h @@ -32,7 +32,6 @@ #include "target/interface/builder_interface.h" -#include "target/base/generator_loader.h" #include "target/serialization/generator_serialization.h" #include "target/common/path.h" diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index ab0a55dc..3ec2310b 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -43,10 +43,7 @@ #include "target/friend/link_target.h" // Internal -#include "target/base/target_loader.h" -#include "target/base/target_storer.h" #include "target/common/path.h" - #include "target/serialization/target_serialization.h" // Env @@ -146,7 +143,6 @@ class Target : public internal::BuilderInterface, std::string name_; TargetType type_; const Toolchain &toolchain_; - // internal::TargetLoader loader_; internal::TargetSerialization serialization_; // Friend classes @@ -161,9 +157,6 @@ class Target : public internal::BuilderInterface, std::mutex task_state_mutex_; env::TaskState task_state_{env::TaskState::SUCCESS}; - std::mutex compiled_source_files_mutex_; - // internal::path_unordered_set compiled_source_files_; - // env::Command command_; tf::Taskflow tf_; diff --git a/buildcc/lib/target/include/target/target_info.h b/buildcc/lib/target/include/target/target_info.h index b05cff85..4250e85c 100644 --- a/buildcc/lib/target/include/target/target_info.h +++ b/buildcc/lib/target/include/target/target_info.h @@ -19,7 +19,6 @@ #include -#include "target/base/target_storer.h" #include "target/common/target_config.h" #include "target/common/target_env.h" #include "target/common/target_state.h" diff --git a/buildcc/lib/target/src/generator/generator_loader.cpp b/buildcc/lib/target/src/generator/generator_loader.cpp deleted file mode 100644 index 0a54b820..00000000 --- a/buildcc/lib/target/src/generator/generator_loader.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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. - */ - -#include "target/base/generator_loader.h" - -#include "env/logging.h" -#include "env/util.h" - -// Private -#include "target/private/schema_util.h" - -#include "generator_generated.h" - -namespace buildcc::internal { - -bool GeneratorLoader::Load() { - env::log_trace(name_, __FUNCTION__); - - auto file_path = GetBinaryPath(); - std::string buffer; - bool is_loaded = - env::load_file(path_as_string(file_path).c_str(), true, &buffer); - if (!is_loaded) { - return false; - } - - flatbuffers::Verifier verifier((const uint8_t *)buffer.c_str(), - buffer.length()); - const bool is_verified = fbs::VerifyGeneratorBuffer(verifier); - if (!is_verified) { - return false; - } - - const auto *generator = fbs::GetGenerator((const void *)buffer.c_str()); - - extract_path(generator->inputs(), loaded_input_files_); - extract(generator->outputs(), loaded_output_files_); - extract(generator->commands(), loaded_commands_); - - loaded_ = true; - return true; -} - -} // namespace buildcc::internal diff --git a/buildcc/lib/target/src/generator/generator_storer.cpp b/buildcc/lib/target/src/generator/generator_storer.cpp deleted file mode 100644 index 2ba589e7..00000000 --- a/buildcc/lib/target/src/generator/generator_storer.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ - -#include "target/generator.h" - -#include "flatbuffers/flatbuffers.h" - -#include "env/util.h" - -#include "generator_generated.h" -#include "target/private/schema_util.h" - -namespace fbs = schema::internal; - -namespace buildcc {} // namespace buildcc diff --git a/buildcc/lib/target/src/target/target_loader.cpp b/buildcc/lib/target/src/target/target_loader.cpp deleted file mode 100644 index 35d40d13..00000000 --- a/buildcc/lib/target/src/target/target_loader.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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. - */ - -#include "target/base/target_loader.h" - -#include "env/logging.h" -#include "env/util.h" - -// Private -#include "target/private/schema_util.h" -#include "target_generated.h" - -namespace buildcc::internal { - -// Public functions -bool TargetLoader::Load() { - env::log_trace(name_, __FUNCTION__); - - auto file_path = GetBinaryPath(); - std::string buffer; - bool is_loaded = - env::load_file(path_as_string(file_path).c_str(), true, &buffer); - if (!is_loaded) { - return false; - } - - flatbuffers::Verifier verifier((const uint8_t *)buffer.c_str(), - buffer.length()); - const bool is_verified = fbs::VerifyTargetBuffer(verifier); - if (!is_verified) { - return false; - } - - const auto *target = fbs::GetTarget((const void *)buffer.c_str()); - // target->name()->c_str(); - // target->type(); - - extract_path(target->source_files(), loaded_sources_); - extract_path(target->header_files(), loaded_headers_); - extract_path(target->pch_files(), loaded_pchs_); - extract_path(target->lib_deps(), loaded_lib_deps_); - - extract(target->external_lib_deps(), loaded_external_lib_dirs_); - - extract(target->include_dirs(), loaded_include_dirs_); - extract(target->lib_dirs(), loaded_lib_dirs_); - - extract(target->preprocessor_flags(), loaded_preprocessor_flags_); - extract(target->common_compile_flags(), loaded_common_compile_flags_); - extract(target->pch_compile_flags(), loaded_pch_compile_flags_); - extract(target->pch_object_flags(), loaded_pch_object_flags_); - extract(target->asm_compile_flags(), loaded_asm_compile_flags_); - extract(target->c_compile_flags(), loaded_c_compile_flags_); - extract(target->cpp_compile_flags(), loaded_cpp_compile_flags_); - extract(target->link_flags(), loaded_link_flags_); - - extract_path(target->compile_dependencies(), loaded_compile_dependencies_); - extract_path(target->link_dependencies(), loaded_link_dependencies_); - - loaded_pch_compiled_ = target->pch_compiled(); - loaded_target_linked_ = target->target_linked(); - - loaded_ = true; - return true; -} - -// Private functions -void TargetLoader::Initialize() {} - -} // namespace buildcc::internal diff --git a/buildcc/lib/target/src/target/target_storer.cpp b/buildcc/lib/target/src/target/target_storer.cpp deleted file mode 100644 index f1a17c82..00000000 --- a/buildcc/lib/target/src/target/target_storer.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ - -#include "target/target.h" - -#include -#include - -#include "env/logging.h" -#include "env/util.h" - -#include "target/private/schema_util.h" -#include "target_generated.h" - -namespace fbs = schema::internal; - -namespace {} // namespace - -namespace buildcc {} // namespace buildcc From b1303b73794e06ad9c1a706ac5545a934de89bee Mon Sep 17 00:00:00 2001 From: coder137 Date: Wed, 9 Feb 2022 21:27:53 -0800 Subject: [PATCH 12/19] Removed virtual Store API from builder_interface --- .../target/include/target/api/recheck_api.h | 78 ------------------- buildcc/lib/target/include/target/generator.h | 3 - .../target/interface/builder_interface.h | 3 - buildcc/lib/target/include/target/target.h | 3 - .../test/target/test_builder_interface.cpp | 1 - 5 files changed, 88 deletions(-) delete mode 100644 buildcc/lib/target/include/target/api/recheck_api.h diff --git a/buildcc/lib/target/include/target/api/recheck_api.h b/buildcc/lib/target/include/target/api/recheck_api.h deleted file mode 100644 index 2090acf2..00000000 --- a/buildcc/lib/target/include/target/api/recheck_api.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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_API_RECHECK_API_H_ -#define TARGET_API_RECHECK_API_H_ - -#include "target/common/path.h" - -namespace buildcc::internal { - -template -inline bool recheck_changed(const T &previous, const T ¤t) { - bool changed = false; - if (previous != current) { - changed = true; - } - return changed; -} - -enum class PathChanged { - kPathNotChanged, - kPathRemoved, - kPathAdded, - kPathUpdated -}; - -inline PathChanged -recheck_path_changed(const path_unordered_set &previous_path, - const path_unordered_set ¤t_path) { - // * Old path is removed - PathChanged path_changed = kPathNotChanged; - const bool removed = std::any_of( - previous_path.begin(), previous_path.end(), [&](const internal::Path &p) { - return current_path.find(p) == current_path.end(); - }); - if (removed) { - path_changed = kPathRemoved; - } - (void)std::any_of(current_path.cbegin(), current_path.cend(), - [&](const internal::Path &p) -> bool { - bool changed = false; - const auto find = previous_path.find(p); - const bool added_cond = (find == previous_path.end()); - if (added_cond) { - changed = true; - path_changed = kPathAdded; - } else { - const bool updated_cond = - (p.GetLastWriteTimestamp() > - find->GetLastWriteTimestamp()); - if (updated_cond) { - changed = true; - path_changed = kPathUpdated; - } else { - changed = false; - } - } - return changed; - }); - return path_changed; -} - -}; // namespace buildcc::internal - -#endif diff --git a/buildcc/lib/target/include/target/generator.h b/buildcc/lib/target/include/target/generator.h index 949e9fcd..2e8b22f2 100644 --- a/buildcc/lib/target/include/target/generator.h +++ b/buildcc/lib/target/include/target/generator.h @@ -124,9 +124,6 @@ class Generator : public internal::BuilderInterface { void Convert(); void BuildGenerate(); - // TODO, Remove this later - bool Store() override { return false; } - // Recheck states void InputRemoved(); void InputAdded(); diff --git a/buildcc/lib/target/include/target/interface/builder_interface.h b/buildcc/lib/target/include/target/interface/builder_interface.h index d3ea59e9..cf2b7be8 100644 --- a/buildcc/lib/target/include/target/interface/builder_interface.h +++ b/buildcc/lib/target/include/target/interface/builder_interface.h @@ -106,9 +106,6 @@ class BuilderInterface { }); } -private: - virtual bool Store() = 0; - protected: bool dirty_{false}; std::string unique_id_; diff --git a/buildcc/lib/target/include/target/target.h b/buildcc/lib/target/include/target/target.h index 3ec2310b..f70ed25b 100644 --- a/buildcc/lib/target/include/target/target.h +++ b/buildcc/lib/target/include/target/target.h @@ -113,9 +113,6 @@ class Target : public internal::BuilderInterface, RecheckExternalLib(const std::vector &previous_external_libs, const std::vector ¤t_external_libs); - // Fbs - bool Store() override { return false; } - // Tasks void SetTaskStateFailure(); int GetTaskStateAsInt() const noexcept { diff --git a/buildcc/lib/target/test/target/test_builder_interface.cpp b/buildcc/lib/target/test/target/test_builder_interface.cpp index 8c832b36..84c14749 100644 --- a/buildcc/lib/target/test/target/test_builder_interface.cpp +++ b/buildcc/lib/target/test/target/test_builder_interface.cpp @@ -32,7 +32,6 @@ class TestBuilderInterface : public buildcc::internal::BuilderInterface { } private: - bool Store() override { return false; } buildcc::internal::path_unordered_set previous_; buildcc::internal::path_unordered_set current_; }; From 1d13feb80aed7f22e9752a8c6fea01c9612471ae Mon Sep 17 00:00:00 2001 From: Niket Naidu Date: Wed, 9 Feb 2022 23:13:54 -0800 Subject: [PATCH 13/19] Update path.h --- buildcc/lib/target/include/target/common/path.h | 1 + 1 file changed, 1 insertion(+) diff --git a/buildcc/lib/target/include/target/common/path.h b/buildcc/lib/target/include/target/common/path.h index 38b864a8..fdfadfa4 100644 --- a/buildcc/lib/target/include/target/common/path.h +++ b/buildcc/lib/target/include/target/common/path.h @@ -18,6 +18,7 @@ #define TARGET_COMMON_PATH_H_ #include +#include #include // The Path class defined below is meant to be used with Sets From f5b1ece3933ed3b562faeaeef94205983aaf7b32 Mon Sep 17 00:00:00 2001 From: coder137 Date: Thu, 10 Feb 2022 01:08:38 -0800 Subject: [PATCH 14/19] Removed RelationalPathFiles --- .../lib/target/include/target/common/path.h | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/buildcc/lib/target/include/target/common/path.h b/buildcc/lib/target/include/target/common/path.h index fdfadfa4..ad4314f1 100644 --- a/buildcc/lib/target/include/target/common/path.h +++ b/buildcc/lib/target/include/target/common/path.h @@ -174,47 +174,6 @@ path_schema_convert(const path_unordered_set &internal_path_set) { return path_set; } -// * Relation between -// - internal timestamp verified files (Path + Timestamp) -// - user facing file paths (Only Path) -// ? Why has this been done? -// We cannot guarantee that filepaths would be present -// when the user is defining the build -// The input to a Generator / Target might also be generated! -// We must only verify the File timestamp AFTER dependent Generator(s) / -// Target(s) have been built -// ? Why not do everything inside path_unordered_set? -// Users might want to query just the `fs_unordered_set` instead of the -// entire internal::path_unordered_set (The timestamp is internal -// information that the user does not need) In this case we opt for runtime -// (speed) optimization instead of memory optimization by caching the `user` -// information and `internal` information together -struct RelationalPathFiles { - RelationalPathFiles() {} - RelationalPathFiles(const path_unordered_set &i, const fs_unordered_set &u) - : internal(i), user(u) {} - - /** - * @brief Convert from fs_unordered_set to path_unordered_set - * Can assert throw if file does not exist when calling `CreateExistingPath` - */ - void Convert() { - if (done_once) { - return; - } - - done_once = true; - internal = path_schema_convert(user, Path::CreateExistingPath); - } - -public: - path_unordered_set internal; - fs_unordered_set user; - -private: - bool done_once{false}; -}; - } // namespace buildcc::internal namespace buildcc { From ded53639356de1673d14e6eec48fe5bfe6ee0cc1 Mon Sep 17 00:00:00 2001 From: coder137 Date: Thu, 10 Feb 2022 03:02:00 -0800 Subject: [PATCH 15/19] Removed loader_interface --- .../lib/target/cmake/common_target_src.cmake | 1 - .../target/interface/loader_interface.h | 40 ------------------- 2 files changed, 41 deletions(-) delete mode 100644 buildcc/lib/target/include/target/interface/loader_interface.h diff --git a/buildcc/lib/target/cmake/common_target_src.cmake b/buildcc/lib/target/cmake/common_target_src.cmake index a8cd30ee..88ec2a02 100644 --- a/buildcc/lib/target/cmake/common_target_src.cmake +++ b/buildcc/lib/target/cmake/common_target_src.cmake @@ -1,6 +1,5 @@ set(COMMON_TARGET_SRCS # Interfaces - include/target/interface/loader_interface.h include/target/interface/builder_interface.h include/target/interface/serialization_interface.h diff --git a/buildcc/lib/target/include/target/interface/loader_interface.h b/buildcc/lib/target/include/target/interface/loader_interface.h deleted file mode 100644 index 9bf838bd..00000000 --- a/buildcc/lib/target/include/target/interface/loader_interface.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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_INTERFACE_LOADER_INTERFACE_H_ -#define TARGET_INTERFACE_LOADER_INTERFACE_H_ - -#include - -namespace fs = std::filesystem; - -namespace buildcc::internal { - -class LoaderInterface { -public: - virtual bool Load() = 0; - - const fs::path &GetBinaryPath() const { return binary_path_; }; - bool IsLoaded() const noexcept { return loaded_; }; - -protected: - bool loaded_{false}; - fs::path binary_path_; -}; - -} // namespace buildcc::internal - -#endif From 32247872d90bb608abb43c4d5e711a77208caa97 Mon Sep 17 00:00:00 2001 From: coder137 Date: Thu, 10 Feb 2022 03:03:25 -0800 Subject: [PATCH 16/19] Updated serialization_interface.h --- .../target/include/target/interface/serialization_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildcc/lib/target/include/target/interface/serialization_interface.h b/buildcc/lib/target/include/target/interface/serialization_interface.h index 7cb71a70..2e2ca654 100644 --- a/buildcc/lib/target/include/target/interface/serialization_interface.h +++ b/buildcc/lib/target/include/target/interface/serialization_interface.h @@ -30,7 +30,7 @@ namespace buildcc::internal { class SerializationInterface { public: - SerializationInterface(const fs::path serialized_file) + SerializationInterface(const fs::path &serialized_file) : serialized_file_(serialized_file) {} virtual ~SerializationInterface() {} From 3f29cf5f2a99b8c67e979d60ec2b9efe48a5c823 Mon Sep 17 00:00:00 2001 From: coder137 Date: Thu, 10 Feb 2022 03:03:47 -0800 Subject: [PATCH 17/19] Added test_serialization_interface test case --- buildcc/lib/target/test/target/CMakeLists.txt | 8 ++ .../target/test_serialization_interface.cpp | 115 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 buildcc/lib/target/test/target/test_serialization_interface.cpp diff --git a/buildcc/lib/target/test/target/CMakeLists.txt b/buildcc/lib/target/test/target/CMakeLists.txt index 2797dfc6..9b914b55 100644 --- a/buildcc/lib/target/test/target/CMakeLists.txt +++ b/buildcc/lib/target/test/target/CMakeLists.txt @@ -14,7 +14,15 @@ add_executable(test_builder_interface ) target_link_libraries(test_builder_interface PRIVATE target_interface) +add_executable(test_serialization_interface + test_serialization_interface.cpp +) +target_link_libraries(test_serialization_interface PRIVATE target_interface) + add_test(NAME test_builder_interface COMMAND test_builder_interface) +add_test(NAME test_serialization_interface COMMAND test_serialization_interface + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) # Common add_executable(test_target_config diff --git a/buildcc/lib/target/test/target/test_serialization_interface.cpp b/buildcc/lib/target/test/target/test_serialization_interface.cpp new file mode 100644 index 00000000..b5083059 --- /dev/null +++ b/buildcc/lib/target/test/target/test_serialization_interface.cpp @@ -0,0 +1,115 @@ +#include "target/interface/serialization_interface.h" + +// NOTE, Make sure all these includes are AFTER the system and header includes +#include "CppUTest/CommandLineTestRunner.h" +#include "CppUTest/MemoryLeakDetectorNewMacros.h" +#include "CppUTest/TestHarness.h" +#include "CppUTest/Utest.h" +#include "CppUTestExt/MockSupport.h" + +class TestSerializationInterface + : public buildcc::internal::SerializationInterface { +public: + TestSerializationInterface(const fs::path &serialized_file) + : SerializationInterface(serialized_file) {} + + void VerifyExpectation(int calls, bool return_value) { + mock() + .expectNCalls(calls, "verify") + .onObject(this) + .andReturnValue(return_value); + } + + void LoadExpectation(int calls, bool return_value) { + mock() + .expectNCalls(calls, "load") + .onObject(this) + .andReturnValue(return_value); + } + + void StoreExpectation(int calls, bool return_value) { + mock() + .expectNCalls(calls, "store") + .onObject(this) + .andReturnValue(return_value); + } + +private: + bool Verify(const std::string &serialized_data) override { + (void)serialized_data; + return mock().actualCall("verify").onObject(this).returnBoolValue(); + } + + bool Load(const std::string &serialized_data) override { + (void)serialized_data; + return mock().actualCall("load").onObject(this).returnBoolValue(); + } + + bool Store(const fs::path &absolute_serialized_file) override { + (void)absolute_serialized_file; + return mock().actualCall("store").onObject(this).returnBoolValue(); + } +}; + +// clang-format off +TEST_GROUP(TestSerializationInterfaceGroup) +{ + void teardown() { + mock().clear(); + } +}; +// clang-format on + +TEST(TestSerializationInterfaceGroup, Verify_False) { + TestSerializationInterface test_serialization_interface( + fs::current_path() / "data" / "dummy_main.c"); + + test_serialization_interface.VerifyExpectation(1, false); + bool loaded = test_serialization_interface.LoadFromFile(); + CHECK_FALSE(loaded); +} + +TEST(TestSerializationInterfaceGroup, Load_False) { + TestSerializationInterface test_serialization_interface( + fs::current_path() / "data" / "dummy_main.c"); + + test_serialization_interface.VerifyExpectation(1, true); + test_serialization_interface.LoadExpectation(1, false); + bool loaded = test_serialization_interface.LoadFromFile(); + CHECK_FALSE(loaded); +} + +TEST(TestSerializationInterfaceGroup, Load_True) { + TestSerializationInterface test_serialization_interface( + fs::current_path() / "data" / "dummy_main.c"); + + test_serialization_interface.VerifyExpectation(1, true); + test_serialization_interface.LoadExpectation(1, true); + bool loaded = test_serialization_interface.LoadFromFile(); + CHECK_TRUE(loaded); +} + +TEST(TestSerializationInterfaceGroup, Store_False) { + TestSerializationInterface test_serialization_interface( + fs::current_path() / "data" / "dummy_main.c"); + test_serialization_interface.StoreExpectation(1, false); + bool stored = test_serialization_interface.StoreToFile(); + CHECK_FALSE(stored); +} + +TEST(TestSerializationInterfaceGroup, Store_True) { + TestSerializationInterface test_serialization_interface( + fs::current_path() / "data" / "dummy_main.c"); + test_serialization_interface.StoreExpectation(1, true); + bool stored = test_serialization_interface.StoreToFile(); + CHECK_TRUE(stored); + + std::string serialized_file = + test_serialization_interface.GetSerializedFile().string(); + std::string compare = (fs::current_path() / "data" / "dummy_main.c").string(); + STRCMP_EQUAL(serialized_file.c_str(), compare.c_str()); +} + +int main(int ac, char **av) { + return CommandLineTestRunner::RunAllTests(ac, av); +} From 8158a2ecc5a6ec67f16aae5ccdaf555d07d119ab Mon Sep 17 00:00:00 2001 From: coder137 Date: Thu, 10 Feb 2022 18:18:48 -0800 Subject: [PATCH 18/19] Updated build_buildcc.cpp --- bootstrap/src/build_buildcc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/src/build_buildcc.cpp b/bootstrap/src/build_buildcc.cpp index 23fe6df6..fd538a3b 100644 --- a/bootstrap/src/build_buildcc.cpp +++ b/bootstrap/src/build_buildcc.cpp @@ -69,11 +69,11 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen, target.AddIncludeDir("lib/target/include"); target.GlobHeaders("lib/target/include/target"); target.GlobHeaders("lib/target/include/target/api"); - target.GlobHeaders("lib/target/include/target/base"); target.GlobHeaders("lib/target/include/target/common"); target.GlobHeaders("lib/target/include/target/friend"); target.GlobHeaders("lib/target/include/target/interface"); target.GlobHeaders("lib/target/include/target/private"); + target.GlobHeaders("lib/target/include/target/serialization"); // ARGS target.GlobSources("lib/args/src"); From b67e7dbef4f89b393caadb089f4ff7356a867f72 Mon Sep 17 00:00:00 2001 From: coder137 Date: Thu, 10 Feb 2022 18:36:02 -0800 Subject: [PATCH 19/19] Updated test_target_source with GetBinaryPath --- buildcc/lib/target/test/target/test_target_source.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/buildcc/lib/target/test/target/test_target_source.cpp b/buildcc/lib/target/test/target/test_target_source.cpp index 13d3974f..f2664083 100644 --- a/buildcc/lib/target/test/target/test_target_source.cpp +++ b/buildcc/lib/target/test/target/test_target_source.cpp @@ -107,8 +107,7 @@ TEST(TargetTestSourceGroup, Target_Build_SourceCompile) { mock().checkExpectations(); - buildcc::internal::TargetSerialization serialization( - intermediate_path / (std::string(NAME) + ".bin")); + buildcc::internal::TargetSerialization serialization(simple.GetBinaryPath()); bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); @@ -152,7 +151,7 @@ TEST(TargetTestSourceGroup, Target_Build_SourceRecompile) { buildcc::m::TargetRunner(simple); buildcc::internal::TargetSerialization serialization( - intermediate_path / (std::string(NAME) + ".bin")); + simple.GetBinaryPath()); bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); @@ -184,7 +183,7 @@ TEST(TargetTestSourceGroup, Target_Build_SourceRecompile) { buildcc::m::TargetRunner(simple); buildcc::internal::TargetSerialization serialization( - intermediate_path / (std::string(NAME) + ".bin")); + simple.GetBinaryPath()); bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded); @@ -215,7 +214,7 @@ TEST(TargetTestSourceGroup, Target_Build_SourceRecompile) { buildcc::m::TargetRunner(simple); buildcc::internal::TargetSerialization serialization( - intermediate_path / (std::string(NAME) + ".bin")); + simple.GetBinaryPath()); bool is_loaded = serialization.LoadFromFile(); CHECK_TRUE(is_loaded);