From b974c91fe438541781c2df6f4fe0b8a48ab0a124 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Fri, 21 Mar 2025 14:32:08 +0100 Subject: [PATCH] package/pkg-golang: support _SUBDIR Some packages have their actual source tree in a sub-directory (even if that is the only source in the repository); this is the case for example with the Amazon ECR credential helper (to be packaged in a follow up commit): https://github.com/awslabs/amazon-ecr-credential-helper Do the build in _SUBDIR, and also do the vendoring in there. We don't need the build to generate executables inside _SUBDIR, so we just keep using $(@D)/bin as a place to generate them (and install them from). Signed-off-by: Yann E. MORIN Cc: Christian Stewart Reviewed-by: Christian Stewart Signed-off-by: Julien Olivain --- package/pkg-golang.mk | 13 +++++++++---- support/download/go-post-process | 5 +++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk index bdf8de4d66..a4e8bd30cc 100644 --- a/package/pkg-golang.mk +++ b/package/pkg-golang.mk @@ -79,8 +79,8 @@ $(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; \ + if [ ! -f $$(@D)/$$($(2)_SUBDIR)/go.mod ]; then \ + printf "module $$($(2)_GOMOD)\n" > $$(@D)/$$($(2)_SUBDIR)/go.mod; \ fi endef $(2)_POST_PATCH_HOOKS += $(2)_GEN_GOMOD @@ -91,6 +91,11 @@ $(2)_DL_ENV += \ GOPROXY=direct \ $$($(2)_GO_ENV) +# If building in a sub directory, do the vendoring in there +ifneq ($$($(2)_SUBDIR),) +$(2)_DOWNLOAD_POST_PROCESS_OPTS += -s$$($(2)_SUBDIR) +endif + # Because we append vendored info, we can't rely on the values being empty # once we eventually get into the generic-package infra. So, we duplicate # the heuristics here @@ -135,7 +140,7 @@ endif # Build package for target define $(2)_BUILD_CMDS $$(foreach d,$$($(2)_BUILD_TARGETS),\ - cd $$(@D); \ + cd $$(@D)/$$($(2)_SUBDIR); \ $$(HOST_GO_TARGET_ENV) \ $$($(2)_GO_ENV) \ $$(GO_BIN) build -v $$($(2)_BUILD_OPTS) \ @@ -147,7 +152,7 @@ else # Build package for host define $(2)_BUILD_CMDS $$(foreach d,$$($(2)_BUILD_TARGETS),\ - cd $$(@D); \ + cd $$(@D)/$$($(2)_SUBDIR); \ $$(HOST_GO_HOST_ENV) \ $$($(2)_GO_ENV) \ $$(GO_BIN) build -v $$($(2)_BUILD_OPTS) \ diff --git a/support/download/go-post-process b/support/download/go-post-process index ef96a76948..edc23ec564 100755 --- a/support/download/go-post-process +++ b/support/download/go-post-process @@ -5,10 +5,11 @@ set -e . "${0%/*}/helpers" # Parse our options -while getopts "n:o:" OPT; do +while getopts "n:o:s:" OPT; do case "${OPT}" in o) output="${OPTARG}";; n) base_name="${OPTARG}";; + s) subdir="${OPTARG}";; :) error "option '%s' expects a mandatory argument\n" "${OPTARG}";; \?) error "unknown option '%s'\n" "${OPTARG}";; esac @@ -22,7 +23,7 @@ fi post_process_unpack "${base_name}" "${output}" # Do the Go vendoring -pushd "${base_name}" > /dev/null +pushd "${base_name}/${subdir}" > /dev/null if [ ! -f go.mod ]; then echo "ERROR: no vendor/ folder and no go.mod, aborting"