From a516d920efaeb18de81bc38c70064b7c9a111453 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Tue, 5 Jan 2016 01:00:41 +0300 Subject: reimplement patch-tool-mxe in Makefile fix #1063 --- Makefile | 83 ++++++++++++++++++++++++++++++++++++++- tools/patch-tool-mxe | 109 ++------------------------------------------------- 2 files changed, 86 insertions(+), 106 deletions(-) diff --git a/Makefile b/Makefile index ff76dda..23ae9d3 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ REQUIREMENTS := autoconf automake autopoint bash bison bzip2 flex \ PREFIX := $(PWD)/usr LOG_DIR := $(PWD)/log +GITS_DIR := $(PWD)/gits GIT_HEAD := $(shell git rev-parse HEAD) TIMESTAMP := $(shell date +%Y%m%d_%H%M%S) PKG_DIR := $(PWD)/pkg @@ -154,7 +155,8 @@ endef PRELOAD_VARS := LD_PRELOAD DYLD_FORCE_FLAT_NAMESPACE DYLD_INSERT_LIBRARIES # use a minimal whitelist of safe environment variables -ENV_WHITELIST := PATH LANG MAKE% MXE% %PROXY %proxy LD_LIBRARY_PATH $(PRELOAD_VARS) ACLOCAL_PATH +# HOME is needed for ~/.gitconfig for patch-tool-mxe +ENV_WHITELIST := PATH HOME LANG MAKE% MXE% %PROXY %proxy LD_LIBRARY_PATH $(PRELOAD_VARS) ACLOCAL_PATH unexport $(filter-out $(ENV_WHITELIST),$(shell env | cut -d '=' -f1)) # disable wine with readonly directory (created by mxe-conf) @@ -793,3 +795,82 @@ versions.json: $(foreach PKG,$(PKGS), $(TOP_DIR)/src/$(PKG).mk) "$($(PKG)_VERSION)",';)} >> $@ @echo ' "": null' >> $@ @echo '}' >> $@ + +# for patch-tool-mxe + +GIT_DIR = $(if $(patsubst .,,$($(1)_SUBDIR)) \ + ,$(GITS_DIR)/$($(1)_SUBDIR),$(GITS_DIR)/$(1)) + +GIT_CMD = git \ + --work-tree='$(call GIT_DIR,$(1))' \ + --git-dir='$(call GIT_DIR,$(1))'/.git + +define INIT_GIT + # unpack to gits/tmp/pkg + rm -rf '$(GITS_DIR)/tmp' + mkdir -p '$(GITS_DIR)/tmp/$(1)' + cd '$(GITS_DIR)/tmp/$(1)' && $(call UNPACK_PKG_ARCHIVE,$(1)) + # if PKG_SUBDIR is ".", the following will move gits/tmp/pkg + mv '$(abspath $(GITS_DIR)/tmp/$(1)/$($(1)_SUBDIR))' '$(call GIT_DIR,$(1))' + rm -rf '$(GITS_DIR)/tmp' + # initialize git + $(call GIT_CMD,$(1)) init + $(call GIT_CMD,$(1)) add -A + $(call GIT_CMD,$(1)) commit -m "init" + $(call GIT_CMD,$(1)) tag dist +endef + +init-git-%: download-only-% + $(if $(call set_is_member,$*,$(PKGS)), \ + $(if $(wildcard $(call GIT_DIR,$*)), \ + $(error $(call GIT_DIR,$*) already exists), \ + $(call INIT_GIT,$*)), \ + $(error Package $* not found in index.html)) + +PATCH_NAME = 1-fixes + +# can't use PKG_PATCHES here, because it returns existing patches +# while export-patch creates new patch +PATCH_BY_NAME = $(patsubst %.mk,%-$(2).patch,$(PKG_MAKEFILES)) + +define IMPORT_PATCH + cd '$(call GIT_DIR,$(1))' \ + && cat '$(PATCH_BY_NAME)' \ + | sed '/^From/,$$ !d' \ + | sed s/'^From: MXE'/"From: fix@me"/'g;' \ + | $(call GIT_CMD,$(1)) am --keep-cr +endef + +import-patch-%: + $(if $(call set_is_member,$*,$(PKGS)), \ + $(if $(wildcard $(call GIT_DIR,$*)), \ + $(call IMPORT_PATCH,$*,$(PATCH_NAME)), \ + $(error $(call GIT_DIR,$*) does not exist)), \ + $(error Package $* not found in index.html)) + +define EXPORT_PATCH + cd '$(call GIT_DIR,$(1))' \ + && ( \ + echo 'This file is part of MXE.'; \ + echo 'See index.html for further information.'; \ + echo ''; \ + echo 'Contains ad hoc patches for cross building.'; \ + echo ''; \ + $(call GIT_CMD,$(1)) format-patch \ + --no-numbered \ + -p \ + --no-signature \ + --stdout \ + --text \ + dist..HEAD \ + | sed 's/^From [0-9a-f]\{40\} /From 0000000000000000000000000000000000000000 /' \ + | sed 's/^index .......\.\......../index 1111111..2222222/' \ + ) > '$(PATCH_BY_NAME)' +endef + +export-patch-%: + $(if $(call set_is_member,$*,$(PKGS)), \ + $(if $(wildcard $(call GIT_DIR,$*)), \ + $(call EXPORT_PATCH,$*,$(PATCH_NAME)), \ + $(error $(call GIT_DIR,$*) does not exist)), \ + $(error Package $* not found in index.html)) diff --git a/tools/patch-tool-mxe b/tools/patch-tool-mxe index ab021cb..cdc9614 100755 --- a/tools/patch-tool-mxe +++ b/tools/patch-tool-mxe @@ -10,122 +10,21 @@ patch_name=${3:-1-fixes} setupEnv() { # MXE directory export mxedir=$(cd $(dirname $0) && cd .. && pwd) - - # directory for unpacked tarballs/git repos - export gitsdir=${mxedir}/gits - - mkdir -p ${gitsdir} - - - export pkg_version=`grep '^$(PKG)_VERSION' $mxedir/src/$pkg.mk | \ - sed 's/.*:= \(.*\)/\1/'` - - export pkg_short_version=`echo $pkg_version | sed s/'\(.*\)\.[^.]*$'/'\1'/` - - export pkg_subdir=`grep '^$(PKG)_SUBDIR' $mxedir/src/$pkg.mk | \ - sed 's/.*:= \(.*\)/\1/' | \ - sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \ - sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \ - sed s/'$(PKG)'/$pkg/;` - - export pkg_file=`grep '^$(PKG)_FILE\>' $mxedir/src/$pkg.mk | \ - sed 's/.*:= \(.*\)/\1/' | \ - sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \ - sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \ - sed s/'$($(PKG)_SUBDIR)'/$pkg_subdir/ | \ - sed s/'$(PKG)'/$pkg/;` - - #echo $pkg - #echo $pkg_version - #echo $pkg_subdir - #echo $pkg_file - } -# init + function init_git { setupEnv - cd $gitsdir - - if [ -d $gitsdir/$pkg_subdir ]; then - echo "Error: $gitsdir/$pkg_subdir already exists. Cancelling init." >&2 - exit 1 - fi - - echo "Checking for cached $pkg_file" - if [ ! -f $mxedir/pkg/$pkg_file ]; then - make -C "$mxedir" download-only-$pkg - echo "Building the mxe Makefile target 'download-only-$pkg' to get missing file" - if [ ! $? -eq 0 ]; then - echo "Could not build target download-only-$pkg - cancelling init." >&2 - exit 1 - fi - fi - - echo "Unpacking archive..." - (echo $pkg_file | grep "\.tar\.gz") || (echo $pkg_file | grep "\.tgz") \ - >> /dev/null && tar xf $mxedir/pkg/$pkg_file - (echo $pkg_file | grep "\.tar\.bz2") || (echo $pkg_file | grep "\.tbz2") \ - >> /dev/null && tar xf $mxedir/pkg/$pkg_file - (echo $pkg_file | grep "\.tar\.xz") || (echo $pkg_file | grep "\.txz") \ - >> /dev/null && xz -dc $mxedir/pkg/$pkg_file | tar xf - - echo $pkg_file | grep "\.zip" >> /dev/null && unzip $mxedir/pkg/$pkg_file >> /dev/null - - echo "Initializing repo and adding all as first commit" - cd $gitsdir/$pkg_subdir && \ - (git init; git add -A; git commit -m "init") > /dev/null - - echo "Creating 'dist' tag for distribution tarball state" - git tag dist - - echo "Repository ready in $gitsdir/$pkg_subdir" + make -C $mxedir init-git-$pkg } function export_patch { setupEnv - if [ ! -d $gitsdir/$pkg_subdir ]; then - echo "Error: $gitsdir/$pkg_subdir does not exist, so cannot export patches. Cancelling export." >&2 - exit 1 - fi - - cd $gitsdir/$pkg_subdir && \ - ( - echo 'This file is part of MXE.' - echo 'See index.html for further information.' - echo '' - echo 'Contains ad hoc patches for cross building.' - echo '' - git format-patch \ - --no-numbered \ - -p \ - --no-signature \ - --stdout \ - --text \ - dist..HEAD | \ - sed 's/^From [0-9a-f]\{40\} /From 0000000000000000000000000000000000000000 /' | \ - sed 's/^index .......\.\......../index 1111111..2222222/' - ) > $mxedir/src/${pkg}-${patch_name}.patch && \ - echo "Generated ${mxedir}/src/${pkg}-${patch_name}.patch" + make -C $mxedir export-patch-$pkg PATCH_NAME=${patch_name} } function import_patch { setupEnv - if [ ! -d $gitsdir/$pkg_subdir ]; then - echo "Error: $gitsdir/$pkg_subdir does not exist, so cannot import patches. Cancelling import - try 'init' first." >&2 - exit 1 - fi - - if [ -f ${mxedir}/src/${pkg}-${patch_name}.patch ]; then - cd $gitsdir/$pkg_subdir && \ - cat ${mxedir}/src/${pkg}-${patch_name}.patch | \ - sed '/^From/,$ !d' | \ - sed s/'^From: MXE'/"From: fix@me"/'g;' | \ - git am --keep-cr && \ - echo "Imported ${mxedir}/src/${pkg}-${patch_name}.patch" - else - echo "patch file ${mxedir}/src/${pkg}-${patch_name}.patch not found." - echo "Cancelling import." >&2 - exit 1 - fi + make -C $mxedir import-patch-$pkg PATCH_NAME=${patch_name} } case "$cmd" in -- cgit v0.12 From adb07e2153696a9ef4c9b4a8cc931054e0788fdf Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Tue, 5 Jan 2016 17:23:38 +0300 Subject: patch-tool-mxe can import all patches of a package --- Makefile | 14 +++++++++++--- tools/patch-tool-mxe | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 23ae9d3..e91f216 100644 --- a/Makefile +++ b/Makefile @@ -835,16 +835,24 @@ PATCH_BY_NAME = $(patsubst %.mk,%-$(2).patch,$(PKG_MAKEFILES)) define IMPORT_PATCH cd '$(call GIT_DIR,$(1))' \ - && cat '$(PATCH_BY_NAME)' \ + && cat '$(2)' \ | sed '/^From/,$$ !d' \ | sed s/'^From: MXE'/"From: fix@me"/'g;' \ - | $(call GIT_CMD,$(1)) am --keep-cr + | $(call GIT_CMD,$(1)) am --keep-cr ; endef import-patch-%: $(if $(call set_is_member,$*,$(PKGS)), \ $(if $(wildcard $(call GIT_DIR,$*)), \ - $(call IMPORT_PATCH,$*,$(PATCH_NAME)), \ + $(call IMPORT_PATCH,$*,$(call PATCH_BY_NAME,$*,$(PATCH_NAME))), \ + $(error $(call GIT_DIR,$*) does not exist)), \ + $(error Package $* not found in index.html)) + +import-all-patches-%: + $(if $(call set_is_member,$*,$(PKGS)), \ + $(if $(wildcard $(call GIT_DIR,$*)), \ + $(foreach PKG_PATCH,$(call PKG_PATCHES,$*), \ + $(call IMPORT_PATCH,$*,$(PKG_PATCH))), \ $(error $(call GIT_DIR,$*) does not exist)), \ $(error Package $* not found in index.html)) diff --git a/tools/patch-tool-mxe b/tools/patch-tool-mxe index cdc9614..b7720e6 100755 --- a/tools/patch-tool-mxe +++ b/tools/patch-tool-mxe @@ -27,6 +27,11 @@ function import_patch { make -C $mxedir import-patch-$pkg PATCH_NAME=${patch_name} } +function import_all_patches { + setupEnv + make -C $mxedir import-all-patches-$pkg +} + case "$cmd" in init) init_git $pkg @@ -34,6 +39,9 @@ case "$cmd" in import) import_patch $pkg ;; + import-all) + import_all_patches $pkg + ;; export) export_patch $pkg ;; @@ -44,6 +52,7 @@ case "$cmd" in where COMMAND is one of: init - create a git directory for the package with the raw source import - apply the "pkgname-PATCHNAME.patch" patch commits + import-all - apply commits from all the patches of the package export - create/replace the "pkgname-PATCHNAME.patch" patch with a patch of all commits since init. If PATCHNAME is not set, it is default to "1-fixes". -- cgit v0.12 From efc287a8d99f35176daf79af6ccd174eed8acd36 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Tue, 5 Jan 2016 21:20:43 +0300 Subject: move patching functions and targets to patch.mk See https://github.com/mxe/mxe/pull/1134#issuecomment-168873410 See https://github.com/mxe/mxe/pull/1134#issuecomment-169867926 --- Makefile | 85 +-------------------------------------------------- patch.mk | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/build-pkg.lua | 1 + 3 files changed, 89 insertions(+), 84 deletions(-) create mode 100644 patch.mk diff --git a/Makefile b/Makefile index e91f216..d18e4c0 100644 --- a/Makefile +++ b/Makefile @@ -798,87 +798,4 @@ versions.json: $(foreach PKG,$(PKGS), $(TOP_DIR)/src/$(PKG).mk) # for patch-tool-mxe -GIT_DIR = $(if $(patsubst .,,$($(1)_SUBDIR)) \ - ,$(GITS_DIR)/$($(1)_SUBDIR),$(GITS_DIR)/$(1)) - -GIT_CMD = git \ - --work-tree='$(call GIT_DIR,$(1))' \ - --git-dir='$(call GIT_DIR,$(1))'/.git - -define INIT_GIT - # unpack to gits/tmp/pkg - rm -rf '$(GITS_DIR)/tmp' - mkdir -p '$(GITS_DIR)/tmp/$(1)' - cd '$(GITS_DIR)/tmp/$(1)' && $(call UNPACK_PKG_ARCHIVE,$(1)) - # if PKG_SUBDIR is ".", the following will move gits/tmp/pkg - mv '$(abspath $(GITS_DIR)/tmp/$(1)/$($(1)_SUBDIR))' '$(call GIT_DIR,$(1))' - rm -rf '$(GITS_DIR)/tmp' - # initialize git - $(call GIT_CMD,$(1)) init - $(call GIT_CMD,$(1)) add -A - $(call GIT_CMD,$(1)) commit -m "init" - $(call GIT_CMD,$(1)) tag dist -endef - -init-git-%: download-only-% - $(if $(call set_is_member,$*,$(PKGS)), \ - $(if $(wildcard $(call GIT_DIR,$*)), \ - $(error $(call GIT_DIR,$*) already exists), \ - $(call INIT_GIT,$*)), \ - $(error Package $* not found in index.html)) - -PATCH_NAME = 1-fixes - -# can't use PKG_PATCHES here, because it returns existing patches -# while export-patch creates new patch -PATCH_BY_NAME = $(patsubst %.mk,%-$(2).patch,$(PKG_MAKEFILES)) - -define IMPORT_PATCH - cd '$(call GIT_DIR,$(1))' \ - && cat '$(2)' \ - | sed '/^From/,$$ !d' \ - | sed s/'^From: MXE'/"From: fix@me"/'g;' \ - | $(call GIT_CMD,$(1)) am --keep-cr ; -endef - -import-patch-%: - $(if $(call set_is_member,$*,$(PKGS)), \ - $(if $(wildcard $(call GIT_DIR,$*)), \ - $(call IMPORT_PATCH,$*,$(call PATCH_BY_NAME,$*,$(PATCH_NAME))), \ - $(error $(call GIT_DIR,$*) does not exist)), \ - $(error Package $* not found in index.html)) - -import-all-patches-%: - $(if $(call set_is_member,$*,$(PKGS)), \ - $(if $(wildcard $(call GIT_DIR,$*)), \ - $(foreach PKG_PATCH,$(call PKG_PATCHES,$*), \ - $(call IMPORT_PATCH,$*,$(PKG_PATCH))), \ - $(error $(call GIT_DIR,$*) does not exist)), \ - $(error Package $* not found in index.html)) - -define EXPORT_PATCH - cd '$(call GIT_DIR,$(1))' \ - && ( \ - echo 'This file is part of MXE.'; \ - echo 'See index.html for further information.'; \ - echo ''; \ - echo 'Contains ad hoc patches for cross building.'; \ - echo ''; \ - $(call GIT_CMD,$(1)) format-patch \ - --no-numbered \ - -p \ - --no-signature \ - --stdout \ - --text \ - dist..HEAD \ - | sed 's/^From [0-9a-f]\{40\} /From 0000000000000000000000000000000000000000 /' \ - | sed 's/^index .......\.\......../index 1111111..2222222/' \ - ) > '$(PATCH_BY_NAME)' -endef - -export-patch-%: - $(if $(call set_is_member,$*,$(PKGS)), \ - $(if $(wildcard $(call GIT_DIR,$*)), \ - $(call EXPORT_PATCH,$*,$(PATCH_NAME)), \ - $(error $(call GIT_DIR,$*) does not exist)), \ - $(error Package $* not found in index.html)) +include patch.mk diff --git a/patch.mk b/patch.mk new file mode 100644 index 0000000..87c72d0 --- /dev/null +++ b/patch.mk @@ -0,0 +1,87 @@ +# This file is part of MXE. +# See index.html for further information. + +GIT_DIR = $(if $(patsubst .,,$($(1)_SUBDIR)) \ + ,$(GITS_DIR)/$($(1)_SUBDIR),$(GITS_DIR)/$(1)) + +GIT_CMD = git \ + --work-tree='$(call GIT_DIR,$(1))' \ + --git-dir='$(call GIT_DIR,$(1))'/.git + +PATCH_NAME = 1-fixes + +# can't use PKG_PATCHES here, because it returns existing patches +# while export-patch creates new patch +PATCH_BY_NAME = $(patsubst %.mk,%-$(2).patch,$(PKG_MAKEFILES)) + +define INIT_GIT + # unpack to gits/tmp/pkg + rm -rf '$(GITS_DIR)/tmp' + mkdir -p '$(GITS_DIR)/tmp/$(1)' + cd '$(GITS_DIR)/tmp/$(1)' && $(call UNPACK_PKG_ARCHIVE,$(1)) + # if PKG_SUBDIR is ".", the following will move gits/tmp/pkg + mv '$(abspath $(GITS_DIR)/tmp/$(1)/$($(1)_SUBDIR))' '$(call GIT_DIR,$(1))' + rm -rf '$(GITS_DIR)/tmp' + # initialize git + $(call GIT_CMD,$(1)) init + $(call GIT_CMD,$(1)) add -A + $(call GIT_CMD,$(1)) commit -m "init" + $(call GIT_CMD,$(1)) tag dist +endef + +define IMPORT_PATCH + cd '$(call GIT_DIR,$(1))' \ + && cat '$(2)' \ + | sed '/^From/,$$ !d' \ + | sed s/'^From: MXE'/"From: fix@me"/'g;' \ + | $(call GIT_CMD,$(1)) am --keep-cr ; +endef + +define EXPORT_PATCH + cd '$(call GIT_DIR,$(1))' \ + && ( \ + echo 'This file is part of MXE.'; \ + echo 'See index.html for further information.'; \ + echo ''; \ + echo 'Contains ad hoc patches for cross building.'; \ + echo ''; \ + $(call GIT_CMD,$(1)) format-patch \ + --no-numbered \ + -p \ + --no-signature \ + --stdout \ + --text \ + dist..HEAD \ + | sed 's/^From [0-9a-f]\{40\} /From 0000000000000000000000000000000000000000 /' \ + | sed 's/^index .......\.\......../index 1111111..2222222/' \ + ) > '$(PATCH_BY_NAME)' +endef + +init-git-%: download-only-% + $(if $(call set_is_member,$*,$(PKGS)), \ + $(if $(wildcard $(call GIT_DIR,$*)), \ + $(error $(call GIT_DIR,$*) already exists), \ + $(call INIT_GIT,$*)), \ + $(error Package $* not found in index.html)) + +import-patch-%: + $(if $(call set_is_member,$*,$(PKGS)), \ + $(if $(wildcard $(call GIT_DIR,$*)), \ + $(call IMPORT_PATCH,$*,$(call PATCH_BY_NAME,$*,$(PATCH_NAME))), \ + $(error $(call GIT_DIR,$*) does not exist)), \ + $(error Package $* not found in index.html)) + +import-all-patches-%: + $(if $(call set_is_member,$*,$(PKGS)), \ + $(if $(wildcard $(call GIT_DIR,$*)), \ + $(foreach PKG_PATCH,$(call PKG_PATCHES,$*), \ + $(call IMPORT_PATCH,$*,$(PKG_PATCH))), \ + $(error $(call GIT_DIR,$*) does not exist)), \ + $(error Package $* not found in index.html)) + +export-patch-%: + $(if $(call set_is_member,$*,$(PKGS)), \ + $(if $(wildcard $(call GIT_DIR,$*)), \ + $(call EXPORT_PATCH,$*,$(PATCH_NAME)), \ + $(error $(call GIT_DIR,$*) does not exist)), \ + $(error Package $* not found in index.html)) diff --git a/tools/build-pkg.lua b/tools/build-pkg.lua index e9e7287..7cd853f 100755 --- a/tools/build-pkg.lua +++ b/tools/build-pkg.lua @@ -800,6 +800,7 @@ local function makeMxeSourcePackage() 'CNAME', 'LICENSE.md', 'Makefile', + 'patch.mk', 'README.md', 'assets', 'doc', -- cgit v0.12 From 0edd0899ba948fc2ce775d257eb35c6efc3347f7 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Thu, 7 Jan 2016 16:42:14 +0300 Subject: patch-tool-mxe: add "-M9" to git format-patch See https://github.com/mxe/mxe/pull/1131#issuecomment-168547049 --- patch.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/patch.mk b/patch.mk index 87c72d0..c67e7b3 100644 --- a/patch.mk +++ b/patch.mk @@ -51,6 +51,7 @@ define EXPORT_PATCH --no-signature \ --stdout \ --text \ + -M9 \ dist..HEAD \ | sed 's/^From [0-9a-f]\{40\} /From 0000000000000000000000000000000000000000 /' \ | sed 's/^index .......\.\......../index 1111111..2222222/' \ -- cgit v0.12