X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fconfig.cpp;h=a83a641a5bcaa66dbfcf2eda1ee477ab13648306;hb=afed9d3a6326790b77b786cbc1e76b725a14dbe5;hp=c8e9aaa7e57623a9506c3e248c8e11a21d73b810;hpb=b3b2a8666defb9e1a5937bcfefc1bc8e02793aab;p=builder.git diff --git a/source/config.cpp b/source/config.cpp index c8e9aaa..a83a641 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -5,10 +5,13 @@ Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include #include +#include +#include +#include #include #include -#include #include #include "builder.h" #include "config.h" @@ -63,12 +66,12 @@ void Config::select_last_profile() { try { - IO::File in((package.get_source()/".profile.cache").str()); + IO::File in((package.get_source()/".profile").str()); string profile; in.getline(profile); set_option("profile", profile); } - catch(const SystemError &) + catch(const IO::FileNotFound &) { } freeze_mtime=true; @@ -88,13 +91,8 @@ void Config::select_profile(const string &profile) if(!package.get_builder().get_dry_run()) { - try - { - IO::File out((package.get_source()/".profile.cache").str().c_str()); - IO::print(out, "%s\n", profile); - } - catch(const SystemError &) - { } + IO::File out((package.get_source()/".profile").str(), IO::M_WRITE); + IO::print(out, "%s\n", profile); } freeze_mtime=true; @@ -154,15 +152,17 @@ void Config::finish() } else { - for(end=dollar+1; (isalnum(opt.value[end]) && opt.value[end]!='_'); ++end); + for(end=dollar+1; (isalnum(opt.value[end]) && opt.value[end]!='_'); ++end) ; var=opt.value.substr(dollar+1, end-dollar-1); } string value; if(is_option(var)) value=get_option(var).value; - else - value=getenv(var.c_str()); + else if(var=="arch") + value=package.get_builder().get_current_arch().get_name(); + else if(const char *ptr=getenv(var.c_str())) + value=ptr; opt.value.replace(dollar, end-dollar, value); @@ -178,21 +178,16 @@ void Config::finish() void Config::save() const { - Path fn=package.get_source()/".options.cache"; + FS::Path fn=package.get_source()/".options.cache"; OptionMap::const_iterator i=options.find("profile"); if(i!=options.end()) fn=package.get_source()/(".options."+i->second.value+".cache"); - try - { - IO::File out(fn.str()); + IO::File out(fn.str(), IO::M_WRITE); - for(i=options.begin(); i!=options.end(); ++i) - IO::print(out, "option \"%s\" \"%s\";\n", i->second.name, i->second.value); - } - catch(const SystemError &) - { } + for(i=options.begin(); i!=options.end(); ++i) + IO::print(out, "option \"%s\" \"%s\";\n", i->second.name, i->second.value); } bool Config::set_option(const string &opt, const string &val) @@ -212,23 +207,20 @@ bool Config::set_option(const string &opt, const string &val) void Config::load() { - Path fn=package.get_source()/".options.cache"; - - OptionMap::iterator i=options.find("profile"); - if(i!=options.end()) - fn=package.get_source()/(".options."+i->second.value+".cache"); + FS::Path fn=package.get_source()/(".options."+get_option("profile").value); try { - IO::File in(fn.str()); + IO::File inf(fn.str()); + IO::Buffered in(inf); - mtime=Time::TimeStamp::from_unixtime(stat(fn).st_mtime); + mtime=Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime); DataFile::Parser parser(in, fn.str()); Loader loader(*this); loader.load(parser); } - catch(const SystemError &) + catch(const IO::FileNotFound &) { } }