Skip to content

Commit e7e8768

Browse files
ararslangiordano
andauthored
Vendor the terminfo database for use with base/terminfo.jl (#55411)
This adds the `terminfo` database to `deps/`, providing a better user experience on systems that don't have `terminfo` on the system by default. The database is built using BinaryBuilder but is not actually platform-specific (it's built for `AnyPlatform`) and as such, this fetches the artifact directly rather than adding a new JLL to stdlib, and it requires no compilation. A build flag, `WITH_TERMINFO`, is added here and assumed true by default, allowing users to set `WITH_TERMINFO=0` in Make.user to avoid bundling `terminfo` should they want to do so. The lookup policy for `terminfo` entries is still compliant with what's described in `terminfo(5)`; the bundled directory is taken to be the first "compiled in" location, i.e. prepended to `@TERMINFO_DIRS@`. This allows any user settings that exist locally, such as custom entries or locations, to take precedence. Fixes #55274 Co-authored-by: Mosè Giordano <[email protected]>
1 parent 57aef91 commit e7e8768

File tree

8 files changed

+78
-4
lines changed

8 files changed

+78
-4
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ endif
403403
# Install appdata file
404404
mkdir -p $(DESTDIR)$(datarootdir)/metainfo/
405405
$(INSTALL_F) $(JULIAHOME)/contrib/julia.appdata.xml $(DESTDIR)$(datarootdir)/metainfo/
406+
# Install terminal info database
407+
ifneq ($(WITH_TERMINFO),0)
408+
cp -R -L $(build_datarootdir)/terminfo $(DESTDIR)$(datarootdir)
409+
endif
406410

407411
# Update RPATH entries and JL_SYSTEM_IMAGE_PATH if $(private_libdir_rel) != $(build_private_libdir_rel)
408412
ifneq ($(private_libdir_rel),$(build_private_libdir_rel))

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ Deprecated or removed
171171
External dependencies
172172
---------------------
173173

