From e9e131e5f7c0ab9480b6cc48e2130150cf5a814b Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
Date: Tue, 16 Feb 2021 22:58:48 -0500
Subject: [PATCH] contrib: Fix onnx build, which depends on the repo metadata.

Commit 8e2b334db normalized how the onnx sources are fetched; compared
to earlier code, it strips the .git metadata.  While usually a nice
thing to do (as the .git metadata is not fixed and thus a checksum for
the resulting tarball archive cannot be computed), in this case it
breaks the build, which relies on it.

The solution is to add a 4th argument to the 'download_git' procedure,
that allows preserving the .git repository metadata.

* contrib/src/main.mak (download_git): Add a new argument and document it.
* contrib/src/onnx/rules.mak
($(TARBALLS)/onnxruntime-$(ONNX_VERSION).tar.xz): Use it.

Reported-by: Aline <aline.gondimsantos@savoirfairelinux.com>
Change-Id: Ia5a5dad2a8dd2c292b8b8d8b8e5f63361a9484ef
---
 contrib/src/main.mak       | 3 ++-
 contrib/src/onnx/rules.mak | 4 +---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/contrib/src/main.mak b/contrib/src/main.mak
index b04f001717..e77981f054 100644
--- a/contrib/src/main.mak
+++ b/contrib/src/main.mak
@@ -330,6 +330,7 @@ HOSTVARS := $(HOSTTOOLS) \
 # $1: The URL of the Git repository.
 # $2: The remote branch to clone.
 # $3: The git refspec to checkout.
+# $4: Set to anything to preserve the .git directory
 ifeq ($(DISABLE_CONTRIB_DOWNLOADS),TRUE)
 download_git = $(error Trying to clone $(1) but DISABLE_CONTRIB_DOWNLOADS is TRUE, aborting.)
 else
@@ -337,7 +338,7 @@ download_git = \
 	rm -Rf $(@:.tar.xz=) && \
 	$(GIT) clone $(2:%=--branch %) $(1) $(@:.tar.xz=) && \
 	(cd $(@:.tar.xz=) && $(GIT) checkout $(3:%= %)) && \
-	rm -Rf $(@:%.tar.xz=%)/.git && \
+	(test -z "$(4)" && rm -Rf $(@:%.tar.xz=%)/.git) || true && \
 	(cd $(dir $@) && \
 	tar cJ $(notdir $(@:.tar.xz=))) > $@ && \
 	rm -Rf $(@:.tar.xz=)
diff --git a/contrib/src/onnx/rules.mak b/contrib/src/onnx/rules.mak
index 513c9a453b..c631564f4c 100644
--- a/contrib/src/onnx/rules.mak
+++ b/contrib/src/onnx/rules.mak
@@ -3,7 +3,7 @@ ONNX_VERSION := v1.6.0
 ONNX_URL := https://github.com/microsoft/onnxruntime.git
 
 $(TARBALLS)/onnxruntime-$(ONNX_VERSION).tar.xz:
-	$(call download_git,$(ONNX_URL),master,$(ONNX_VERSION))
+	$(call download_git,$(ONNX_URL),master,$(ONNX_VERSION),preserve .git)
 
 .sum-onnx: onnxruntime-$(ONNX_VERSION).tar.xz
 	$(warning $@ not implemented)
@@ -34,5 +34,3 @@ endif
 	if [ ! -d "$(PREFIX)/include/onnxruntime" ] ; then ( mkdir $(PREFIX)/include/onnxruntime ) fi
 	cd $< && cp -r ./include/onnxruntime/core/* $(PREFIX)/include/onnxruntime/
 	touch $@
-
-
-- 
GitLab