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

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

CVSweb <webmaster@jp.NetBSD.org>