Skip to content

Commit 1798889

Browse files
authored
Refactoring getter apis (#178)
1 parent f54bbf0 commit 1798889

24 files changed

+162
-169
lines changed

buildcc/lib/target/include/target/api/target_info_getter.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ template <typename T> class TargetInfoGetter {
4444
const TargetConfig &GetConfig() const;
4545

4646
// Target Storer
47-
const internal::fs_unordered_set &GetCurrentSourceFiles() const;
48-
const internal::fs_unordered_set &GetCurrentHeaderFiles() const;
49-
const internal::fs_unordered_set &GetCurrentPchFiles() const;
50-
const std::vector<fs::path> &GetTargetLibDeps() const;
51-
const std::vector<std::string> &GetCurrentExternalLibDeps() const;
52-
const internal::fs_unordered_set &GetCurrentIncludeDirs() const;
53-
const internal::fs_unordered_set &GetCurrentLibDirs() const;
54-
const std::unordered_set<std::string> &GetCurrentPreprocessorFlags() const;
55-
const std::unordered_set<std::string> &GetCurrentCommonCompileFlags() const;
56-
const std::unordered_set<std::string> &GetCurrentPchCompileFlags() const;
57-
const std::unordered_set<std::string> &GetCurrentPchObjectFlags() const;
58-
const std::unordered_set<std::string> &GetCurrentAsmCompileFlags() const;
59-
const std::unordered_set<std::string> &GetCurrentCCompileFlags() const;
60-
const std::unordered_set<std::string> &GetCurrentCppCompileFlags() const;
61-
const std::unordered_set<std::string> &GetCurrentLinkFlags() const;
62-
const internal::fs_unordered_set &GetCurrentCompileDependencies() const;
63-
const internal::fs_unordered_set &GetCurrentLinkDependencies() const;
47+
const fs_unordered_set &GetSourceFiles() const;
48+
const fs_unordered_set &GetHeaderFiles() const;
49+
const fs_unordered_set &GetPchFiles() const;
50+
const std::vector<fs::path> &GetLibDeps() const;
51+
const std::vector<std::string> &GetExternalLibDeps() const;
52+
const fs_unordered_set &GetIncludeDirs() const;
53+
const fs_unordered_set &GetLibDirs() const;
54+
const std::unordered_set<std::string> &GetPreprocessorFlags() const;
55+
const std::unordered_set<std::string> &GetCommonCompileFlags() const;
56+
const std::unordered_set<std::string> &GetPchCompileFlags() const;
57+
const std::unordered_set<std::string> &GetPchObjectFlags() const;
58+
const std::unordered_set<std::string> &GetAsmCompileFlags() const;
59+
const std::unordered_set<std::string> &GetCCompileFlags() const;
60+
const std::unordered_set<std::string> &GetCppCompileFlags() const;
61+
const std::unordered_set<std::string> &GetLinkFlags() const;
62+
const fs_unordered_set &GetCompileDependencies() const;
63+
const fs_unordered_set &GetLinkDependencies() const;
6464
};
6565

6666
} // namespace buildcc::base

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class GeneratorLoader : public LoaderInterface {
4545
return loaded_input_files_;
4646
}
4747

