Skip to content

Commit 4723e5d

Browse files
authored
[CRTP] Target Deps API (#154)
1 parent c17cd32 commit 4723e5d

File tree

7 files changed

+106
-52
lines changed

7 files changed

+106
-52
lines changed

buildcc/lib/target/cmake/mock_target.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_library(mock_target STATIC
1313
src/api/lib_api.cpp
1414
src/api/pch_api.cpp
1515
src/api/flag_api.cpp
16+
src/api/deps_api.cpp
1617

1718
# Generator
1819
src/generator/generator_loader.cpp
@@ -33,8 +34,6 @@ add_library(mock_target STATIC
3334
src/target/target_loader.cpp
3435
src/target/target_storer.cpp
3536

36-
src/target/additional_deps.cpp
37-
3837
src/target/build.cpp
3938

4039
# Target mocks

buildcc/lib/target/cmake/target.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ set(TARGET_SRCS
2424
src/api/lib_api.cpp
2525
src/api/pch_api.cpp
2626
src/api/flag_api.cpp
27+
src/api/deps_api.cpp
2728
include/target/api/copy_api.h
2829
include/target/api/source_api.h
2930
include/target/api/include_api.h
3031
include/target/api/lib_api.h
3132
include/target/api/pch_api.h
3233
include/target/api/flag_api.h
34+
include/target/api/deps_api.h
3335

3436
# Generator
3537
src/generator/generator_loader.cpp
@@ -56,8 +58,6 @@ set(TARGET_SRCS
5658
include/target/target_storer.h
5759
include/target/target.h
5860

59-
src/target/additional_deps.cpp
60-
6161
src/target/recheck_states.cpp
6262

6363
src/target/build.cpp
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2021 Niket Naidu. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef TARGET_API_DEPS_API_H_
18+
#define TARGET_API_DEPS_API_H_
19+
20+
#include <filesystem>
21+
22+
namespace fs = std::filesystem;
23+
24+
namespace buildcc::base {
25+
26+
// Requires
27+
// - TargetStorer
28+
// - TargetState
29+
// - TargetEnv
30+
template <typename T> class DepsApi {
31+
public:
32+
void AddCompileDependency(const fs::path &relative_path);
33+
void AddCompileDependencyAbsolute(const fs::path &absolute_path);
34+
void AddLinkDependency(const fs::path &relative_path);
35+
void AddLinkDependencyAbsolute(const fs::path &absolute_path);
36+
};
37+
38+
} // namespace buildcc::base
39+
40+
#endif

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
namespace buildcc::base {
2323

24+
// Requires
25+
// - TargetStorer
26+
// - TargetState
2427
template <typename T> class FlagApi {
2528
public:
2629
void AddPreprocessorFlag(const std::string &flag);

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
// API
4040
#include "target/api/copy_api.h"
41+
#include "target/api/deps_api.h"
4142
#include "target/api/flag_api.h"
4243
#include "target/api/include_api.h"
4344
#include "target/api/lib_api.h"
@@ -75,7 +76,8 @@ class Target : public BuilderInterface,
7576
public IncludeApi<Target>,
7677
public LibApi<Target>,
7778
public PchApi<Target>,
78-
public FlagApi<Target> {
79+
public FlagApi<Target>,
80+
public DepsApi<Target> {
7981

8082
public:
8183
explicit Target(const std::string &name, TargetType type,
@@ -95,14 +97,6 @@ class Target : public BuilderInterface,
9597
// Builders
9698
void Build() override;
9799

98-
// Setters
99-
100-
// * Rebuild
101-
void AddCompileDependency(const fs::path &relative_path);
102-
void AddCompileDependencyAbsolute(const fs::path &absolute_path);
103-
void AddLinkDependency(const fs::path &relative_path);
104-
void AddLinkDependencyAbsolute(const fs::path &absolute_path);
105-
106100
// TODO, Add more setters
107101

108102
//
@@ -222,6 +216,7 @@ class Target : public BuilderInterface,
222216
friend class LibApi<Target>;
223217
friend class PchApi<Target>;
224218
friend class FlagApi<Target>;
219+
friend class DepsApi<Target>;
225220

226221
private:
227222
void Initialize();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2021 Niket Naidu. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "target/api/deps_api.h"
18+
19+
#include "target/target.h"
20+
21+
namespace buildcc::base {
22+
23+
template <typename T>
24+
void DepsApi<T>::AddCompileDependencyAbsolute(const fs::path &absolute_path) {
25+
T &t = static_cast<T &>(*this);
26+
27+
t.state_.ExpectsUnlock();
28+
t.storer_.current_compile_dependencies.user.insert(absolute_path);
29+
}
30+
template <typename T>
31+
void DepsApi<T>::AddLinkDependencyAbsolute(const fs::path &absolute_path) {
32+
T &t = static_cast<T &>(*this);
33+
34+
t.state_.ExpectsUnlock();
35+
t.storer_.current_link_dependencies.user.insert(absolute_path);
36+
}
37+
38+
template <typename T>
39+
void DepsApi<T>::AddCompileDependency(const fs::path &relative_path) {
40+
T &t = static_cast<T &>(*this);
41+
42+
fs::path absolute_path = t.env_.GetTargetRootDir() / relative_path;
43+
AddCompileDependencyAbsolute(absolute_path);
44+
}
45+
46+
template <typename T>
47+
void DepsApi<T>::AddLinkDependency(const fs::path &relative_path) {
48+
T &t = static_cast<T &>(*this);
49+
50+
fs::path absolute_path = t.env_.GetTargetRootDir() / relative_path;
51+
AddLinkDependencyAbsolute(absolute_path);
52+
}
53+
54+
template class DepsApi<Target>;
55+
56+
} // namespace buildcc::base

buildcc/lib/target/src/target/additional_deps.cpp

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

0 commit comments

Comments
 (0)