Skip to content

Commit 58e618f

Browse files
authored
Target task state (#165)
1 parent ca1d8ae commit 58e618f

32 files changed

+691
-177
lines changed

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,6 @@ Build C, C++ and ASM files in C++
5757
- Users can define their own custom arguments.
5858
- Argument passing has been made easy using the `buildcc::Args` module.
5959

60-
**Taskflow dependency for hybrid/simple example**
61-
![Hybrid Simple example](example/hybrid/simple/graph.PNG)
62-
63-
- Build GCC and MSVC Targets simultaneously
64-
- 1 C and 1 CPP example for both toolchains
65-
66-
**Taskflow dependency for hybrid/pch example**
67-
![Hybrid PCH example](example/hybrid/pch/graph.PNG)
68-
69-
- Activate PCH for GCC and MSVC Targets
70-
- 1 C and 1 CPP example for both toolchains
71-
72-
**Taskflow dependency for hybrid/dep_chaining example**
73-
![Hybrid Dep Chain example](example/hybrid/dep_chaining/graph.PNG)
74-
75-
- Chain **Generator** with **Targets** for Dependency
76-
- 1 C and 1 CPP example for both toolchains
77-
7860
# Software Architecture
7961

8062
### Interface lib dependencies
@@ -119,6 +101,26 @@ Build C, C++ and ASM files in C++
119101

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

104+
## Visual hybrid example graphs
105+
106+
**Taskflow dependency for hybrid/simple example**
107+
![Hybrid Simple example](example/hybrid/simple/graph.PNG)
108+
109+
- Build GCC and MSVC Targets simultaneously
110+
- 1 C and 1 CPP example for both toolchains
111+
112+
**Taskflow dependency for hybrid/pch example**
113+
![Hybrid PCH example](example/hybrid/pch/graph.PNG)
114+
115+
- Activate PCH for GCC and MSVC Targets
116+
- 1 C and 1 CPP example for both toolchains
117+
118+
**Taskflow dependency for hybrid/dep_chaining example**
119+
![Hybrid Dep Chain example](example/hybrid/dep_chaining/graph.PNG)
120+
121+
- Chain **Generator** with **Targets** for Dependency
122+
- 1 C and 1 CPP example for both toolchains
123+
122124
# User Guide
123125

124126
Developers interested in using **_BuildCC_**

buildcc/lib/target/cmake/mock_target.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(mock_target STATIC
77
mock/generator/recheck_states.cpp
88

99
# Target mocks
10-
mock/target/tasks.cpp
10+
src/target/tasks.cpp
1111
mock/target/runner.cpp
1212
mock/target/recheck_states.cpp
1313
)

buildcc/lib/target/include/target/base/target_loader.h

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,52 +42,71 @@ class TargetLoader : public LoaderInterface {
4242
bool Load() override;
4343

4444
// Getters
45-
const path_unordered_set &GetLoadedSources() const { return loaded_sources_; }
46-
const path_unordered_set &GetLoadedHeaders() const { return loaded_headers_; }
47-
const path_unordered_set &GetLoadedPchs() const { return loaded_pchs_; }
48-
const path_unordered_set &GetLoadedLibDeps() const {
45+
const path_unordered_set &GetLoadedSources() const noexcept {
46+
return loaded_sources_;
47+
}
48+
const path_unordered_set &GetLoadedHeaders() const noexcept {
49+
return loaded_headers_;
50+
}
51+
const path_unordered_set &GetLoadedPchs() const noexcept {
52+
return loaded_pchs_;
53+
}
54+
const path_unordered_set &GetLoadedLibDeps() const noexcept {
4955
return loaded_lib_deps_;
5056
}
51-
const std::unordered_set<std::string> &GetLoadedExternalLibDeps() const {
57+
const std::unordered_set<std::string> &
58+
GetLoadedExternalLibDeps() const noexcept {
5259
return loaded_external_lib_dirs_;
5360
}
5461

55-
const fs_unordered_set &GetLoadedIncludeDirs() const {
62+
const fs_unordered_set &GetLoadedIncludeDirs() const noexcept {
5663
return loaded_include_dirs_;
5764
}
58-
const fs_unordered_set &GetLoadedLibDirs() const { return loaded_lib_dirs_; }
59-
const std::unordered_set<std::string> &GetLoadedPreprocessorFlags() const {
65+
const fs_unordered_set &GetLoadedLibDirs() const noexcept {
66+
return loaded_lib_dirs_;
67+
}
68+
const std::unordered_set<std::string> &
69+
GetLoadedPreprocessorFlags() const noexcept {
6070
return loaded_preprocessor_flags_;
6171
}
62-
const std::unordered_set<std::string> &GetLoadedCommonCompileFlags() const {
72+
const std::unordered_set<std::string> &
73+
GetLoadedCommonCompileFlags() const noexcept {
6374
return loaded_common_compile_flags_;
6475
}
65-
const std::unordered_set<std::string> &GetLoadedPchCompileFlags() const {
76+
const std::unordered_set<std::string> &
77+
GetLoadedPchCompileFlags() const noexcept {
6678
return loaded_pch_compile_flags_;
6779
}
68-
const std::unordered_set<std::string> &GetLoadedPchObjectFlags() const {
80+
const std::unordered_set<std::string> &
81+
GetLoadedPchObjectFlags() const noexcept {
6982
return loaded_pch_object_flags_;
7083
}
71-
const std::unordered_set<std::string> &GetLoadedAsmCompileFlags() const {
84+
const std::unordered_set<std::string> &
85+
GetLoadedAsmCompileFlags() const noexcept {
7286
return loaded_asm_compile_flags_;
7387
}
74-
const std::unordered_set<std::string> &GetLoadedCCompileFlags() const {
88+
const std::unordered_set<std::string> &
89+
GetLoadedCCompileFlags() const noexcept {
7590
return loaded_c_compile_flags_;
7691
}
77-
const std::unordered_set<std::string> &GetLoadedCppCompileFlags() const {
92+
const std::unordered_set<std::string> &
93+
GetLoadedCppCompileFlags() const noexcept {
7894
return loaded_cpp_compile_flags_;
7995
}
80-
const std::unordered_set<std::string> &GetLoadedLinkFlags() const {
96+
const std::unordered_set<std::string> &GetLoadedLinkFlags() const noexcept {
8197
return loaded_link_flags_;
8298
}
8399

84-
const path_unordered_set &GetLoadedCompileDependencies() const {
100+
const path_unordered_set &GetLoadedCompileDependencies() const noexcept {
85101
return loaded_compile_dependencies_;
86102
}
87-
const path_unordered_set &GetLoadedLinkDependencies() const {
103+
const path_unordered_set &GetLoadedLinkDependencies() const noexcept {
88104
return loaded_link_dependencies_;
89105
}
90106

107+
bool GetLoadedPchCompiled() const noexcept { return loaded_pch_compiled_; }
108+
bool GetLoadedTargetLinked() const noexcept { return loaded_target_linked_; }
109+
91110
private:
92111
void Initialize();
93112

@@ -116,6 +135,9 @@ class TargetLoader : public LoaderInterface {
116135

117136
path_unordered_set loaded_compile_dependencies_;
118137
path_unordered_set loaded_link_dependencies_;
138+
139+
bool loaded_pch_compiled_{false};
140+
bool loaded_target_linked_{false};
119141
};
120142

121143
} // namespace buildcc::internal

buildcc/lib/target/include/target/base/target_storer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ struct TargetStorer {
4545

4646
internal::RelationalPathFiles current_compile_dependencies;
4747
internal::RelationalPathFiles current_link_dependencies;
48+
49+
bool pch_compiled{false};
50+
bool target_linked{false};
4851
};
4952

5053
} // namespace buildcc::internal

buildcc/lib/target/include/target/friend/compile_object.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ class CompileObject {
6060
private:
6161
fs::path ConstructObjectPath(const fs::path &absolute_source_file) const;
6262

63-
void BuildObjectCompile(std::vector<fs::path> &source_files,
64-
std::vector<fs::path> &dummy_source_files);
63+
void BuildObjectCompile(std::vector<internal::Path> &source_files,
64+
std::vector<internal::Path> &dummy_source_files);
6565

6666
void PreObjectCompile();
6767

68-
void CompileSources(std::vector<fs::path> &source_files);
69-
void RecompileSources(std::vector<fs::path> &source_files,
70-
std::vector<fs::path> &dummy_source_files);
68+
void CompileSources(std::vector<internal::Path> &source_files);
69+
void RecompileSources(std::vector<internal::Path> &source_files,
70+
std::vector<internal::Path> &dummy_source_files);
7171

7272
private:
7373
Target &target_;

buildcc/lib/target/include/target/target.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
#include <filesystem>
2121
#include <functional>
2222
#include <initializer_list>
23+
#include <mutex>
2324
#include <optional>
2425
#include <string>
25-
#include <string_view>
2626
#include <unordered_map>
2727
#include <unordered_set>
2828
#include <vector>
@@ -47,9 +47,12 @@
4747
#include "target/base/target_storer.h"
4848
#include "target/common/path.h"
4949

50+
// Env
51+
#include "env/env.h"
52+
#include "env/task_state.h"
53+
5054
// Components
5155
#include "command/command.h"
52-
#include "env/env.h"
5356
#include "toolchain/toolchain.h"
5457

5558
// Third Party
@@ -82,6 +85,9 @@ class Target : public BuilderInterface,
8285
// Builders
8386
void Build() override;
8487

88+
// Getters
89+
env::TaskState GetTaskState() const noexcept { return task_state_; }
90+
8591
private:
8692
friend class CompilePch;
8793
friend class CompileObject;
@@ -111,6 +117,14 @@ class Target : public BuilderInterface,
111117
bool Store() override;
112118

113119
// Tasks
120+
void SetTaskStateFailure();
121+
int GetTaskStateAsInt() const noexcept {
122+
return static_cast<int>(task_state_);
123+
}
124+
125+
void StartTask();
126+
void EndTask();
127+
tf::Task CheckStateTask();
114128
void TaskDeps();
115129

116130
// Callbacks for unit tests
@@ -136,6 +150,16 @@ class Target : public BuilderInterface,
136150
CompileObject compile_object_;
137151
LinkTarget link_target_;
138152

153+
// Task states
154+
tf::Task target_start_task_;
155+
tf::Task target_end_task_;
156+
157+
std::mutex task_state_mutex_;
158+
env::TaskState task_state_{env::TaskState::SUCCESS};
159+
160+
std::mutex compiled_source_files_mutex_;
161+
internal::path_unordered_set compiled_source_files_;
162+
139163
//
140164
Command command_;
141165
tf::Taskflow tf_;

buildcc/lib/target/mock/target/tasks.cpp

Lines changed: 0 additions & 23 deletions
This file was deleted.

buildcc/lib/target/src/generator/task.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
namespace {
2222
constexpr const char *const kStartGeneratorTaskName = "Start Generator";
23-
constexpr const char *const kPreGenerateTaskName = "PreGenerate";
2423
constexpr const char *const kEndGeneratorTaskName = "End Generator";
2524

2625
constexpr const char *const kCommandTaskName = "Command";
@@ -34,6 +33,12 @@ void Generator::GenerateTask() {
3433
tf::Task start_task = tf_.emplace([this]() {
3534
switch (env::get_task_state()) {
3635
case env::TaskState::SUCCESS:
36+
try {
37+
Convert();
38+
BuildGenerate();
39+
} catch (...) {
40+
task_state_ = env::TaskState::FAILURE;
41+
}
3742
break;
3843
default:
3944
task_state_ = env::TaskState::FAILURE;
@@ -43,17 +48,6 @@ void Generator::GenerateTask() {
4348
});
4449
start_task.name(kStartGeneratorTaskName);
4550

46-
tf::Task pregenerate_task = tf_.emplace([&]() {
47-
try {
48-
Convert();
49-
BuildGenerate();
50-
} catch (...) {
51-
task_state_ = env::TaskState::FAILURE;
52-
}
53-
return static_cast<int>(task_state_);
54-
});
55-
pregenerate_task.name(kPreGenerateTaskName);
56-
5751
tf::Task generate_task = tf_.emplace([&](tf::Subflow &subflow) {
5852
auto run_command = [this](const std::string &command) {
5953
try {
@@ -124,8 +118,7 @@ void Generator::GenerateTask() {
124118
end_task.name(kEndGeneratorTaskName);
125119

126120
// Dependencies
127-
start_task.precede(pregenerate_task, end_task);
128-
pregenerate_task.precede(generate_task, end_task);
121+
start_task.precede(generate_task, end_task);
129122
generate_task.precede(end_task);
130123
}
131124

buildcc/lib/target/src/target/build.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ void Target::Build() {
9797
// Load the serialized file
9898
(void)loader_.Load();
9999

100+
// Target State Tasks
101+
StartTask();
102+
EndTask();
103+
100104
// PCH Compile
101105
if (state_.ContainsPch()) {
102106
command_.AddDefaultArguments({

0 commit comments

Comments
 (0)