# $Id: bzr-package.mk,v 1.14 2010/03/27 13:10:37 obache Exp $ # # This file provides simple access to Bazaar repositories, so that packages # can be created from Bazaar instead of from released tarballs. Whenever a # package is fetched from Bazaar, an archive is created from it and saved # in ${DISTDIR}/bzr-packages, to save bandwidth. # # === User-settable variables === # # CHECKOUT_DATE # Date to check out in ISO format (YYYY-MM-DD). # # === Package-settable variables === # # A package using this file shall define the following variables: # # -------------------- # VCS_REPOSITORIES # A list of unique identifiers. For each of those identifiers, the # following variables define the details of how to access the # Bazaar repository. ${id} in following variables refers this name. # # VCS_ROOT must be defined. # # VCS_ROOT.${id} # The VCSROOT for the VCS repository, including anonbzr password, # if applicable. # # VCS_MODULE.${id} # The VCS module to check out. # # Default value: ${id} # # VCS_DISTBASE.${id} # The prefix for cached archive file name. # # Default value: ${VCS_MODULE.${repo}} # # VCS_TAG.${id} # Overridable VCS tag for a repository. # # Default: ${VCS_TAG} (today at midnight) # -------------------- # It may define the following variables: # # VCS_CERTS # Files holding SSL certificates of the bzr servers. # # VCS_TAG # The default VCS tag that is checked out. May be overridden by # VCS_TAG.${id}. # # Default value: today at midnight. (Not appliable for bzr for the moment) # # === Variables defined here === # # This file defines the following variables: # # VCS_ROOT_SOURCEFORGE # Common VCS repository locations for use in the VCS_ROOT # variables. # # It also provides default values for the following variables, differing # from the system-wide defaults: # # DISTFILES # Is set to an empty list, since that is the right choice for most # of the Bazaar packages. # # PKGREVISION # If PKGREVISION is not set, set it to today's date. This is # useful for packages that automatically grab the latest code # from bazaar every time they are built. # TODO: Reconsider this, and instead use the Bazaar revision # number in the package version somehow. # # Keywords: bazaar # .if !defined(_PKG_MK_VCS_PACKAGE_MK) _PKG_MK_VCS_PACKAGE_MK= # defined BUILD_DEPENDS+= bzr>=1.0:../../devel/bzr # # defaults for user-visible input variables # DISTFILES?= # empty PKGNAME?= ${DISTNAME:C,-[0-9].*,,}-bzr-${_VCS_PKGVERSION} # Enforce PKGREVISION unless VCS_TAG is set .if empty(VCS_TAG) . if defined(CHECKOUT_DATE) PKGREVISION?= $(CHECKOUT_DATE:S/-//g) . else PKGREVISION?= $(_VCS_PKGVERSION:S/.//g) . endif .endif # # definition of user-visible output variables # # # End of the interface part. Start of the implementation part. # # # Input validation # .if !defined(VCS_REPOSITORIES) PKG_FAIL_REASON+= "[vcs-package.mk] VCS_REPOSITORIES must be set." VCS_REPOSITORIES?= # none .endif .for repo in ${VCS_REPOSITORIES} . if !defined(VCS_ROOT.${repo}) PKG_FAIL_REASON+= "[vcs-package.mk] VCS_ROOT."${repo:Q}" must be set." . endif .endfor # # Internal variables # USE_TOOLS+= date pax _VCS_RSH= ssh _VCS_CMD= ${VCS_TYPE} _VCS_ENV= # empty _VCS_ENV+= VCS_RSH=${_VCS_RSH:Q} _VCS_FLAGS?= _VCS_CHECKOUT_FLAGS+= --verbose _VCS_TODAY_CMD= ${DATE} -u +'%Y-%m-%d' _VCS_TODAY= ${_VCS_TODAY_CMD:sh} _VCS_PKGVERSION_CMD= ${DATE} -u +'%Y.%m.%d' _VCS_PKGVERSION= ${_VCS_PKGVERSION_CMD:sh} _VCS_DISTDIR= ${DISTDIR}/${VCS_TYPE}-packages # Generation of repository-specific variables # # determine appropriate checkout date or tag .for repo in ${VCS_REPOSITORIES} VCS_MODULE.${repo}?= ${repo} . if defined(VCS_TAG.${repo}) _VCS_TAG_FLAG.${repo}= -r${VCS_TAG.${repo}} _VCS_TAG.${repo}= ${VCS_TAG.${repo}} . elif defined(VCS_TAG) _VCS_TAG_FLAG.${repo}= -r${VCS_TAG} _VCS_TAG.${repo}= ${VCS_TAG} . elif defined(CHECKOUT_DATE) _VCS_TAG_FLAG.${repo}= -r{${CHECKOUT_DATE}} _VCS_TAG.${repo}= {${CHECKOUT_DATE}} . else #_VCS_TAG_FLAG.${repo}= -r{${_VCS_TODAY} 00:00 +0000} # for name of DISTFILE (only) _VCS_TAG.${repo}= ${_VCS_TODAY} . endif _VCS_UPDATE_LOG.${repo}= /tmp/${VCS_TYPE}-${VCS_MODULE.${repo}}-update # Cache support: . if !defined(NO_VCS_CACHE.${repo}) \ || defined(NO_VCS_CACHE.${repo}) && empty(NO_VCS_CACHE.${repo}:M[Yy][Ee][Ss]) # cache file name . if !defined(VCS_DISTBASE.${repo}) VCS_DISTBASE.${repo}= ${VCS_MODULE.${repo}} . endif _VCS_DISTFILE.${repo}= ${VCS_DISTBASE.${repo}}-${_VCS_TAG.${repo}}.tar.gz # command to extract cache file _VCS_EXTRACT_CACHED.${repo}= \ p="$$(ls -td ${_VCS_DISTDIR}/${VCS_DISTBASE.${repo}}-* | head -n 1)"; \ if [ -n "$$p" ]; then \ ${STEP_MSG} "(1) Extracting cached ${VCS_TYPE} archive \"""$$p\"."; \ pax -r -z -f "$$p"; \ else \ ${STEP_MSG} "(1a) No cache file found."; \ fi _VCS_CHECK_UPDATE.${repo}= \ "$$(grep ^[ADMU] ${_VCS_TMP_RESULT.${repo}} | head -n 1)" _VCS_CHECKOUT_CMD.${repo}= \ ${STEP_MSG} "(2a) Downloading "${VCS_MODULE.${repo}:Q}" from "${VCS_ROOT.${repo}:Q}"."; _VCS_CHECKOUT_CMD.${repo}+= ${SETENV} ${_VCS_ENV} _VCS_CHECKOUT_CMD.${repo}+= ${_VCS_CMD} _VCS_CHECKOUT_CMD.${repo}+= checkout _VCS_CHECKOUT_CMD.${repo}+= ${_VCS_CHECKOUT_FLAGS} _VCS_CHECKOUT_CMD.${repo}+= ${_VCS_TAG_FLAG.${repo}:Q} _VCS_CHECKOUT_CMD.${repo}+= ${_VCS_FLAGS} _VCS_CHECKOUT_CMD.${repo}+= ${VCS_ROOT.${repo}:Q} _VCS_CHECKOUT_CMD.${repo}+= ${VCS_MODULE.${repo}:Q} _VCS_UPDATE_CMD.${repo}= \ ${STEP_MSG} "(2b) Updating "${VCS_MODULE.${repo}:Q}" from "${VCS_ROOT.${repo}:Q}"."; _VCS_UPDATE_CMD.${repo}+= ${SETENV} ${_VCS_ENV} _VCS_UPDATE_CMD.${repo}+= ${_VCS_CMD} _VCS_UPDATE_CMD.${repo}+= update _VCS_UPDATE_CMD.${repo}+= ${VCS_MODULE.${repo}:Q} # create cache archive _VCS_CREATE_CACHE.${repo}= \ ${STEP_MSG} "(5) Creating cached Bazaar archive "${_VCS_DISTFILE.${repo}:Q}"."; \ ${MKDIR} ${_VCS_DISTDIR:Q}; \ pax -w -z -f ${_VCS_DISTDIR}/${_VCS_DISTFILE.${repo}:Q} ${VCS_MODULE.${repo}:Q} . else # I have to set them to noop: _VCS_DISTFILE.${repo}= : _VCS_EXTRACT_CACHED.${repo}= : _VCS_CREATE_CACHE.${repo}= : . endif .endfor pre-extract: do-vcs-extract do-vcs-extract: .PHONY .if defined(VCS_CERTS) && !empty(VCS_CERTS) ${RUN}${MKDIR} -p ${_VCS_CONFIG_DIR}/auth/${VCS_TYPE}.ssl.server ${RUN}${CP} ${VCS_CERTS} ${_VCS_CONFIG_DIR}/auth/${VCS_TYPE}.ssl.server .endif .for repo in ${VCS_REPOSITORIES} ${RUN} cd ${WRKDIR}; \ if [ ! -d ${_VCS_DISTDIR} ]; then mkdir -p ${_VCS_DISTDIR:Q}; fi; \ ${_VCS_EXTRACT_CACHED.${repo}}; \ if [ -n "$$p" -o -d */.bzr ]; then \ ${_VCS_UPDATE_CMD.${repo}} > ${_VCS_UPDATE_LOG.${repo}} 2>&1; \ else \ ${_VCS_CHECKOUT_CMD.${repo}} > ${_VCS_UPDATE_LOG.${repo}}; \ if [ ! -z ${_VCS_UPDATE_LOG.${repo}} ];then \ if [ -n ${_VCS_CHECK_UPDATE.${repo}} ]; then \ ${_VCS_CREATE_CACHE.${repo}}; \ else \ ${STEP_MSG} "(6a) Skip creating cache file for no update."; \ fi; \ else \ if [ -z ${_VCS_UPDATE_LOG.${repo}} -a ${VCS_TYPE} = 'bzr']; then \ ${_VCS_CREATE_CACHE.${repo}}; \ fi; \ ${STEP_MSG} "(6b) Skip creating cache file."; \ fi; \ fi .endfor .endif # To be tested: # no any cache file yet -> write cache # cache file exist and no update -> no write cache # cache file exist, file added/delete -> write cache # cache file exist and update there -> write cache