summaryrefslogtreecommitdiff
path: root/tools/minicargo/repository.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-08-20 20:54:45 +0800
committerJohn Hodge <tpg@mutabah.net>2017-08-20 20:54:45 +0800
commit19f32ced09e7538cde01cb443b19e0a7a1c5667f (patch)
tree06a47471b98e8cf64b5fb3f529dd176f7586ebcb /tools/minicargo/repository.cpp
parent4ca497d863c1c93689e5dd7581c164d1ce885569 (diff)
downloadmrust-19f32ced09e7538cde01cb443b19e0a7a1c5667f.tar.gz
minicargo - Dependency loading
Diffstat (limited to 'tools/minicargo/repository.cpp')
-rw-r--r--tools/minicargo/repository.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/tools/minicargo/repository.cpp b/tools/minicargo/repository.cpp
new file mode 100644
index 00000000..0a097f66
--- /dev/null
+++ b/tools/minicargo/repository.cpp
@@ -0,0 +1,70 @@
+/*
+ */
+#include "repository.h"
+#include "debug.h"
+
+void Repository::load_cache(const ::helpers::path& path)
+{
+ throw "";
+}
+void Repository::load_vendored(const ::helpers::path& path)
+{
+ // Enumerate folders in this folder, try to open Cargo.toml files
+ // Extract package name and version from each manifest
+}
+
+::std::shared_ptr<PackageManifest> Repository::from_path(::helpers::path path)
+{
+ DEBUG("Repository::from_path(" << path << ")");
+ // 1. Normalise path
+ path = path.normalise();
+ DEBUG("path = " << path);
+
+ auto it = m_path_cache.find(path);
+ if(it == m_path_cache.end())
+ {
+ ::std::shared_ptr<PackageManifest> rv ( new PackageManifest(PackageManifest::load_from_toml(path)) );
+
+ m_path_cache.insert( ::std::make_pair(::std::move(path), rv) );
+
+ return rv;
+ }
+ else
+ {
+ return it->second;
+ }
+}
+::std::shared_ptr<PackageManifest> Repository::find(const ::std::string& name, const PackageVersionSpec& version)
+{
+ auto itp = m_cache.equal_range(name);
+
+ Entry* best = nullptr;
+ for(auto i = itp.first; i != itp.second; ++i)
+ {
+ if( version.accepts(i->second.version) )
+ {
+ if( !best || best->version < i->second.version )
+ {
+ best = &i->second;
+ }
+ }
+ }
+
+ if( best )
+ {
+ if( !best->loaded_manifest )
+ {
+ if( best->manifest_path == "" )
+ {
+ throw "TODO: Download package";
+ }
+ best->loaded_manifest = ::std::shared_ptr<PackageManifest>( new PackageManifest(PackageManifest::load_from_toml(best->manifest_path)) );
+ }
+
+ return best->loaded_manifest;
+ }
+ else
+ {
+ return {};
+ }
+}