Skip to content

Instantly share code, notes, and snippets.

@beer-psi
Last active March 19, 2022 15:35
Show Gist options
  • Save beer-psi/380431cdcdfae74c93de6cf9d3a67f20 to your computer and use it in GitHub Desktop.
Save beer-psi/380431cdcdfae74c93de6cf9d3a67f20 to your computer and use it in GitHub Desktop.
Adding git build manifest to Theos package versions
include $(THEOS)/makefiles/package.mk
# Git-based versioning
# If not a git repo (downloaded tarball etc.), use version from control file
# If git repo:
# - If on tag, use version from control file
# - If not on tag, use version from control file with added git manfest
# - Release version is $(PACKAGE_VERSION)+git$(GIT_DATE).$(GIT_COMMIT_HASH)
# - Debug version is $(PACKAGE_VERSION)-debug.$(_DEBUG_NUMBER)+git$(GIT_DATE).$(GIT_COMMIT_HASH)
# $(_DEBUG_NUMBER) is incremental.
ifeq ($(shell git rev-parse --is-inside-work-tree),true)
ifeq ($(shell git name-rev --name-only --tags HEAD),undefined)
_PACKAGE_NAME := $(shell grep '^Package:' $(_THEOS_DEB_PACKAGE_CONTROL_PATH) | cut -d' ' -f2-)
_PACKAGE_VERSION := $(or $(shell git describe --tags --abbrev=0 | sed -r 's/^(v|V)//g'),$(shell grep '^Version:' $(_THEOS_DEB_PACKAGE_CONTROL_PATH) | cut -d' ' -f2-))
_GIT_DATE := $(shell git show -s --format=%cs | tr -d "-")
_GIT_COMMIT_HASH := $(shell git rev-parse --short HEAD)
THEOS_PACKAGE_BASE_VERSION := $(_PACKAGE_VERSION)+git$(_GIT_DATE).$(_GIT_COMMIT_HASH)
ifeq ($(call __theos_bool,$(or $(debug),$(DEBUG))),$(_THEOS_TRUE))
_DEBUG_NUMBER := $(shell THEOS_PROJECT_DIR=$(THEOS_PROJECT_DIR) $(THEOS_BIN_PATH)/package_version.sh -N "$(_PACKAGE_NAME)" -V $(THEOS_PACKAGE_BASE_VERSION))
_THEOS_INTERNAL_PACKAGE_VERSION := $(_PACKAGE_VERSION)-debug.$(_DEBUG_NUMBER)+git$(_GIT_DATE).$(_GIT_COMMIT_HASH)
else
_THEOS_INTERNAL_PACKAGE_VERSION := $(THEOS_PACKAGE_BASE_VERSION)
endif
endif
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment