Annotation of pkgsrc/mk/pkgformat/pkg/replace.mk, revision 1.6

1.6     ! roy         1: # $NetBSD: replace.mk,v 1.5 2017/08/19 00:30:19 jlam Exp $
1.1       reed        2: #
                      3: 
                      4: # _pkgformat-destdir-replace:
1.3       joerg       5: #      Updates a package in-place on the system.
1.1       reed        6: #
                      7: # See also:
                      8: #      replace
                      9: #
                     10: # XXX: The whole replacement, from deinstalling the old package up
1.3       joerg      11: # to installing the new package, should be one transaction.
1.1       reed       12: #
                     13: _pkgformat-replace: \
                     14:        replace-tarup \
                     15:        replace-preserve-installed-info \
                     16:        replace-preserve-required-by \
                     17:        deinstall \
                     18:        install-clean \
                     19:        install \
                     20:        replace-fixup-required-by \
                     21:        replace-fixup-installed-info \
                     22:        .PHONY
                     23: 
1.4       gdt        24: # tarup is omitted for DESTDIR, because the benefits are very small
1.1       reed       25: _pkgformat-destdir-replace: \
                     26:        replace-destdir \
                     27:        .PHONY
                     28: 
                     29: # _pkgformat-undo-replace:
                     30: #      Undoes the actions from a previous _pkgformat-replace.
                     31: #
                     32: # See also:
                     33: #      undo-replace
                     34: #
                     35: _pkgformat-undo-replace: \
                     36:        undo-replace-check \
                     37:        replace-preserve-installed-info \
                     38:        replace-preserve-required-by \
                     39:        deinstall \
                     40:        undo-replace-install \
                     41:        replace-fixup-required-by \
                     42:        replace-clean \
                     43:        .PHONY
                     44: 
                     45: _pkgformat-destdir-undo-replace: \
                     46:        undo-replace-check \
                     47:        undo-destdir-replace-install \
                     48:        replace-clean \
                     49:        .PHONY
                     50: 
                     51: _INSTALLED_INFO_FILE=  ${WRKDIR}/.replace-+INSTALLED_INFO
                     52: _REQUIRED_BY_FILE=     ${WRKDIR}/.replace-+REQUIRED_BY
                     53: 
                     54: _COOKIE.replace=       ${WRKDIR}/.replace_done
                     55: _REPLACE_OLDNAME_FILE= ${WRKDIR}/.replace_oldname
                     56: _REPLACE_NEWNAME_FILE= ${WRKDIR}/.replace_newname
                     57: 
                     58: _REPLACE_OLDNAME_CMD=  \
                     59:        [ -f ${_REPLACE_OLDNAME_FILE} ] \
                     60:        || ${FAIL_MSG} "[${.TARGET}] ${_REPLACE_OLDNAME_FILE}: File not found"; \
                     61:        oldname=`${CAT} ${_REPLACE_OLDNAME_FILE}`
                     62: 
                     63: _REPLACE_NEWNAME_CMD=  \
                     64:        [ -f ${_REPLACE_NEWNAME_FILE} ] \
                     65:        || ${FAIL_MSG} "[${.TARGET}] ${_REPLACE_NEWNAME_FILE}: File not found"; \
                     66:        newname=`${CAT} ${_REPLACE_NEWNAME_FILE}`
                     67: 
                     68: # Verifies that there was a previous "replace" action performed that can be undone.
                     69: #
                     70: undo-replace-check: .PHONY
                     71:        ${RUN} [ -f ${_COOKIE.replace} ] \
                     72:        || ${FAIL_MSG} "No replacement to undo!"
                     73: 
                     74: # Generates a binary package for the (older) installed package using pkg_tarup.
                     75: #
                     76: replace-tarup: .PHONY
                     77:        ${RUN} [ -x ${_PKG_TARUP_CMD:Q} ] \
                     78:        || ${FAIL_MSG} ${_PKG_TARUP_CMD:Q}" was not found.";            \
                     79:        ${_REPLACE_OLDNAME_CMD};                                        \
                     80:        ${PKGSRC_SETENV} PKG_DBDIR=${_PKG_DBDIR} PKG_SUFX=${PKG_SUFX}   \
                     81:                PKGREPOSITORY=${WRKDIR}                                 \
                     82:                ${_PKG_TARUP_CMD} $${oldname} ||                        \
                     83:        ${FAIL_MSG} "Could not pkg_tarup $${oldname}".
                     84: 
                     85: # Re-installs the old package that has been saved by replace-tarup.
                     86: #
                     87: undo-replace-install: .PHONY
                     88:        @${PHASE_MSG} "Re-adding ${PKGNAME} from saved tar-up package."
                     89:        ${RUN} ${_REPLACE_OLDNAME_CMD};                                 \
                     90:        ${ECHO} "Installing saved package ${WRKDIR}/$${oldname}${PKG_SUFX}"; \
