- Notifications
You must be signed in to change notification settings - Fork3
Custom generator#212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Custom generator#212
Changes fromall commits
Commits
Show all changes
51 commits Select commitHold shift + click to select a range
b11d4d7 Added custom_generator.fbs
coder13785aa660 Added custom_generator_serialization.h/.cpp
coder137d0e60fc Updated schema
coder13727529de Updated schema
coder1376d7aab6 Updated CustomGenerator schema
coder137357d3a7 Updated schema
coder1376a8b4cf Added schema test for custom_generator_serialization
coder137c344210 Updated builder_interface and test
coder1374bb1dd5 Added custom_generator
coder1379ce04a6 Added initial test custom generator
coder137fbeef3b Updated custom generator API
coder13701dbe58 Updated custom_generator and tests
coder137ad9db48 Updated custom_generator and tests
coder137edefce7 Minor update to test_custom_generator.cpp
coder1376df772b Updated custom_generator.cpp
coder1379670090 Updated test_custom_generator.cpp
coder1377a35ffd Updated custom_generator
coder137bad1658 Updated custom_generator basic unit tests
coder137c865e14 Updated failure tests for custom_generator
coder1371aa5f7e Updated test_custom_generator
coder137b9a6598 Update custom_generator fix for potential dependency bug condition
coder13790f19c0 Updated custom_generator.cpp
coder13722c3978 Update command.cpp with try catch for exception handling
coder137c72d783 Added Map Removed condition
coder137d744d8e Shifted header from generator.h to custom_generator.h
coder137e6b619d Added recheck_states.cpp
coder137e6c01f5 Added recheck_states mocks
coder13731a0bbb Adedd Id states
coder137cb81241 Updated buildcc.h
coder1374d2890b Updated unit tests
coder1377bf8d32 Updated test_custom_generator.cpp
coder1371e836e7 Added comments
coder13721d4ab0 Updated custom_generator to handle subflow dependencies
coder137e364c9b Updated custom_generator
coder137f3c65ee Added dependency basic check
coder1372224dd5 Added dependency_file test
coder137affa14e Updated custom_generator.cpp TaskRunner
coder1377f92800 Fix recheck_states
coder1379a40fb4 Updated with map remove condition
coder137fdc4a45 Updated Map Add condition
coder1379c27129 Updated custom_generator
coder137ba36b0f Updated unit tests for update example
coder137e3554f9 Updated test_custom_generator for output changed condition
coder137e0abbdb Updated custom_generator with try/catch for dependency callback
coder1378cadce6 Removed parallel from custom_generator
coder13731e00e4 Updated tests for default argument usage
coder1371c4cfa1 Updated AddDefaultArgument usage
coder137692e2e4 Minor update to CMakeLists.txt for toolchains
coder137c669365 Updated bootstrap
coder137225eabd Removed plugin test
coder1374031c39 Update test_custom_generator.cpp
coder137File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 5 additions & 1 deletionbootstrap/src/build_buildcc.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsbuildcc/buildcc.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletionbuildcc/lib/env/src/command.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletionsbuildcc/lib/target/cmake/common_target_src.cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletionsbuildcc/lib/target/cmake/mock_target.cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletionsbuildcc/lib/target/cmake/target.cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletionsbuildcc/lib/target/include/target/custom_generator.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /* | ||
| * 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_CUSTOM_GENERATOR_H_ | ||
| #define TARGET_CUSTOM_GENERATOR_H_ | ||
| #include <mutex> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
| #include "taskflow/taskflow.hpp" | ||
| #include "env/command.h" | ||
| #include "env/task_state.h" | ||
| #include "target/interface/builder_interface.h" | ||
| #include "schema/custom_generator_serialization.h" | ||
| #include "schema/path.h" | ||
| #include "target/common/target_env.h" | ||
| namespace buildcc { | ||
| // TODO, Shift to a different file | ||
| // TODO, Check if we need the "id" here as well | ||
| class CustomGeneratorContext { | ||
| public: | ||
| CustomGeneratorContext(const env::Command &c, const fs_unordered_set &i, | ||
| const fs_unordered_set &o) | ||
| : command(c), inputs(i), outputs(o) {} | ||
| public: | ||
| const env::Command &command; | ||
| const fs_unordered_set &inputs; | ||
| const fs_unordered_set &outputs; | ||
| }; | ||
| // clang-format off | ||
| typedef std::function<bool(CustomGeneratorContext &)> GenerateCb; | ||
| typedef std::function<void(std::unordered_map<std::string, tf::Task> &)> DependencyCb; | ||
| // clang-format on | ||
| struct UserRelInputOutputSchema : internal::RelInputOutputSchema { | ||
| fs_unordered_set inputs; | ||
| GenerateCb generate_cb; | ||
| }; | ||
| struct UserCustomGeneratorSchema : public internal::CustomGeneratorSchema { | ||
| std::unordered_map<std::string, UserRelInputOutputSchema> rels_map; | ||
| void ConvertToInternal() { | ||
| for (auto &r_miter : rels_map) { | ||
| r_miter.second.internal_inputs = path_schema_convert( | ||
| r_miter.second.inputs, internal::Path::CreateExistingPath); | ||
| auto p = internal_rels_map.emplace(r_miter.first, r_miter.second); | ||
| env::assert_fatal(p.second, | ||
| fmt::format("Could not save {}", r_miter.first)); | ||
| } | ||
| } | ||
| }; | ||
| class CustomGenerator : public internal::BuilderInterface { | ||
| public: | ||
| CustomGenerator(const std::string &name, const TargetEnv &env) | ||
| : name_(name), | ||
| env_(env.GetTargetRootDir(), env.GetTargetBuildDir() / name), | ||
| serialization_(env_.GetTargetBuildDir() / fmt::format("{}.bin", name)) { | ||
| Initialize(); | ||
| } | ||
| virtual ~CustomGenerator() = default; | ||
| CustomGenerator(const CustomGenerator &) = delete; | ||
| /** | ||
| * @brief Add default arguments for input, output and command requirements | ||
| * | ||
| * @param arguments Key-Value pair for arguments | ||
| */ | ||
| void AddDefaultArguments( | ||
| const std::unordered_map<std::string, std::string> &arguments); | ||
| /** | ||
| * @brief Single Generator task for inputs->generate_cb->outputs | ||
| * | ||
| * @param id Unique id associated with Generator task | ||
| * @param inputs File inputs | ||
| * @param outputs File outputs | ||
| * @param generate_cb User-defined generate callback to build outputs from the | ||
| * provided inputs | ||
| */ | ||
| void AddGenInfo(const std::string &id, const fs_unordered_set &inputs, | ||
| const fs_unordered_set &outputs, | ||
| const GenerateCb &generate_cb); | ||
| // Callbacks | ||
| /** | ||
| * @brief Setup dependencies between Tasks using their `id` | ||
| * For example: `task_map["id1"].precede(task_map["id2"])` | ||
| * | ||
| * IMPORTANT: Successor tasks will not automatically run if dependent task is | ||
| * run. | ||
| * The Dependency callback only sets precedence (order in which your tasks | ||
| * should run) | ||
| * Default behaviour when dependency callback is not supplied: All task `id`s | ||
| * run in parallel. | ||
| * | ||
| * @param dependency_cb Unordered map of `id` and `task` | ||
| * The map can be safely mutated. | ||
| */ | ||
| void AddDependencyCb(const DependencyCb &dependency_cb); | ||
| void Build() override; | ||
| // Getters | ||
| const fs::path &GetBinaryPath() const { | ||
| return serialization_.GetSerializedFile(); | ||
| } | ||
| const fs::path &GetRootDir() const { return env_.GetTargetRootDir(); } | ||
| const fs::path &GetBuildDir() const { return env_.GetTargetBuildDir(); } | ||
| tf::Taskflow &GetTaskflow() { return tf_; } | ||
| private: | ||
| void Initialize(); | ||
| template <bool run> void TaskRunner(const std::string &id); | ||
| void GenerateTask(); | ||
| void BuildGenerate(std::unordered_map<std::string, UserRelInputOutputSchema> | ||
| &gen_selected_map, | ||
| std::unordered_map<std::string, UserRelInputOutputSchema> | ||
| &dummy_gen_selected_map); | ||
| // Recheck states | ||
| void IdRemoved(); | ||
| void IdAdded(); | ||
| void IdUpdated(); | ||
| private: | ||
| std::string name_; | ||
| TargetEnv env_; | ||
| internal::CustomGeneratorSerialization serialization_; | ||
| // Serialization | ||
| UserCustomGeneratorSchema user_; | ||
| std::mutex success_schema_mutex_; | ||
| std::unordered_map<std::string, UserRelInputOutputSchema> success_schema_; | ||
| // Internal | ||
| env::Command command_; | ||
| tf::Taskflow tf_; | ||
| // Callbacks | ||
| DependencyCb dependency_cb_; | ||
| }; | ||
| } // namespace buildcc | ||
| #endif |
6 changes: 2 additions & 4 deletionsbuildcc/lib/target/include/target/generator.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletionsbuildcc/lib/target/include/target/interface/builder_interface.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletionsbuildcc/lib/target/mock/custom_generator/recheck_states.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #include "target/custom_generator.h" | ||
| #include "expect_custom_generator.h" | ||
| #include "CppUTestExt/MockSupport.h" | ||
| namespace buildcc { | ||
| static constexpr const char *const ID_REMOVED_FUNCTION = | ||
| "CustomGenerator::IdRemoved"; | ||
| static constexpr const char *const ID_ADDED_FUNCTION = | ||
| "CustomGenerator::IdAdded"; | ||
| static constexpr const char *const ID_UPDATED_FUNCTION = | ||
| "CustomGenerator::IdUpdated"; | ||
| void CustomGenerator::IdRemoved() { | ||
| mock().actualCall(ID_REMOVED_FUNCTION).onObject(this); | ||
| } | ||
| void CustomGenerator::IdAdded() { | ||
| mock().actualCall(ID_ADDED_FUNCTION).onObject(this); | ||
| } | ||
| void CustomGenerator::IdUpdated() { | ||
| mock().actualCall(ID_UPDATED_FUNCTION).onObject(this); | ||
| } | ||
| namespace m { | ||
| void CustomGeneratorExpect_IdRemoved(unsigned int calls, | ||
| CustomGenerator *generator) { | ||
| mock().expectNCalls(calls, ID_REMOVED_FUNCTION).onObject(generator); | ||
| } | ||
| void CustomGeneratorExpect_IdAdded(unsigned int calls, | ||
| CustomGenerator *generator) { | ||
| mock().expectNCalls(calls, ID_ADDED_FUNCTION).onObject(generator); | ||
| } | ||
| void CustomGeneratorExpect_IdUpdated(unsigned int calls, | ||
| CustomGenerator *generator) { | ||
| mock().expectNCalls(calls, ID_UPDATED_FUNCTION).onObject(generator); | ||
| } | ||
| } // namespace m | ||
| } // namespace buildcc |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.