On 7/24/18 10:49 PM, Eric Blake wrote:
> On 07/24/2018 03:40 PM, Bernhard Voelker wrote:
>> On 07/24/2018 04:08 PM, Eric Blake wrote:
>>> On 07/19/2018 12:22 PM, Bernhard Voelker wrote:
>>>> On 06/25/2018 06:48 PM, Pádraig Brady wrote:
>>>>> `make gnulib-sync` would definitely be worth doing.
>>>>
>>>> Done in the attached.  WDYT?
>>>
>>> Can we move this to gnulib's maint.mk for sharing with other projects?
>>
>> Ideally yes - the problem is that the list of files to sync from gnulib
>> may be different for each project, and even the basenames of some
>> file sometimes do not match:
>>
>>> +       && cp -v gnulib/doc/COPYINGv3 COPYING \
>>
>> Any idea how to work around that?
> 
> As long as any customizations can be characterized into cfg.mk overrides 
> and the generic rule in maint.mk knows how to honor those overrides, it 
> seems like it should work. But I'm not sure what data representation 
> would be easiest to manipulate into those overrides.

Good idea - see attached 2 patches:

* gnulib patch to provide the 'gnulib-sync' target:
  '0001-maintainer-makefile-provide-make-target-to-update-gn.patch'
  [PATCH] maintainer-makefile: provide make target to update gnulib to latest

* coreutils patch to override the hook to copy some extra files after pulling:
  '0001-maint-prepare-for-using-make-gnulib-sync.patch'
  [PATCH] maint: prepare for using "make gnulib-sync"

With this, 'make gnulib-sync' looks like this:

  $ make gnulib-sync
  + git -C gnulib pull origin master
  From git://git.sv.gnu.org/gnulib
   * branch                master     -> FETCH_HEAD
  Already up to date.
  + make cu_GNULIB_SYNC_HOOK
  make[1]: Entering directory '/home/berny/git/coreutils'
  + cp gnulib/doc/COPYINGv3 COPYING
  + cp gnulib/build-aux/bootstrap bootstrap
  + cp gnulib/tests/init.sh tests/init.sh
  make[1]: Leaving directory '/home/berny/git/coreutils'
  + git status --short --untracked-files=no
   M COPYING
   M bootstrap
   M tests/init.sh

WDYT?

> A different approach would be using git symlinks that point into the git 
> submodule (then your local file is always up-to-date if your submodule 
> is up-to-date).

It works for most files, but I don't think e.g. COPYING should only be a 
symlink.

Have a nice day,
Berny
>From 33a20fc9b2995128805c439c87008c1c86ce55b3 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Thu, 13 Dec 2018 00:45:30 +0100
Subject: [PATCH] maint: prepare for using "make gnulib-sync"

* cfg.mk (cu_GNULIB_SYNC_HOOK): Add target to copy files from gnulib.
(_gl_GNULIB_SYNC_HOOK): Export variable to override gnulib's empty
default.
With this, "make gnulib-sync" (alias "update-gnulib-to-latest")
will copy the files COPYING, bootstrap and tests/init.sh from the
gnulib submodule after pulling.
---
 cfg.mk | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/cfg.mk b/cfg.mk
index a02ed2748..ff5b3a0e7 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -50,6 +50,16 @@ export XZ_OPT = -8e
 
 old_NEWS_hash = 79133b52351baf64693804eed58a0cbc
 
+# Override gnulib to copy some files from there during 'make gnulib-sync'.
+cu_GNULIB_SYNC_HOOK:
+	@{ cd $(srcdir) \
+	    && set -x \
+	    && cp gnulib/doc/COPYINGv3 COPYING \
+	    && cp gnulib/build-aux/bootstrap bootstrap \
+	    && cp gnulib/tests/init.sh tests/init.sh \
+	; }
+export _gl_GNULIB_SYNC_HOOK = cu_GNULIB_SYNC_HOOK
+
 # Add an exemption for sc_makefile_at_at_check.
 _makefile_at_at_check_exceptions = ' && !/^cu_install_prog/ && !/dynamic-dep/'
 
