From b19fe69cdd0d32dc45f166447170bc5c9c54ac5a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 24 Feb 2020 14:14:45 +0200 Subject: Extract version for lld-link --- libbuild2/bin/guess.cxx | 18 ++++++++++++++---- libbuild2/bin/guess.hxx | 5 +++++ libbuild2/bin/init.cxx | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 8 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/bin/guess.cxx b/libbuild2/bin/guess.cxx index 3329cc5..63f5db5 100644 --- a/libbuild2/bin/guess.cxx +++ b/libbuild2/bin/guess.cxx @@ -16,12 +16,16 @@ namespace build2 string id; string signature; string checksum; - semantic_version version; + optional version; guess_result () = default; + guess_result (string&& i, string&& s, semantic_version&& v) : id (move (i)), signature (move (s)), version (move (v)) {} + guess_result (string&& i, string&& s, optional&& v) + : id (move (i)), signature (move (s)), version (move (v)) {} + bool empty () const {return id.empty ();} }; @@ -288,7 +292,7 @@ namespace build2 move (arr.id), move (arr.signature), move (arr.checksum), - move (arr.version), + move (*arr.version), move (rlp), move (rlr.id), @@ -325,7 +329,7 @@ namespace build2 auto f = [&ld] (string& l, bool) -> guess_result { string id; - semantic_version ver; + optional ver; // Microsoft link.exe output starts with "Microsoft (R) ". // @@ -337,6 +341,8 @@ namespace build2 // else if (l.compare (0, 4, "LLD ") == 0) { + ver = parse_version (l, 4); + // The only way to distinguish between various LLD drivers is via // their name. Handle potential prefixes (say a target) and // suffixes (say a version). @@ -446,7 +452,11 @@ namespace build2 fail << "unable to guess " << ld << " signature"; return ld_info { - move (pp), move (r.id), move (r.signature), move (r.checksum)}; + move (pp), + move (r.id), + move (r.signature), + move (r.checksum), + move (r.version)}; } rc_info diff --git a/libbuild2/bin/guess.hxx b/libbuild2/bin/guess.hxx index 255932b..27bb5ed 100644 --- a/libbuild2/bin/guess.hxx +++ b/libbuild2/bin/guess.hxx @@ -72,12 +72,17 @@ namespace build2 // toolchain-specific manner (usually the output of --version/-version/-v) // and is not bulletproof. // + // Note that for now the version is extracted only for some linkers. Once + // it's done for all of them, we should drop optional. + // struct ld_info { process_path path; string id; string signature; string checksum; + + optional version; }; ld_info diff --git a/libbuild2/bin/init.cxx b/libbuild2/bin/init.cxx index 4565eb8..f6faab5 100644 --- a/libbuild2/bin/init.cxx +++ b/libbuild2/bin/init.cxx @@ -781,17 +781,46 @@ namespace build2 // if (verb >= (p.second ? 2 : 3)) { - text << "bin.ld " << project (rs) << '@' << rs << '\n' + diag_record dr (text); + + { + dr << "bin.ld " << project (rs) << '@' << rs << '\n' << " ld " << ldi.path << '\n' - << " id " << ldi.id << '\n' - << " signature " << ldi.signature << '\n' - << " checksum " << ldi.checksum; + << " id " << ldi.id << '\n'; + } + + if (ldi.version) + { + dr << " version " << ldi.version->string () << '\n' + << " major " << ldi.version->major << '\n' + << " minor " << ldi.version->minor << '\n' + << " patch " << ldi.version->patch << '\n'; + } + + if (ldi.version && !ldi.version->build.empty ()) + { + dr << " build " << ldi.version->build << '\n'; + } + + dr << " signature " << ldi.signature << '\n' + << " checksum " << ldi.checksum; } rs.assign ("bin.ld.path") = move (ldi.path); rs.assign ("bin.ld.id") = move (ldi.id); rs.assign ("bin.ld.signature") = move (ldi.signature); rs.assign ("bin.ld.checksum") = move (ldi.checksum); + + if (ldi.version) + { + semantic_version& v (*ldi.version); + + rs.assign ("bin.ld.version") = v.string (); + rs.assign ("bin.ld.version.major") = v.major; + rs.assign ("bin.ld.version.minor") = v.minor; + rs.assign ("bin.ld.version.patch") = v.patch; + rs.assign ("bin.ld.version.build") = move (v.build); + } } return true; -- cgit v1.1