Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4f9dd90

Browse files
authored
[Cleanup] CRTP header only (#219)
1 parent4d9a71e commit4f9dd90

File tree

20 files changed

+333
-646
lines changed

20 files changed

+333
-646
lines changed

‎buildcc/lib/target/cmake/common_target_src.cmake‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ set(COMMON_TARGET_SRCS
1313
include/target/common/util.h
1414

1515
# API
16-
src/api/source_api.cpp
17-
src/api/include_api.cpp
1816
src/api/lib_api.cpp
19-
src/api/pch_api.cpp
20-
src/api/flag_api.cpp
21-
src/api/deps_api.cpp
2217
include/target/api/source_api.h
2318
include/target/api/include_api.h
2419
include/target/api/lib_api.h
@@ -28,9 +23,7 @@ set(COMMON_TARGET_SRCS
2823
src/api/sync_api.cpp
2924
include/target/api/sync_api.h
3025

31-
src/api/target_info_getter.cpp
3226
src/api/target_getter.cpp
33-
include/target/api/target_info_getter.h
3427
include/target/api/target_getter.h
3528

3629
# Generator

‎buildcc/lib/target/include/target/api/deps_api.h‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,73 @@
1919

2020
#include<filesystem>
2121

22+
#include"schema/path.h"
23+
2224
namespacefs= std::filesystem;
2325

2426
namespacebuildcc::internal {
2527

2628
// Requires
27-
// - TargetStorer
28-
// - TargetEnv
29+
// User::CompileDependencies
30+
// User::LinkDependencies
31+
// TargetEnv
2932
template<typename T>classDepsApi {
3033
public:
3134
// TODO, AddPchDependency
3235
// TODO, Rename AddObjectDependency
3336
// TODO, Rename AddTargetDependency
3437

38+
const fs_unordered_set &GetCompileDependencies()const {
39+
constauto &t =static_cast<const T &>(*this);
40+
return t.user_.compile_dependencies;
41+
}
42+
43+
const fs_unordered_set &GetLinkDependencies()const {
44+
constauto &t =static_cast<const T &>(*this);
45+
return t.user_.link_dependencies;
46+
}
47+
3548
/**
3649
* @brief Recompile sources to object if compile dependency is removed, added
3750
* or newer from the previous build
3851
*/
39-
voidAddCompileDependency(const fs::path &relative_path);
52+
voidAddCompileDependencyAbsolute(const fs::path &absolute_path) {
53+
auto &t =static_cast<T &>(*this);
54+
55+
t.user_.compile_dependencies.insert(absolute_path);
56+
}
4057

4158
/**
4259
* @brief Recompile sources to object if compile dependency is removed, added
4360
* or newer from the previous build
4461
*/
45-
voidAddCompileDependencyAbsolute(const fs::path &absolute_path);
62+
voidAddCompileDependency(const fs::path &relative_path) {
63+
auto &t =static_cast<T &>(*this);
64+
65+
fs::path absolute_path = t.env_.GetTargetRootDir() / relative_path;
66+
AddCompileDependencyAbsolute(absolute_path);
67+
}
4668

4769
/**
4870
* @brief Relink target if link dependency is removed, added or newer from
4971
* previous build
5072
*/
51-
voidAddLinkDependency(const fs::path &relative_path);
73+
voidAddLinkDependencyAbsolute(const fs::path &absolute_path) {
74+
auto &t =static_cast<T &>(*this);
75+
76+
t.user_.link_dependencies.insert(absolute_path);
77+
}
5278

5379
/**
5480
* @brief Relink target if link dependency is removed, added or newer from
5581
* previous build
5682
*/
57-
voidAddLinkDependencyAbsolute(const fs::path &absolute_path);
83+
voidAddLinkDependency(const fs::path &relative_path) {
84+
auto &t =static_cast<T &>(*this);
85+
86+
fs::path absolute_path = t.env_.GetTargetRootDir() / relative_path;
87+
AddLinkDependencyAbsolute(absolute_path);
88+
}
5889
};
5990

6091
}// namespace buildcc::internal

‎buildcc/lib/target/include/target/api/include_api.h‎

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,83 @@
1919

2020
#include<filesystem>
2121

22+
#include"schema/path.h"
23+
2224
namespacefs= std::filesystem;
2325

2426
namespacebuildcc::internal {
2527

2628
// Requires
27-
// - TargetStorer
28-
// - TargetConfig
29-
// - TargetEnv
29+
// Toolchain
30+
// User::Headers
31+
// User::IncludeDirs
32+
// TargetEnv
3033
template<typename T>classIncludeApi {
3134
public:
35+
const fs_unordered_set &GetHeaderFiles()const {
36+
constauto &t =static_cast<const T &>(*this);
37+
return t.user_.headers;
38+
}
39+
40+
const fs_unordered_set &GetIncludeDirs()const {
41+
constauto &t =static_cast<const T &>(*this);
42+
return t.user_.include_dirs;
43+
}
44+
45+
voidAddHeaderAbsolute(const fs::path &absolute_filepath) {
46+
auto &t =static_cast<T &>(*this);
47+
48+
t.toolchain_.GetConfig().ExpectsValidHeader(absolute_filepath);
49+
t.user_.headers.insert(absolute_filepath);
50+
}
51+
52+
voidGlobHeadersAbsolute(const fs::path &absolute_path) {
53+
auto &t =static_cast<T &>(*this);
54+
55+
for (constauto &p :fs::directory_iterator(absolute_path)) {
56+
if (t.toolchain_.GetConfig().IsValidHeader(p.path())) {
57+
AddHeaderAbsolute(p.path());
58+
}
59+
}
60+
}
61+
62+
voidAddIncludeDirAbsolute(const fs::path &absolute_include_dir,
63+
bool glob_headers =false) {
64+
auto &t =static_cast<T &>(*this);
65+
66+
t.user_.include_dirs.insert(absolute_include_dir);
67+
68+
if (glob_headers) {
69+
GlobHeadersAbsolute(absolute_include_dir);
70+
}
71+
}
72+
3273
voidAddHeader(const fs::path &relative_filename,
33-
const fs::path &relative_to_target_path ="");
34-
voidAddHeaderAbsolute(const fs::path &absolute_filepath);
74+
const fs::path &relative_to_target_path ="") {
75+
auto &t =static_cast<T &>(*this);
76+
77+
// Check Source
78+
fs::path absolute_filepath =
79+
t.env_.GetTargetRootDir() / relative_to_target_path / relative_filename;
80+
AddHeaderAbsolute(absolute_filepath);
81+
}
3582

36-
voidGlobHeaders(const fs::path &relative_to_target_path ="");
37-
voidGlobHeadersAbsolute(const fs::path &absolute_path);
83+
voidGlobHeaders(const fs::path &relative_to_target_path ="") {
84+
auto &t =static_cast<T &>(*this);
85+
86+
fs::path absolute_path =
87+
t.env_.GetTargetRootDir() / relative_to_target_path;
88+
GlobHeadersAbsolute(absolute_path);
89+
}
3890

3991
voidAddIncludeDir(const fs::path &relative_include_dir,
40-
bool glob_headers =false);
41-
voidAddIncludeDirAbsolute(const fs::path &absolute_include_dir,
42-
bool glob_headers =false);
92+
bool glob_headers =false) {
93+
auto &t =static_cast<T &>(*this);
94+
95+
const fs::path absolute_include_dir =
96+
t.env_.GetTargetRootDir() / relative_include_dir;
97+
AddIncludeDirAbsolute(absolute_include_dir, glob_headers);
98+
}
4399
};
44100

45101
}// namespace buildcc::internal

‎buildcc/lib/target/include/target/api/lib_api.h‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
#include<filesystem>
2121
#include<string>
22+
#include<vector>
23+
24+
#include"schema/path.h"
2225

2326
namespacefs= std::filesystem;
2427

@@ -31,16 +34,47 @@ class Target;
3134
namespacebuildcc::internal {
3235

3336
// Requires
34-
// - TargetStorer
35-
// - TargetEnv
36-
// T::GetTargetPath
37+
// User::LibDirs
38+
// User::Libs
39+
// User::ExternalLibs
40+
// TargetEnv
41+
// Target::GetTargetPath
3742
template<typename T>classLibApi {
3843
public:
39-
voidAddLibDep(const Target &lib_dep);
40-
voidAddLibDep(const std::string &lib_dep);
44+
const std::vector<fs::path> &GetLibDeps()const {
45+
constauto &t =static_cast<const T &>(*this);
46+
return t.user_.libs;
47+
}
48+
49+
const std::vector<std::string> &GetExternalLibDeps()const {
50+
constauto &t =static_cast<const T &>(*this);
51+
return t.user_.external_libs;
52+
}
53+
54+
const fs_unordered_set &GetLibDirs()const {
55+
constauto &t =static_cast<const T &>(*this);
56+
return t.user_.lib_dirs;
57+
}
4158

42-
voidAddLibDir(const fs::path &relative_lib_dir);
43-
voidAddLibDirAbsolute(const fs::path &absolute_lib_dir);
59+
voidAddLibDirAbsolute(const fs::path &absolute_lib_dir) {
60+
auto &t =static_cast<T &>(*this);
61+
t.user_.lib_dirs.insert(absolute_lib_dir);
62+
}
63+
64+
voidAddLibDir(const fs::path &relative_lib_dir) {
65+
auto &t =static_cast<T &>(*this);
66+
fs::path final_lib_dir = t.env_.GetTargetRootDir() / relative_lib_dir;
67+
AddLibDirAbsolute(final_lib_dir);
68+
}
69+
70+
voidAddLibDep(const std::string &lib_dep) {
71+
auto &t =static_cast<T &>(*this);
72+
t.user_.external_libs.push_back(lib_dep);
73+
}
74+
75+
// Target class has been forward declared
76+
// This is because this file is meant to be used by `TargetInfo` and `Target`
77+
voidAddLibDep(const Target &lib_dep);
4478
};
4579

4680
}// namespace buildcc::internal

‎buildcc/lib/target/include/target/api/pch_api.h‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,42 @@
1919

2020
#include<filesystem>
2121

22+
#include"schema/path.h"
23+
2224
namespacefs= std::filesystem;
2325

2426
namespacebuildcc::internal {
2527

2628
// Requires
27-
//- TargetStorer
28-
//- TargetConfig
29-
//-TargetEnv
29+
//Toolchain
30+
//User::Pchs
31+
// TargetEnv
3032
template<typename T>classPchApi {
3133
public:
34+
const fs_unordered_set &GetPchFiles()const {
35+
constauto &t =static_cast<const T &>(*this);
36+
return t.user_.pchs;
37+
}
38+
39+
voidAddPchAbsolute(const fs::path &absolute_filepath) {
40+
auto &t =static_cast<T &>(*this);
41+
42+
t.toolchain_.GetConfig().ExpectsValidHeader(absolute_filepath);
43+
44+
const fs::path absolute_pch =fs::path(absolute_filepath).make_preferred();
45+
t.user_.pchs.insert(absolute_pch);
46+
}
47+
3248
voidAddPch(const fs::path &relative_filename,
33-
const fs::path &relative_to_target_path ="");
34-
voidAddPchAbsolute(const fs::path &absolute_filepath);
49+
const fs::path &relative_to_target_path ="") {
50+
auto &t =static_cast<T &>(*this);
51+
52+
// Compute the absolute source path
53+
fs::path absolute_pch =
54+
t.env_.GetTargetRootDir() / relative_to_target_path / relative_filename;
55+
56+
AddPchAbsolute(absolute_pch);
57+
}
3558
};
3659

3760
}// namespace buildcc::internal

