Skip to content

Commit

Permalink
fixes attribution generation for cgo projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxesn committed Oct 16, 2023
1 parent 6935d19 commit 93674b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions build/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ 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
export GOFLAGS=-mod=vendor
# 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"

Expand All @@ -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")

Expand Down
3 changes: 2 additions & 1 deletion build/lib/gather_licenses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 93674b5

Please sign in to comment.