From 93674b5efa21ffd4fd2199f244d564fb7f78b163 Mon Sep 17 00:00:00 2001 From: Jackson West Date: Mon, 16 Oct 2023 16:25:25 -0500 Subject: [PATCH] fixes attribution generation for cgo projects --- Common.mk | 2 +- build/lib/common.sh | 6 ++++-- build/lib/gather_licenses.sh | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Common.mk b/Common.mk index a1786c4531..6e4cba1b19 100644 --- a/Common.mk +++ b/Common.mk @@ -630,7 +630,7 @@ $(OUTPUT_DIR)/%ttribution/go-license.csv: BINARY_TARGET=$(if $(filter .,$(*D)),, $(OUTPUT_DIR)/%ttribution/go-license.csv: GO_MOD_PATH=$(if $(BINARY_TARGET),$(GO_MOD_TARGET_FOR_BINARY_$(call TO_UPPER,$(BINARY_TARGET))),$(word 1,$(UNIQ_GO_MOD_PATHS))) $(OUTPUT_DIR)/%ttribution/go-license.csv: LICENSE_PACKAGE_FILTER=$(GO_MOD_$(subst /,_,$(GO_MOD_PATH))_LICENSE_PACKAGE_FILTER) $(OUTPUT_DIR)/%ttribution/go-license.csv: $$(call GO_MOD_DOWNLOAD_TARGET_FROM_GO_MOD_PATH,$$(GO_MOD_PATH)) | ensure-jq $$(ENABLE_LOGGING) - @$(BASE_DIRECTORY)/build/lib/gather_licenses.sh $(REPO) $(MAKE_ROOT)/$(OUTPUT_DIR)/$(BINARY_TARGET) "$(LICENSE_PACKAGE_FILTER)" $(GO_MOD_PATH) $(GOLANG_VERSION) $(LICENSE_THRESHOLD) + @$(BASE_DIRECTORY)/build/lib/gather_licenses.sh $(REPO) $(MAKE_ROOT)/$(OUTPUT_DIR)/$(BINARY_TARGET) "$(LICENSE_PACKAGE_FILTER)" $(GO_MOD_PATH) $(GOLANG_VERSION) $(LICENSE_THRESHOLD) $(CGO_ENABLED) .PHONY: gather-licenses gather-licenses: $(GATHER_LICENSES_TARGETS) diff --git a/build/lib/common.sh b/build/lib/common.sh index 715eadff00..9400267bde 100755 --- a/build/lib/common.sh +++ b/build/lib/common.sh @@ -129,7 +129,8 @@ function build::gather_licenses() { local -r patterns=$2 local -r golang_version=$3 local -r threshold=$4 - + local -r cgo_enabled=$5 + # Force deps to only be pulled form vendor directories # this is important in a couple cases where license files # have to be manually created @@ -137,6 +138,7 @@ function build::gather_licenses() { # force platform to be linux to ensure all deps are picked up export GOOS=linux export GOARCH=amd64 + export CGO_ENABLED=$cgo_enabled build::common::use_go_version "$golang_version" @@ -156,7 +158,7 @@ function build::gather_licenses() { # go-licenses can be a bit noisy with its output and lot of it can be confusing # the following messages are safe to ignore since we do not need the license url for our process - NOISY_MESSAGES="cannot determine URL for|Error discovering license URL|unsupported package host|contains non-Go code|has empty version|vendor.*\.(h|s)$" + NOISY_MESSAGES="cannot determine URL for|Error discovering license URL|unsupported package host|contains non-Go code|has empty version|\.(h|s|c)$" build::common::echo_and_run go-licenses save --confidence_threshold $threshold --force $patterns --save_path "${outputdir}/LICENSES" 2> >(grep -vE "$NOISY_MESSAGES") diff --git a/build/lib/gather_licenses.sh b/build/lib/gather_licenses.sh index 3f3eceb56e..1b09fae363 100755 --- a/build/lib/gather_licenses.sh +++ b/build/lib/gather_licenses.sh @@ -23,9 +23,10 @@ PACKAGE_FILTER="$3" REPO_SUBPATH="${4:-}" GOLANG_VERSION="${5:-}" LICENSE_THRESHOLD="${6:-}" +CGO_ENABLED="${7:-}" SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" source "${SCRIPT_ROOT}/common.sh" cd $REPO/$REPO_SUBPATH -build::gather_licenses $OUTPUT_DIR "$PACKAGE_FILTER" "$GOLANG_VERSION" "$LICENSE_THRESHOLD" +build::gather_licenses $OUTPUT_DIR "$PACKAGE_FILTER" "$GOLANG_VERSION" "$LICENSE_THRESHOLD" "$CGO_ENABLED"