diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-04-28 10:35:33 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-04-28 10:35:33 +0200 |
commit | 0ea4d93ee1d5e984722532da37966ebca7a0482b (patch) | |
tree | 168c197ffe876ab24652c38f19351239252c260d | |
parent | 6fc0a1001eeb2e54c070f5da457f5ec8919257a6 (diff) |
Automatically cleanup previous versioned libraries
-rw-r--r-- | build2/cc/link | 6 | ||||
-rw-r--r-- | build2/cc/link.cxx | 57 |
2 files changed, 59 insertions, 4 deletions
diff --git a/build2/cc/link b/build2/cc/link index 9e9e7cf..0dace7c 100644 --- a/build2/cc/link +++ b/build2/cc/link @@ -60,6 +60,12 @@ namespace build2 inline const path& effect_soname () const {return soname.empty () ? real : soname;} + + // Cleanup pattern used to remove previous versions. If empty, no + // cleanup is performed. The above (current) names are automatically + // filtered out. + // + const path clean; }; libs_paths diff --git a/build2/cc/link.cxx b/build2/cc/link.cxx index b15f340..e25ea04 100644 --- a/build2/cc/link.cxx +++ b/build2/cc/link.cxx @@ -230,19 +230,31 @@ namespace build2 // We start with the basic path. // path b (ls.dir); + path cp; // Clean pattern. { if (pfx == nullptr) + { b /= ls.name; + } else { b /= pfx; b += ls.name; } + cp = b; + cp += "?*"; // Don't match empty (like the libfoo.so symlink). + if (sfx != nullptr) + { b += sfx; + cp += sfx; + } } + append_ext (cp); + cp += "*"; // For .d, .pdb, etc. A bit dangerous though. + // On Windows the real path is to libs{} and the link path is to the // import library. // @@ -271,7 +283,7 @@ namespace build2 const path& re (ls.derive_path (move (b))); - return libs_paths {move (lk), move (so), move (in), re}; + return libs_paths {move (lk), move (so), move (in), re, move (cp)}; } recipe link:: @@ -1546,6 +1558,46 @@ namespace build2 args.push_back (nullptr); + // Cleanup old (versioned) libraries. + // + if (lt == otype::s) + { + const libs_paths& paths (t.data<libs_paths> ()); + const path& p (paths.clean); + + if (!p.empty ()) + { + if (verb >= 3) + text << "rm " << p; + + auto rm = [&paths] (path&& m, const string&, bool interm) + { + if (!interm) + { + // Filter out paths that have one of the current paths as a + // prefix. + // + auto test = [&m] (const path& p) + { + const string& s (p.string ()); + return s.empty () || m.string ().compare (0, s.size (), s) != 0; + }; + + if (test (paths.real) && + test (paths.interm) && + test (paths.soname) && + test (paths.link)) + { + try_rmfile (m, true); // Ignore errors. + } + } + return true; + }; + + path_search (p, rm); + } + } + if (verb >= 2) print_process (args); else if (verb) @@ -1657,9 +1709,6 @@ namespace build2 // auto ln = [] (const path& f, const path& l) { - // Note that we don't bother making the paths relative since they - // will only be seen at verbosity level 3. - // if (verb >= 3) text << "ln -sf " << f << ' ' << l; |