‎buildcc/lib/target/include/target/api/source_api.h‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,61 @@
1919

2020
#include<filesystem>
2121

22+
#include"schema/path.h"
23+
2224
namespacefs= std::filesystem;
2325

2426
namespacebuildcc::internal {
2527

2628
// Requires
27-
//- TargetStorer
28-
//- TargetConfig
29-
//-TargetEnv
29+
//Toolchain
30+
//User::Sources
31+
// TargetEnv
3032
template<typename T>classSourceApi {
3133
public:
32-
voidAddSourceAbsolute(const fs::path &absolute_source);
33-
voidGlobSourcesAbsolute(const fs::path &absolute_source_dir);
34+
const fs_unordered_set &GetSourceFiles()const {
35+
constauto &t =static_cast<const T &>(*this);
36+
return t.user_.sources;
37+
}
38+
39+
voidAddSourceAbsolute(const fs::path &absolute_source) {
40+
auto &t =static_cast<T &>(*this);
41+
42+
t.toolchain_.GetConfig().ExpectsValidSource(absolute_source);
43+
t.user_.sources.emplace(fs::path(absolute_source).make_preferred());
44+
}
45+
46+
voidGlobSourcesAbsolute(const fs::path &absolute_source_dir) {
47+
auto &t =static_cast<T &>(*this);
48+
49+
for (constauto &p :fs::directory_iterator(absolute_source_dir)) {
50+
if (t.toolchain_.GetConfig().IsValidSource(p.path())) {
51+
AddSourceAbsolute(p.path());
52+
}
53+
}
54+
}
3455

3556
voidAddSource(const fs::path &relative_source,
36-
const fs::path &relative_to_target_path ="");
37-
voidGlobSources(const fs::path &relative_to_target_path ="");
57+
const fs::path &relative_to_target_path ="") {
58+
auto &t =static_cast<T &>(*this);
59+
60+
// Compute the absolute source path
61+
fs::path absolute_source =
62+
t.env_.GetTargetRootDir() / relative_to_target_path / relative_source;
63+
AddSourceAbsolute(absolute_source);
64+
}
65+
66+
voidGlobSources(const fs::path &relative_to_target_path ="") {
67+
auto &t =static_cast<T &>(*this);
68+
69+
fs::path absolute_input_path =
70+
t.env_.GetTargetRootDir() / relative_to_target_path;
71+
for (constauto &p :fs::directory_iterator(absolute_input_path)) {
72+
if (t.toolchain_.GetConfig().IsValidSource(p.path())) {
73+
AddSourceAbsolute(p.path());
74+
}
75+
}
76+
}
3877
};
3978

4079
}// namespace buildcc::internal

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp