Skip to content

Reapply "[Support] Remove terminfo dependency (#92865)" #93889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clang/cmake/caches/Fuchsia-stage2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ set(LLVM_ENABLE_LLD ON CACHE BOOL "")
set(LLVM_ENABLE_LTO ON CACHE BOOL "")
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
Expand Down
7 changes: 0 additions & 7 deletions clang/cmake/caches/Fuchsia.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
Expand All @@ -34,7 +33,6 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
LibXml2_ROOT
LLVM_ENABLE_CURL
LLVM_ENABLE_HTTPLIB
LLVM_ENABLE_TERMINFO
LLVM_ENABLE_LIBEDIT
CURL_ROOT
OpenSSL_ROOT
Expand All @@ -47,11 +45,6 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
CURSES_LIBRARIES
PANEL_LIBRARIES

# Deprecated
Terminfo_ROOT

Terminfo_LIBRARIES

# Deprecated
LibEdit_ROOT

Expand Down
4 changes: 1 addition & 3 deletions clang/cmake/caches/VectorEngine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
# ninja
#

# Disable TERMINFO, ZLIB, and ZSTD for VE since there is no pre-compiled
# libraries.
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
# Disable ZLIB, and ZSTD for VE since there is no pre-compiled libraries.
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
set(LLVM_ENABLE_ZSTD OFF CACHE BOOL "")

Expand Down
2 changes: 1 addition & 1 deletion clang/utils/analyzer/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def is_cmake_needed():
"cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "
"-DCMAKE_INSTALL_PREFIX=/analyzer -DLLVM_TARGETS_TO_BUILD=X86 "
'-DLLVM_ENABLE_PROJECTS="clang;openmp" -DLLVM_BUILD_RUNTIME=OFF '
"-DLLVM_ENABLE_TERMINFO=OFF -DCLANG_ENABLE_ARCMT=OFF "
"-DCLANG_ENABLE_ARCMT=OFF "
"-DCLANG_ENABLE_STATIC_ANALYZER=ON"
)

Expand Down
15 changes: 0 additions & 15 deletions compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,6 @@ check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO)

# Look for terminfo library, used in unittests that depend on LLVMSupport.
if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
set(MAYBE_REQUIRED REQUIRED)
else()
set(MAYBE_REQUIRED)
endif()
if(LLVM_ENABLE_TERMINFO)
find_library(COMPILER_RT_TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw ${MAYBE_REQUIRED})
endif()
if(COMPILER_RT_TERMINFO_LIB)
set(LLVM_ENABLE_TERMINFO 1)
else()
set(LLVM_ENABLE_TERMINFO 0)
endif()

if (ANDROID AND COMPILER_RT_HAS_LIBDL)
# Android's libstdc++ has a dependency on libdl.
list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ if [[ ! -f ${LLVM_BUILD}/build.ninja ]]; then
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_ENABLE_ZLIB=ON \
-DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_THREADS=OFF \
$LLVM_SRC
fi
Expand Down
5 changes: 0 additions & 5 deletions compiler-rt/lib/xray/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ set(XRAY_UNITTEST_LINK_FLAGS
${COMPILER_RT_CXX_LINK_LIBS})

if (NOT APPLE)
# Needed by LLVMSupport.
append_list_if(
LLVM_ENABLE_TERMINFO
-l${COMPILER_RT_TERMINFO_LIB} XRAY_UNITTEST_LINK_FLAGS)

# We add the library directories one at a time in our CFLAGS.
foreach (DIR ${LLVM_LIBRARY_DIR})
list(APPEND XRAY_UNITTEST_LINK_FLAGS -L${DIR})
Expand Down
1 change: 0 additions & 1 deletion lldb/docs/resources/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ further by passing the appropriate cmake options, such as:
-DLLDB_ENABLE_PYTHON=0
-DLLDB_ENABLE_LIBEDIT=0
-DLLDB_ENABLE_CURSES=0
-DLLVM_ENABLE_TERMINFO=0

(see :ref:`Optional Dependencies` for more)

Expand Down
3 changes: 0 additions & 3 deletions lldb/source/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ set(LLDB_LIBEDIT_LIBS)

if (LLDB_ENABLE_CURSES)
list(APPEND LLDB_CURSES_LIBS ${PANEL_LIBRARIES} ${CURSES_LIBRARIES})
if(LLVM_ENABLE_TERMINFO)
list(APPEND LLDB_CURSES_LIBS ${Terminfo_LIBRARIES})
endif()
if (LLVM_BUILD_STATIC)
list(APPEND LLDB_CURSES_LIBS gpm)
endif()
Expand Down
2 changes: 0 additions & 2 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,6 @@ set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should sear
set(LLVM_TARGET_ARCH "host"
CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")

option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)

set(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON")

option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON)
Expand Down
10 changes: 0 additions & 10 deletions llvm/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,11 @@ if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
else()
set(HAVE_LIBEDIT 0)
endif()
if(LLVM_ENABLE_TERMINFO)
if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
find_package(Terminfo REQUIRED)
else()
find_package(Terminfo)
endif()
set(LLVM_ENABLE_TERMINFO "${Terminfo_FOUND}")
endif()
else()
set(HAVE_LIBEDIT 0)
set(LLVM_ENABLE_TERMINFO 0)
endif()
else()
set(HAVE_LIBEDIT 0)
set(LLVM_ENABLE_TERMINFO 0)
endif()

if(LLVM_HAS_LOGF128)
Expand Down
55 changes: 0 additions & 55 deletions llvm/cmake/modules/FindTerminfo.cmake

This file was deleted.

5 changes: 0 additions & 5 deletions llvm/cmake/modules/LLVMConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ if(LLVM_ENABLE_LIBEDIT)
find_package(LibEdit)
endif()

set(LLVM_ENABLE_TERMINFO @LLVM_ENABLE_TERMINFO@)
if(LLVM_ENABLE_TERMINFO)
find_package(Terminfo)
endif()

set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@)

set(LLVM_ENABLE_UNWIND_TABLES @LLVM_ENABLE_UNWIND_TABLES@)
Expand Down
4 changes: 4 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ Changes to LLVM infrastructure
Changes to building LLVM
------------------------

- The ``LLVM_ENABLE_TERMINFO`` flag has been removed. LLVM no longer depends on
terminfo and now always uses the ``TERM`` environment variable for color
support autodetection.

Changes to TableGen
-------------------

Expand Down
3 changes: 0 additions & 3 deletions llvm/include/llvm/Config/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@
/* Define to 1 if you have the <sys/types.h> header file. */
#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}

/* Define if the setupterm() function is supported this platform. */
#cmakedefine LLVM_ENABLE_TERMINFO ${LLVM_ENABLE_TERMINFO}

/* Define to 1 if you have the <termios.h> header file. */
#cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H}

Expand Down
11 changes: 0 additions & 11 deletions llvm/lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ elseif( CMAKE_HOST_UNIX )
STRING(REGEX REPLACE "^lib" "" Backtrace_LIBFILE ${Backtrace_LIBFILE})
set(system_libs ${system_libs} ${Backtrace_LIBFILE})
endif()
if( LLVM_ENABLE_TERMINFO )
set(imported_libs ${imported_libs} Terminfo::terminfo)
endif()
set(system_libs ${system_libs} ${LLVM_ATOMIC_LIB})
set(system_libs ${system_libs} ${LLVM_PTHREAD_LIB})
if( UNIX AND NOT (BEOS OR HAIKU) )
Expand Down Expand Up @@ -325,14 +322,6 @@ if(LLVM_ENABLE_ZSTD)
set(llvm_system_libs ${llvm_system_libs} "${zstd_library}")
endif()

if(LLVM_ENABLE_TERMINFO)
if(NOT terminfo_library)
get_property(terminfo_library TARGET Terminfo::terminfo PROPERTY LOCATION)
endif()
get_library_name(${terminfo_library} terminfo_library)
set(llvm_system_libs ${llvm_system_libs} "${terminfo_library}")
endif()

set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")


Expand Down
60 changes: 4 additions & 56 deletions llvm/lib/Support/Unix/Process.inc
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,9 @@ unsigned Process::StandardErrColumns() {
return getColumns();
}

#ifdef LLVM_ENABLE_TERMINFO
// We manually declare these extern functions because finding the correct
// headers from various terminfo, curses, or other sources is harder than
// writing their specs down.
extern "C" int setupterm(char *term, int filedes, int *errret);
extern "C" struct term *set_curterm(struct term *termp);
extern "C" int del_curterm(struct term *termp);
extern "C" int tigetnum(char *capname);
#endif

bool checkTerminalEnvironmentForColors() {
static bool terminalHasColors() {
// Check if the current terminal is one of terminals that are known to support
// ANSI color escape codes.
if (const char *TermStr = std::getenv("TERM")) {
return StringSwitch<bool>(TermStr)
.Case("ansi", true)
Expand All @@ -368,54 +360,10 @@ bool checkTerminalEnvironmentForColors() {
return false;
}

static bool terminalHasColors(int fd) {
#ifdef LLVM_ENABLE_TERMINFO
// First, acquire a global lock because these C routines are thread hostile.
static std::mutex TermColorMutex;
std::lock_guard<std::mutex> G(TermColorMutex);

struct term *previous_term = set_curterm(nullptr);
int errret = 0;
if (setupterm(nullptr, fd, &errret) != 0)
// Regardless of why, if we can't get terminfo, we shouldn't try to print
// colors.
return false;

// Test whether the terminal as set up supports color output. How to do this
// isn't entirely obvious. We can use the curses routine 'has_colors' but it
// would be nice to avoid a dependency on curses proper when we can make do
// with a minimal terminfo parsing library. Also, we don't really care whether
// the terminal supports the curses-specific color changing routines, merely
// if it will interpret ANSI color escape codes in a reasonable way. Thus, the
// strategy here is just to query the baseline colors capability and if it
// supports colors at all to assume it will translate the escape codes into
// whatever range of colors it does support. We can add more detailed tests
// here if users report them as necessary.
//
// The 'tigetnum' routine returns -2 or -1 on errors, and might return 0 if
// the terminfo says that no colors are supported.
int colors_ti = tigetnum(const_cast<char *>("colors"));
bool HasColors =
colors_ti >= 0 ? colors_ti : checkTerminalEnvironmentForColors();

// Now extract the structure allocated by setupterm and free its memory
// through a really silly dance.
struct term *termp = set_curterm(previous_term);
(void)del_curterm(termp); // Drop any errors here.

// Return true if we found a color capabilities for the current terminal.
return HasColors;
#else
// When the terminfo database is not available, check if the current terminal
// is one of terminals that are known to support ANSI color escape codes.
return checkTerminalEnvironmentForColors();
#endif
}

bool Process::FileDescriptorHasColors(int fd) {
// A file descriptor has colors if it is displayed and the terminal has
// colors.
return FileDescriptorIsDisplayed(fd) && terminalHasColors(fd);
return FileDescriptorIsDisplayed(fd) && terminalHasColors();
}

bool Process::StandardOutHasColors() {
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/gn/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ configure is used for three classes of feature checks:

For the last two points, it would be nice if LLVM didn't have a single
``config.h`` header, but one header per toggle. That way, when e.g.
``llvm_enable_terminfo`` is toggled, only the 3 files caring about that setting
``llvm_enable_zlib`` is toggled, only the 3 files caring about that setting
would need to be rebuilt, instead of everything including ``config.h``.

GN doesn't believe in users setting arbitrary cflags from an environment
Expand Down
12 changes: 0 additions & 12 deletions llvm/utils/gn/build/libs/terminfo/BUILD.gn

This file was deleted.

4 changes: 0 additions & 4 deletions llvm/utils/gn/build/libs/terminfo/enable.gni

This file was deleted.

7 changes: 0 additions & 7 deletions llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import("//llvm/utils/gn/build/buildflags.gni")
import("//llvm/utils/gn/build/libs/curl/enable.gni")
import("//llvm/utils/gn/build/libs/edit/enable.gni")
import("//llvm/utils/gn/build/libs/pthread/enable.gni")
import("//llvm/utils/gn/build/libs/terminfo/enable.gni")
import("//llvm/utils/gn/build/libs/xar/enable.gni")
import("//llvm/utils/gn/build/libs/xml/enable.gni")
import("//llvm/utils/gn/build/libs/zlib/enable.gni")
Expand Down Expand Up @@ -294,12 +293,6 @@ write_cmake_config("config") {
values += [ "HAVE_LIBEDIT=" ]
}

if (llvm_enable_terminfo) {
values += [ "LLVM_ENABLE_TERMINFO=1" ]
} else {
values += [ "LLVM_ENABLE_TERMINFO=" ]
}

if (llvm_enable_libxml2) {
values += [ "LLVM_ENABLE_LIBXML2=1" ]
} else {
Expand Down
1 change: 0 additions & 1 deletion llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ static_library("Support") {
"//llvm/include/llvm/Support:write_vcsrevision",
"//llvm/lib/Demangle",
"//llvm/utils/gn/build/libs/pthread",
"//llvm/utils/gn/build/libs/terminfo",
"//llvm/utils/gn/build/libs/zlib",
]

Expand Down
Loading
Loading