]> git.tdb.fi Git - builder.git/commitdiff
Externalize file existence check from Builder::load_build_file
authorMikko Rasa <tdb@tdb.fi>
Sun, 22 Jul 2012 14:12:32 +0000 (17:12 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 22 Jul 2012 14:12:32 +0000 (17:12 +0300)
source/builder.cpp
source/builder.h
source/packagemanager.cpp

index 665983100894acad49db12d8eb478055713c9ad8..d598a9f5cb2caa8bc6e5f8d238bdaad9c0ddd86a 100644 (file)
@@ -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<FS::Path> 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<FS::Path>::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()
index af31f6942c4bf6117eead01cec3943628f60d2f6..b10d4600168b99aa3abdde1fe20b9bfb73e3e964 100644 (file)
@@ -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
index ac1851d73c2ac3573b8e91afa46e4e8d9b68bdcb..4d4228279d62e6b8de5c8571b02dfb69bd60d1b1 100644 (file)
@@ -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;