diff --git a/Makefile.common b/Makefile.common index d1e17a8..bbf4ff6 100644 --- a/Makefile.common +++ b/Makefile.common @@ -205,12 +205,12 @@ bumpnogit: $(__missingsources): sources -fetch-from-srpm: - @tmp=$$(mktemp -d -p "."); \ +# First argument is a Clear Linux build number (e.g. 22000) +define fetch-from-srpm + tmp=$$(mktemp -d -p "."); \ srpm=$$(rpmspec --srpm -q --qf "%{NVR}.src.rpm\n" $(SPECFILE)); \ - if cd "$$tmp" && ! curl -f -L -O $(LATEST_SRPMS)/$$srpm; then \ - echo "Failed to download $$srpm from latest Clear Linux release." >&2; \ - echo "Run \"git pull\" and try again." >&2; \ + if cd "$$tmp" && ! curl -s -S -f -L -O $(DOWNLOAD_MIRROR)/releases/$(1)/clear/source/SRPMS/$$srpm; then \ + echo "Failed to download $$srpm from Clear Linux release $(1)." >&2; \ cd .. && rm -rf "$$tmp"; \ exit 1; \ fi; \ @@ -218,23 +218,26 @@ fetch-from-srpm: cd ..; \ srclist=$$(rpmspec --srpm -q --qf "[%{SOURCE}\n]" $(SPECFILE)); \ for s in $$srclist; do \ - if ! mv "$$tmp"/$$s .; then \ + if ! mv --no-clobber "$$tmp"/$$s .; then \ echo "Missing source file \"$$s\" in $${srpm}." >&2; \ rm -rf "$$tmp"; \ exit 1; \ fi; \ echo "Retrieved source file $$s ..."; \ done; \ - rm -rf "$$tmp"; + rm -rf "$$tmp" +endef -#help sources: If SOURCES_URL is defined, download required upstream source -#help files from that location. Otherwise, try to extract source files from the -#help SRPM in the latest Clear Linux release, as specified by the LATEST_SRPMS -#help variable. This will run automatically, as a dependency. NOTE: A Koji -#help server can make use of this "make sources" command, since it lives in a -#help repo named "common". If you use this makefile in Koji, ensure -#help "make sources" continues to work for both remote and local builds, since -#help it is a prerequisite of several commands for building packages. +#help sources: If SOURCES_URL is defined, download required upstream source files +#help from that location. Otherwise, try to download source files according to the +#help URLs listed in the spec file. If any of the source files fail to download, +#help check for the relevant SRPM from published releases of Clear Linux OS, and +#help extract the files if found. Note that SRPMs are taken from the DOWNLOAD_MIRROR +#help location. This will run automatically, as a dependency. NOTE: A Koji server can +#help make use of this "make sources" command, since it lives in a repo named +#help "common". If you use this makefile in Koji, ensure "make sources" continues to +#help work for both remote and local builds, since it is a prerequisite of several +#help commands for building packages. ifneq ($(strip $(SOURCES_URL)),) sources: upstream while read u; do \ @@ -250,7 +253,23 @@ sources: upstream done < upstream else sources: - $(MAKE) fetch-from-srpm + @$(MAKE) generateupstream; \ + [ $$? -eq 0 ] && exit 0; \ + nvr="$$(rpmspec --srpm -q --qf '%{NAME}\t%{VERSION}\t%{RELEASE}\n' $(SPECFILE))"; \ + latest_builds=$$(git -C $(TOPLVL)/projects/common tag -l | sort -rn); \ + for b in $$latest_builds; do \ + url="$(DOWNLOAD_MIRROR)/releases/$$b/clear/source/package-sources"; \ + echo "Checking for source files in build $$b ..."; \ + if grep -q "$$nvr" <(curl -s -f -L $$url); then \ + $(call fetch-from-srpm,$$b); \ + if [ $$? -eq 0 ]; then \ + echo "Source files retrieved from build $$b"; \ + exit 0; \ + fi; \ + fi; \ + done; \ + echo "Source files not found for package"; \ + exit 1 endif prekoji-checks: @@ -372,18 +391,20 @@ install: #help calculating their hashes. Autospec performs this step automatically, so ignore #help it for packages managed with autospec. generateupstream: - @rm -f upstream + @mv upstream upstream.bak @urls=$$(rpmspec -D '_vendor clr' -P $(SPECFILE) | sed -n "s|^Source[0-9]*[[:blank:]]*:[[:blank:]]*\(..*://..*\)$$|\1|p"); \ for url in $$urls; do \ filename=$$(basename $$url); \ if [ ! -e $$filename ]; then \ if ! curl --fail -L -O $$url; then \ echo "Failed to download $$url"; \ + mv --no-clobber upstream.bak upstream; \ exit 1; \ fi; \ fi; \ echo $$(sha1sum $$filename | cut -d\ -f1)/$$filename >> upstream; \ done + @rm upstream.bak @cat upstream #help drop-abandoned: Remove all unused patches from the git tree