1.5       jlam       91:        ${SETENV} ${PKGTOOLS_ENV} ${PKG_ADD} ${WRKDIR}/$${oldname}${PKG_SUFX}
1.1       reed       92: 
                     93: undo-destdir-replace-install: .PHONY
                     94:        @${PHASE_MSG} "Re-adding ${PKGNAME} from saved tar-up package."
                     95:        ${RUN} ${_REPLACE_OLDNAME_CMD};                                 \
                     96:        ${ECHO} "Installing saved package ${WRKDIR}/$${oldname}${PKG_SUFX}"; \
1.5       jlam       97:        ${SETENV} ${PKGTOOLS_ENV} ${PKG_ADD} -U -D ${WRKDIR}/$${oldname}${PKG_SUFX}
1.1       reed       98: 
                     99: # Computes and saves the full names of the installed package to be replaced
                    100: # (oldname) and the package that will be installed (newname), so that these
                    101: # names are available later.
                    102: #
                    103: replace-names: .PHONY
                    104:        ${RUN} if [ x"${OLDNAME}" = x ]; then                           \
                    105:                wildcard=${PKGWILDCARD:Q};                              \
                    106:        else                                                            \
                    107:                wildcard="${OLDNAME}-[0-9]*";                           \
                    108:        fi;                                                             \
                    109:        ${_PKG_BEST_EXISTS} "$${wildcard}" > ${_REPLACE_OLDNAME_FILE}
                    110:        ${RUN} ${ECHO} ${PKGNAME} > ${_REPLACE_NEWNAME_FILE}
                    111:        ${RUN} ${CP} -f ${_REPLACE_NEWNAME_FILE} ${_COOKIE.replace}
                    112: 
                    113: # Saves and removes the +INSTALLED_INFO file from the installed package.
                    114: #
                    115: replace-preserve-installed-info: .PHONY
                    116:        @${STEP_MSG} "Preserving existing +INSTALLED_INFO file."
                    117:        ${RUN} ${_REPLACE_OLDNAME_CMD};                                 \
                    118:        installed_info="${_PKG_DBDIR}/$$oldname/+INSTALLED_INFO";       \
                    119:        ${TEST} ! -f "$$installed_info" ||                              \
                    120:        ${MV} $$installed_info ${_INSTALLED_INFO_FILE}
                    121: 
                    122: # Saves and removes the +REQUIRED_BY file from the installed package.
                    123: #
                    124: replace-preserve-required-by: .PHONY
                    125:        @${STEP_MSG} "Preserving existing +REQUIRED_BY file."
                    126:        ${RUN} ${_REPLACE_OLDNAME_CMD};                                 \
                    127:        required_by="${_PKG_DBDIR}/$$oldname/+REQUIRED_BY";             \
                    128:        ${TEST} ! -f "$$required_by" ||                                 \
                    129:        ${MV} $$required_by ${_REQUIRED_BY_FILE}
                    130: 
                    131: # Fixes the +CONTENTS files of dependent packages to refer to the
                    132: # replacement package, and puts the +REQUIRED_BY file back into place.
                    133: # It also sets the unsafe_depends_strict tag on each dependent package,
                    134: # and sets the unsafe_depends tag if the replaced package has a different
                    135: # version.
                    136: #
                    137: # XXX Only set unsafe_depends if there is an ABI change.
                    138: #
                    139: replace-fixup-required-by: .PHONY
                    140:        @${STEP_MSG} "Fixing @pkgdep entries in dependent packages."
                    141:        ${RUN} ${_REPLACE_OLDNAME_CMD};                                 \
                    142:        ${_REPLACE_NEWNAME_CMD};                                        \
                    143:        ${TEST} -f ${_REQUIRED_BY_FILE} || exit 0;                      \
                    144:        ${CAT} ${_REQUIRED_BY_FILE} |                                   \
                    145:        while read pkg; do                                              \
                    146:                case $$pkg in                                           \
                    147:                "")     continue ;;                                     \
                    148:                /*)     pkgdir="$$pkg" ;;                               \
                    149:                *)      pkgdir="${_PKG_DBDIR}/$$pkg" ;;                 \
                    150:                esac;                                                   \
                    151:                contents="$$pkgdir/+CONTENTS";                          \
                    152:                newcontents="$$contents.$$$$";                          \
                    153:                ${PKGSRC_SETENV} OLDNAME="$$oldname" NEWNAME="$$newname"        \
                    154:                ${AWK} '($$0 ~ "^@pkgdep " ENVIRON["OLDNAME"])          \
                    155:                        { print "@pkgdep " ENVIRON["NEWNAME"]; next }   \
                    156:                        { print }'                                      \
                    157:                        $$contents > $$newcontents;                     \
                    158:                ${MV} -f $$newcontents $$contents;                      \
                    159:                ${PKG_ADMIN} set unsafe_depends_strict=YES $$pkg;       \
                    160:                if ${TEST} "$$oldname" != "$$newname"; then             \
                    161:                        ${PKG_ADMIN} set unsafe_depends=YES $$pkg;      \
                    162:                fi;                                                     \
                    163:        done;                                                           \
                    164:        ${MV} ${_REQUIRED_BY_FILE} ${_PKG_DBDIR}/$$newname/+REQUIRED_BY
                    165: 
                    166: # Removes unsafe_depends* and rebuild tags from this package.
                    167: #
                    168: # XXX: pkg_admin should not complain on unset with no +INSTALLED_INFO.
                    169: #
                    170: replace-fixup-installed-info: .PHONY
                    171:        @${STEP_MSG} "Removing unsafe_depends and rebuild tags."
                    172:        ${RUN} ${_REPLACE_NEWNAME_CMD};                                 \
                    173:        [ ! -f ${_INSTALLED_INFO_FILE} ] ||                     \
                    174:        ${MV} ${_INSTALLED_INFO_FILE} ${_PKG_DBDIR}/$$newname/+INSTALLED_INFO; \
                    175:        for var in unsafe_depends unsafe_depends_strict rebuild; do     \
                    176:                ${TEST} ! -f ${_PKG_DBDIR}/$$newname/+INSTALLED_INFO || \
                    177:                ${PKG_ADMIN} unset $$var $$newname;                     \
                    178:        done
                    179: 
                    180: # Removes the state files for the "replace" target, so that it may be re-invoked.
                    181: #
                    182: replace-clean: .PHONY
                    183:        ${RUN} ${_REPLACE_OLDNAME_CMD};                                 \
                    184:        ${_REPLACE_NEWNAME_CMD};                                        \
                    185:        ${RM} -f ${WRKDIR}/$$oldname${PKG_SUFX};                        \
                    186:        ${RM} -f ${WRKDIR}/$$newname${PKG_SUFX};                        \
                    187:        ${RM} -f ${_REPLACE_OLDNAME_FILE} ${_REPLACE_NEWNAME_FILE}      \
                    188:                ${_COOKIE.replace}
                    189: 
                    190: # Logically we would like to do a "pkg_add -U".  However, that fails
                    191: # if there is a depending package that exactly depends on the package
                    192: # being replaced, so we override that check with -D.  Historically,
                    193: # 'make replace' would replace a package regardless of whether that
                    194: # broke depending packages (typically due to shlib ABI changes,
                    195: # especially major version bumps).  Therefore, make replace in DESTDIR
                    196: # mode should behave the same way.  unsafe_depends will be set on
                    197: # depending packages, and then those may be rebuilt via a manual
                    198: # process or by pkg_rolling-replace.
                    199: replace-destdir: .PHONY
                    200:        @${PHASE_MSG} "Updating using binary package of "${PKGNAME:Q}
                    201: .if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
                    202:        @${MKDIR} ${_CROSS_DESTDIR}${PREFIX}
1.5       jlam      203:        ${SETENV} ${PKGTOOLS_ENV} ${PKG_ADD} -U -D -m ${MACHINE_ARCH} -I -p ${_CROSS_DESTDIR}${PREFIX} ${STAGE_PKGFILE}
1.1       reed      204:        @${ECHO} "Fixing recorded cwd..."
                    205:        @${SED} -e 's|@cwd ${_CROSS_DESTDIR}|@cwd |' ${_PKG_DBDIR}/${PKGNAME:Q}/+CONTENTS > ${_PKG_DBDIR}/${PKGNAME:Q}/+CONTENTS.tmp
                    206:        @${MV} ${_PKG_DBDIR}/${PKGNAME:Q}/+CONTENTS.tmp ${_PKG_DBDIR}/${PKGNAME:Q}/+CONTENTS
                    207: .else
1.5       jlam      208:        ${SETENV} ${PKGTOOLS_ENV} ${PKG_ADD} -U -D ${STAGE_PKGFILE}
1.1       reed      209: .endif
                    210:        ${RUN}${_REPLACE_OLDNAME_CMD}; \
                    211:        ${PKG_INFO} -qR ${PKGNAME:Q} | while read pkg; do \
                    212:                [ -n "$$pkg" ] || continue; \
                    213:                ${PKG_ADMIN} set unsafe_depends_strict=YES "$$pkg"; \
                    214:                if [ "$$oldname" != ${PKGNAME:Q} ]; then \
                    215:                        ${PKG_ADMIN} set unsafe_depends=YES "$$pkg"; \
                    216:                fi; \
                    217:        done
                    218:        ${RUN}${PKG_ADMIN} unset unsafe_depends ${PKGNAME:Q}
                    219:        ${RUN}${PKG_ADMIN} unset unsafe_depends_strict ${PKGNAME:Q}
                    220:        ${RUN}${PKG_ADMIN} unset rebuild ${PKGNAME:Q}

CVSweb <webmaster@jp.NetBSD.org>