cmSiteNameCommand
| 12 | |
| 13 | // cmSiteNameCommand |
| 14 | bool cmSiteNameCommand(std::vector<std::string> const& args, |
| 15 | cmExecutionStatus& status) |
| 16 | { |
| 17 | if (args.size() != 1) { |
| 18 | status.SetError("called with incorrect number of arguments"); |
| 19 | return false; |
| 20 | } |
| 21 | std::vector<std::string> paths; |
| 22 | paths.emplace_back("/usr/bsd"); |
| 23 | paths.emplace_back("/usr/sbin"); |
| 24 | paths.emplace_back("/usr/bin"); |
| 25 | paths.emplace_back("/bin"); |
| 26 | paths.emplace_back("/sbin"); |
| 27 | paths.emplace_back("/usr/local/bin"); |
| 28 | |
| 29 | cmValue cacheValue = status.GetMakefile().GetDefinition(args[0]); |
| 30 | if (cacheValue) { |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | cmValue temp = status.GetMakefile().GetDefinition("HOSTNAME"); |
| 35 | std::string hostname_cmd; |
| 36 | if (temp) { |
| 37 | hostname_cmd = *temp; |
| 38 | } else { |
| 39 | hostname_cmd = cmSystemTools::FindProgram("hostname", paths); |
| 40 | } |
| 41 | |
| 42 | std::string siteName = "unknown"; |
| 43 | #if defined(_WIN32) && !defined(__CYGWIN__) |
| 44 | std::string host; |
| 45 | if (cmSystemTools::ReadRegistryValue( |
| 46 | "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\" |
| 47 | "Control\\ComputerName\\ComputerName;ComputerName", |
| 48 | host)) { |
| 49 | siteName = host; |
| 50 | } |
| 51 | #else |
| 52 | // try to find the hostname for this computer |
| 53 | if (!cmIsOff(hostname_cmd)) { |
| 54 | std::string host; |
| 55 | cmSystemTools::RunSingleCommand(hostname_cmd, &host, nullptr, nullptr, |
| 56 | nullptr, cmSystemTools::OUTPUT_NONE); |
| 57 | |
| 58 | // got the hostname |
| 59 | if (!host.empty()) { |
| 60 | // remove any white space from the host name |
| 61 | std::string hostRegExp = "[ \t\n\r]*([^\t\n\r ]*)[ \t\n\r]*"; |
| 62 | cmsys::RegularExpression hostReg(hostRegExp.c_str()); |
| 63 | if (hostReg.find(host.c_str())) { |
| 64 | // strip whitespace |
| 65 | host = hostReg.match(1); |
| 66 | } |
| 67 | |
| 68 | if (!host.empty()) { |
| 69 | siteName = host; |
| 70 | } |
| 71 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…