summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast/crate.cpp23
-rw-r--r--src/ast/crate.hpp3
-rw-r--r--src/main.cpp11
3 files changed, 31 insertions, 6 deletions
diff --git a/src/ast/crate.cpp b/src/ast/crate.cpp
index 394cd47b..f003a00b 100644
--- a/src/ast/crate.cpp
+++ b/src/ast/crate.cpp
@@ -8,6 +8,9 @@
#include <hir/main_bindings.hpp> // HIR_Deserialise
#include <fstream>
+::std::vector<::std::string> AST::g_crate_load_dirs = { };
+::std::map<::std::string, ::std::string> AST::g_crate_overrides;
+
namespace {
bool check_item_cfg(const ::AST::MetaItems& attrs)
{
@@ -99,15 +102,23 @@ void Crate::load_externs()
void Crate::load_extern_crate(Span sp, const ::std::string& name)
{
DEBUG("Loading crate '" << name << "'");
- // TODO: Search a list of load paths for the crate
- ::std::vector< ::std::string> paths { "output/", "output/test_deps/" };
::std::string path;
- for(const auto& p : paths){
- path = p + "lib" + name + ".hir";
+ auto it = g_crate_overrides.find(name);
+ if(it != g_crate_overrides.end())
+ {
+ path = it->second;
+ }
+ else
+ {
+ // Search a list of load paths for the crate
+ for(const auto& p : g_crate_load_dirs)
+ {
+ path = p + "/lib" + name + ".hir";
- if( ::std::ifstream(path).good() ) {
- break ;
+ if( ::std::ifstream(path).good() ) {
+ break ;
+ }
}
}
if( !::std::ifstream(path).good() ) {
diff --git a/src/ast/crate.hpp b/src/ast/crate.hpp
index f9594a83..53dea1b9 100644
--- a/src/ast/crate.hpp
+++ b/src/ast/crate.hpp
@@ -89,4 +89,7 @@ public:
const MacroRules* find_macro_rules(const ::std::string& name) const;
};
+extern ::std::vector<::std::string> g_crate_load_dirs;
+extern ::std::map<::std::string, ::std::string> g_crate_overrides;
+
} // namespace AST
diff --git a/src/main.cpp b/src/main.cpp
index 7b1d94be..b883a828 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -224,6 +224,11 @@ int main(int argc, char *argv[])
// Load external crates.
CompilePhaseV("LoadCrates", [&]() {
+ // Hacky!
+ for(const auto& ld : params.lib_search_dirs)
+ {
+ AST::g_crate_load_dirs.push_back(ld);
+ }
crate.load_externs();
});
@@ -570,6 +575,12 @@ int main(int argc, char *argv[])
// ::std::cerr << "Internal Compiler Error: " << e << ::std::endl;
// return 2;
//}
+
+ // TODO: Make this conditional
+#if 0
+ ::std::cout << "Press enter to exit..." << ::std::endl;
+ ::std::cin.get();
+#endif
return 0;
}