################################################################################
#
# bzr.cygclass - functions for building packages from BZR checkouts
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006-2016 Yaakov Selkowitz
# Provided by the Cygwin Ports project <http://sourceware.org/cygwinports/>
#
# cygport is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cygport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cygport.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

#****h* Cygclasses/bzr.cygclass
#  SYNOPSIS
#  BZR_URI="..."
#  [BZR_REV="..."]
#  inherit bzr
#  DESCRIPTION
#  Developed by Canonical Ltd., the company behind Ubuntu Linux,
#  |html <a href="http://bazaar.canonical.com/">Bazaar</a> is a distributed
#  version control system which is most commonly used by software hosted on
#  |html <a href="http://launchpad.net/projects">Launchpad</a>.
#
#  This cygclass creates source tarballs from Bazaar checkouts.
#  NOTES
#  This cygclass sets a special SRC_URI for the tarball it creates.  If
#  additional sources are required, be sure to _add_ to SRC_URI rather than
#  outright setting it.
#  REQUIRES
#  bzr
#****

# is this truly needed?
BZR_MODULE=${BZR_MODULE:-${ORIG_PN:-${PN}}}

bzr_tarball="${BZR_MODULE}-bzr-${PV}.tar.bz2"

SRC_URI="${bzr_tarball} "
SRC_DIR="${BZR_MODULE}"

bzr_fetch() {
	local bzr_rev

	check_prog_req bzr

#****v* bzr.cygclass/BZR_URI
#  DESCRIPTION
#  URI of upstream Bazaar repository/branch
#  NOTES
#  This variable is required when inherit()ing bzr.
#
#  Software hosted on Launchpad will have a special URI beginning with "lp:";
#  see `bzr help launchpad' for details.
#****
	if ! defined BZR_URI
	then
		error "BZR_URI must be defined"
	fi

#****v* bzr.cygclass/BZR_REV
#  DESCRIPTION
#  Specific revision to checkout
#  NOTES
#  This variable is optional.  If unset, the latest revision for the branch
#  specified in BZR_URI will be fetched.
#
#  See `bzr help revisionspec' for possible forms of revision identifiers.
#****
	if defined BZR_REV
	then
		bzr_rev="-r ${BZR_REV}"
	fi

	# T likely doesn't exist at this point, so create it first
	mkdir -p ${T}
	cd ${T}
	verbose bzr branch ${BZR_URI} ${BZR_MODULE} ${bzr_rev}

	tar ${_tar_bz2_flag}cf ${top}/${bzr_tarball} --exclude-vcs ${BZR_MODULE}
}

readonly -f bzr_fetch
