All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v2 05/12] support/download/go-post-process: implement Go vendoring support
Date: Sat, 19 Dec 2020 16:35:18 +0100	[thread overview]
Message-ID: <20201219153525.1361175-6-thomas.petazzoni@bootlin.com> (raw)
In-Reply-To: <20201219153525.1361175-1-thomas.petazzoni@bootlin.com>

This commit introduces the download post-process script
support/download/go-post-process, and hooks it into the Go package
infrastructure.

The -modcacherw flag is added to ensure that the Go cache is
read/write, and can be deleted properly upon "make clean".

The <pkg>_LICENSE variable of golang packages is expanded with ",
vendored dependencies licenses probably not listed" as currently for
all packages, the licenses of the vendored dependencies are not taken
into account.

The logic to generate go.mod when not available is moved to the
download post-process helper, as it must be done before "go mod
vendor" is executed. Also, "go mod init" is used instead of manually
crafting go.mod. This was suggested by Christian Stewart
<christian@paral.in>. The Go module name is passed down to
go-post-process using the BR_GOMOD environment variable.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 package/pkg-golang.mk            | 20 ++++++++++--------
 support/download/go-post-process | 35 ++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 9 deletions(-)
 create mode 100755 support/download/go-post-process

diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk
index d07242310d..00a74a4d18 100644
--- a/package/pkg-golang.mk
+++ b/package/pkg-golang.mk
@@ -42,12 +42,13 @@ define inner-golang-package
 
 $(2)_BUILD_OPTS += \
 	-ldflags "$$($(2)_LDFLAGS)" \
+	-modcacherw \
 	-tags "$$($(2)_TAGS)" \
 	-trimpath \
 	-p $(PARALLEL_JOBS)
 
 # Target packages need the Go compiler on the host.
-$(2)_DEPENDENCIES += host-go
+$(2)_DOWNLOAD_DEPENDENCIES += host-go
 
 $(2)_BUILD_TARGETS ?= .
 
@@ -72,14 +73,15 @@ $(2)_SRC_SOFTWARE = $$(word 2,$$(subst /, ,$$(call notdomain,$$($(2)_SITE))))
 # If the go.mod file does not exist, one is written with this root path.
 $(2)_GOMOD ?= $$($(2)_SRC_DOMAIN)/$$($(2)_SRC_VENDOR)/$$($(2)_SRC_SOFTWARE)
 
-# Generate a go.mod file if it doesn't exist. Note: Go is configured
-# to use the "vendor" dir and not make network calls.
-define $(2)_GEN_GOMOD
-	if [ ! -f $$(@D)/go.mod ]; then \
-		printf "module $$($(2)_GOMOD)\n" > $$(@D)/go.mod; \
-	fi
-endef
-$(2)_POST_PATCH_HOOKS += $(2)_GEN_GOMOD
+$(2)_DOWNLOAD_POST_PROCESS = go
+$(2)_DL_ENV = \
+	$(HOST_GO_COMMON_ENV) \
+	GOPROXY=direct \
+	BR_GOMOD=$$($(2)_GOMOD)
+
+# Due to vendoring, it is pretty likely that not all licenses are
+# listed in <pkg>_LICENSE.
+$(2)_LICENSE += , vendored dependencies licenses probably not listed
 
 # Build step. Only define it if not already defined by the package .mk
 # file.
