diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-03-17 09:00:28 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-03-17 09:00:28 +0200 |
commit | 7b56e3f90be0efece268e85832dd9828a7490b13 (patch) | |
tree | 421e41248be48276f2bb89a7f34f5db16ab6445d | |
parent | 639c02bd1dc9892fecadb353b23d35028668183d (diff) |
Diagnose invalid paths in -print-search-dirs output
For example, some mis-configured MinGW GCC builds include /mingw/lib.
-rw-r--r-- | libbuild2/cc/gcc.cxx | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/libbuild2/cc/gcc.cxx b/libbuild2/cc/gcc.cxx index 30f2092..3376c16 100644 --- a/libbuild2/cc/gcc.cxx +++ b/libbuild2/cc/gcc.cxx @@ -153,7 +153,8 @@ namespace build2 // // For now we ignore framework paths and to filter them out we will // only consider valid paths to existing directories, skipping those - // which we fail to normalize or stat. + // which we fail to normalize or stat. @@ Maybe this is a bit too + // loose, especially compared to gcc_library_search_dirs()? // string s; for (bool found (false); getline (is, s); ) @@ -165,18 +166,23 @@ namespace build2 if (s[0] != ' ') break; + dir_path d; try { - dir_path d (s, 1, s.size () - 1); + d = dir_path (s, 1, s.size () - 1); - if (d.absolute () && exists (d, true) && - find (r.begin (), r.end (), d.normalize ()) == r.end ()) - r.emplace_back (move (d)); + if (d.relative () || !exists (d, true)) + continue; + + d.normalize (); } catch (const invalid_path&) { - // Skip this path. + continue; } + + if (find (r.begin (), r.end (), d) == r.end ()) + r.emplace_back (move (d)); } } @@ -334,9 +340,23 @@ namespace build2 // for (string::size_type b (0);; e = l.find (d, (b = e + 1))) { - dir_path d (l, b, (e != string::npos ? e - b : e)); + dir_path d; + try + { + d = dir_path (l, b, (e != string::npos ? e - b : e)); + + if (d.relative ()) + throw invalid_path (move (d).string ()); + + d.normalize (); + } + catch (const invalid_path& e) + { + fail << "invalid directory '" << e.path << "'" << " in " + << args[0] << " -print-search-dirs output"; + } - if (find (r.begin (), r.end (), d.normalize ()) == r.end ()) + if (find (r.begin (), r.end (), d) == r.end ()) r.emplace_back (move (d)); if (e == string::npos) |