From: Mikko Rasa Date: Tue, 6 Sep 2011 11:47:24 +0000 (+0000) Subject: Further changes for library compatibility X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=0458300fda4f345f865a7f3ee4fc0f2020a91983 Further changes for library compatibility --- diff --git a/Build b/Build index a446a23..ac0982a 100644 --- a/Build +++ b/Build @@ -7,7 +7,6 @@ package "builder" require "mspcore"; require "mspdatafile"; - require "mspfs"; require "sigc++-2.0"; program "builder" diff --git a/source/architecture.cpp b/source/architecture.cpp index 9c96e8a..fbb2461 100644 --- a/source/architecture.cpp +++ b/source/architecture.cpp @@ -9,7 +9,7 @@ Distributed under the LGPL #ifndef WIN32 #include #endif -#include +#include #include #include "architecture.h" #include "builder.h" @@ -152,7 +152,7 @@ std::string Architecture::get_tool(const string &t) const return native_arch.get_tool(t); } else - throw KeyError("Unknown tool", t); + throw invalid_argument("Unknown tool"); } bool Architecture::match_name(const string &pattern) const @@ -189,7 +189,7 @@ void Architecture::parse_specification(const string &spec) if(part==types[j]) { if(!type.empty() && part!=type) - throw InvalidParameterValue("Conflicting type specification"); + throw invalid_argument("Conflicting type specification"); type = part; ok = true; } @@ -200,7 +200,7 @@ void Architecture::parse_specification(const string &spec) if(type.empty()) type = cpus[j+1]; else if(cpus[j+1]!=type) - throw InvalidParameterValue("Conflicting CPU specification"); + throw invalid_argument("Conflicting CPU specification"); cpu = part; ok = true; } @@ -219,7 +219,7 @@ void Architecture::parse_specification(const string &spec) } if(!ok) - throw InvalidParameterValue("Unrecognized part in arch specification: "+*i); + throw invalid_argument("Unrecognized part in arch specification: "+*i); } } diff --git a/source/binary.cpp b/source/binary.cpp index 636def9..59dc1f9 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -6,7 +6,7 @@ Distributed under the LGPL */ #include -#include +#include #include "binary.h" #include "builder.h" #include "component.h" diff --git a/source/builder.cpp b/source/builder.cpp index 3c58f02..c8091ff 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -7,17 +7,15 @@ Distributed under the LGPL #include #include -#include #include #include #include #include #include #include -#include #include #include -#include +#include #include #include #include @@ -114,7 +112,7 @@ Builder::Builder(int argc, char **argv): else if(analyze_mode=="rdeps") analyzer->set_mode(Analyzer::RDEPS); else - throw UsageError("Invalid analyze mode"); + throw usage_error("Invalid analyze mode"); analyzer->set_max_depth(max_depth); analyzer->set_full_paths(full_paths); @@ -337,7 +335,7 @@ string Builder::run_pkgconfig(const string &pkg, const string &what) int status; string res = run_command(argv, &status); if(status) - throw Exception(format("pkg-config for package %s failed", pkg)); + throw runtime_error(format("pkg-config for package %s failed", pkg)); return res; } diff --git a/source/component.cpp b/source/component.cpp index e48e4f5..d1ab858 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -6,7 +6,6 @@ Distributed under the LGPL */ #include -#include #include #include #include diff --git a/source/config.cpp b/source/config.cpp index 0676ded..87573e2 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -5,10 +5,9 @@ Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include +#include #include #include -#include #include #include #include @@ -31,11 +30,7 @@ void Config::add_option(const string &n, const string &v, const string &d) const Config::Option &Config::get_option(const string &name) const { - OptionMap::const_iterator i = options.find(name); - if(i==options.end()) - throw KeyError("Unknown option", name); - - return i->second; + return get_item(options, name); } bool Config::is_option(const string &name) const @@ -137,7 +132,7 @@ void Config::load() { IO::BufferedFile in(fn.str()); - mtime = Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime); + mtime = FS::stat(fn).get_modify_time(); DataFile::Parser parser(in, fn.str()); Loader loader(*this); diff --git a/source/copy.cpp b/source/copy.cpp index 581221a..11d72c6 100644 --- a/source/copy.cpp +++ b/source/copy.cpp @@ -6,6 +6,7 @@ Distributed under the LGPL */ #include +#include #include #include #include @@ -49,7 +50,7 @@ void Copy::Worker::main() { unlink(copy.dest); } - catch(const Exception &e) + catch(const exception &e) { IO::print(IO::cerr, "%s\n", e.what()); done = error = true; @@ -70,7 +71,7 @@ void Copy::Worker::main() out.write(buf, len); } } - catch(const Exception &e) + catch(const exception &e) { IO::print(IO::cerr, "%s\n", e.what()); done = error = true; @@ -78,8 +79,9 @@ void Copy::Worker::main() } // Preserve file permissions - struct stat st = FS::stat(copy.src); - chmod(copy.dest.str().c_str(), st.st_mode&0777); + struct stat st; + if(stat(copy.src.str().c_str(), &st)==0) + chmod(copy.dest.str().c_str(), st.st_mode&0777); done = true; } diff --git a/source/dependencycache.cpp b/source/dependencycache.cpp index 7505e98..f691d54 100644 --- a/source/dependencycache.cpp +++ b/source/dependencycache.cpp @@ -5,8 +5,8 @@ Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include #include -#include #include #include #include @@ -30,11 +30,7 @@ void DependencyCache::set_deps(const string &tgt, const StringList &d) const StringList &DependencyCache::get_deps(const string &tgt) const { - DepsMap::const_iterator i = deps.find(tgt); - if(i==deps.end()) - throw KeyError("Unknown dependencies", tgt); - - return i->second; + return get_item(deps, tgt); } void DependencyCache::save() const @@ -68,7 +64,7 @@ void DependencyCache::load() deps[parts[0]] = StringList(parts.begin()+1, parts.end()); } - mtime = Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime); + mtime = FS::stat(fn).get_modify_time(); } catch(const IO::file_not_found &) { } diff --git a/source/feature.cpp b/source/feature.cpp index 7c19af5..54ed514 100644 --- a/source/feature.cpp +++ b/source/feature.cpp @@ -8,7 +8,7 @@ Distributed under the LGPL #include "feature.h" Feature::Loader::Loader(Feature &f): - Msp::DataFile::BasicLoader(f) + Msp::DataFile::ObjectLoader(f) { add("description", &Feature::descr); add("default", &Feature::def_value); diff --git a/source/feature.h b/source/feature.h index 1d4bf51..e5176c4 100644 --- a/source/feature.h +++ b/source/feature.h @@ -8,11 +8,11 @@ Distributed under the LGPL #ifndef FEATURE_H_ #define FEATURE_H_ -#include +#include struct Feature { - class Loader: public Msp::DataFile::BasicLoader + class Loader: public Msp::DataFile::ObjectLoader { public: Loader(Feature &); diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 061a3ae..da5cd7a 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -22,11 +22,10 @@ FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a): { builder.add_target(this); - struct stat st; - if(!FS::lstat(path, st)) + if(FS::Stat st = FS::lstat(path)) { - mtime = Time::TimeStamp::from_unixtime(st.st_mtime); - size = st.st_size; + mtime = st.get_modify_time(); + size = st.get_size(); } } diff --git a/source/install.cpp b/source/install.cpp index 0578ba7..ecf50ee 100644 --- a/source/install.cpp +++ b/source/install.cpp @@ -51,7 +51,7 @@ Action *Install::create_action() FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string &loc) { if(!tgt.get_package()) - throw InvalidParameterValue("Can't install package-less targets"); + throw invalid_argument("Can't install package-less targets"); FS::Path base = tgt.get_package()->get_builder().get_prefix(); string tgtname = FS::basename(tgt.get_path()); @@ -62,7 +62,7 @@ FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string else if(const Header *hdr = dynamic_cast(&tgt)) { if(hdr->get_component()->get_type()!=Component::HEADERS) - throw Exception("Header install from non-header component?"); + throw logic_error("Header install from non-header component?"); mid = "include/"+hdr->get_component()->get_name(); } else if(dynamic_cast(&tgt)) @@ -87,7 +87,7 @@ FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string mid = "share/"+tgt.get_package()->get_name(); if(mid.empty()) - throw InvalidParameterValue("Don't know where to install "+tgtname); + throw invalid_argument("Don't know where to install "+tgtname); return (base/mid/tgtname).str(); } diff --git a/source/sharedlibrary.cpp b/source/sharedlibrary.cpp index a322517..868e822 100644 --- a/source/sharedlibrary.cpp +++ b/source/sharedlibrary.cpp @@ -5,7 +5,7 @@ Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include +#include #include "component.h" #include "sharedlibrary.h" #include "sourcepackage.h" diff --git a/source/sourcefile.cpp b/source/sourcefile.cpp index 0fc989d..bc2d993 100644 --- a/source/sourcefile.cpp +++ b/source/sourcefile.cpp @@ -5,8 +5,8 @@ Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include #include -#include #include #include #include "builder.h" @@ -46,7 +46,7 @@ void SourceFile::find_depends() includes = deps_cache.get_deps(relname); deps_found = true; } - catch(const KeyError &) + catch(const key_error &) { } } diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index a466089..7160013 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -76,7 +76,7 @@ LibMode SourcePackage::get_library_mode() const else if(mode=="none") return DYNAMIC; else - throw Exception("Unknown library mode"); + throw runtime_error("unknown library mode"); } string SourcePackage::expand_string(const string &str) const @@ -87,7 +87,7 @@ string SourcePackage::expand_string(const string &str) const while((dollar = result.find('$'))!=string::npos) { if(n>1000) - throw Exception("Too much variable expansions"); + throw bad_expansion("nested too deep"); string::size_type end; string var; @@ -95,7 +95,7 @@ string SourcePackage::expand_string(const string &str) const { end = result.find('}', dollar+2); if(end==string::npos) - throw Exception("Unterminated variable reference"); + throw bad_expansion("unterminated variable reference"); var = result.substr(dollar+2, end-dollar-2); ++end; } diff --git a/source/sourcepackage.h b/source/sourcepackage.h index 5218592..6793d25 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -8,6 +8,7 @@ Distributed under the LGPL #ifndef SOURCEPACKAGE_H_ #define SOURCEPACKAGE_H_ +#include #include #include "buildinfo.h" #include "component.h" @@ -19,6 +20,13 @@ Distributed under the LGPL class Builder; +class bad_expansion: public std::runtime_error +{ +public: + bad_expansion(const std::string &w): std::runtime_error(w) { } + virtual ~bad_expansion() throw() { } +}; + /** A package that can be built by Builder. */ diff --git a/source/tar.cpp b/source/tar.cpp index bfb4f5f..1869865 100644 --- a/source/tar.cpp +++ b/source/tar.cpp @@ -64,12 +64,12 @@ void Tar::Worker::main() memcpy(buf, rel_path.data(), rel_path.size()); - struct stat st = FS::stat(ft->get_path()); - store_number(buf+100, st.st_mode, 7); - store_number(buf+108, st.st_uid, 7); - store_number(buf+116, st.st_gid, 7); - store_number(buf+124, st.st_size, 11); - store_number(buf+136, st.st_mtime, 11); + FS::Stat st = FS::stat(ft->get_path()); + store_number(buf+100, 0666, 7); + store_number(buf+108, 0, 7); + store_number(buf+116, 0, 7); + store_number(buf+124, st.get_size(), 11); + store_number(buf+136, st.get_modify_time().to_unixtime(), 11); buf[156] = '0'; memset(buf+148, ' ', 8); @@ -81,7 +81,7 @@ void Tar::Worker::main() out.write(buf, 512); IO::File in(ft->get_path().str()); - for(int j=0; j #include #include "filetarget.h" #include "sourcepackage.h" @@ -21,7 +22,7 @@ Unlink::Unlink(Builder &b, const FileTarget &t): { unlink(t.get_path()); } - catch(const Msp::SystemError &) + catch(const Msp::system_error &) { } }