Skip to content

Commit fe45fe5

Browse files
committed
Remove Build's callbacks.
1 parent f586899 commit fe45fe5

File tree

7 files changed

+6
-102
lines changed

7 files changed

+6
-102
lines changed

src/sw/core/sw_context.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ void SwCoreContext::loadPackages(TargetMap &targets, const TargetMap &predefined
158158
}
159159
}
160160

161-
162161
SwContext::SwContext(const path &local_storage_root_dir)
163162
: SwCoreContext(local_storage_root_dir)
164163
{

src/sw/driver/build.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ void NativeTargetEntryPoint::addChild(const TargetBaseTypePtr &t)
8888
b.getChildren()[t->getPackage()].push_back_inactive(t);
8989
else
9090
b.getChildren()[t->getPackage()].push_back(t);
91-
//b.getChildren()[t->getPackage()].setEntryPoint(shared_from_this());
92-
module_data.added_targets.push_back(t.get());
9391
}
9492

9593
NativeBuiltinTargetEntryPoint::NativeBuiltinTargetEntryPoint(Build &b, BuildFunction bf/*, const BuildSettings &s*/)
@@ -123,24 +121,6 @@ struct SW_DRIVER_CPP_API NativeModuleTargetEntryPoint : NativeTargetEntryPoint
123121
}
124122
};
125123

126-
namespace detail
127-
{
128-
129-
void EventCallback::operator()(Target &t, CallbackType e)
130-
{
131-
if (!pkgs.empty() && pkgs.find(t.getPackage()) == pkgs.end())
132-
return;
133-
if (!types.empty() && types.find(e) == types.end())
134-
return;
135-
if (types.empty() && typed_cb)
136-
throw std::logic_error("Typed callback passed, but no types provided");
137-
if (!cb)
138-
throw std::logic_error("No callback provided");
139-
cb(t, e);
140-
}
141-
142-
}
143-
144124
String toString(FrontendType t)
145125
{
146126
switch (t)
@@ -1060,21 +1040,6 @@ void Build::load_dll(const path &dll, const std::set<TargetSettings> &settings)
10601040
ep->loadPackages(getChildren(), s, {}); // load all
10611041
}
10621042

1063-
void Build::call_event(Target &t, CallbackType et)
1064-
{
1065-
for (auto &e : events)
1066-
{
1067-
try
1068-
{
1069-
e(t, et);
1070-
}
1071-
catch (const std::bad_cast &e)
1072-
{
1073-
LOG_DEBUG(logger, "bad cast in callback: " << e.what());
1074-
}
1075-
}
1076-
}
1077-
10781043
const StringSet &Build::getAvailableFrontendNames()
10791044
{
10801045
static StringSet s = []

src/sw/driver/build.h

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,6 @@ struct SwContext;
3636
template <class T>
3737
struct ExecutionPlan;
3838

39-
namespace detail
40-
{
41-
42-
struct EventCallback
43-
{
44-
using BasicEventCallback = std::function<void(Target &t, CallbackType e)>;
45-
using TypedEventCallback = std::function<void(Target &t)>;
46-
47-
PackageIdSet pkgs;
48-
std::set<CallbackType> types;
49-
BasicEventCallback cb;
50-
bool typed_cb = false;
51-
52-
void operator()(Target &t, CallbackType e);
53-
54-
template <class F, class ... Args>
55-
void add(const F &a, Args &&... args)
56-
{
57-
if constexpr (std::is_same_v<F, BasicEventCallback> ||
58-
std::is_convertible_v<F, BasicEventCallback>)
59-
cb = a;
60-
else if constexpr (std::is_same_v<F, TypedEventCallback> ||
61-
std::is_convertible_v<F, TypedEventCallback>)
62-
{
63-
typed_cb = true;
64-
cb = [a](Target &t, CallbackType)
65-
{
66-
a(t);
67-
};
68-
}
69-
else if constexpr (std::is_same_v<F, CallbackType>)
70-
types.insert(a);
71-
else
72-
pkgs.insert(String(a));
73-
74-
if constexpr (sizeof...(Args) > 0)
75-
add(std::forward<Args>(args)...);
76-
}
77-
};
78-
79-
}
80-
8139
using FilesMap = std::unordered_map<path, path>;
8240

8341
enum class FrontendType
@@ -116,7 +74,6 @@ struct ModuleSwappableData
11674
TargetSettings current_settings;
11775
BuildSettings bs;
11876
PackageIdSet known_targets;
119-
std::vector<Target*> added_targets;
12077
};
12178

12279
struct PrepareConfigEntryPoint;
@@ -194,19 +151,6 @@ struct SW_DRIVER_CPP_API Build : SimpleBuild
194151
const String &getCurrentModule() const;
195152
void addChild(const TargetBaseTypePtr &t);
196153