48-
const internal::fs_unordered_set &GetLoadedOutputFiles() const noexcept {
48+
const fs_unordered_set &GetLoadedOutputFiles() const noexcept {
4949
return loaded_output_files_;
5050
}
5151

@@ -58,7 +58,7 @@ class GeneratorLoader : public LoaderInterface {
5858
fs::path path_;
5959

6060
internal::path_unordered_set loaded_input_files_;
61-
internal::fs_unordered_set loaded_output_files_;
61+
fs_unordered_set loaded_output_files_;
6262
std::vector<std::string> loaded_commands_;
6363
};
6464

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ struct TargetStorer {
3232
std::vector<fs::path> current_user_lib_deps;
3333
internal::path_unordered_set current_internal_lib_deps;
3434

35-
internal::fs_unordered_set current_include_dirs;
36-
internal::fs_unordered_set current_lib_dirs;
35+
fs_unordered_set current_include_dirs;
36+
fs_unordered_set current_lib_dirs;
3737

3838
// NOTE, Order matters (user takes care of the order here)
3939
std::vector<std::string> current_user_external_lib_deps;

buildcc/lib/target/include/target/common/path.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ inline std::string path_as_string(const fs::path &p) {
194194
return internal::Path::CreateNewPath(p).GetPathAsString();
195195
}
196196

197+
typedef internal::fs_unordered_set fs_unordered_set;
198+
197199
} // namespace buildcc
198200

199201
// FMT specialization

buildcc/lib/target/include/target/common/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ template <typename T> std::string aggregate(const T &list) {
2929
return fmt::format("{}", fmt::join(list, " "));
3030
}
3131

32-
std::string aggregate(const buildcc::internal::fs_unordered_set &paths);
32+
std::string aggregate(const buildcc::fs_unordered_set &paths);
3333

3434
std::string aggregate_with_prefix(const std::string &prefix,
3535
const fs_unordered_set &dirs);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CompileObject {
5454
GetObjectDataMap() const {
5555
return object_files_;
5656
}
57-
internal::fs_unordered_set GetCompiledSources() const;
57+
fs_unordered_set GetCompiledSources() const;
5858
tf::Task &GetTask() { return compile_task_; }
5959

6060
private:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Generator : public BuilderInterface {
132132

133133
// Serialization
134134
internal::RelationalPathFiles current_input_files_;
135-
internal::fs_unordered_set current_output_files_;
135+
fs_unordered_set current_output_files_;
136136
std::vector<std::string> current_commands_;
137137
bool parallel_{false};
138138

buildcc/lib/target/include/target/private/schema_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ create_fbs_vector_string(flatbuffers::FlatBufferBuilder &builder,
113113

114114
inline std::vector<flatbuffers::Offset<flatbuffers::String>>
115115
create_fbs_vector_string(flatbuffers::FlatBufferBuilder &builder,
116-
const buildcc::internal::fs_unordered_set &fslist) {
116+
const buildcc::fs_unordered_set &fslist) {
117117
std::vector<flatbuffers::Offset<flatbuffers::String>> strs;
118118
std::transform(
119119
fslist.begin(), fslist.end(), std::back_inserter(strs),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class Target : public BuilderInterface,
105105
// Recompilation checks
106106
void RecheckPaths(const internal::path_unordered_set &previous_path,
107107
const internal::path_unordered_set &current_path);
108-
void RecheckDirs(const internal::fs_unordered_set &previous_dirs,
109-
const internal::fs_unordered_set &current_dirs);
108+
void RecheckDirs(const fs_unordered_set &previous_dirs,
109+
const fs_unordered_set &current_dirs);
110110
void RecheckFlags(const std::unordered_set<std::string> &previous_flags,
111111
const std::unordered_set<std::string> &current_flags);
112112
void RecheckExternalLib(

buildcc/lib/target/src/api/target_info_getter.cpp

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,135 +64,128 @@ const TargetConfig &TargetInfoGetter<T>::GetConfig() const {
6464

6565
// Target Storer
6666
template <typename T>
67-
const internal::fs_unordered_set &
68-
TargetInfoGetter<T>::GetCurrentSourceFiles() const {
67+
const fs_unordered_set &TargetInfoGetter<T>::GetSourceFiles() const {
6968
const T &t = static_cast<const T &>(*this);
7069

7170
return t.storer_.current_source_files.user;
7271
}
7372

7473
template <typename T>
75-
const internal::fs_unordered_set &
76-
TargetInfoGetter<T>::GetCurrentHeaderFiles() const {
74+
const fs_unordered_set &TargetInfoGetter<T>::GetHeaderFiles() const {
7775
const T &t = static_cast<const T &>(*this);
7876

7977
return t.storer_.current_header_files.user;
8078
}
8179

8280
template <typename T>
83-
const internal::fs_unordered_set &
84-
TargetInfoGetter<T>::GetCurrentPchFiles() const {
81+
const fs_unordered_set &TargetInfoGetter<T>::GetPchFiles() const {
8582
const T &t = static_cast<const T &>(*this);
8683

8784
return t.storer_.current_pch_files.user;
8885
}
8986

9087
template <typename T>
91-
const std::vector<fs::path> &TargetInfoGetter<T>::GetTargetLibDeps() const {
88+
const std::vector<fs::path> &TargetInfoGetter<T>::GetLibDeps() const {
9289
const T &t = static_cast<const T &>(*this);
9390

9491
return t.storer_.current_user_lib_deps;
9592
}
9693

9794
template <typename T>
9895
const std::vector<std::string> &
99-
TargetInfoGetter<T>::GetCurrentExternalLibDeps() const {
96+
TargetInfoGetter<T>::GetExternalLibDeps() const {
10097
const T &t = static_cast<const T &>(*this);
10198

10299
return t.storer_.current_user_external_lib_deps;
103100
}
104101

105102
template <typename T>
106-
const internal::fs_unordered_set &
107-
TargetInfoGetter<T>::GetCurrentIncludeDirs() const {
103+
const fs_unordered_set &TargetInfoGetter<T>::GetIncludeDirs() const {
108104
const T &t = static_cast<const T &>(*this);
109105

110106
return t.storer_.current_include_dirs;
111107
}
112108

113109
template <typename T>
114-
const internal::fs_unordered_set &
115-
TargetInfoGetter<T>::GetCurrentLibDirs() const {
110+
const fs_unordered_set &TargetInfoGetter<T>::GetLibDirs() const {
116111
const T &t = static_cast<const T &>(*this);
117112

118113
return t.storer_.current_lib_dirs;
119114
}
120115

121116
template <typename T>
122117
const std::unordered_set<std::string> &
123-
TargetInfoGetter<T>::GetCurrentPreprocessorFlags() const {
118+
TargetInfoGetter<T>::GetPreprocessorFlags() const {
124119
const T &t = static_cast<const T &>(*this);
125120

126121
return t.storer_.current_preprocessor_flags;
127122
}
128123

129124
template <typename T>
130125
const std::unordered_set<std::string> &
131-
TargetInfoGetter<T>::GetCurrentCommonCompileFlags() const {
126+
TargetInfoGetter<T>::GetCommonCompileFlags() const {
132127
const T &t = static_cast<const T &>(*this);
133128

134129
return t.storer_.current_common_compile_flags;
135130
}
136131

137132
template <typename T>
138133
const std::unordered_set<std::string> &
139-
TargetInfoGetter<T>::GetCurrentPchCompileFlags() const {
134+
TargetInfoGetter<T>::GetPchCompileFlags() const {
140135
const T &t = static_cast<const T &>(*this);
141136

142137
return t.storer_.current_pch_compile_flags;
143138
}
144139

145140
template <typename T>
146141
const std::unordered_set<std::string> &
147-
TargetInfoGetter<T>::GetCurrentPchObjectFlags() const {
142+
TargetInfoGetter<T>::GetPchObjectFlags() const {
148143
const T &t = static_cast<const T &>(*this);
149144

150145
return t.storer_.current_pch_object_flags;
151146
}
152147

153148
template <typename T>
154149
const std::unordered_set<std::string> &
155-
TargetInfoGetter<T>::GetCurrentAsmCompileFlags() const {
150+
TargetInfoGetter<T>::GetAsmCompileFlags() const {
156151
const T &t = static_cast<const T &>(*this);
157152

158153
return t.storer_.current_asm_compile_flags;
159154
}
160155

161156
template <typename T>
162157
const std::unordered_set<std::string> &
163-
TargetInfoGetter<T>::GetCurrentCCompileFlags() const {
158+
TargetInfoGetter<T>::GetCCompileFlags() const {
164159
const T &t = static_cast<const T &>(*this);
165160

166161
return t.storer_.current_c_compile_flags;
167162
}
168163

169164
template <typename T>
170165
const std::unordered_set<std::string> &
171-
TargetInfoGetter<T>::GetCurrentCppCompileFlags() const {
166+
TargetInfoGetter<T>::GetCppCompileFlags() const {
172167
const T &t = static_cast<const T &>(*this);
173168

174169
return t.storer_.current_cpp_compile_flags;
175170
}
176171

177172
template <typename T>
178173
const std::unordered_set<std::string> &
179-
TargetInfoGetter<T>::GetCurrentLinkFlags() const {
174+
TargetInfoGetter<T>::GetLinkFlags() const {
180175
const T &t = static_cast<const T &>(*this);
181176

182177
return t.storer_.current_link_flags;
183178
}
184179

185180
template <typename T>
186-
const internal::fs_unordered_set &
187-
TargetInfoGetter<T>::GetCurrentCompileDependencies() const {
181+
const fs_unordered_set &TargetInfoGetter<T>::GetCompileDependencies() const {
188182
const T &t = static_cast<const T &>(*this);
189183

190184
return t.storer_.current_compile_dependencies.user;
191185
}
192186

193187
template <typename T>
194-
const internal::fs_unordered_set &
195-
TargetInfoGetter<T>::GetCurrentLinkDependencies() const {
188+
const fs_unordered_set &TargetInfoGetter<T>::GetLinkDependencies() const {
196189
const T &t = static_cast<const T &>(*this);
197190

198191
return t.storer_.current_link_dependencies.user;

buildcc/lib/target/src/common/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace buildcc::internal {
2525

2626
// Aggregates
2727

28-
std::string aggregate(const buildcc::internal::fs_unordered_set &paths) {
28+
std::string aggregate(const buildcc::fs_unordered_set &paths) {
2929
std::vector<std::string> agg;
3030
std::transform(
3131
paths.begin(), paths.end(), std::back_inserter(agg),

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,15 @@ void Target::Build() {
7575
// Target default arguments
7676
command_.AddDefaultArguments({
7777
{kIncludeDirs, internal::aggregate_with_prefix(config_.prefix_include_dir,
78-
GetCurrentIncludeDirs())},
79-
{kLibDirs, internal::aggregate_with_prefix(config_.prefix_lib_dir,
80-
GetCurrentLibDirs())},
78+
GetIncludeDirs())},
79+
{kLibDirs,
80+
internal::aggregate_with_prefix(config_.prefix_lib_dir, GetLibDirs())},
8181

82-
{kPreprocessorFlags, internal::aggregate(GetCurrentPreprocessorFlags())},
83-
{kCommonCompileFlags,
84-
internal::aggregate(GetCurrentCommonCompileFlags())},
82+
{kPreprocessorFlags, internal::aggregate(GetPreprocessorFlags())},
83+
{kCommonCompileFlags, internal::aggregate(GetCommonCompileFlags())},
8584
// TODO, Cache more flags here
8685
// ASM, C and CPP flags
87-
{kLinkFlags, internal::aggregate(GetCurrentLinkFlags())},
86+
{kLinkFlags, internal::aggregate(GetLinkFlags())},
8887

8988
// Toolchain executables here
9089
{kAsmCompiler, toolchain_.GetAsmCompiler()},
@@ -104,8 +103,8 @@ void Target::Build() {
104103
// PCH Compile
105104
if (state_.ContainsPch()) {
106105
command_.AddDefaultArguments({
107-
{kPchCompileFlags, internal::aggregate(GetCurrentPchCompileFlags())},
108-
{kPchObjectFlags, internal::aggregate(GetCurrentPchObjectFlags())},
106+
{kPchCompileFlags, internal::aggregate(GetPchCompileFlags())},
107+
{kPchObjectFlags, internal::aggregate(GetPchObjectFlags())},
109108
{kPchObjectOutput, fmt::format("{}", compile_pch_.GetObjectPath())},
110109
});
111110

buildcc/lib/target/src/target/friend/compile_object.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void CompileObject::CacheCompileCommands() {
6262
}
6363
}
6464

65-
internal::fs_unordered_set CompileObject::GetCompiledSources() const {
66-
internal::fs_unordered_set compiled_sources;
65+
fs_unordered_set CompileObject::GetCompiledSources() const {
66+
fs_unordered_set compiled_sources;
6767
for (const auto &p : object_files_) {
6868
compiled_sources.insert(p.second.output);
6969
}
@@ -145,19 +145,19 @@ void CompileObject::BuildObjectCompile(
145145
target_.dirty_ = true;
146146
} else {
147147
target_.RecheckFlags(loader.GetLoadedPreprocessorFlags(),
148-
target_.GetCurrentPreprocessorFlags());
148+
target_.GetPreprocessorFlags());
149149
target_.RecheckFlags(loader.GetLoadedCommonCompileFlags(),
150-
target_.GetCurrentCommonCompileFlags());
150+
target_.GetCommonCompileFlags());
151151
target_.RecheckFlags(loader.GetLoadedPchObjectFlags(),
152-
target_.GetCurrentPchObjectFlags());
152+
target_.GetPchObjectFlags());
153153
target_.RecheckFlags(loader.GetLoadedAsmCompileFlags(),
154-
target_.GetCurrentAsmCompileFlags());
154+
target_.GetAsmCompileFlags());
155155
target_.RecheckFlags(loader.GetLoadedCCompileFlags(),
156-
target_.GetCurrentCCompileFlags());
156+
target_.GetCCompileFlags());
157157
target_.RecheckFlags(loader.GetLoadedCppCompileFlags(),
158-
target_.GetCurrentCppCompileFlags());
158+
target_.GetCppCompileFlags());
159159
target_.RecheckDirs(loader.GetLoadedIncludeDirs(),
160-
target_.GetCurrentIncludeDirs());
160+
target_.GetIncludeDirs());
161161
target_.RecheckPaths(loader.GetLoadedHeaders(),
162162
storer.current_header_files.internal);
163163
target_.RecheckPaths(loader.GetLoadedCompileDependencies(),

0 commit comments

Comments
 (0)