summaryrefslogtreecommitdiff
path: root/tools/minicargo/manifest.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2018-12-30 13:18:07 +0800
committerJohn Hodge <tpg@ucc.asn.au>2018-12-30 13:18:07 +0800
commitbd64912c9847479800ba24c1e1fea7191197c591 (patch)
treebb6e6dd5af0d962df3998b931600e4bc9fc685ff /tools/minicargo/manifest.cpp
parentc2af54e57545b55be1a5c32cfe4ffbc4b6e114a4 (diff)
downloadmrust-bd64912c9847479800ba24c1e1fea7191197c591.tar.gz
minicargo - Cleanup and planning for better `cfg()` handing
Diffstat (limited to 'tools/minicargo/manifest.cpp')
-rw-r--r--tools/minicargo/manifest.cpp175
1 files changed, 6 insertions, 169 deletions
diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp
index bbaa24f6..79db0e35 100644
--- a/tools/minicargo/manifest.cpp
+++ b/tools/minicargo/manifest.cpp
@@ -13,20 +13,15 @@
#include <algorithm>
#include <cctype> // toupper
#include "repository.h"
+#include "cfg.hpp"
// TODO: Extract this from the target at runtime (by invoking the compiler on the passed target)
#ifdef _WIN32
# define TARGET_NAME "i586-windows-msvc"
-# define CFG_UNIX false
-# define CFG_WINDOWS true
#elif defined(__NetBSD__)
# define TARGET_NAME "x86_64-unknown-netbsd"
-# define CFG_UNIX true
-# define CFG_WINDOWS false
#else
# define TARGET_NAME "x86_64-unknown-linux-gnu"
-# define CFG_UNIX true
-# define CFG_WINDOWS false
#endif
static ::std::vector<::std::shared_ptr<PackageManifest>> g_loaded_manifests;
@@ -241,169 +236,7 @@ PackageManifest PackageManifest::load_from_toml(const ::std::string& path)
// - It can be a target spec, or a cfg(foo) same as rustc
bool success;
if( cfg.substr(0, 4) == "cfg(" ) {
- class Parser
- {
- public:
- class Tok
- {
- friend class Parser;
- const char* s;
- const char* e;
- Tok(const char* s, const char* e):
- s(s), e(e)
- {
- }
- public:
- bool operator==(const char* v) const {
- return (strlen(v) == e - s) && memcmp(s, v, e-s) == 0;
- }
- bool operator!=(const char* v) const {
- return (strlen(v) != e - s) || memcmp(s, v, e-s) != 0;
- }
- ::std::string to_string() const {
- return ::std::string(s, e);
- }
- };
- private:
- const char* m_pos;
- Tok m_cur;
-
- public:
- Parser(const char* s):
- m_pos(s),
- m_cur(nullptr,nullptr)
- {
- consume();
- }
- const Tok& cur() const {
- return m_cur;
- }
-
- Tok consume() {
- auto rv = m_cur;
- m_cur = get_next();
- //::std::cout << "consume: " << rv.to_string() << " => " << m_cur.to_string() << ::std::endl;
- return rv;
- }
- bool consume_if(const char* s) {
- if( cur() == s ) {
- consume();
- return true;
- }
- else {
- return false;
- }
- }
- private:
- Tok get_next() {
- while(*m_pos == ' ')
- m_pos ++;
- if(*m_pos == 0)
- return Tok { m_pos, m_pos };
- switch(*m_pos)
- {
- case '(': case ')':
- case ',': case '=':
- return Tok { m_pos++, m_pos };
- case '"': {
- auto s = m_pos;
- m_pos ++;
- while( *m_pos != '"' )
- {
- if( *m_pos == '\\' )
- {
- TODO("Escape sequences in cfg parser");
- }
- m_pos ++;
- }
- m_pos ++;
- return Tok { s, m_pos }; }
- default:
- if( isalnum(*m_pos) || *m_pos == '_' )
- {
- auto s = m_pos;
- while(isalnum(*m_pos) || *m_pos == '_')
- m_pos ++;
- return Tok { s, m_pos };
- }
- else
- {
- throw ::std::runtime_error(format("Unexpected character in cfg() - ", *m_pos));
- }
- }
- }
- };
-
- struct H {
- static bool check_cfg(Parser& p)
- {
- if( p.consume_if("not") ) {
- if( !p.consume_if("(") )
- throw ::std::runtime_error("Expected '(' after `not`");
- auto rv = !check_cfg(p);
- if( !p.consume_if(")") )
- throw ::std::runtime_error("Expected ')' after `not` content");
- return rv;
- }
- else if( p.consume_if("all") ) {
- if( !p.consume_if("(") )
- throw ::std::runtime_error("Expected '(' after `all`");
- bool rv = true;
- do
- {
- rv &= check_cfg(p);
- } while(p.consume_if(","));
- if( !p.consume_if(")") )
- throw ::std::runtime_error("Expected ')' after `all` content");
- return rv;
- }
- // Strings
- else if( p.consume_if("target_os") ) {
- if( !p.consume_if("=") )
- throw ::std::runtime_error("Expected '=' after target_os");
- auto t = p.consume();
- if( t == "\"emscripten\"" ) {
- return false;
- }
- else if( t == "\"macos\"" ) {
- return false;
- }
- else {
- TODO("Handle target_os string - " << t.to_string());
- }
- }
- else if( p.consume_if("target_arch") ) {
- if( !p.consume_if("=") )
- throw ::std::runtime_error("Expected '=' after target");
- auto t = p.consume();
- if( t == "\"wasm32\"" ) {
- return false;
- }
- else{
- TODO("Handle target_arch string - " << t.to_string());
- }
- }
- // Flags
- else if( p.consume_if("unix") ) {
- return CFG_UNIX;
- }
- else if( p.consume_if("windows") ) {
- return CFG_WINDOWS;
- }
- else if( p.consume_if("stage0") ) {
- return false;
- }
- else {
- TODO("Unknown fragment in cfg - " << p.cur().to_string());
- throw ::std::runtime_error("");
- }
- }
- };
-
- Parser p { cfg.data() + 4 };
- success = H::check_cfg(p);
- if( !p.consume_if(")") )
- throw ::std::runtime_error(format("Expected ')' after cfg condition - got", p.cur().to_string()));
+ success = Cfg_Check(cfg.c_str());
}
else {
// It's a target name
@@ -428,6 +261,10 @@ PackageManifest PackageManifest::load_from_toml(const ::std::string& path)
it->fill_from_kv(was_added, key_val, 4);
}
+ else if( real_section == "dev-dependencies" )
+ {
+ // TODO: Developemnt (test/bench) deps
+ }
else
{
TODO("Unknown manifest section for target - " << real_section);