svn commit: r566427 - in head: Mk/Uses devel/qt5/files

Adriaan de Groot adridg at FreeBSD.org
Tue Feb 23 20:11:57 UTC 2021


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, at need_add,${_sub_need_add},' \
+		-e 's, at need_remove,${_sub_need_remove},' \
+		-e 's, at need_clean,${_sub_need_clean},' \
+		-e 's, at need_bin,${_sub_need_bin},' \
+		${PORTSDIR}/devel/${_QT_RELNAME}/${FILESDIR:T}/pkg-change.in > \
+		${WRKDIR}/pkg-change.tmp
+	@${SED} -e 's, at install,,' -e 's, at deinstall,##,' ${WRKDIR}/pkg-change.tmp | ${SED} -e '/##/d' > ${PKGINSTALL}
+	@${SED} -e 's, at install,##,' -e 's, at 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 <QtCore/modules/qconfig-${QT_MODNAME}.h>' >> ${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).
+ at deinstall		qi="%%QT_INCDIR%%"
+ at deinstall		qc="$qi/QtCore/qconfig-modules.h"
+ at 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
+ at install		POST-INSTALL)
+##
+## Add the line #include qconfig-<this module>.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.
+##
+ at install@need_add	{ echo "#include <QtCore/modules/qconfig-$qm.h>"
+ at install@need_add		[ -f "$qc" ] && /bin/cat "$qc"
+ at install@need_add	} | /usr/bin/sort -u -o "$qc.new"
+ at install@need_add	/bin/mv "$qc.new" "$qc"
+##
+## This removes the line that #includes qconfig-<this module>.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)
+##
+ at install@need_remove	[ \! -e "$qc" ] && touch "$qc"
+ at 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)
+##
+ at install@need_bin	{ type update-qtchooser-wrapper && update-qtchooser-wrapper ; } >/dev/null 2>&1
+ at install		;;
+ at deinstall		POST-DEINSTALL)
+##
+## This removes the line that #includes qconfig-<this module>.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)
+##
+ at deinstall		[ \! -e "$qc" ] && touch "$qc"
+ at deinstall		sed -i "" "/qconfig-$qm\.h/ d" "$qc"
+##
+## When qtcore is removed, the whole config dir can go away as well.
+##
+ at deinstall		[ \! -e "$qi/QtCore/qconfig.h" ] && \
+ at deinstall		[ \! -s "$qc" ] && (
+ at deinstall			rm -f "$qc"
+ at deinstall			rmdir "$qi/QtCore"
+ at deinstall			rmdir "$qi"
+ at deinstall		) > /dev/null 2>&1
+##
+## If there are binaries, and qtchooser is installed, update it.
+##   (This code is identical in install- and deinstall-scripts)
+##
+ at deinstall@need_bin	{ type update-qtchooser-wrapper && update-qtchooser-wrapper ; } >/dev/null 2>&1
+ at 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.
+			:


More information about the svn-ports-all mailing list