-- 
2.19.2

>From 5a07e65cd38fa949294e384fd5635408df4f2fab Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Thu, 13 Dec 2018 00:35:23 +0100
Subject: [PATCH] maintainer-makefile: provide make target to update gnulib to
 latest

* top/maint.mk (gnulib-sync, update-gnulib-to-latest): Add targets,
using the following hook variable to optionally e.g copy some files
from gnulib into the own package after pulling.
(_gl_GNULIB_SYNC_HOOK): Add hook variable to be
optionally overridden in 'cfg.mk'.  Default to ...
(_gl_GNULIB_SYNC_HOOK_empty): ... this empty target.
---
 ChangeLog    | 10 ++++++++++
 top/maint.mk | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index e3c929b52..313eb2a83 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-10-28  Bernhard Voelker  <[email protected]>
+
+	maintainer-makefile: provide make target to update gnulib to latest
+	* top/maint.mk (gnulib-sync, update-gnulib-to-latest): Add targets,
+	using the following hook variable to optionally e.g copy some files
+	from gnulib into the own package after pulling.
+	(_gl_GNULIB_SYNC_HOOK): Add hook variable to be
+	optionally overridden in 'cfg.mk'.  Default to ...
+	(_gl_GNULIB_SYNC_HOOK_empty): ... this empty target.
+
 2018-12-13  Bruno Haible  <[email protected]>
 
 	select tests: Avoid test failure on Cygwin.
diff --git a/top/maint.mk b/top/maint.mk
index 4889ebacc..b90a776dc 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -1571,6 +1571,42 @@ update-copyright:
 	  $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \
 	  | $(update-copyright-env) xargs $(srcdir)/$(_build-aux)/$@
 
+# 'gnulib-sync': Update gnulib to latest.
+# Prerequisite: the working tree of both your package and gnulib are clean
+# (which is checked first).
+# To optionally copy some additional files from there right after the pull,
+# override the '_gl_GNULIB_SYNC_HOOK' make variable in your 'cfg.mk' with
+# the name of the make target which is then actually taking over the files.
+# This can be useful for files you need to have physically in your repository,
+# like e.g. 'COPYING' (for legal reasons) or 'bootstrap'.
+# Example:
+#   my_GNULIB_SYNC_HOOK:
+#   	@{ cd $(srcdir) \
+#   	    && cp gnulib/doc/COPYINGv3 COPYING \
+#   	    && cp gnulib/build-aux/bootstrap bootstrap \
+#   	; }
+#   export _gl_GNULIB_SYNC_HOOK = my_GNULIB_SYNC_HOOK
+#
+# Declare the default hook target (empty).
+.PHONY: _gl_GNULIB_SYNC_HOOK_empty
+_gl_GNULIB_SYNC_HOOK ?= _gl_GNULIB_SYNC_HOOK_empty
+_gl_GNULIB_SYNC_HOOK_empty:
+
+.PHONY: gnulib-sync update-gnulib-to-latest
+gnulib-sync update-gnulib-to-latest:
+	@{ cd $(srcdir) \
+	    && { printf 'gnulib: ' && git -C gnulib describe --always --dirty \
+		  && printf 'your package: ' && git describe --always --dirty \
+		  || echo dirty; \
+		  } | grep 'dirty$$' \
+			&& { echo "$@: error: tree is dirty" >&2; exit 1; } \
+			|| : \
+	    && set -x \
+	    && git -C gnulib pull origin master \
+	    && $(MAKE) $(_gl_GNULIB_SYNC_HOOK) \
+	    && git status --short --untracked-files=no \
+	; }
+
 # This tight_scope test is skipped with a warning if $(_gl_TS_headers) is not
 # overridden and $(_gl_TS_dir)/Makefile.am does not mention noinst_HEADERS.
 
-- 
2.19.2

Reply via email to