Blame SOURCES/Makefile

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