Skip to content

Target task state #165

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
963a19c
Update task.cpp
coder137 Nov 29, 2021
98bc265
Update target_loader.h
coder137 Nov 30, 2021
4578bb0
Update compile_pch.cpp
coder137 Nov 30, 2021
46ca30b
Removed mock target tasks.cpp
coder137 Nov 30, 2021
e6326a6
Updated target
coder137 Nov 30, 2021
b6c51ca
Update target.h
coder137 Nov 30, 2021
311effc
Update tasks.cpp
coder137 Nov 30, 2021
31dd6c9
Updated tasks with TaskState functions
coder137 Nov 30, 2021
c62566b
Update target.h
coder137 Nov 30, 2021
97a1544
Update tasks.cpp
coder137 Nov 30, 2021
3485c0f
Updated compile_object
coder137 Nov 30, 2021
c70f42b
Update tasks.cpp
coder137 Nov 30, 2021
c9ccf8f
Update link_target.cpp
coder137 Nov 30, 2021
2372a5e
Update tasks.cpp
coder137 Nov 30, 2021
268c38d
Updated target.h and tasks.cpp with pch_files and source files for fa…
coder137 Nov 30, 2021
5fd9143
Update source / pch files with mutex lock
coder137 Nov 30, 2021
b52ae56
Update tasks.cpp
coder137 Nov 30, 2021
d80a5aa
Updated target unit tests
coder137 Nov 30, 2021
bdb00ec
Update tasks.cpp
coder137 Nov 30, 2021
bf0c0d5
Updated target_failure_state for compile_object and link_target
coder137 Nov 30, 2021
2cf07d3
Update test_target_failure_states.cpp
coder137 Nov 30, 2021
b270e8c
Update test_target_failure_states.cpp
coder137 Nov 30, 2021
dc6bd8c
Update tasks.cpp
coder137 Nov 30, 2021
2d89889
Update test_target_failure_states.cpp
coder137 Nov 30, 2021
6617a55
Update tasks.cpp
coder137 Nov 30, 2021
49d81c5
Update test_target_failure_states.cpp
coder137 Nov 30, 2021
64f776a
Update tasks.cpp
coder137 Nov 30, 2021
37b239d
Update tasks.cpp
coder137 Nov 30, 2021
124b7e2
Update tasks.cpp
coder137 Nov 30, 2021
eacf4fd
Update test_target_failure_states.cpp
coder137 Nov 30, 2021
26f2ac4
Update link_target.cpp
coder137 Dec 1, 2021
14db901
Update tasks.cpp
coder137 Dec 1, 2021
a8edf65
Update target.fbs
coder137 Dec 1, 2021
65341dd
Updated target_loader and target_storer
coder137 Dec 1, 2021
e942262
Update link_target.cpp
coder137 Dec 1, 2021
142d23f
Update test_target_failure_states.cpp
coder137 Dec 1, 2021
b6352b3
Renamed source_files to compiled_source_files
coder137 Dec 1, 2021
4360583
Update target.fbs
coder137 Dec 1, 2021
3458329
Updated target_loader and target_storer
coder137 Dec 1, 2021
e43d0fa
Updated tasks
coder137 Dec 1, 2021
47eb3bc
Update compile_pch.cpp
coder137 Dec 1, 2021
005a342
Update tasks.cpp
coder137 Dec 1, 2021
5200081
Update target.h
coder137 Dec 1, 2021
e5f1feb
Update tasks.cpp
coder137 Dec 1, 2021
48e0756
Update graph.PNG
coder137 Dec 1, 2021
cfa8bce
Update graph.PNG
coder137 Dec 1, 2021
471e741
Update graph.PNG
coder137 Dec 1, 2021
9351cde
Update README.md
coder137 Dec 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,6 @@ Build C, C++ and ASM files in C++
- Users can define their own custom arguments.
- Argument passing has been made easy using the `buildcc::Args` module.

**Taskflow dependency for hybrid/simple example**
![Hybrid Simple example](example/hybrid/simple/graph.PNG)

- Build GCC and MSVC Targets simultaneously
- 1 C and 1 CPP example for both toolchains

**Taskflow dependency for hybrid/pch example**
![Hybrid PCH example](example/hybrid/pch/graph.PNG)

- Activate PCH for GCC and MSVC Targets
- 1 C and 1 CPP example for both toolchains

**Taskflow dependency for hybrid/dep_chaining example**
![Hybrid Dep Chain example](example/hybrid/dep_chaining/graph.PNG)

- Chain **Generator** with **Targets** for Dependency
- 1 C and 1 CPP example for both toolchains

# Software Architecture

