| author | |
| committer | |
| log | 8b1900e5df76a126404c6905b9e91136c738da55 |
| tree | 1edd5524c2af6ba134e89f1026a1450507b47f02 |
| parent | ec6f15b0f5e1de517ac130241e3576f1afdd50cf |
| signature |
This reverts commit ec7d7a5b14540ea3b2bab9f11318630338467965, reversing
changes made to 81c441f8855d4c58f0b2ff86d3d007cf0bf395d3.
It looks like this broke colors in Windows Command Prompt (#3147)
and this method of detecting native C ABI isn't working well (#3121).4 files changed, 20 insertions(+), 40 deletions(-)
src/os.cpp+15-15| ... | ... | @@ -1125,27 +1125,29 @@ Error os_get_cwd(Buf *out_cwd) { |
| 1125 | 1125 | #endif |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | #if defined(ZIG_OS_WINDOWS) | |
| 1128 | 1129 | #define is_wprefix(s, prefix) \ |
| 1129 | 1130 | (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0) |
| 1130 | bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) { | |
| 1131 | #if defined(ZIG_OS_WINDOWS) | |
| 1132 | HANDLE handle = (HANDLE)_get_osfhandle(fd); | |
| 1133 | ||
| 1134 | // Cygwin/msys's pty is a pipe. | |
| 1135 | if (handle == INVALID_HANDLE_VALUE || GetFileType(handle) != FILE_TYPE_PIPE) { | |
| 1131 | static bool is_stderr_cyg_pty(void) { | |
| 1132 | HANDLE stderr_handle = GetStdHandle(STD_ERROR_HANDLE); | |
| 1133 | if (stderr_handle == INVALID_HANDLE_VALUE) | |
| 1136 | 1134 | return false; |
| 1137 | } | |
| 1138 | 1135 | |
| 1139 | 1136 | int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH; |
| 1137 | FILE_NAME_INFO *nameinfo; | |
| 1140 | 1138 | WCHAR *p = NULL; |
| 1141 | 1139 | |
| 1142 | FILE_NAME_INFO *nameinfo = (FILE_NAME_INFO *)allocate<char>(size); | |
| 1140 | // Cygwin/msys's pty is a pipe. | |
| 1141 | if (GetFileType(stderr_handle) != FILE_TYPE_PIPE) { | |
| 1142 | return 0; | |
| 1143 | } | |
| 1144 | nameinfo = (FILE_NAME_INFO *)allocate<char>(size); | |
| 1143 | 1145 | if (nameinfo == NULL) { |
| 1144 | return false; | |
| 1146 | return 0; | |
| 1145 | 1147 | } |
| 1146 | 1148 | // Check the name of the pipe: |
| 1147 | 1149 | // '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master' |
| 1148 | if (GetFileInformationByHandleEx(handle, FileNameInfo, nameinfo, size)) { | |
| 1150 | if (GetFileInformationByHandleEx(stderr_handle, FileNameInfo, nameinfo, size)) { | |
| 1149 | 1151 | nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0'; |
| 1150 | 1152 | p = nameinfo->FileName; |
| 1151 | 1153 | if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */ |
| ... | ... | @@ -1178,14 +1180,12 @@ bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) { |
| 1178 | 1180 | } |
| 1179 | 1181 | free(nameinfo); |
| 1180 | 1182 | return (p != NULL); |
| 1181 | #else | |
| 1182 | return false; | |
| 1183 | #endif | |
| 1184 | 1183 | } |
| 1184 | #endif | |
| 1185 | 1185 | |
| 1186 | 1186 | bool os_stderr_tty(void) { |
| 1187 | 1187 | #if defined(ZIG_OS_WINDOWS) |
| 1188 | return _isatty(fileno(stderr)) != 0 || os_is_cygwin_pty(fileno(stderr)); | |
| 1188 | return _isatty(_fileno(stderr)) != 0 || is_stderr_cyg_pty(); | |
| 1189 | 1189 | #elif defined(ZIG_OS_POSIX) |
| 1190 | 1190 | return isatty(STDERR_FILENO) != 0; |
| 1191 | 1191 | #else |
| ... | ... | @@ -1486,7 +1486,7 @@ WORD original_console_attributes = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BL |
| 1486 | 1486 | |
| 1487 | 1487 | void os_stderr_set_color(TermColor color) { |
| 1488 | 1488 | #if defined(ZIG_OS_WINDOWS) |
| 1489 | if (os_stderr_tty()) { | |
| 1489 | if (is_stderr_cyg_pty()) { | |
| 1490 | 1490 | set_color_posix(color); |
| 1491 | 1491 | return; |
| 1492 | 1492 | } |
src/os.hpp-8| ... | ... | @@ -11,7 +11,6 @@ |
| 11 | 11 | #include "list.hpp" |
| 12 | 12 | #include "buffer.hpp" |
| 13 | 13 | #include "error.hpp" |
| 14 | #include "target.hpp" | |
| 15 | 14 | #include "zig_llvm.h" |
| 16 | 15 | #include "windows_sdk.h" |
| 17 | 16 | |
| ... | ... | @@ -89,11 +88,6 @@ struct Termination { |
| 89 | 88 | #define OsFile int |
| 90 | 89 | #endif |
| 91 | 90 | |
| 92 | #if defined(ZIG_OS_WINDOWS) | |
| 93 | #undef fileno | |
| 94 | #define fileno _fileno | |
| 95 | #endif | |
| 96 | ||
| 97 | 91 | struct OsTimeStamp { |
| 98 | 92 | uint64_t sec; |
| 99 | 93 | uint64_t nsec; |
| ... | ... | @@ -158,8 +152,6 @@ Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_include_path(ZigWindowsSDK *sdk, Buf |
| 158 | 152 | Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_lib_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type); |
| 159 | 153 | Error ATTRIBUTE_MUST_USE os_get_win32_kern32_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type); |
| 160 | 154 | |
| 161 | bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd); | |
| 162 | ||
| 163 | 155 | Error ATTRIBUTE_MUST_USE os_self_exe_shared_libs(ZigList<Buf *> &paths); |
| 164 | 156 | |
| 165 | 157 | #endif |
src/target.cpp+1-14| ... | ... | @@ -491,16 +491,6 @@ Error target_parse_glibc_version(ZigGLibCVersion *glibc_ver, const char *text) { |
| 491 | 491 | return ErrorNone; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | static ZigLLVM_EnvironmentType target_get_win32_abi() { | |
| 495 | FILE* files[] = { stdin, stdout, stderr, nullptr }; | |
| 496 | for (int i = 0; files[i] != nullptr; i++) { | |
| 497 | if (os_is_cygwin_pty(fileno(files[i]))) { | |
| 498 | return ZigLLVM_GNU; | |
| 499 | } | |
| 500 | } | |
| 501 | return ZigLLVM_MSVC; | |
| 502 | } | |
| 503 | ||
| 504 | 494 | void get_native_target(ZigTarget *target) { |
| 505 | 495 | // first zero initialize |
| 506 | 496 | *target = {}; |
| ... | ... | @@ -515,9 +505,6 @@ void get_native_target(ZigTarget *target) { |
| 515 | 505 | &target->abi, |
| 516 | 506 | &oformat); |
| 517 | 507 | target->os = get_zig_os_type(os_type); |
| 518 | if (target->os == OsWindows) { | |
| 519 | target->abi = target_get_win32_abi(); | |
| 520 | } | |
| 521 | 508 | target->is_native = true; |
| 522 | 509 | if (target->abi == ZigLLVM_UnknownEnvironment) { |
| 523 | 510 | target->abi = target_default_abi(target->arch, target->os); |
| ... | ... | @@ -1614,7 +1601,7 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { |
| 1614 | 1601 | return ZigLLVM_GNU; |
| 1615 | 1602 | case OsUefi: |
| 1616 | 1603 | case OsWindows: |
| 1617 | return ZigLLVM_MSVC; | |
| 1604 | return ZigLLVM_MSVC; | |
| 1618 | 1605 | case OsLinux: |
| 1619 | 1606 | case OsWASI: |
| 1620 | 1607 | return ZigLLVM_Musl; |
std/os/windows.zig+4-3| ... | ... | @@ -65,7 +65,7 @@ pub const CreateFileError = error{ |
| 65 | 65 | InvalidUtf8, |
| 66 | 66 | |
| 67 | 67 | /// On Windows, file paths cannot contain these characters: |
| 68 | /// '*', '?', '"', '<', '>', '|', and '/' (when the ABI is not GNU) | |
| 68 | /// '/', '*', '?', '"', '<', '>', '|' | |
| 69 | 69 | BadPathName, |
| 70 | 70 | |
| 71 | 71 | Unexpected, |
| ... | ... | @@ -836,10 +836,11 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) |
| 836 | 836 | // > converting the name to an NT-style name, except when using the "\\?\" |
| 837 | 837 | // > prefix as detailed in the following sections. |
| 838 | 838 | // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation |
| 839 | // Because we want the larger maximum path length for absolute paths, we | |
| 840 | // disallow forward slashes in zig std lib file functions on Windows. | |
| 839 | 841 | for (s) |byte| { |
| 840 | 842 | switch (byte) { |
| 841 | '*', '?', '"', '<', '>', '|' => return error.BadPathName, | |
| 842 | '/' => if (builtin.abi == .msvc) return error.BadPathName, | |
| 843 | '/', '*', '?', '"', '<', '>', '|' => return error.BadPathName, | |
| 843 | 844 | else => {}, |
| 844 | 845 | } |
| 845 | 846 | } |