]> git.tdb.fi Git - builder.git/blobdiff - source/builder.cpp
Guard against build type being missing
[builder.git] / source / builder.cpp
index 5475c7dab99aaa6baf610ec6a6a3529d21b0b5bc..46bc704140690a1678af3f3f8f4f3b06ed218818 100644 (file)
@@ -1,4 +1,5 @@
 #include <set>
+#include <msp/core/except.h>
 #include <msp/core/maputils.h>
 #include <msp/datafile/parser.h>
 #include <msp/fs/dir.h>
@@ -70,6 +71,13 @@ vector<string> Builder::get_build_types() const
        return keys;
 }
 
+const BuildType &Builder::get_build_type() const
+{
+       if(!build_type)
+               throw invalid_state("no build type");
+       return *build_type;
+}
+
 void Builder::set_build_type(const string &name)
 {
        build_type = &get_item(build_types, name);
@@ -324,7 +332,7 @@ void Builder::Loader::build_type(const string &n)
 {
        BuildType btype(n);
        load_sub(btype);
-       BuildTypeMap::iterator i = obj.build_types.insert(BuildTypeMap::value_type(n, btype)).first;
+       auto i = obj.build_types.insert({ n, btype }).first;
        if(!obj.build_type)
                obj.build_type = &i->second;
 }
@@ -333,10 +341,7 @@ void Builder::Loader::package(const string &n)
 {
        SourcePackage *pkg = new SourcePackage(obj, n, get_source());
 
-       if(options)
-               load_sub(*pkg, *options);
-       else
-               load_sub(*pkg);
+       load_sub(*pkg, options);
 
        if(obj.build_type)
                pkg->set_build_type(*obj.build_type);