From owner-svn-ports-all@freebsd.org Tue Feb 23 20:11:57 2021 Return-Path: Delivered-To: svn-ports-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 492D0550EC2; Tue, 23 Feb 2021 20:11:57 +0000 (UTC) (envelope-from adridg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DlVZP1fHMz4YJX; Tue, 23 Feb 2021 20:11:57 +0000 (UTC) (envelope-from adridg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2B82D1F4DE; Tue, 23 Feb 2021 20:11:57 +0000 (UTC) (envelope-from adridg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 11NKBvIi080165; Tue, 23 Feb 2021 20:11:57 GMT (envelope-from adridg@FreeBSD.org) Received: (from adridg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 11NKBuTB080164; Tue, 23 Feb 2021 20:11:56 GMT (envelope-from adridg@FreeBSD.org) Message-Id: <202102232011.11NKBuTB080164@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adridg set sender to adridg@FreeBSD.org using -f From: Adriaan de Groot Date: Tue, 23 Feb 2021 20:11:56 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r566427 - in head: Mk/Uses devel/qt5/files X-SVN-Group: ports-head X-SVN-Commit-Author: adridg X-SVN-Commit-Paths: in head: Mk/Uses devel/qt5/files X-SVN-Commit-Revision: 566427 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Feb 2021 20:11:57 -0000 Author: adridg Date: Tue Feb 23 20:11:56 2021 New Revision: 566427 URL: https://svnweb.freebsd.org/changeset/ports/566427 Log: Re-work Qt5 install- and deinstall scripts. Qt5 packages *together* manage a header file qconfig-modules.h which `#includes` other headers. A given Qt5 package may get a line in there, or it might not: that depends on package settings. On installing a package, add the line (if needed), on deinstall, remove the line (if it was there). There's a tricky case, too: upgrading a package that *had* a line, but no longer has one. That behaves like deinstall. Previously we used @postexec and @postunexec lines, but these were fragile in their own special way. See the linked PRs for examples -- or tcberner's comment that his qconfig-modules.h file *was* a screenful, and is now much shorter (and alphabetical, too!) An additional complication comes from needing to update qtchooser, *if* it is installed and *if* the package needs it. There was another set of @postexec lines for that. Migrate all the update logic to a shell script (there already was one for deinstall, now make it do triple-duty). From the template file, `pkg-change.in`, we generate a pkg-install and a pkg-deinstall script that does the right thing. PR: 253356 253360 Reported by: Nimaje on IRC Reviewed by: tcberner Added: head/devel/qt5/files/pkg-change.in (contents, props changed) Deleted: head/devel/qt5/files/pkg-deinstall.in Modified: head/Mk/Uses/qt-dist.mk Modified: head/Mk/Uses/qt-dist.mk ============================================================================== --- head/Mk/Uses/qt-dist.mk Tue Feb 23 20:07:56 2021 (r566426) +++ head/Mk/Uses/qt-dist.mk Tue Feb 23 20:11:56 2021 (r566427) @@ -196,11 +196,9 @@ QT_DEFINES?= # For qconfig.h flags (without "QT_" pre QT_CONFIG?= # For *.pri files QT_CONFIG flags. . if ${QT_DEFINES} QMAKE_ARGS+= DEFINES+="${QT_DEFINES:O:u:C/^([^-])/QT_\1/:C/^-/QT_NO_/:O}" -. if ${QT_DEFINES:N-*} -# Use a script to cleanup qconfig-modules.h (see qt-post-install). -PKGDEINSTALL= ${WRKDIR}/pkg-deinstall -. endif . endif # ${QT_DEFINES} +PKGDEINSTALL= ${WRKDIR}/pkg-install +PKGINSTALL= ${WRKDIR}/pkg-deinstall . if ${QT_CONFIG:N-*} QMAKE_ARGS+= QT_CONFIG+="${QT_CONFIG:N-*:O:u}" . endif @@ -346,17 +344,55 @@ qt5-pre-configure: . endfor . endif +. if ${QT_DEFINES:N-*} +# There **are** defines, so we need to **add** this port to the +# qconfig-modules.h header; make @need_add empty and comment out +# the @need_remove lines in the script (see below in qt-post-install). +# If there are no defines, do it the other way around. +_sub_need_add= +_sub_need_remove= \#\# +. else +_sub_need_add= \#\# +_sub_need_remove= +. endif +# Handle misc/qtchooser wrapper installation and deinstallation +# If a port installs Qt version-specific binaries (e.g. "designer" which +# existed as a Qt4 application and exists as a Qt5 application and will +# probably be a Qt6 application) which should have a qtchooser-based wrapper, +# the port should set `QT_BINARIES=yes`. +. if defined(QT_BINARIES) +_sub_need_bin= +. else +_sub_need_bin= \#\# +. endif +. if ${QT_MODNAME} == core +# QtCore (e.g. devel/qt5-core) is the one that starts the header, +# and is also the one that can clean it up when deinstalled. +_sub_need_clean= +. else +_sub_need_clean= \#\# +. endif post-install: qt-post-install qt-post-install: -. if ${QT_DEFINES:N-*} -# We can't use SUB_FILES with a shared pkg-deinstall.in. -# We need it to be a script instead of a group of @unexecs, otherwise -# qconfig-modules.h cleanup will be run in pre-deinstall stage, which is -# useless. This will probably be replaced by a Keywords/ script in the future. +# We can't use SUB_FILES with the shared pkg-change.in. +# We need it to be a script instead of a group of @unexecs. +# Do two steps of processing -- introducing the Qt variables, +# and replacing the @tags with comment (or nothing) characters +# according to the port's settings -- in one sed and write +# to pkg-change.tmp. Then split it up and minify for the +# install and deinstall step. @${SED} -e 's,%%QT_MODNAME%%,${QT_MODNAME},g' \ -e 's,%%QT_INCDIR%%,${QT_INCDIR},g' \ - ${PORTSDIR}/devel/${_QT_RELNAME}/${FILESDIR:T}/${PKGDEINSTALL:T}.in > \ - ${PKGDEINSTALL} + -e 's,@need_add,${_sub_need_add},' \ + -e 's,@need_remove,${_sub_need_remove},' \ + -e 's,@need_clean,${_sub_need_clean},' \ + -e 's,@need_bin,${_sub_need_bin},' \ + ${PORTSDIR}/devel/${_QT_RELNAME}/${FILESDIR:T}/pkg-change.in > \ + ${WRKDIR}/pkg-change.tmp + @${SED} -e 's,@install,,' -e 's,@deinstall,##,' ${WRKDIR}/pkg-change.tmp | ${SED} -e '/##/d' > ${PKGINSTALL} + @${SED} -e 's,@install,##,' -e 's,@deinstall,,' ${WRKDIR}/pkg-change.tmp | ${SED} -e '/##/d' > ${PKGDEINSTALL} + @${REINPLACE_CMD} 's/\t//g' ${PKGINSTALL} ${PKGDEINSTALL} +. if ${QT_DEFINES:N-*} @${MKDIR} ${STAGEDIR}${QT_INCDIR}/QtCore/modules @${ECHO_CMD} -n \ > ${STAGEDIR}${QT_INCDIR}/QtCore/modules/qconfig-${QT_MODNAME}.h @@ -372,8 +408,6 @@ qt-post-install: . endfor @${ECHO_CMD} "${PREFIX}/${QT_INCDIR_REL}/QtCore/modules/qconfig-${QT_MODNAME}.h" \ >> ${TMPPLIST} - @${ECHO_CMD} "@exec echo '#include ' >> ${PREFIX}/${QT_INCDIR_REL}/QtCore/qconfig-modules.h" \ - >> ${TMPPLIST} . endif # ${QT_DEFINES:N-*} . if ${QT_CONFIG:N-*} @${MKDIR} ${STAGEDIR}${QT_MKSPECDIR}/modules @@ -383,16 +417,4 @@ qt-post-install: >> ${TMPPLIST} . endif # ${QT_CONFIG:N-*} . endif # M5 - -# Handle misc/qtchooser wrapper installation and deinstallation -# If a port installs Qt version-specific binaries (e.g. "designer" which existed as a Qt4 application -# and exists as a Qt5 application and will probably be a Qt6 application) which should have a -# qtchooser-based wrapper, the port should set `QT_BINARIES=yes`. -# -# When QT_BINARIES is set to yes, compatibility symlinks (designer -> qtchooser, so that -# qtchooser can run designer-qt5 or whatever is the selected Qt version) are installed by the port. -. if defined(QT_BINARIES) - ${ECHO_CMD} '@postexec if type update-qtchooser-wrapper >/dev/null 2>&1; then update-qtchooser-wrapper; fi' >> ${TMPPLIST} - ${ECHO_CMD} '@postunexec if type update-qtchooser-wrapper >/dev/null 2>&1; then update-qtchooser-wrapper; fi' >> ${TMPPLIST} -. endif .endif # defined(_QT_DIST_MK_INCLUDED) Added: head/devel/qt5/files/pkg-change.in ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/devel/qt5/files/pkg-change.in Tue Feb 23 20:11:56 2021 (r566427) @@ -0,0 +1,104 @@ +#!/bin/sh +## +## ### PROCESSING +## +## This file is processed three ways: +## - to replace %%variables%% with the intended values +## - to replace @tag with ## or blank as appropriate +## - to filter out lines containing ## +## +## The resulting "minified" script is used as pkg-install or pkg-deinstall +## script in the package. +## +## Lines with @tag at the beginning should be read as conditional; +## multiple @tags are read as "and", so the **rest** of the line +## only ends up in the resulting script when all the @tags are true. +## +## The file is formatted for 8-wide tab stops with hard tabs, +## so that the shell-script itself can be read in column 24, +## e.g. v--- here +## take care not to insert tabs in the actual shell commands. +## +## +## ### ABOUT +## +## A Qt module should be listed in QtCore/qconfig-modules.h only once, +## and only if that is needed (e.g. if it has a qconfig-*.h of its own). +## In case 1 (listed), update the target file by appending and sorting: +## - echo the new line and existing contents if any +## - .. pipe to sort -u +## - .. then move the sorted-uniqued output to the config-modules.h +## In case 2 (unlisted), update the target file by deleting a line +## +## Removing QtCore *may* leave behind an empty file, and in that case +## clean up the config file and directories entirely. +## +## A module with versionable binaries (like "designer" which might have +## a Qt4, Qt5 and Qt6 version) can update the unversioned binary names +## via qt-chooser. +## +## +## On deinstall, we need QT_INCDIR separately, so define variables $qi and $qc +## differently from install (which needs only $qc). +@deinstall qi="%%QT_INCDIR%%" +@deinstall qc="$qi/QtCore/qconfig-modules.h" +@install qc="%%QT_INCDIR%%/QtCore/qconfig-modules.h" + qm="%%QT_MODNAME%%" +## +## Distinguish the pkg step and call the relevant shell functions defined above. +## + case $2 in +@install POST-INSTALL) +## +## Add the line #include qconfig-.h to the global +## qconfig-modules.h; afterwards that global file exists. +## +## We might be adding to a non-existent file, which is why there +## is the slightly-weird construction with a subshell piping to sort. +## +@install@need_add { echo "#include " +@install@need_add [ -f "$qc" ] && /bin/cat "$qc" +@install@need_add } | /usr/bin/sort -u -o "$qc.new" +@install@need_add /bin/mv "$qc.new" "$qc" +## +## This removes the line that #includes qconfig-.h +## from the global qconfig-modules.h; afterwards, that global file exists +## although it may be empty. +## (This code is identical in install- and deinstall-scripts, unconditional in deinstall) +## +@install@need_remove [ \! -e "$qc" ] && touch "$qc" +@install@need_remove sed -i "" "/qconfig-$qm\.h/ d" "$qc" +## +## If there are binaries, and qtchooser is installed, update it. +## (This code is identical in install- and deinstall-scripts) +## +@install@need_bin { type update-qtchooser-wrapper && update-qtchooser-wrapper ; } >/dev/null 2>&1 +@install ;; +@deinstall POST-DEINSTALL) +## +## This removes the line that #includes qconfig-.h +## from the global qconfig-modules.h; afterwards, that global file exists +## although it may be empty. +## (This code is identical in install- and deinstall-scripts, unconditional in deinstall) +## +@deinstall [ \! -e "$qc" ] && touch "$qc" +@deinstall sed -i "" "/qconfig-$qm\.h/ d" "$qc" +## +## When qtcore is removed, the whole config dir can go away as well. +## +@deinstall [ \! -e "$qi/QtCore/qconfig.h" ] && \ +@deinstall [ \! -s "$qc" ] && ( +@deinstall rm -f "$qc" +@deinstall rmdir "$qi/QtCore" +@deinstall rmdir "$qi" +@deinstall ) > /dev/null 2>&1 +## +## If there are binaries, and qtchooser is installed, update it. +## (This code is identical in install- and deinstall-scripts) +## +@deinstall@need_bin { type update-qtchooser-wrapper && update-qtchooser-wrapper ; } >/dev/null 2>&1 +@deinstall ;; + esac +## Avoid exit code from any of the commands-above (e.g. checking for +## qtchooser updates) from leaking out of this script: be true. + :