Skip to content

Commit

Permalink
Remove multiconfig. Initial entry points.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed May 21, 2019
1 parent 38ddf62 commit cb443de
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 374 deletions.
292 changes: 84 additions & 208 deletions src/sw/driver/build.cpp

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions src/sw/driver/build.h
Expand Up @@ -100,6 +100,23 @@ struct SW_DRIVER_CPP_API Test : driver::CommandBuilder
}
};

struct TargetEntryPoint
{
virtual ~TargetEntryPoint() = default;

virtual TargetBaseTypePtr create(const PackageIdSet &pkgs) = 0;
};

using TargetMapInternal1 = std::map<TargetSettings, TargetBaseTypePtr>;
struct TargetMapInternal : TargetMapInternal1
{
std::shared_ptr<TargetEntryPoint> ep;

void create();
};
using TargetMap = PackageVersionMapBase<TargetMapInternal, std::unordered_map, primitives::version::VersionMap>;


// simple interface for users
struct SolutionX : TargetBase
{
Expand Down Expand Up @@ -176,6 +193,7 @@ struct SW_DRIVER_CPP_API Build : TargetBase
PackageDescriptionMap getPackages() const;
BuildSettings createSettings() const;
const BuildSettings &addSettings(const BuildSettings &);
path build_configs(const std::unordered_set<LocalPackage> &pkgs);

/*void addTargetSettings(const String &ppath_regex, const VersionRange &vr, const TargetSettingsDataContainer &);
template <class T>
Expand Down Expand Up @@ -290,7 +308,7 @@ struct SW_DRIVER_CPP_API Build : TargetBase
void execute(CommandExecutionPlan &p) const;

bool isConfigSelected(const String &s) const;
const Module &loadModule(const path &fn) const;
Module loadModule(const path &fn) const;

void prepare();
bool prepareStep();
Expand All @@ -303,9 +321,6 @@ struct SW_DRIVER_CPP_API Build : TargetBase
//Solution &addSolution();
//Solution &addCustomSolution();

// hide?
path build_configs(const std::unordered_set<LocalPackage> &pkgs);

private:
bool remove_ide_explans = false;
//std::optional<const Solution *> host;
Expand Down
6 changes: 0 additions & 6 deletions src/sw/driver/build_self.cpp
Expand Up @@ -7,12 +7,6 @@
#define SW_PACKAGE_API
#include <sw/driver/sw.h>

#include "build.h"
#include "sw_context.h"

#include <boost/algorithm/string.hpp>
#include <primitives/executor.h>

// disable custom pragma warnings
#ifdef _MSC_VER
#pragma warning(push)
Expand Down
4 changes: 2 additions & 2 deletions src/sw/driver/checks.cpp
Expand Up @@ -188,15 +188,15 @@ CheckSet::CheckSet(Checker &checker)
{
}

Checker::Checker(const Build &build)
Checker::Checker(Build &build)
: build(build)
{
//checksStorage = std::make_unique<ChecksStorage>();
}

CheckSet &Checker::addSet(const String &name)
{
auto p = sets[current_gn].emplace(name, CheckSet(*this));
auto p = sets[build.current_gn].emplace(name, CheckSet(*this));
p.first->second.name = name;
return p.first->second;
}
Expand Down
7 changes: 2 additions & 5 deletions src/sw/driver/checks.h
Expand Up @@ -336,15 +336,12 @@ struct SW_DRIVER_CPP_API CheckSet

struct SW_DRIVER_CPP_API Checker
{
const Build &build;
Build &build;

/// child sets
std::unordered_map<PackageVersionGroupNumber, std::unordered_map<String /* set name */, CheckSet>> sets;

/// some unique identification of current module
PackageVersionGroupNumber current_gn = 0;

Checker(const Build &build);
Checker(Build &build);

CheckSet &addSet(const String &name);

Expand Down
49 changes: 20 additions & 29 deletions src/sw/driver/module.cpp
Expand Up @@ -7,6 +7,7 @@
#include "module.h"

#include <boost/dll.hpp>
#include <boost/dll/import_mangled.hpp>
#include <boost/thread/lock_types.hpp>
#include <primitives/sw/cl.h>

Expand All @@ -18,41 +19,27 @@ static cl::opt<bool> do_not_remove_bad_module("do-not-remove-bad-module");
namespace sw
{

ModuleStorage &getModuleStorage()
{
static ModuleStorage modules;
return modules;
}

const Module &ModuleStorage::get(const path &dll)
const Module::DynamicLibrary &ModuleStorage::get(const path &dll)
{
if (dll.empty())
throw SW_RUNTIME_ERROR("Empty module");

boost::upgrade_lock lk(m);
auto i = modules.find(dll);
if (i != modules.end())
return i->second;
return *i->second;
boost::upgrade_to_unique_lock lk2(lk);
return modules.emplace(dll, dll).first->second;
}

Module::Module(const path &dll)
: dll(dll)
{
String err;
err = "Module " + normalize_path(dll) + " is in bad shape";
try
{
module = new boost::dll::shared_library(
#ifdef _WIN32
dll.wstring()
#else
dll.u8string()
#endif
, boost::dll::load_mode::rtld_now | boost::dll::load_mode::rtld_global
auto module = std::make_unique<Module::DynamicLibrary>(dll,
boost::dll::load_mode::rtld_now | boost::dll::load_mode::rtld_global
//, ec
);

return *modules.emplace(dll, std::move(module)).first->second;
}
catch (std::exception &e)
{
Expand All @@ -70,14 +57,18 @@ Module::Module(const path &dll)
fs::remove(dll);
throw;
}
}

#define LOAD_NAME(f, n) \
do \
{ \
f##_.name = #f; \
f##_.m = this; \
if (module->has(n)) \
f##_ = module->get<decltype(f##_)::function_type>(n); \
Module::Module(const Module::DynamicLibrary &dll, const String &suffix)
: module(dll)
{
#define LOAD_NAME(f, n) \
do \
{ \
f##_.name = #f; \
f##_.m = this; \
if (!module.symbol_storage().get_function<decltype(f##_)::function_type>(n + suffix).empty()) \
f##_ = module.get_function<decltype(f##_)::function_type>(n + suffix); \
} while (0)

#define LOAD(f) LOAD_NAME(f, f##_.name)
Expand All @@ -91,9 +82,9 @@ Module::Module(const path &dll)
#undef LOAD_NAME
}

Module::~Module()
path Module::getLocation() const
{
delete module;
return module.shared_lib().location();
}

void Module::build(Build &s) const
Expand Down
27 changes: 13 additions & 14 deletions src/sw/driver/module.h
Expand Up @@ -8,14 +8,16 @@

#include "build.h"

#include <boost/dll/shared_library.hpp>
#include <boost/dll/smart_library.hpp>
#include <boost/thread/shared_mutex.hpp>

namespace sw
{

struct SW_DRIVER_CPP_API Module
{
using DynamicLibrary = boost::dll::experimental::smart_library;

template <class F, bool Required = false>
struct LibraryCall
{
Expand Down Expand Up @@ -46,7 +48,7 @@ struct SW_DRIVER_CPP_API Module
{
String err = "error in module";
if (m)
err += " (" + normalize_path(m->dll) + ")";
err += " (" + normalize_path(m->getLocation()) + ")";
err += ": ";
if (s && !s->current_module.empty())
err += s->current_module + ": ";
Expand All @@ -57,7 +59,7 @@ struct SW_DRIVER_CPP_API Module
{
String err = "error in module";
if (m)
err += " (" + normalize_path(m->dll) + ")";
err += " (" + normalize_path(m->getLocation()) + ")";
err += ": ";
if (s && !s->current_module.empty())
err += s->current_module + ": ";
Expand All @@ -72,7 +74,7 @@ struct SW_DRIVER_CPP_API Module
err += " '" + name + "'";
err += " is not present in the module";
if (m)
err += " (" + normalize_path(m->dll) + ")";
err += " (" + normalize_path(m->getLocation()) + ")";
if (s && !s->current_module.empty())
err += ": " + s->current_module;
throw SW_RUNTIME_ERROR(err);
Expand All @@ -81,12 +83,9 @@ struct SW_DRIVER_CPP_API Module
}
};

path dll;
boost::dll::shared_library *module = nullptr;
const DynamicLibrary &module;

Module(const path &dll);
Module(const Module &) = delete;
~Module();
Module(const Module::DynamicLibrary &, const String &suffix = {});

// api
void build(Build &s) const;
Expand All @@ -99,27 +98,27 @@ struct SW_DRIVER_CPP_API Module
{
if (!module)
throw SW_RUNTIME_ERROR("empty module");
return module->get<F>(name)(std::forward<Args>(args)...);
return module.get_function<F>(name)(std::forward<Args>(args)...);
}

private:
mutable LibraryCall<void(Build &), true> build_;
mutable LibraryCall<void(Build &)> configure_;
mutable LibraryCall<void(Checker &)> check_;
mutable LibraryCall<int(), true> sw_get_module_abi_version_;

path getLocation() const;
};

struct SW_DRIVER_CPP_API ModuleStorage
{
std::unordered_map<path, Module> modules;
std::unordered_map<path, std::unique_ptr<Module::DynamicLibrary>> modules;
boost::upgrade_mutex m;

ModuleStorage() = default;
ModuleStorage(const ModuleStorage &) = delete;

const Module &get(const path &dll);
const Module::DynamicLibrary &get(const path &dll);
};

ModuleStorage &getModuleStorage(const Build &owner);

}
2 changes: 1 addition & 1 deletion src/sw/driver/sw.h
Expand Up @@ -128,5 +128,5 @@ using sw::toString;
#endif

//#ifdef _MSC_VER
#include "sw1.h"
//#include "sw1.h"
//#endif
15 changes: 14 additions & 1 deletion src/sw/driver/sw_context.cpp
Expand Up @@ -7,6 +7,7 @@
#include "sw_context.h"

#include "checks_storage.h"
#include "module.h"

namespace sw
{
Expand All @@ -15,9 +16,16 @@ SwContext::SwContext(const path &local_storage_root_dir)
: SwBuilderContext(local_storage_root_dir)
{
source_dir = fs::canonical(fs::current_path());
module_storage = std::make_unique<ModuleStorage>();
}

SwContext::~SwContext() = default;
SwContext::~SwContext()
{
// do not clear modules on exception, because it may come from there
// TODO: cleanup modules data first
if (std::uncaught_exceptions())
module_storage.release();
}

ChecksStorage &SwContext::getChecksStorage(const String &config) const
{
Expand All @@ -42,5 +50,10 @@ ChecksStorage &SwContext::getChecksStorage(const String &config, const path &fn)
return *i->second;
}

ModuleStorage &SwContext::getModuleStorage() const
{
return *module_storage;
}

}

3 changes: 3 additions & 0 deletions src/sw/driver/sw_context.h
Expand Up @@ -14,6 +14,7 @@ namespace sw
{

struct ChecksStorage;
struct ModuleStorage;

struct SW_DRIVER_CPP_API SwContext : SwBuilderContext
{
Expand All @@ -24,9 +25,11 @@ struct SW_DRIVER_CPP_API SwContext : SwBuilderContext

ChecksStorage &getChecksStorage(const String &config) const;
ChecksStorage &getChecksStorage(const String &config, const path &fn) const;
ModuleStorage &getModuleStorage() const;

private:
mutable std::unordered_map<String, std::unique_ptr<ChecksStorage>> checksStorages;
std::unique_ptr<ModuleStorage> module_storage;
};

} // namespace sw
4 changes: 2 additions & 2 deletions src/sw/driver/target/base.cpp
Expand Up @@ -75,12 +75,12 @@ String toString(TargetType T)
throw SW_RUNTIME_ERROR("unreachable code");
}

bool TargetInternalId::operator<(const TargetInternalId &rhs) const
bool TargetSettings::operator<(const TargetSettings &rhs) const
{
return std::tie(ss, dependencies, features) < std::tie(rhs.ss, rhs.dependencies, rhs.features);
}

String TargetInternalId::getConfig() const
String TargetSettings::getConfig() const
{
return ss.getConfig();
}
Expand Down

0 comments on commit cb443de

Please sign in to comment.