Blame SOURCES/Makefile

6ad68d
VERSION := $(shell rpm --specfile *.spec --qf '%{VERSION}\n' | head -1)
6ad68d
RELEASE := $(shell rpm --specfile *.spec --qf '%{RELEASE}\n' | head -1 | cut -d. -f1)
ad1bcd
CHANGELOGTIME := $(shell rpm --specfile *.spec --qf '%{CHANGELOGTIME}\n' | head -1)
ad1bcd
SOURCE_DATE_EPOCH := $(shell echo $$(( $(CHANGELOGTIME) - $(CHANGELOGTIME) % 86400 )))
28ad2d
897738
NAME       := grafana
897738
RPM_NAME   := $(NAME)
6ad68d
SOURCE_DIR := $(NAME)-$(VERSION)
6ad68d
SOURCE_TAR := $(NAME)-$(VERSION).tar.gz
6ad68d
VENDOR_TAR := $(RPM_NAME)-vendor-$(VERSION)-$(RELEASE).tar.xz
6ad68d
WEBPACK_TAR := $(RPM_NAME)-webpack-$(VERSION)-$(RELEASE).tar.gz
6ad68d
6ad68d
# patches which must be applied before creating the vendor tarball, for example:
6ad68d
# - changes in dependency versions
6ad68d
# - changes in Go module imports (which affect the vendored Go modules)
6ad68d
PATCHES_PRE_VENDOR := \
6ad68d
	005-remove-unused-dependencies.patch \
ad1bcd
	008-remove-unused-frontend-crypto.patch \
ad1bcd
	012-support-go1.18.patch \
ad1bcd
	013-CVE-2021-23648.patch \
ad1bcd
	014-CVE-2022-21698.patch
6ad68d
6ad68d
# patches which must be applied before creating the webpack, for example:
6ad68d
# - changes in Node.js sources or vendored dependencies
ad1bcd
PATCHES_PRE_WEBPACK := \
ad1bcd
	008-remove-unused-frontend-crypto.patch
897738
897738
897738
all: $(SOURCE_TAR) $(VENDOR_TAR) $(WEBPACK_TAR)
897738
897738
$(SOURCE_TAR):
897738
	spectool -g $(RPM_NAME).spec
897738
897738
$(VENDOR_TAR): $(SOURCE_TAR)
ad1bcd
	# Start with a clean state
6ad68d
	rm -rf $(SOURCE_DIR)
ad1bcd
	tar pxf $(SOURCE_TAR)
28ad2d
6ad68d
	# Patches to apply before vendoring
6ad68d
	for patch in $(PATCHES_PRE_VENDOR); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
897738
28ad2d
	# Go
6ad68d
	cd $(SOURCE_DIR) && go mod vendor -v
897738
	# Remove unused crypto
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/cast5/cast5.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/ed25519/ed25519.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/const.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/ed25519/internal/edwards25519/edwards25519.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/elgamal/elgamal.go
6ad68d
	rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/packet/ocfb.go
6ad68d
	awk '$$2~/^v/ && $$4 != "indirect" {print "Provides: bundled(golang(" $$1 ")) = " substr($$2, 2)}' $(SOURCE_DIR)/go.mod | \
28ad2d
		sed -E 's/=(.*)-(.*)-(.*)/=\1-\2.\3/g' > $@.manifest
28ad2d
28ad2d
	# Node.js
ad1bcd
	cd $(SOURCE_DIR) && yarn install --frozen-lockfile
28ad2d
	# Remove files with licensing issues
6ad68d
	find $(SOURCE_DIR) -type d -name 'node-notifier' -prune -exec rm -r {} \;
6ad68d
	find $(SOURCE_DIR) -type d -name 'property-information' -prune -exec rm -r {} \;
6ad68d
	find $(SOURCE_DIR) -type f -name '*.exe' -delete
6ad68d
	rm -r $(SOURCE_DIR)/node_modules/visjs-network/examples
6ad68d
	./list_bundled_nodejs_packages.py $(SOURCE_DIR) >> $@.manifest
28ad2d
28ad2d
	# Create tarball
ad1bcd
	XZ_OPT=-9 tar \
ad1bcd
		--sort=name \
ad1bcd
		--mtime="@$(SOURCE_DATE_EPOCH)" --clamp-mtime \
ad1bcd
		--owner=0 --group=0 --numeric-owner \
ad1bcd
		-cJf $@ \
6ad68d
		$(SOURCE_DIR)/vendor \
ad1bcd
		$$(find $(SOURCE_DIR) -type d -name "node_modules" -prune | LC_ALL=C sort)
28ad2d
897738
$(WEBPACK_TAR): $(VENDOR_TAR)
ad1bcd
	# Start with a clean state
6ad68d
	rm -rf $(SOURCE_DIR)
ad1bcd
	tar pxf $(SOURCE_TAR)
ad1bcd
	tar pxf $(VENDOR_TAR)
6ad68d
6ad68d
	# Patches to apply before creating the webpack
6ad68d
	for patch in $(PATCHES_PRE_WEBPACK); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
6ad68d
ad1bcd
	# Build frontend
6ad68d
	cd $(SOURCE_DIR) && \
28ad2d
		../build_frontend.sh
28ad2d
ad1bcd
	# Create tarball
ad1bcd
	tar \
ad1bcd
		--sort=name \
ad1bcd
		--mtime="@$(SOURCE_DATE_EPOCH)" --clamp-mtime \
ad1bcd
		--owner=0 --group=0 --numeric-owner \
ad1bcd
		-czf $@ \
ad1bcd
		$(SOURCE_DIR)/public/build \
ad1bcd
		$(SOURCE_DIR)/public/views \
ad1bcd
		$(SOURCE_DIR)/plugins-bundled
28ad2d
28ad2d
clean:
897738
	rm -rf *.tar.gz *.tar.xz *.manifest *.rpm $(NAME)-*/