diff options
author | John Hodge <tpg@mutabah.net> | 2017-08-19 17:37:07 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2017-08-19 17:39:08 +0800 |
commit | a3ca810d74c09235cbd501f606ed1b979691aba3 (patch) | |
tree | 50b94b73cd49849c7bab9bde821ba41d8c9d3f62 /tools/minicargo/build.cpp | |
parent | 42f772e01d1cae1fa774bb0b670670dbefa813ea (diff) | |
download | mrust-a3ca810d74c09235cbd501f606ed1b979691aba3.tar.gz |
minicargo - Draft implementation, spawns mrustc on windows
Diffstat (limited to 'tools/minicargo/build.cpp')
-rw-r--r-- | tools/minicargo/build.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp new file mode 100644 index 00000000..a8032760 --- /dev/null +++ b/tools/minicargo/build.cpp @@ -0,0 +1,83 @@ +/* + */ +#include "manifest.h" +#include <vector> +#include <algorithm> + +struct BuildList +{ + struct BuildEnt { + const PackageManifest* package; + unsigned level; + }; + ::std::vector<BuildEnt> m_list; + + void add_package(const PackageManifest& p, unsigned level); + void sort_list(); + + struct Iter { + const BuildList& l; + size_t i; + + const PackageManifest& operator*() const { + return *this->l.m_list[this->l.m_list.size() - this->i - 1].package; + } + void operator++() { + this->i++; + } + bool operator!=(const Iter& x) const { + return this->i != x.i; + } + Iter begin() const { + return *this; + } + Iter end() { + return Iter{ this->l, this->l.m_list.size() }; + } + }; + + Iter iter() const { + return Iter { *this, 0 }; + } +}; + +void MiniCargo_Build(const PackageManifest& manifest) +{ + BuildList list; + // Generate sorted dependency list + for (const auto& dep : manifest.dependencies()) + { + list.add_package(dep.get_package(), 1); + } + + + // Build dependencies + for(const auto& p : list.iter()) + { + p.build_lib(); + } + + manifest.build_lib(); + // TODO: If the manifest doesn't have a library, build the binary +} + +void BuildList::add_package(const PackageManifest& p, unsigned level) +{ + for(auto& ent : m_list) + { + if(ent.package == &p) + { + ent.level = level; + return ; + } + } + m_list.push_back({ &p, level }); + for (const auto& dep : p.dependencies()) + { + add_package(dep.get_package(), level+1); + } +} +void BuildList::sort_list() +{ + ::std::sort(m_list.begin(), m_list.end(), [](const auto& a, const auto& b){ return a.level < b.level; }); +} |