diff options
author | regnat <rg@regnat.ovh> | 2020-09-09 11:18:12 +0200 |
---|---|---|
committer | regnat <rg@regnat.ovh> | 2020-09-16 13:53:08 +0200 |
commit | fa32560169ffa55b9e0b6d5f04c3792acf0c544a (patch) | |
tree | 61c605aebb1c2385ba4401f55059da1e55a4cd21 /src | |
parent | 7d5bdf8b5679cc7b2b9b4d9caf5af9ca52211336 (diff) |
Fix the registration of stores
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/dummy-store.cc | 2 | ||||
-rw-r--r-- | src/libstore/http-binary-cache-store.cc | 2 | ||||
-rw-r--r-- | src/libstore/legacy-ssh-store.cc | 2 | ||||
-rw-r--r-- | src/libstore/local-binary-cache-store.cc | 2 | ||||
-rw-r--r-- | src/libstore/remote-store.cc | 2 | ||||
-rw-r--r-- | src/libstore/s3-binary-cache-store.cc | 2 | ||||
-rw-r--r-- | src/libstore/ssh-store.cc | 2 | ||||
-rw-r--r-- | src/libstore/store-api.cc | 3 | ||||
-rw-r--r-- | src/libstore/store-api.hh | 27 |
9 files changed, 26 insertions, 18 deletions
diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc index a677e201e..dd1880877 100644 --- a/src/libstore/dummy-store.cc +++ b/src/libstore/dummy-store.cc @@ -50,6 +50,6 @@ struct DummyStore : public Store { unsupported("buildDerivation"); } }; -[[maybe_unused]] static RegisterStoreImplementation<DummyStore> regStore(); +static RegisterStoreImplementation<DummyStore> regStore; } diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc index 6c3a16faf..c1abe35cb 100644 --- a/src/libstore/http-binary-cache-store.cc +++ b/src/libstore/http-binary-cache-store.cc @@ -170,6 +170,6 @@ protected: }; -[[maybe_unused]] static RegisterStoreImplementation<HttpBinaryCacheStore> regStore(); +static RegisterStoreImplementation<HttpBinaryCacheStore> regStore; } diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 72f28a82d..552b4b176 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -326,6 +326,6 @@ public: } }; -[[maybe_unused]] static RegisterStoreImplementation<LegacySSHStore> regStore(); +static RegisterStoreImplementation<LegacySSHStore> regStore; } diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index 752838d3f..808a1338f 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -96,6 +96,6 @@ std::vector<std::string> LocalBinaryCacheStore::uriPrefixes() return {"file"}; } -[[maybe_unused]] static RegisterStoreImplementation<LocalBinaryCacheStore> regStore(); +static RegisterStoreImplementation<LocalBinaryCacheStore> regStore; } diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 824b6b140..5f455a62a 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -982,6 +982,6 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink * sink, Source * return nullptr; } -[[maybe_unused]] static RegisterStoreImplementation<UDSRemoteStore> regStore(); +static RegisterStoreImplementation<UDSRemoteStore> regStore; } diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index 1bf4d5955..f426b43a9 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -431,7 +431,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore }; -[[maybe_unused]] static RegisterStoreImplementation<S3BinaryCacheStoreImpl> regStore(); +static RegisterStoreImplementation<S3BinaryCacheStoreImpl> regStore; } diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc index 02208ee82..8177a95b0 100644 --- a/src/libstore/ssh-store.cc +++ b/src/libstore/ssh-store.cc @@ -76,6 +76,6 @@ ref<RemoteStore::Connection> SSHStore::openConnection() return conn; } -[[maybe_unused]] static RegisterStoreImplementation<SSHStore> regStore(); +static RegisterStoreImplementation<SSHStore> regStore; } diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 4a46b5160..0f321b434 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -1093,7 +1093,7 @@ ref<Store> openStore(const std::string & uri_, return ref<Store>(store); } - for (auto implem : *implementations) { + for (auto implem : *Implementations::registered) { auto store = implem.open(uri, params); if (store) { store->warnUnknownSettings(); @@ -1136,5 +1136,6 @@ std::list<ref<Store>> getDefaultSubstituters() return stores; } +std::vector<StoreFactory> * Implementations::registered = 0; } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 28365542d..61080978e 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -749,25 +749,32 @@ std::list<ref<Store>> getDefaultSubstituters(); struct StoreFactory { - std::vector<std::string> uriPrefixes; std::function<std::shared_ptr<Store> (const std::string & uri, const Store::Params & params)> open; }; -typedef std::vector<StoreFactory> Implementations; -static Implementations * implementations = new Implementations; - -template<typename T> -struct RegisterStoreImplementation +struct Implementations { - RegisterStoreImplementation() + static std::vector<StoreFactory> * registered; + + template<typename T> + static void add() { + if (!registered) registered = new std::vector<StoreFactory>(); StoreFactory factory{ - .uriPrefixes = T::uriPrefixes(), .open = ([](const std::string & uri, const Store::Params & params) -> std::shared_ptr<Store> - { return std::make_shared<T>(uri, params); }) + { return std::make_shared<T>(uri, params); }), }; - implementations->push_back(factory); + registered->push_back(factory); + } +}; + +template<typename T> +struct RegisterStoreImplementation +{ + RegisterStoreImplementation() + { + Implementations::add<T>(); } }; |