]> git.tdb.fi Git - builder.git/commitdiff
If a binary package is not found, briefly describe what was missing
authorMikko Rasa <tdb@tdb.fi>
Thu, 29 Dec 2022 18:30:10 +0000 (20:30 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 30 Dec 2022 08:12:49 +0000 (10:12 +0200)
source/lib/binarypackage.cpp

index adfca1a273bd4ae86b1296e23225918000f0c6cd..a366878be25302ae75d3650e4bac1ca35361a5d3 100644 (file)
@@ -1,3 +1,4 @@
+#include <limits>
 #include <msp/core/algorithm.h>
 #include <msp/io/print.h>
 #include <msp/strings/utils.h>
@@ -71,6 +72,8 @@ void BinaryPackage::do_prepare()
        bases.push_back(FS::Path());
 
        bool system = false;
+       unsigned least_missing = numeric_limits<unsigned>::max();
+       string missing_name;
        for(const FS::Path &b: bases)
        {
                FS::Path prefix = b;
@@ -89,9 +92,12 @@ void BinaryPackage::do_prepare()
                for(FS::Path &p: libpath)
                        p = prefix/p;
 
-               bool all_found = true;
+               unsigned missing_count = 0;
+               string first_missing;
                for(const string &l: export_binfo.libs)
-                       all_found &= (builder.get_vfs().find_library(l, libpath, export_binfo.libmode, system)!=0);
+                       if(!builder.get_vfs().find_library(l, libpath, export_binfo.libmode, system))
+                               if(!missing_count++)
+                                       first_missing = format("library %s", l);
 
                VirtualFileSystem::SearchPath incpath = export_binfo.incpath;
                if(!system && incpath.empty())
@@ -100,21 +106,28 @@ void BinaryPackage::do_prepare()
                        p = prefix/p;
 
                for(const string &h: headers)
-                       all_found &= (builder.get_vfs().find_header(h, 0, incpath, system)!=0);
+                       if(!builder.get_vfs().find_header(h, 0, incpath, system))
+                               if(!missing_count++)
+                                       first_missing = h;
 
-               if(all_found)
+               if(!missing_count)
                {
                        base_path = prefix;
                        builder.get_logger().log("configure", "%s found in %s", name, ((system && use_pkgconfig) ? "system" : base_path.str()));
                        break;
                }
+               else if(missing_count<least_missing)
+               {
+                       least_missing = missing_count;
+                       missing_name = first_missing;
+               }
        }
 
        if(base_path.empty())
        {
-               // TODO report which files were not found
-               builder.get_logger().log("problems", "Cannot locate files for %s", name);
-               problems.push_back("Cannot locate files");
+               string missing_descr = (least_missing>1 ? format("%s and %d other files", missing_name, least_missing-1) : missing_name);
+               builder.get_logger().log("problems", "Cannot locate %s for %s", missing_descr, name);
+               problems.push_back(format("Cannot locate %s", missing_descr));
                return;
        }