summaryrefslogtreecommitdiff
path: root/tools/minicargo/repository.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-08-24 11:14:22 +0800
committerJohn Hodge <tpg@mutabah.net>2017-08-24 11:14:22 +0800
commitf559abbdff252cb5073d7df368054146719d37fc (patch)
tree583e39574a653db19c5aa66e7523535f74e03b5a /tools/minicargo/repository.cpp
parentd42d8b2f9292b0e9568bd9758cdd7527e74201eb (diff)
downloadmrust-f559abbdff252cb5073d7df368054146719d37fc.tar.gz
minicargo repository - Load from vendor dir (Windows untested)
Diffstat (limited to 'tools/minicargo/repository.cpp')
-rw-r--r--tools/minicargo/repository.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/tools/minicargo/repository.cpp b/tools/minicargo/repository.cpp
index c6fe284f..09aa0bad 100644
--- a/tools/minicargo/repository.cpp
+++ b/tools/minicargo/repository.cpp
@@ -2,6 +2,12 @@
*/
#include "repository.h"
#include "debug.h"
+#include <fstream>
+#if _WIN32
+#else
+# include <dirent.h>
+#endif
+#include "toml.h"
void Repository::load_cache(const ::helpers::path& path)
{
@@ -11,6 +17,74 @@ 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
+ #if _WIN32
+ WIN32_FIND_DATA find_data;
+ HANDLE find_handle = FindFirstFile( (path / "*").str().c_str(), &find_data );
+ if( find_handle == INVALID_HANDLE_VALUE )
+ throw ::std::runtime_error(::format( "Unable to open vendor directory '", path, "'" ));
+ do
+ {
+ auto manifest_path = path / find_data.cFileName / "Cargo.toml";
+ #else
+ auto* dp = opendir(path.str().c_str());
+ if( dp == nullptr )
+ throw ::std::runtime_error(::format( "Unable to open vendor directory '", path, "'" ));
+ while( const auto* dent = readdir(dp) )
+ {
+ auto manifest_path = path / dent->d_name / "Cargo.toml";
+ #endif
+
+ if( ! ::std::ifstream(manifest_path.str()).good() )
+ continue ;
+ DEBUG("Opening manifest " << manifest_path);
+
+ // Scan the manifiest until both the name and version are set
+ bool name_set = false;
+ ::std::string name;
+ bool ver_set = false;
+ PackageVersion ver;
+
+ TomlFile toml_file(manifest_path);
+ for(auto key_val : toml_file)
+ {
+ if(key_val.path.size() != 2)
+ continue ;
+ if(key_val.path[0] == "package") {
+ if( key_val.path[1] == "name" ) {
+ //assert( !name_set );
+ name = key_val.value.as_string();
+ name_set = true;
+ if( name_set && ver_set )
+ break;
+ }
+ else if( key_val.path[1] == "version" ) {
+ //assert( !ver_set );
+ ver = PackageVersion::from_string(key_val.value.as_string());
+ ver_set = true;
+ if( name_set && ver_set )
+ break;
+ }
+ else
+ ;
+ }
+ }
+
+ DEBUG("Package '" << name << "' v" << ver);
+ if(name == "")
+ continue ;
+
+ Entry cache_ent;
+ cache_ent.manifest_path = manifest_path;
+ cache_ent.version = ver;
+ m_cache.insert(::std::make_pair( name, ::std::move(cache_ent) ));
+
+ #ifndef _WIN32
+ }
+ closedir(dp);
+ #else
+ } while( FindNextFile(find_handle, &find_data) );
+ FindClose(find_handle);
+ #endif
}
::std::shared_ptr<PackageManifest> Repository::from_path(::helpers::path in_path)