pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

mk/git-package.mk: optimize for single-repository case



Module Name:	pkgsrc-wip
Committed By:	Roland Illig <rillig%NetBSD.org@localhost>
Pushed By:	rillig
Date:		Sun Feb 25 15:33:29 2018 +0000
Changeset:	0d8eff801efb0033ed5b5ce77bc8a5509ba5d0c5

Modified Files:
	mk/git-package.mk

Log Message:
mk/git-package.mk: optimize for single-repository case

In the majority of cases, a package corresponds to a single Git
repository. Therefore, having three separate lines in the package
Makefile is only overhead. The only line that such a package needs is

    GIT_REPO=       git://git%github.com@localhost/NetBSD/pkgsrc

This automatically sets GIT_REPOSITORIES, GIT_MODULE and WRKSRC.

This change is completely backwards-compatible, allowing the affected
packages to be migrated on a case-to-case basis.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=0d8eff801efb0033ed5b5ce77bc8a5509ba5d0c5

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 mk/git-package.mk | 120 +++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 83 insertions(+), 37 deletions(-)

diffs:
diff --git a/mk/git-package.mk b/mk/git-package.mk
index 15ceb1d95f..2a90439d05 100644
--- a/mk/git-package.mk
+++ b/mk/git-package.mk
@@ -1,45 +1,65 @@
 # $NetBSD$
 #
-# This file provides simple access to git repositories, so that packages
-# can be created from git instead of from released tarballs.
+# This file provides simple access to Git repositories, so that packages
+# can be created from Git instead of from released tarballs.
 #
-# A package using this file shall define the following variables:
+# Package-settable variables:
 #
-#	GIT_REPOSITORIES
-#		A list of unique identifiers /id/ for which appropriate
-#		GIT_REPO must be defined.
+# GIT_REPO
+#	The URL of the Git repository.
 #
-#	GIT_REPO.${id}
-#		The git repository.
+#	Examples:
+#		https://github.com/NetBSD/pkgsrc
+#		git://git%github.com@localhost:NetBSD/pkgsrc.git
+#		git%github.com@localhost:NetBSD/pkgsrc.git
 #
-#		Examples:
-#			https://github.com/NetBSD/pkgsrc
-#			git://git%github.com@localhost:NetBSD/pkgsrc.git
-#			git%github.com@localhost:NetBSD/pkgsrc.git
+# GIT_MODULE (optional)
+#	The name of the Git module.
 #
-# It may define the following variables:
+#	This is where the repository gets extracted.
 #
-#	GIT_BRANCH.${id}
-#		The branch to check out.
+#	Default:
+#		For the GIT_MODULE variable, the default value is derived
+#		from the last path component of GIT_REPO (so for
+#		git://git%github.com@localhost:NetBSD/pkgsrc.git, it becomes pkgsrc).
+#		For the GIT_MODULE.${repo} variables, the default is ${repo}.
 #
-#		This should seldomly be used since it prevents the build
-#		from being reproducible. Prefer a tag or a revision
-#		instead.
+# GIT_BRANCH (optional)
+#	The branch to check out.
 #
-#	GIT_REVISION.${id}
-#		The revision to check out.
+#	This should seldomly be used since it prevents the build from being
+#	reproducible. Prefer a tag or a revision instead.
 #
-#		Example: 8a311b3069ee79731eec38ca13eb13772cc49223
+# GIT_REVISION (optional)
+#	The revision to check out.
 #
-#	GIT_TAG.${id}
-#		The tag to check out.
+#	Example: 8a311b3069ee79731eec38ca13eb13772cc49223
 #
-#		Example: v1.0.0
+# GIT_TAG (optional)
+#	The tag to check out.
 #
-#	GIT_ENV.${id}
-#		The environment variables for the git command.
+#	Example: v1.0.0
 #
-#		Example: GIT_SSL_NO_VERIFY=true
+# GIT_ENV (optional)
+#	The environment variables for the git commands.
+#
+#	Example: GIT_SSL_NO_VERIFY=true
+#
+# GIT_REPOSITORIES (optional)
+#	For packages that need multiple Git repositories, this is the list
+#	of repository IDs. Each of these repositories is configured separately,
+#	using parameterized variables like GIT_REPO.${repo} instead of the
+#	above GIT_REPO.
+#
+#	Example:
+#
+#		GIT_REPOSITORIES=	first second
+#		GIT_MODULE.first=	first
+#		GIT_REPO.first=		git://git%github.com@localhost:NetBSD/pkgsrc.git
+#		GIT_REVISION.first=	8a311b3069ee79731eec38ca13eb13772cc49223
+#		GIT_MODULE.second=	second
+#		GIT_REPO.second=	git://git%github.com@localhost:NetBSD/pkgsrc.git
+#		GIT_BRANCH.second=	master
 #
 # Keywords: git github
 