174+
- The terminal info database, `terminfo`, is now vendored by default, providing a better
175+
REPL user experience when `terminfo` is not available on the system. Julia can be built
176+
without vendoring the database using the Makefile option `WITH_TERMINFO=0`. ([#55411])
177+
174178
Tooling Improvements
175179
--------------------
176180

base/terminfo.jl

+10-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ end
245245
Locate the terminfo file for `term`, return `nothing` if none could be found.
246246
247247
The lookup policy is described in `terminfo(5)` "Fetching Compiled
248-
Descriptions".
248+
Descriptions". A terminfo database is included by default with Julia and is
249+
taken to be the first entry of `@TERMINFO_DIRS@`.
249250
"""
250251
function find_terminfo_file(term::String)
251252
isempty(term) && return
@@ -261,15 +262,23 @@ function find_terminfo_file(term::String)
261262
append!(terminfo_dirs,
262263
replace(split(ENV["TERMINFO_DIRS"], ':'),
263264
"" => "/usr/share/terminfo"))
265+
push!(terminfo_dirs, normpath(Sys.BINDIR, DATAROOTDIR, "terminfo"))
264266
Sys.isunix() &&
265267
push!(terminfo_dirs, "/etc/terminfo", "/lib/terminfo", "/usr/share/terminfo")
266268
for dir in terminfo_dirs
267269
if isfile(joinpath(dir, chr, term))
268270
return joinpath(dir, chr, term)
269271
elseif isfile(joinpath(dir, chrcode, term))
270272
return joinpath(dir, chrcode, term)
273+
elseif isfile(joinpath(dir, lowercase(chr), lowercase(term)))
274+
# The vendored terminfo database is fully lowercase to avoid issues on
275+
# case-sensitive filesystems. On Unix-like systems, terminfo files with
276+
# different cases are hard links to one another, so this is still
277+
# correct for non-vendored terminfo, just redundant.
278+
return joinpath(dir, lowercase(chr), lowercase(term))
271279
end
272280
end
281+
return nothing
273282
end
274283

275284
"""

deps/Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ ifeq ($(WITH_NVTX),1)
175175
DEP_LIBS += nvtx
176176
endif
177177

178+
ifneq ($(WITH_TERMINFO),0)
179+
DEP_LIBS += terminfo
180+
endif
181+
178182
# Only compile standalone LAPACK if we are not using OpenBLAS.
179183
# OpenBLAS otherwise compiles LAPACK as part of its build.
180184
# This is useful where one wants to use the vendor BLAS, but
@@ -197,7 +201,8 @@ DEP_LIBS_STAGED := $(DEP_LIBS)
197201
DEP_LIBS_STAGED_ALL := llvm llvm-tools clang llvmunwind unwind libuv pcre \
198202
openlibm dsfmt blastrampoline openblas lapack gmp mpfr patchelf utf8proc \
199203
objconv mbedtls libssh2 nghttp2 curl libgit2 libwhich zlib p7zip csl \
200-
sanitizers libsuitesparse lld libtracyclient ittapi nvtx JuliaSyntax
204+
sanitizers libsuitesparse lld libtracyclient ittapi nvtx JuliaSyntax \
205+
terminfo
201206
DEP_LIBS_ALL := $(DEP_LIBS_STAGED_ALL)
202207

203208
ifneq ($(USE_BINARYBUILDER_OPENBLAS),0)
@@ -259,6 +264,7 @@ include $(SRCDIR)/libgit2.mk
259264
include $(SRCDIR)/libwhich.mk
260265
include $(SRCDIR)/p7zip.mk
261266
include $(SRCDIR)/libtracyclient.mk
267+
include $(SRCDIR)/terminfo.mk
262268

263269
# vendored Julia libs
264270
include $(SRCDIR)/JuliaSyntax.mk

deps/checksums/terminfo

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TermInfoDB-v2023.12.9.any.tar.gz/md5/573d9b5adaf6af500e3dfae6e3d15ebf
2+
TermInfoDB-v2023.12.9.any.tar.gz/sha512/e0a5bfe54346f9d5690a840628b329f6fac7375b0d29337bc70813ae3553a72bb397f8034d221c544289e40c4cfc685d5805777b7528f05bbe0123b5905c24a4

deps/terminfo.mk

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## TERMINFO-DB ##
2+
include $(SRCDIR)/terminfo.version
3+
4+
$(SRCCACHE)/TermInfoDB-v$(TERMINFO_VER).any.tar.gz: | $(SRCCACHE)
5+
$(JLDOWNLOAD) $@ https://github.com/JuliaBinaryWrappers/TermInfoDB_jll.jl/releases/download/$(TERMINFO_TAG)/TermInfoDB.v$(TERMINFO_VER).any.tar.gz
6+
touch -c $@
7+
8+
$(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)/source-extracted: $(SRCCACHE)/TermInfoDB-v$(TERMINFO_VER).any.tar.gz
9+
$(JLCHECKSUM) $<
10+
rm -rf $(dir $@)
11+
mkdir -p $(dir $@)
12+
$(TAR) -C $(dir $@) --strip-components 1 -xf $<
13+
echo 1 > $@
14+
15+
checksum-terminfo: $(SRCCACHE)/TermInfoDB-v$(TERMINFO_VER).any.tar.gz
16+
$(JLCHECKSUM) $<
17+
18+
$(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)/build-compiled: $(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)/source-extracted
19+
echo 1 > $@
20+
21+
$(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)/build-checked: $(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)/build-compiled
22+
echo 1 > $@
23+
24+
define TERMINFO_INSTALL
25+
mkdir -p $2/$$(build_datarootdir)
26+
cp -R $1/terminfo $2/$$(build_datarootdir)
27+
endef
28+
$(eval $(call staged-install, \
29+
terminfo,TermInfoDB-v$(TERMINFO_VER), \
30+
TERMINFO_INSTALL,,,,))
31+
32+
clean-terminfo:
33+
-rm -f $(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)/build-compiled
34+
35+
distclean-terminfo:
36+
rm -rf $(SRCCACHE)/TermInfoDB*.tar.gz $(SRCCACHE)/TermInfoDB-v$(TERMINFO_VER) $(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)
37+
38+
get-terminfo: $(SRCCACHE)/TermInfoDB-v$(TERMINFO_VER).any.tar.gz
39+
extract-terminfo: $(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)/source-extracted
40+
configure-terminfo: extract-terminfo
41+
compile-terminfo: $(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)/build-compiled
42+
fastcheck-terminfo: check-terminfo
43+
check-terminfo: $(BUILDDIR)/TermInfoDB-v$(TERMINFO_VER)/build-checked

deps/terminfo.version

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- makefile -*-
2+
TERMINFO_VER := 2023.12.9
3+
TERMINFO_TAG := TermInfoDB-v$(TERMINFO_VER)+0

stdlib/REPL/test/precompilation.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ if !Sys.iswindows()
1515
@testset "No interactive startup compilation" begin
1616
f, _ = mktemp()
1717

18-
# start an interactive session
19-
cmd = `$(Base.julia_cmd()[1]) --trace-compile=$f -q --startup-file=no -i`
18+
# start an interactive session, ensuring `TERM` is unset since it can trigger
19+
# different amounts of precompilation stemming from `base/terminfo.jl` depending
20+
# on the value, making the test here unreliable
21+
cmd = addenv(`$(Base.julia_cmd()[1]) --trace-compile=$f -q --startup-file=no -i`,
22+
Dict("TERM" => ""))
2023
pts, ptm = open_fake_pty()
2124
p = run(cmd, pts, pts, pts; wait=false)
2225
Base.close_stdio(pts)

0 commit comments

Comments
 (0)