197-
// events
198-
template <class ... Args>
199-
void registerCallback(Args &&... args)
200-
{
201-
static_assert(sizeof...(Args) != 0, "Missing callback");
202-
203-
detail::EventCallback c;
204-
c.add(std::forward<Args>(args)...);
205-
events.push_back(c);
206-
}
207-
void call_event(Target &t, CallbackType et);
208-
//
209-
210154
// tests
211155
// TODO: implement some of https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-tests
212156
Commands tests;
@@ -249,8 +193,6 @@ struct SW_DRIVER_CPP_API Build : SimpleBuild
249193
Module loadModule(const path &fn) const;
250194

251195
private:
252-
std::vector<detail::EventCallback> events;
253-
254196
// basic frontends
255197
void load_dll(const path &dll, const std::set<TargetSettings> &);
256198
void load_configless(const path &file_or_dir);

src/sw/driver/build_self.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ DECLARE_STATIC_LOGGER(logger, "build.self");
2121

2222
using TargetEntryPointMap = std::unordered_map<sw::PackageId, std::shared_ptr<sw::NativeBuiltinTargetEntryPoint>>;
2323

24+
#define SW_CPP_DRIVER_API_VERSION 1
2425
#include <build_self.generated.h>
2526

2627
namespace sw

src/sw/driver/target/base.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ TargetBase &TargetBase::addTarget2(bool add, const TargetBaseTypePtr &t, const P
156156
// set some general settings, then init, then register
157157
setupTarget(t.get());
158158

159-
getSolution().call_event(*t, CallbackType::CreateTarget);
160159
t->call(CallbackType::CreateTarget);
161160

162161
// try to guess whether it's local package or not
@@ -235,13 +234,11 @@ TargetBase &TargetBase::addTarget2(bool add, const TargetBaseTypePtr &t, const P
235234
while (t->init())
236235
;
237236

238-
getSolution().call_event(*t, CallbackType::CreateTargetInitialized);
239237
t->call(CallbackType::CreateTargetInitialized);
240238

241239
auto &ref = addChild(t);
242240
//t->ts = getSolution().getSettings();
243241
//t->bs = t->ts;
244-
//getSolution().call_event(*t, CallbackType::CreateTargetInitialized);
245242
//t->call(CallbackType::CreateTargetInitialized);
246243
return ref;
247244
}

src/sw/driver/target/native.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,6 @@ bool NativeCompiledTarget::prepare()
18321832
{
18331833
LOG_TRACE(logger, "Preparing target: " + getPackage().ppath.toString());
18341834

1835-
getSolution().call_event(*this, CallbackType::BeginPrepare);
18361835
call(CallbackType::BeginPrepare);
18371836

18381837
if (UseModules)
@@ -2582,7 +2581,6 @@ bool NativeCompiledTarget::prepare()
25822581
getSelectedTool()->setInputLibraryDependencies(O1);
25832582
}
25842583

2585-
getSolution().call_event(*this, CallbackType::EndPrepare);
25862584
call(CallbackType::EndPrepare);
25872585
}
25882586
RETURN_PREPARE_MULTIPASS_NEXT_PASS;

sw.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ void configure(Build &s)
77
//auto ss = s.createSettings();
88
//ss.Native.LibrariesType = LibraryType::Static;
99
//s.addSettings(ss);
10-
10+
11+
#ifndef SW_CPP_DRIVER_API_VERSION
1112
s.registerCallback([](auto &t, auto cbt)
1213
{
1314
if (cbt != sw::CallbackType::CreateTarget)
@@ -24,12 +25,13 @@ void configure(Build &s)
2425
}
2526
});
2627

27-
/*if (s.isConfigSelected("cygwin2macos"))
28+
if (s.isConfigSelected("cygwin2macos"))
2829
s.loadModule("utils/cc/cygwin2macos.cpp").call<void(Solution&)>("configure", s);
2930
else if (s.isConfigSelected("win2macos"))
3031
s.loadModule("utils/cc/win2macos.cpp").call<void(Solution&)>("configure", s);
3132
else if (s.isConfigSelected("win2android"))
32-
s.loadModule("utils/cc/win2android.cpp").call<void(Solution&)>("configure", s);*/
33+
s.loadModule("utils/cc/win2android.cpp").call<void(Solution&)>("configure", s);
34+
#endif
3335

3436
//s.getSettings().Native.ConfigurationType = ConfigurationType::ReleaseWithDebugInformation;
3537
//s.getSettings().Native.CompilerType = CompilerType::ClangCl;

0 commit comments

Comments
 (0)