### Interface lib dependencies
Expand Down Expand Up @@ -119,6 +101,26 @@ Build C, C++ and ASM files in C++

Contains **proof of concept** and **real world** [examples](example/README.md).

## Visual hybrid example graphs

**Taskflow dependency for hybrid/simple example**
![Hybrid Simple example](example/hybrid/simple/graph.PNG)

- Build GCC and MSVC Targets simultaneously
- 1 C and 1 CPP example for both toolchains

**Taskflow dependency for hybrid/pch example**
![Hybrid PCH example](example/hybrid/pch/graph.PNG)

- Activate PCH for GCC and MSVC Targets
- 1 C and 1 CPP example for both toolchains

**Taskflow dependency for hybrid/dep_chaining example**
![Hybrid Dep Chain example](example/hybrid/dep_chaining/graph.PNG)

- Chain **Generator** with **Targets** for Dependency
- 1 C and 1 CPP example for both toolchains

# User Guide

Developers interested in using **_BuildCC_**
Expand Down
2 changes: 1 addition & 1 deletion buildcc/lib/target/cmake/mock_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_library(mock_target STATIC
mock/generator/recheck_states.cpp

# Target mocks
mock/target/tasks.cpp
src/target/tasks.cpp
mock/target/runner.cpp
mock/target/recheck_states.cpp
)
Expand Down
56 changes: 39 additions & 17 deletions buildcc/lib/target/include/target/base/target_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,52 +42,71 @@ class TargetLoader : public LoaderInterface {
bool Load() override;

// Getters
const path_unordered_set &GetLoadedSources() const { return loaded_sources_; }
const path_unordered_set &GetLoadedHeaders() const { return loaded_headers_; }
const path_unordered_set &GetLoadedPchs() const { return loaded_pchs_; }
const path_unordered_set &GetLoadedLibDeps() const {
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<std::string> &GetLoadedExternalLibDeps() const {
const std::unordered_set<std::string> &
GetLoadedExternalLibDeps() const noexcept {
return loaded_external_lib_dirs_;
}

const fs_unordered_set &GetLoadedIncludeDirs() const {
const fs_unordered_set &GetLoadedIncludeDirs() const noexcept {
return loaded_include_dirs_;
}
const fs_unordered_set &GetLoadedLibDirs() const { return loaded_lib_dirs_; }
const std::unordered_set<std::string> &GetLoadedPreprocessorFlags() const {
const fs_unordered_set &GetLoadedLibDirs() const noexcept {
return loaded_lib_dirs_;
}
const std::unordered_set<std::string> &
GetLoadedPreprocessorFlags() const noexcept {
return loaded_preprocessor_flags_;
}
const std::unordered_set<std::string> &GetLoadedCommonCompileFlags() const {
const std::unordered_set<std::string> &
GetLoadedCommonCompileFlags() const noexcept {
return loaded_common_compile_flags_;
}
const std::unordered_set<std::string> &GetLoadedPchCompileFlags() const {
const std::unordered_set<std::string> &
GetLoadedPchCompileFlags() const noexcept {
return loaded_pch_compile_flags_;
}
const std::unordered_set<std::string> &GetLoadedPchObjectFlags() const {
const std::unordered_set<std::string> &
GetLoadedPchObjectFlags() const noexcept {
return loaded_pch_object_flags_;
}
const std::unordered_set<std::string> &GetLoadedAsmCompileFlags() const {
const std::unordered_set<std::string> &
GetLoadedAsmCompileFlags() const noexcept {
return loaded_asm_compile_flags_;
}
const std::unordered_set<std::string> &GetLoadedCCompileFlags() const {
const std::unordered_set<std::string> &
GetLoadedCCompileFlags() const noexcept {
return loaded_c_compile_flags_;
}
const std::unordered_set<std::string> &GetLoadedCppCompileFlags() const {
const std::unordered_set<std::string> &
GetLoadedCppCompileFlags() const noexcept {
return loaded_cpp_compile_flags_;
}
const std::unordered_set<std::string> &GetLoadedLinkFlags() const {
const std::unordered_set<std::string> &GetLoadedLinkFlags() const noexcept {
return loaded_link_flags_;
}

const path_unordered_set &GetLoadedCompileDependencies() const {
const path_unordered_set &GetLoadedCompileDependencies() const noexcept {
return loaded_compile_dependencies_;
}
const path_unordered_set &GetLoadedLinkDependencies() const {
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();

Expand Down Expand Up @@ -116,6 +135,9 @@ class TargetLoader : public LoaderInterface {

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
Expand Down
3 changes: 3 additions & 0 deletions buildcc/lib/target/include/target/base/target_storer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ struct TargetStorer {

internal::RelationalPathFiles current_compile_dependencies;
internal::RelationalPathFiles current_link_dependencies;

bool pch_compiled{false};
bool target_linked{false};
};

} // namespace buildcc::internal
Expand Down
10 changes: 5 additions & 5 deletions buildcc/lib/target/include/target/friend/compile_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class CompileObject {
private:
fs::path ConstructObjectPath(const fs::path &absolute_source_file) const;

void BuildObjectCompile(std::vector<fs::path> &source_files,
std::vector<fs::path> &dummy_source_files);
void BuildObjectCompile(std::vector<internal::Path> &source_files,
std::vector<internal::Path> &dummy_source_files);

void PreObjectCompile();

void CompileSources(std::vector<fs::path> &source_files);
void RecompileSources(std::vector<fs::path> &source_files,
std::vector<fs::path> &dummy_source_files);
void CompileSources(std::vector<internal::Path> &source_files);
void RecompileSources(std::vector<internal::Path> &source_files,
std::vector<internal::Path> &dummy_source_files);

private:
Target &target_;
Expand Down
28 changes: 26 additions & 2 deletions buildcc/lib/target/include/target/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <filesystem>
#include <functional>
#include <initializer_list>
#include <mutex>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>
Expand All @@ -47,9 +47,12 @@
#include "target/base/target_storer.h"
#include "target/common/path.h"

// Env
#include "env/env.h"
#include "env/task_state.h"

// Components
#include "command/command.h"
#include "env/env.h"
#include "toolchain/toolchain.h"

// Third Party
Expand Down Expand Up @@ -82,6 +85,9 @@ class Target : public BuilderInterface,
// Builders
void Build() override;

// Getters
env::TaskState GetTaskState() const noexcept { return task_state_; }

private:
friend class CompilePch;
friend class CompileObject;
Expand Down Expand Up @@ -111,6 +117,14 @@ class Target : public BuilderInterface,
bool Store() override;

// Tasks
void SetTaskStateFailure();
int GetTaskStateAsInt() const noexcept {
return static_cast<int>(task_state_);
}

void StartTask();
void EndTask();
tf::Task CheckStateTask();
void TaskDeps();

// Callbacks for unit tests
Expand All @@ -136,6 +150,16 @@ class Target : public BuilderInterface,
CompileObject compile_object_;
LinkTarget link_target_;

// Task states
tf::Task target_start_task_;
tf::Task target_end_task_;

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_;

//
Command command_;
tf::Taskflow tf_;
Expand Down
23 changes: 0 additions & 23 deletions buildcc/lib/target/mock/target/tasks.cpp

This file was deleted.

21 changes: 7 additions & 14 deletions buildcc/lib/target/src/generator/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

namespace {
constexpr const char *const kStartGeneratorTaskName = "Start Generator";
constexpr const char *const kPreGenerateTaskName = "PreGenerate";
constexpr const char *const kEndGeneratorTaskName = "End Generator";

constexpr const char *const kCommandTaskName = "Command";
Expand All @@ -34,6 +33,12 @@ void Generator::GenerateTask() {
tf::Task start_task = tf_.emplace([this]() {
switch (env::get_task_state()) {
case env::TaskState::SUCCESS:
try {
Convert();
BuildGenerate();
} catch (...) {
task_state_ = env::TaskState::FAILURE;
}
break;
default:
task_state_ = env::TaskState::FAILURE;
Expand All @@ -43,17 +48,6 @@ void Generator::GenerateTask() {
});
start_task.name(kStartGeneratorTaskName);

tf::Task pregenerate_task = tf_.emplace([&]() {
try {
Convert();
BuildGenerate();
} catch (...) {
task_state_ = env::TaskState::FAILURE;
}
return static_cast<int>(task_state_);
});
pregenerate_task.name(kPreGenerateTaskName);

tf::Task generate_task = tf_.emplace([&](tf::Subflow &subflow) {
auto run_command = [this](const std::string &command) {
try {
Expand Down Expand Up @@ -124,8 +118,7 @@ void Generator::GenerateTask() {
end_task.name(kEndGeneratorTaskName);

// Dependencies
start_task.precede(pregenerate_task, end_task);
pregenerate_task.precede(generate_task, end_task);
start_task.precede(generate_task, end_task);
generate_task.precede(end_task);
}

Expand Down
4 changes: 4 additions & 0 deletions buildcc/lib/target/src/target/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ void Target::Build() {
// Load the serialized file
(void)loader_.Load();

// Target State Tasks
StartTask();
EndTask();

// PCH Compile
if (state_.ContainsPch()) {
command_.AddDefaultArguments({
Expand Down
Loading