Skip to content
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

[terminfo-db] Add a builder for the terminfo database #9165

Merged
merged 12 commits into from
Aug 6, 2024
84 changes: 84 additions & 0 deletions T/TermInfoDB/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using BinaryBuilder

# This is based on https://www.freshports.org/misc/terminfo-db/
name = "TermInfoDB"
version = v"2023.12.9"

v = string(version.major, lpad(version.minor, 2, '0'), lpad(version.patch, 2, '0'))
sources = [
FileSource("https://invisible-island.net/archives/ncurses/current/terminfo-$v.src.gz",
"2debcf2fd689988d44558bcd8a26a104b96542ffc9540f19e2586b3aeecd1c79"),
DirectorySource("./bundled"),
]

script = raw"""
cd ${WORKSPACE}/srcdir/

# Adopting the wisdom of https://mywiki.wooledge.org/ParsingLs (🙏 Mosè)
shopt -s nullglob

gunzip terminfo-*
mkdir -p "${prefix}/share/terminfo"
tic -sx -o "${prefix}/share/terminfo" ./terminfo-*

pushd "${prefix}/share/terminfo/"

# The terminfo filesystem-based database contains both upper- and lowercase directory
# names, which presents a problem for case-insensitive filesystems. Let's rename all
# files and directories to lowercase. Unfortunately, we can't just `mv` the filename
# to its lowercase counterpart because many of these files, including but not limited
# to those whose names differ only by case, are actually hard links to one another
# (they have the same inode) so `mv` sees it as a no-op and just does nothing.
# Hence... this.
for dir in *; do
lcdir="${dir,,}"
mkdir -p "${lcdir}"
for file in ${dir}/*; do
ararslan marked this conversation as resolved.
Show resolved Hide resolved
ararslan marked this conversation as resolved.
Show resolved Hide resolved
file=$(basename "${file}")
lcfile="${file,,}"
if [ "${dir}/${file}" = "${lcdir}/${lcfile}" ]; then
# Already all lowercase, nothing to do
continue
fi
mv -f "${dir}/${file}" "${lcdir}/${lcfile}.TEMP"
rm -f "${lcdir}/${lcfile}"
mv -f "${lcdir}/${lcfile}.TEMP" "${lcdir}/${lcfile}"
if [ -e "${dir}/${file}" ] || [ -e "${lcdir}/${lcfile}.TEMP" ]; then
echo "ERROR: '${dir}/${file}' not successfully renamed to lowercase!!!"
exit 1
fi
done
if [ -z "$(ls -A "${dir}")" ]; then
rm -rf "${dir}"
fi
done

# I'm not about to list the entire contents out as `FileProduct`s, so we'll do our
# own mini-audit by checking that the expected directories exist. We know each is
# non-empty based on the above.
dirs=(*)
expected=(1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x z)
if [ ! -z "$(echo ${dirs[@]} ${expected[@]} | tr ' ' '\n' | sort | uniq -u)" ]; then
echo "ERROR: Build did not produce the expected set of directories!!!"
exit 1
fi

popd

install_license "${WORKSPACE}/srcdir/COPYING"
"""

platforms = [AnyPlatform()]

# I'd rather not list out >2k individual `FileProduct`s so let's just call the entry
# for xterm our "product" and hope the rest are there
products = [
FileProduct("share/terminfo/x/xterm", :terminfo_xterm),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can share/terminfo be the "file" product?

Copy link
Member Author

@ararslan ararslan Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered that as well. I had assumed not but I just checked the implementation of FileProduct and it only requires ispath, not isfile, which suggests that it could potentially work. @giordano, is there any reason why we couldn't do what @tecosaur noted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that'd work as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does versioning work if we change this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't change the version number, Pkg will only install the latest one.

]

dependencies = [
HostBuildDependency("Ncurses_jll"), # for `tic`
]

build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
julia_compat="1.6")
29 changes: 29 additions & 0 deletions T/TermInfoDB/bundled/COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright 2018-2022,2023 Thomas E. Dickey
Copyright 1998-2017,2018 Free Software Foundation, Inc.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, distribute with modifications, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name(s) of the above copyright
holders shall not be used in advertising or otherwise to promote the
sale, use or other dealings in this Software without prior written
authorization.

-- vile:txtmode fc=72
-- $Id: COPYING,v 1.12 2023/01/07 17:55:53 tom Exp $