diff --git a/support/download/go-post-process b/support/download/go-post-process
new file mode 100755
index 0000000000..4ca3e9a710
--- /dev/null
+++ b/support/download/go-post-process
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+
+set -e
+
+. $(dirname $0)/post-process-helpers
+
+# Parse our options
+while getopts "n:o:" OPT; do
+        case "${OPT}" in
+        o)  output="${OPTARG}";;
+        n)  base_name="${OPTARG}";;
+        :)  error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
+        \?) error "unknown option '%s'\n" "${OPTARG}";;
+        esac
+done
+
+# Already vendored tarball, nothing to do
+if tar tf ${output} | grep -q "^[^/]*/vendor" ; then
+	exit 0
+fi
+
+unpack ${base_name} ${output}
+
+# Do the Go vendoring
+pushd ${base_name} > /dev/null
+
+# Generate go.mod if it doesn't exist
+if [ ! -f go.mod ] && [ -n "${BR_GOMOD}" ]; then
+	go mod init ${BR_GOMOD}
+fi
+
+go mod vendor -v -modcacherw
+popd > /dev/null
+
+repack ${base_name} ${output}
-- 
2.29.2

  parent reply	other threads:[~2020-12-19 15:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-19 15:35 [Buildroot] [PATCH v2 00/12] Support for Cargo and Go vendoring Thomas Petazzoni
2020-12-19 15:35 ` [Buildroot] [PATCH v2 01/12] support/download/dl-wrapper: add concept of download post-processing Thomas Petazzoni
2020-12-19 15:35 ` [Buildroot] [PATCH v2 02/12] package/pkg-download.mk: add <pkg>_DOWNLOAD_POST_PROCESS variable Thomas Petazzoni
2020-12-19 15:35 ` [Buildroot] [PATCH v2 03/12] package/pkg-download.mk: add <pkg>_DL_ENV variable Thomas Petazzoni
2020-12-29 16:18   ` Yann E. MORIN
2020-12-19 15:35 ` [Buildroot] [PATCH v2 04/12] support/download/post-process-helpers: add helper function for post process scripts Thomas Petazzoni
2020-12-19 17:39   ` Yann E. MORIN
2020-12-19 20:29     ` Yann E. MORIN
2020-12-20  8:40   ` Yann E. MORIN
2020-12-19 15:35 ` Thomas Petazzoni [this message]
2021-07-29 20:17   ` [Buildroot] [PATCH v2 05/12] support/download/go-post-process: implement Go vendoring support Christian Stewart
2021-07-29 20:50     ` Thomas Petazzoni
2021-07-30 13:18       ` Vincent Fazio
     [not found]       ` <CA+h8R2onPMjOuvC0U6iM8QbhuAQQ9=aQ-yB-rWQkCbhpxcdiHw@mail.gmail.com>
2021-08-01  7:08         ` Yann E. MORIN
     [not found]           ` <CA+h8R2pLN_aYiQ1vp+rTMUsQAcGT88fsAiCC-i9uJpK1y0r4rw@mail.gmail.com>
2021-08-01  9:14             ` Yann E. MORIN
2021-09-19  6:20               ` Christian Stewart via buildroot
2021-09-19  6:42                 ` Christian Stewart via buildroot
2020-12-19 15:35 ` [Buildroot] [PATCH v2 06/12] package/tinifier: new package Thomas Petazzoni
2020-12-19 15:35 ` [Buildroot] [PATCH v2 07/12] package/pkg-cargo.mk: introduce the cargo package infrastructure Thomas Petazzoni
2020-12-19 15:35 ` [Buildroot] [PATCH v2 08/12] docs/manual/cargo: document the cargo-package infrastructure Thomas Petazzoni
2020-12-19 15:35 ` [Buildroot] [PATCH v2 09/12] package/ripgrep: convert to cargo infrastructure Thomas Petazzoni
2020-12-19 15:35 ` [Buildroot] [PATCH v2 10/12] package/sentry-cli: convert to host-cargo-package infrastructure Thomas Petazzoni
2020-12-19 15:35 ` [Buildroot] [PATCH v2 11/12] support/download/cargo-post-process, package/pkg-cargo.mk: enable vendoring for Cargo packages Thomas Petazzoni
2020-12-19 15:35 ` [Buildroot] [PATCH v2 12/12] docs/manual/adding-packages-cargo.txt: rewrite explanation about dependency management Thomas Petazzoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201219153525.1361175-6-thomas.petazzoni@bootlin.com \
    --to=thomas.petazzoni@bootlin.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.