/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/Support/Unix/Host.inc
Line | Count | Source (jump to first uncovered line) |
1 | | //===- llvm/Support/Unix/Host.inc -------------------------------*- C++ -*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file implements the UNIX Host support. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | //===----------------------------------------------------------------------===// |
15 | | //=== WARNING: Implementation here must contain only generic UNIX code that |
16 | | //=== is guaranteed to work on *all* UNIX variants. |
17 | | //===----------------------------------------------------------------------===// |
18 | | |
19 | | #include "Unix.h" |
20 | | #include "llvm/ADT/StringRef.h" |
21 | | #include "llvm/Config/config.h" |
22 | | #include <cctype> |
23 | | #include <string> |
24 | | #include <sys/utsname.h> |
25 | | |
26 | | using namespace llvm; |
27 | | |
28 | 55.3k | static std::string getOSVersion() { |
29 | 55.3k | struct utsname info; |
30 | 55.3k | |
31 | 55.3k | if (uname(&info)) |
32 | 0 | return ""; |
33 | 55.3k | |
34 | 55.3k | return info.release; |
35 | 55.3k | } |
36 | | |
37 | 55.3k | static std::string updateTripleOSVersion(std::string TargetTripleString) { |
38 | 55.3k | // On darwin, we want to update the version to match that of the target. |
39 | 55.3k | std::string::size_type DarwinDashIdx = TargetTripleString.find("-darwin"); |
40 | 55.3k | if (DarwinDashIdx != std::string::npos55.3k ) { |
41 | 55.3k | TargetTripleString.resize(DarwinDashIdx + strlen("-darwin")); |
42 | 55.3k | TargetTripleString += getOSVersion(); |
43 | 55.3k | return TargetTripleString; |
44 | 55.3k | } |
45 | 0 | std::string::size_type MacOSDashIdx = TargetTripleString.find("-macos"); |
46 | 0 | if (MacOSDashIdx != std::string::npos0 ) { |
47 | 0 | TargetTripleString.resize(MacOSDashIdx); |
48 | 0 | // Reset the OS to darwin as the OS version from `uname` doesn't use the |
49 | 0 | // macOS version scheme. |
50 | 0 | TargetTripleString += "-darwin"; |
51 | 0 | TargetTripleString += getOSVersion(); |
52 | 0 | } |
53 | 0 | return TargetTripleString; |
54 | 55.3k | } |
55 | | |
56 | 51.1k | std::string sys::getDefaultTargetTriple() { |
57 | 51.1k | std::string TargetTripleString = |
58 | 51.1k | updateTripleOSVersion(LLVM_DEFAULT_TARGET_TRIPLE); |
59 | 51.1k | |
60 | 51.1k | // Override the default target with an environment variable named by |
61 | 51.1k | // LLVM_TARGET_TRIPLE_ENV. |
62 | | #if defined(LLVM_TARGET_TRIPLE_ENV) |
63 | | if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV)) |
64 | | TargetTripleString = EnvTriple; |
65 | | #endif |
66 | | |
67 | 51.1k | return Triple::normalize(TargetTripleString); |
68 | 51.1k | } |