diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-08-24 11:37:22 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-08-24 11:37:22 +0200 |
commit | beb827d154cdc96dfe3042034bb301f6134f4259 (patch) | |
tree | d65c078506a5dd551ce557da13121caec33dd91a | |
parent | dfb4e3b363ec39c0b1744d9edbf7b2ed89b04ad7 (diff) |
Add target_triplet::representation() in addition to string()
Also stop stripping `none-` prefix from the system component.
-rw-r--r-- | libbutl/target-triplet.cxx | 29 | ||||
-rw-r--r-- | libbutl/target-triplet.mxx | 16 | ||||
-rw-r--r-- | tests/target-triplet/driver.cxx | 18 |
3 files changed, 46 insertions, 17 deletions
diff --git a/libbutl/target-triplet.cxx b/libbutl/target-triplet.cxx index c2535b1..f59875f 100644 --- a/libbutl/target-triplet.cxx +++ b/libbutl/target-triplet.cxx @@ -71,11 +71,6 @@ namespace butl if (l != p) bad ("too many components"); - - // Handle the none-* case here. - // - if (s.compare (l + 1, 5, "none-") == 0) - l += 5; } else { @@ -170,4 +165,28 @@ namespace butl return r; } + + std::string target_triplet:: + representation () const + { + std::string r (cpu); + + { + if (!r.empty ()) r += '-'; + r += vendor.empty () ? "unknown" : vendor.c_str (); + } + + if (!system.empty ()) + { + if (!r.empty ()) r += '-'; + r += system; + } + + if (!version.empty ()) + { + r += version; + } + + return r; + } } diff --git a/libbutl/target-triplet.mxx b/libbutl/target-triplet.mxx index e68bc68..41c0cb5 100644 --- a/libbutl/target-triplet.mxx +++ b/libbutl/target-triplet.mxx @@ -61,8 +61,10 @@ LIBBUTL_MODEXPORT namespace butl // trailing version, again, to make SYSTEM easier to compare to. For example, // *-darwin14.5.0 becomes 'darwin' and '14.5.0'. // - // Again, to make things more regular, if the first component in SYSTEM is - // none, then it is removed (so *-none-eabi becomes just 'eabi'). + // Note also that sometimes the first component in SYSTEM can be 'none' (to + // indicate the absence of an operating system) which is ambigous with the + // vendor (for example, arm-none-eabi). We currently don't try to deal with + // that (that is, you will need to specify arm-unknown-none-eabi). // // Values for two-component systems (e.g., linux-gnu) that don't specify // VENDOR explicitly are inherently ambiguous: is 'linux' VENDOR or part of @@ -121,12 +123,20 @@ LIBBUTL_MODEXPORT namespace butl std::string version; std::string class_; - // Assemble and returning the canonical (i.e., the one we round-trip) + // Assemble and returning the canonical (i.e., without unknown vendor) // target triplet string. // + // Note: not necessarily round-tripp'able, see representation(). + // std::string string () const; + // Return a round-tripp'able target triplet string that always contains + // the vendor. + // + std::string + representation () const; + bool empty () const {return cpu.empty ();} diff --git a/tests/target-triplet/driver.cxx b/tests/target-triplet/driver.cxx index 0bb305e..36131a6 100644 --- a/tests/target-triplet/driver.cxx +++ b/tests/target-triplet/driver.cxx @@ -61,6 +61,14 @@ main () "arm-eabi", "arm", "", "eabi", "")); + assert (test ("arm-unknown-none-eabi", + "arm-none-eabi", + "arm", "", "none-eabi", "")); + + assert (test ("arm-none", + "arm-none", + "arm", "", "none", "")); + assert (test ("arm-none-linux-gnueabi", "arm-linux-gnueabi", "arm", "", "linux-gnueabi", "", "linux")); @@ -93,15 +101,7 @@ main () "x86_64-netbsd", "x86_64", "", "netbsd", "", "bsd")); - // Removal of none-. - // - assert (test ("arm-none", - "arm-none", - "arm", "", "none", "")); - - assert (test ("arm-unknown-none-eabi", - "arm-eabi", - "arm", "", "eabi", "")); + // Version extraction. // |