From 23477a725988c3c896c2853c2417054c1310dabc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 22 Jul 2012 17:12:32 +0300 Subject: [PATCH] Externalize file existence check from Builder::load_build_file --- source/builder.cpp | 22 ++++++++++++---------- source/builder.h | 2 +- source/packagemanager.cpp | 3 ++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/source/builder.cpp b/source/builder.cpp index 6659831..d598a9f 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -165,8 +165,12 @@ Builder::Builder(int argc, char **argv): else current_arch = new Architecture(*this, arch); - load_build_file((FS::get_sys_data_dir(argv[0], "builder")/"builderrc").str()); - load_build_file((FS::get_user_data_dir("builder")/"rc").str()); + list start_files; + start_files.push_back(FS::get_sys_data_dir(argv[0], "builder")/"builderrc"); + start_files.push_back(FS::get_user_data_dir("builder")/"rc"); + for(list::const_iterator i=start_files.begin(); i!=start_files.end(); ++i) + if(FS::exists(*i)) + load_build_file(*i); if(prfx.empty()) { @@ -207,7 +211,8 @@ Builder::~Builder() int Builder::main() { - if(load_build_file(cwd/build_file)) + FS::Path main_file = cwd/build_file; + if(!FS::exists(main_file)) { if(help) { @@ -216,11 +221,13 @@ int Builder::main() } else { - IO::print(IO::cerr, "No build info here.\n"); + IO::print(IO::cerr, "The file %s does not exist.\n", main_file); return 1; } } + load_build_file(main_file); + if(help) { usage(0, "builder", false); @@ -345,11 +352,8 @@ void Builder::usage(const char *reason, const char *argv0, bool brief) } } -int Builder::load_build_file(const FS::Path &fn) +void Builder::load_build_file(const FS::Path &fn) { - if(!FS::exists(fn)) - return -1; - IO::BufferedFile in(fn.str()); logger.log("files", format("Reading %s", fn)); @@ -357,8 +361,6 @@ int Builder::load_build_file(const FS::Path &fn) DataFile::Parser parser(in, fn.str()); Loader loader(*this); loader.load(parser); - - return 0; } bool Builder::prepare_build() diff --git a/source/builder.h b/source/builder.h index af31f69..b10d460 100644 --- a/source/builder.h +++ b/source/builder.h @@ -124,7 +124,7 @@ public: /** Loads a build file. Returns 0 on success or -1 if the file could not be opened. */ - int load_build_file(const Msp::FS::Path &); + void load_build_file(const Msp::FS::Path &); private: /** Prepares packages and targets for building. Returns true if everything diff --git a/source/packagemanager.cpp b/source/packagemanager.cpp index ac1851d..4d42282 100644 --- a/source/packagemanager.cpp +++ b/source/packagemanager.cpp @@ -61,8 +61,9 @@ Package *PackageManager::find_package(const string &name) if(!no_externals) { FS::Path path = get_package_location(name); - if(!path.empty() && !builder.load_build_file(path/"Build")) + if(!path.empty()) { + builder.load_build_file(path/"Build"); i = packages.find(name); if(i!=packages.end()) return i->second; -- 2.43.0