@@ -59,6 +79,18 @@ PKGREVISION?=		${_GIT_PKGVERSION:S/.//g}
 # End of the interface part. Start of the implementation part.
 #
 
+# The standard case of a single repository
+.if defined(GIT_REPO)
+GIT_REPOSITORIES+=	_default
+.  for varbase in GIT_REPO GIT_BRANCH GIT_REVISION GIT_TAG GIT_ENV
+.    if defined(${varbase})
+${varbase}._default=	${${varbase}}
+.    endif
+.  endfor
+GIT_MODULE._default?=	${GIT_REPO:T:.git=}
+WRKSRC?=		${WRKDIR}/${GIT_MODULE._default}
+.endif
+
 #
 # Input validation
 #
@@ -74,6 +106,20 @@ PKG_FAIL_REASON+=	"[git-package.mk] GIT_REPO."${repo:Q}" must be set."
 .  endif
 .endfor
 
+# Debug info for show-all and show-all-git
+_VARGROUPS+=		git
+_PKG_VARS.git=		GIT_REPOSITORIES
+_PKG_VARS.git+=		GIT_REPO GIT_MODULE GIT_BRANCH GIT_REVISION GIT_TAG GIT_ENV
+.for repo in ${GIT_REPOSITORIES}
+.  for pkgvar in GIT_REPO GIT_MODULE GIT_BRANCH GIT_REVISION GIT_TAG GIT_ENV
+_PKG_VARS.git+=		${pkgvar}.${repo}
+.  endfor
+.  for sysvar in _GIT_FLAG _GIT_DISTFILE
+_SYS_VARS.git+=		${sysvar}.${repo}
+.  endfor
+.endfor
+_SYS_VARS.git=		DISTFILES PKGREVISION WRKSRC
+
 #
 # Internal variables
 #
@@ -121,21 +167,21 @@ _GIT_DISTFILE.${repo}=	${PKGBASE}-${GIT_MODULE.${repo}}-gitarchive.tar.gz
 #   command to extract cache file
 _GIT_EXTRACT_CACHED.${repo}=	\
 	if [ -f ${_GIT_DISTDIR}/${_GIT_DISTFILE.${repo}:Q} ]; then		\
-	  ${STEP_MSG} "Extracting cached GIT archive "${_GIT_DISTFILE.${repo}:Q}"."; \
+	  ${STEP_MSG} "Extracting cached Git archive "${_GIT_DISTFILE.${repo}:Q}"."; \
 	  gzip -d -c ${_GIT_DISTDIR}/${_GIT_DISTFILE.${repo}:Q} | pax -r;	\
 	fi
 
 #   create cache archive
 _GIT_CREATE_CACHE.${repo}=	\
-	${STEP_MSG} "Creating cached GIT archive "${_GIT_DISTFILE.${repo}:Q}"."; \
+	${STEP_MSG} "Creating cached Git archive "${_GIT_DISTFILE.${repo}:Q}"."; \
 	${MKDIR} ${_GIT_DISTDIR:Q};					\
 	pax -w ${GIT_MODULE.${repo}:Q} | gzip > ${_GIT_DISTDIR}/${_GIT_DISTFILE.${repo}:Q}.tmp;	\
 	${MV} '${_GIT_DISTDIR}/${_GIT_DISTFILE.${repo}:Q}.tmp' '${_GIT_DISTDIR}/${_GIT_DISTFILE.${repo}:Q}'
 
-#   fetch git repo or update cached one
+#   fetch Git repo or update cached one
 _GIT_FETCH_REPO.${repo}=	\
 	if [ ! -d ${GIT_MODULE.${repo}:Q} ]; then				\
-	  ${STEP_MSG} "Cloning GIT archive "${GIT_MODULE.${repo}:Q}".";		\
+	  ${STEP_MSG} "Cloning Git archive "${GIT_MODULE.${repo}:Q}".";		\
 	  ${SETENV} ${_GIT_ENV.${repo}} ${_GIT_CMD}				\
 	    clone ${_GIT_CLONE_FLAGS.${repo}}					\
 	    ${GIT_REPO.${repo}:Q} ${GIT_MODULE.${repo}:Q};			\
@@ -143,10 +189,10 @@ _GIT_FETCH_REPO.${repo}=	\
 	${STEP_MSG} "Fetching remote branches of "${_GIT_FLAG.${repo}:Q}".";	\
 	${SETENV} ${_GIT_ENV.${repo}} ${_GIT_CMD} -C ${GIT_MODULE.${repo}:Q}	\
 	  remote set-branches origin '*';					\
-	${STEP_MSG} "Updating GIT archive "${GIT_MODULE.${repo}:Q}".";		\
+	${STEP_MSG} "Updating Git archive "${GIT_MODULE.${repo}:Q}".";		\
 	${SETENV} ${_GIT_ENV.${repo}} ${_GIT_CMD} -C ${GIT_MODULE.${repo}:Q}	\
 	  fetch ${_GIT_FETCH_FLAGS.${repo}};					\
-	${STEP_MSG} "Checking out GIT "${_GIT_FLAG.${repo}:Q}".";		\
+	${STEP_MSG} "Checking out Git "${_GIT_FLAG.${repo}:Q}".";		\
 	${SETENV} ${_GIT_ENV.${repo}} ${_GIT_CMD} -C ${GIT_MODULE.${repo}:Q}	\
 	  checkout ${_GIT_CHECKOUT_FLAGS} ${_GIT_FLAG.${repo}:Q};		\
 	${STEP_MSG} "Updating submodules of "${_GIT_FLAG.${repo}:Q}".";		\
@@ -158,12 +204,12 @@ pre-extract: do-git-extract
 
 .PHONY: do-git-extract
 do-git-extract:
-.for _repo_ in ${GIT_REPOSITORIES}
+.for repo in ${GIT_REPOSITORIES}
 	${RUN} cd ${WRKDIR};							\
 	if [ ! -d ${_GIT_DISTDIR:Q} ]; then mkdir -p ${_GIT_DISTDIR:Q}; fi;	\
-	${_GIT_EXTRACT_CACHED.${_repo_}};					\
-	${_GIT_FETCH_REPO.${_repo_}};						\
-	${_GIT_CREATE_CACHE.${_repo_}};
+	${_GIT_EXTRACT_CACHED.${repo}};						\
+	${_GIT_FETCH_REPO.${repo}};						\
+	${_GIT_CREATE_CACHE.${repo}};
 
 .endfor
 


Home | Main Index | Thread Index | Old Index