Skip to content

Commit

Permalink
build: changes to version numbering and build process
Browse files Browse the repository at this point in the history
Use date/time for snapshot version numbers, YYYYMMDDHHMMSS-hash-branch.
Add --snapshot configure option to force snapshot builds.
repo-info.sh and tag-release.sh improvements.
  • Loading branch information
jstebbins committed Sep 23, 2015
1 parent d2aa517 commit 25de99b
Show file tree
Hide file tree
Showing 5 changed files with 344 additions and 159 deletions.
84 changes: 66 additions & 18 deletions make/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import subprocess
import sys
import time
from datetime import datetime, timedelta

from optparse import OptionGroup
from optparse import OptionGroup
Expand Down Expand Up @@ -693,12 +694,13 @@ def __init__( self ):

self.url = 'git://nowhere.com/project/unknown'
self.tag = ''
self.tag_hash = 'deadbeaf'
self.branch = 'unknown'
self.remote = 'unknown'
self.rev = 0
self.hash = 'deadbeaf'
self.shorthash = 'deadbea'
self.date = '0000-00-00 00:00:00 -0000'
self.date = datetime(1, 1, 1)
self.official = 0
self.type = 'developer'

Expand All @@ -714,14 +716,29 @@ def _parseSession( self ):
self.url = value
elif name == 'TAG':
self.tag = value
elif name == 'TAG_HASH':
self.tag_hash = value
elif name == 'BRANCH':
self.branch = value
elif name == 'REMOTE':
self.remote = value
elif name == 'REV':
self.rev = int( value )
elif name == 'DATE':
self.date = value
self.date = datetime.strptime(value[0:19], "%Y-%m-%d %H:%M:%S")

# strptime can't handle UTC offset
m = re.match( '^([-+]?[0-9]{2})([0-9]{2})$', value[20:])
(hh, mn) = m.groups()
utc_off_hour = int(hh)
utc_off_minute = int(mn)
if utc_off_hour >= 0:
utc_off = utc_off_hour * 60 + utc_off_minute
else:
utc_off = utc_off_hour * 60 - utc_off_minute
delta = timedelta(minutes=utc_off)
self.date = self.date - delta

elif name == 'HASH':
self.hash = value
self.shorthash = value[:7]
Expand All @@ -733,7 +750,7 @@ def _parseSession( self ):

if self.url == official_url:
self.official = 1
if self.branch == '' and self.rev == 0:
if not options.snapshot and self.hash == self.tag_hash:
self.type = 'release'
else:
self.type = 'developer'
Expand Down Expand Up @@ -788,6 +805,9 @@ def __init__( self ):
self.vmajor = 0
self.vminor = 0
self.vpoint = 0
self.spoint = 0
self.suffix = ''
self.special = ''

def _action( self ):
## add architecture to URL only for Mac
Expand All @@ -796,33 +816,52 @@ def _action( self ):
else:
url_arch = ''

suffix = ''
if repo.tag != '':
m = re.match( '^([0-9]+)\.([0-9]+)\.([0-9]+)$', repo.tag )
m = re.match( '^([0-9]+)\.([0-9]+)\.([0-9]+)-?(.*)?$', repo.tag )
if not m:
cfg.errln( 'Invalid repo tag format %s\n', repo.tag )
sys.exit( 1 )
(vmajor, vminor, vpoint) = m.groups()
(vmajor, vminor, vpoint, suffix) = m.groups()
self.vmajor = int(vmajor)
self.vminor = int(vminor)
self.vpoint = int(vpoint)
self.suffix = suffix

if repo.type == 'release':
self.version = '%d.%d.%d' % (self.vmajor,self.vminor,self.vpoint)
url_ctype = ''
url_ntype = 'stable'
self.build = time.strftime('%Y%m%d') + '00'
self.title = '%s %s (%s)' % (self.name,self.version,self.build)
else:
if repo.type != 'release' or options.snapshot:
self.version = repo.date.strftime("%Y%m%d%H%M%S")
self.version += '-%s' % (repo.shorthash)
if repo.branch != '':
self.version = '%d.%d.%d-%d-%s-%s' % (self.vmajor, self.vminor,
self.vpoint, repo.rev, repo.shorthash, repo.branch)
else:
self.version = '%d.%d.%d-%d-%s' % (self.vmajor, self.vminor,
self.vpoint, repo.rev, repo.shorthash)
self.version += '-%s' % (repo.branch)

self.debversion = repo.date.strftime("%Y%m%d%H%M%S")
self.debversion += '-%s' % (repo.shorthash)
if repo.branch != '':
self.debversion += '-%s' % (repo.branch)

url_ctype = '_unstable'
url_ntype = 'unstable'
self.build = time.strftime('%Y%m%d') + '01'
self.title = '%s %s (%s)' % (self.name,self.version,self.build)
else:
m = re.match('^([a-zA-Z]+)\.([0-9]+)$', suffix)
if not m:
# Regular release
self.version = '%d.%d.%d' % (self.vmajor,self.vminor,self.vpoint)
self.debversion = '%d.%d.%d' % (self.vmajor, self.vminor, self.vpoint)
url_ctype = ''
url_ntype = 'stable'
else:
(special, spoint,) = m.groups()
self.special = special
self.spoint = int(spoint)
self.version = '%d.%d.%d-%s.%d' % (self.vmajor,self.vminor,self.vpoint, self.special, self.spoint)
self.debversion = '%d.%d.%d~%s.%d' % (self.vmajor, self.vminor, self.vpoint, self.special, self.spoint)
url_ctype = '_unstable'
url_ntype = 'unstable'

self.build = time.strftime('%Y%m%d') + '00'
self.title = '%s %s (%s)' % (self.name,self.version,self.build)

self.url_appcast = 'https://handbrake.fr/appcast%s%s.xml' % (url_ctype,url_arch)
self.url_appnote = 'https://handbrake.fr/appcast/%s.html' % (url_ntype)
Expand Down Expand Up @@ -1278,6 +1317,13 @@ def createCLI():
for select in SelectTool.selects:
select.cli_add_option( grp )
cli.add_option_group( grp )

## add build options
grp = OptionGroup( cli, 'Build Options' )
grp.add_option( '--snapshot', default=False, action='store_true',
help='Force a snapshot build' )
cli.add_option_group( grp )

return cli

###############################################################################
Expand Down Expand Up @@ -1663,7 +1709,9 @@ class Tools:
doc.add( 'HB.version.major', project.vmajor )
doc.add( 'HB.version.minor', project.vminor )
doc.add( 'HB.version.point', project.vpoint )
doc.add( 'HB.version.suffix', project.suffix )
doc.add( 'HB.version', project.version )
doc.add( 'HB.debversion', project.debversion )
doc.add( 'HB.version.hex', '%04x%02x%02x%08x' % (project.vmajor,project.vminor,project.vpoint,repo.rev) )

doc.add( 'HB.build', project.build )
Expand All @@ -1677,7 +1725,7 @@ class Tools:
doc.add( 'HB.repo.remote', repo.remote )
doc.add( 'HB.repo.type', repo.type )
doc.add( 'HB.repo.official', repo.official )
doc.add( 'HB.repo.date', repo.date )
doc.add( 'HB.repo.date', repo.date.strftime("%Y-%m-%d %H:%M:%S") )

doc.addBlank()
doc.add( 'HOST.spec', host.spec )
Expand Down
14 changes: 7 additions & 7 deletions pkg/linux/module.defs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ PKG.rpm.src.tar.bz2 = $(STAGE.out.src/)rpm/$(PKG.rpm.basename).tar.bz2
STAGE.out.rpm.src/ = $(STAGE.out.src/)rpm/

PKG.debian = $(PKG.in/)linux/debian
PKG.cli.deb = $(PKG.out/)$(HB.name)-$(HB.version)-Ubuntu_CLI_$(BUILD.machine).deb
PKG.gui.deb = $(PKG.out/)$(HB.name)-$(HB.version)-Ubuntu_GUI_$(BUILD.machine).deb
PKG.deb.basename = $(HB.name.lower)-$(HB.version)
PKG.src.deb.tar = $(HB.name.lower)_$(HB.version).tar.gz
PKG.cli.deb = $(PKG.out/)$(HB.name)-$(HB.debversion)-Ubuntu_CLI_$(BUILD.machine).deb
PKG.gui.deb = $(PKG.out/)$(HB.name)-$(HB.debversion)-Ubuntu_GUI_$(BUILD.machine).deb
PKG.deb.basename = $(HB.name.lower)-$(HB.debversion)
PKG.src.deb.tar = $(HB.name.lower)_$(HB.debversion).tar.gz
PKG.src.deb.stamp = $(STAGE.out.src/).debsrc.stamp
PKG.src.deb = $(PKG.out/)$(HB.name.lower)_$(HB.version).deb
PKG.src.deb = $(PKG.out/)$(HB.name.lower)_$(HB.debversion).deb

PKG.cli.tmp.deb = $(PKG.out/)$(HB.name.lower)-cli_$(HB.version)_$(PKG.deb.machine).deb
PKG.gui.tmp.deb = $(PKG.out/)$(HB.name.lower)-gtk_$(HB.version)_$(PKG.deb.machine).deb
PKG.cli.tmp.deb = $(PKG.out/)$(HB.name.lower)-cli_$(HB.debversion)_$(PKG.deb.machine).deb
PKG.gui.tmp.deb = $(PKG.out/)$(HB.name.lower)-gtk_$(HB.debversion)_$(PKG.deb.machine).deb

PKG.native.rpm.stamp = $(RPM.out/).rpm.stamp
PKG.rpm.stamp = $(PKG.out/).rpm.stamp
Expand Down
10 changes: 5 additions & 5 deletions pkg/linux/module.rules
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ $(PKG.gui.tmp.deb): GNUmakefile
fakeroot $(MAKE) -C $(SRC/) -f debian/rules clean
$(MAKE) BUILDDIR=$(PWD)/$(BUILD) CONFIGURE=configure -C $(SRC/) -f debian/rules build
echo $(PKG.out/)
fakeroot $(MAKE) FORCEVERSION="-- -v$(HB.version)" BUILDDIR=$(PWD)/$(BUILD) CONFIGURE=configure PKGDESTDIR=$(PWD)/$(PKG.out/) -C $(SRC/) -f debian/rules binary
fakeroot $(MAKE) FORCEVERSION="-- -v$(HB.debversion)" BUILDDIR=$(PWD)/$(BUILD) CONFIGURE=configure PKGDESTDIR=$(PWD)/$(PKG.out/) -C $(SRC/) -f debian/rules binary

$(PKG.gui.deb): | $(dir $(PKG.gui.deb))
$(PKG.gui.deb): $(PKG.gui.tmp.deb)
Expand All @@ -79,8 +79,8 @@ $(PKG.cli.deb): $(PKG.gui.tmp.deb)
# Debian source package rules
#
pkg.push.src.deb:: $(PKG.src.deb.stamp)
(cd $(STAGE.out.src/)vivid && dput handbrake-git-snapshots $(HB.name.lower)_$(HB.version)ppa1~vivid1_source.changes )
(cd $(STAGE.out.src/)trusty && dput handbrake-git-snapshots $(HB.name.lower)_$(HB.version)ppa1~trusty1_source.changes )
(cd $(STAGE.out.src/)vivid && dput handbrake-git-snapshots $(HB.name.lower)_$(HB.debversion)ppa1~vivid1_source.changes )
(cd $(STAGE.out.src/)trusty && dput handbrake-git-snapshots $(HB.name.lower)_$(HB.debversion)ppa1~trusty1_source.changes )

$(PKG.src.deb.stamp): GNUmakefile
-$(RM.exe) -rf $(STAGE.out.src/)
Expand All @@ -92,7 +92,7 @@ $(PKG.src.deb.stamp): GNUmakefile
cp -a $(PWD)/$(PKG.debian) $(STAGE.out.src/)vivid/$(PKG.deb.basename)
$(CP.exe) $(STAGE.out.src/)vivid/$(PKG.deb.basename)/debian/control.vivid $(STAGE.out.src/)vivid/$(PKG.deb.basename)/debian/control
$(CP.exe) $(STAGE.out.src/)vivid/$(PKG.deb.basename)/debian/rules.vivid $(STAGE.out.src/)vivid/$(PKG.deb.basename)/debian/rules
echo "$(HB.name.lower) ($(HB.version)ppa1~vivid1) vivid; urgency=low" > $(STAGE.out.src/)vivid/$(PKG.deb.basename)/debian/changelog
echo "$(HB.name.lower) ($(HB.debversion)-1ppa1~vivid1) vivid; urgency=low" > $(STAGE.out.src/)vivid/$(PKG.deb.basename)/debian/changelog
echo " * Snapshot" >> $(STAGE.out.src/)vivid/$(PKG.deb.basename)/debian/changelog
echo " - See timeline at http://trac.handbrake.fr/timeline" >> $(STAGE.out.src/)vivid/$(PKG.deb.basename)/debian/changelog
echo "" >> $(STAGE.out.src/)vivid/$(PKG.deb.basename)/debian/changelog
Expand All @@ -106,7 +106,7 @@ $(PKG.src.deb.stamp): GNUmakefile
cp -a $(PWD)/$(PKG.debian) $(STAGE.out.src/)trusty/$(PKG.deb.basename)
$(CP.exe) $(STAGE.out.src/)trusty/$(PKG.deb.basename)/debian/control.trusty $(STAGE.out.src/)trusty/$(PKG.deb.basename)/debian/control
$(CP.exe) $(STAGE.out.src/)trusty/$(PKG.deb.basename)/debian/rules.trusty $(STAGE.out.src/)trusty/$(PKG.deb.basename)/debian/rules
echo "$(HB.name.lower) ($(HB.version)ppa1~trusty1) trusty; urgency=low" > $(STAGE.out.src/)trusty/$(PKG.deb.basename)/debian/changelog
echo "$(HB.name.lower) ($(HB.debversion)-1ppa1~trusty1) trusty; urgency=low" > $(STAGE.out.src/)trusty/$(PKG.deb.basename)/debian/changelog
echo " * Snapshot" >> $(STAGE.out.src/)trusty/$(PKG.deb.basename)/debian/changelog
echo " - See timeline at http://trac.handbrake.fr/timeline" >> $(STAGE.out.src/)trusty/$(PKG.deb.basename)/debian/changelog
echo "" >> $(STAGE.out.src/)trusty/$(PKG.deb.basename)/debian/changelog
Expand Down
122 changes: 67 additions & 55 deletions scripts/repo-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,78 @@
#
# Retrieves git repository info for directory ${1} using command ${2}

# Args
REPO_DIR='.'
if [[ ${1} ]]; then
REPO_DIR=${1}
fi
GIT_EXE='git'
if [[ ${2} ]]; then
GIT_EXE=${2}
fi
function repo_info()
{
local repo_dir git_exe commit upstream err

# Switch to working directory
if ! cd ${REPO_DIR} 2>/dev/null; then
echo "Invalid directory ${REPO_DIR}." 1>&2
exit 1
fi
# Process args
repo_dir='.'
if [[ ${1} ]]; then
repo_dir=${1}
fi
git_exe='git'
if [[ ${2} ]]; then
git_exe=${2}
fi

# Switch to working directory
if ! cd ${repo_dir} 2>/dev/null; then
echo "Invalid directory ${repo_dir}." 1>&2
return 1
fi

# Check whether we have git
if ! hash ${GIT_EXE} 2>/dev/null; then
echo "Command '${GIT_EXE}' not found." 1>&2
exit 1
fi
# Check whether we have git
if ! hash ${git_exe} 2>/dev/null; then
echo "Command '${git_exe}' not found." 1>&2
return 1
fi

# Check if there is a valid git repo here
HASH=$(${GIT_EXE} rev-parse HEAD)
ERR=$?
if [[ ${ERR} -ne 0 ]]; then
echo "Not a valid repository." 1>&2
exit ${ERR}
elif [[ -z ${HASH} ]]; then
echo "Not a valid repository." 1>&2
exit 1
fi
# Check if there is a valid git repo here
HASH=$(${git_exe} rev-parse HEAD)
SHORTHASH=$(${git_exe} rev-parse --short HEAD)
err=$?
if [[ ${err} -ne 0 ]]; then
echo "Not a valid repository." 1>&2
return ${err}
elif [[ -z ${HASH} ]]; then
echo "Not a valid repository." 1>&2
return 1
fi

# Retrieve info
URL=$(${GIT_EXE} config remote.origin.url)
TAG=$(${GIT_EXE} describe --tags --abbrev=0)
if [[ ${TAG} ]]; then
REV=$(${GIT_EXE} rev-list ${TAG}.. --count)
else
TAG=$(${GIT_EXE} describe --tags $(${GIT_EXE} rev-list --tags --max-count=1))
# Retrieve info
URL=$(${git_exe} config remote.origin.url)

# check if an annotated tag is reachable from HEAD
TAG=$(${git_exe} describe --tags --abbrev=0 --exact-match --match \[0-9\]\*.\[0-9\]\*.\[0-9\]\* HEAD 2> /dev/null)
if [[ ${TAG} ]]; then
REV=$(${GIT_EXE} rev-list $(${GIT_EXE} merge-base ${TAG} HEAD).. --count)
# if TAG is a release tag and HASH == TAG_HASH, this is release code
TAG_HASH=$(${git_exe} rev-list ${TAG} --max-count=1)
REV=$(${git_exe} rev-list $(${git_exe} merge-base ${TAG} HEAD).. --count)
else
REV=$(${GIT_EXE} rev-list HEAD --count)
REV=$(${git_exe} rev-list HEAD --count)
fi

BRANCH=$(${git_exe} symbolic-ref -q --short HEAD)
REMOTE="${URL}"
upstream=$(${git_exe} config branch.${BRANCH}.remote)
if [[ ${upstream} ]]; then
REMOTE="${upstream}"
fi
fi
BRANCH=$(${GIT_EXE} symbolic-ref -q --short HEAD)
REMOTE="${URL}"
UPSTREAM=$(${GIT_EXE} config branch.${BRANCH}.remote)
if [[ ${UPSTREAM} ]]; then
REMOTE="${UPSTREAM}"
fi
DATE=$(${GIT_EXE} log -1 --format="format:%ai")
DATE=$(${git_exe} log -1 --format="format:%ci")

# Output
# Only write tag and rev if they exist.
echo "URL=${URL}"
echo "HASH=${HASH}"
echo "SHORTHASH=${SHORTHASH}"
if [[ ${TAG} ]]; then echo "TAG=${TAG}"; fi
if [[ ${TAG_HASH} ]]; then echo "TAG_HASH=${TAG_HASH}"; fi
if [[ ${REV} ]]; then echo "REV=${REV}"; fi
echo "BRANCH=${BRANCH}"
echo "REMOTE=${REMOTE}"
echo "DATE=${DATE}"

return 0
}

# Output
# Only write tag and rev if they exist.
echo "URL=${URL}"
echo "HASH=${HASH}"
if [[ ${TAG} ]]; then echo "TAG=${TAG}"; fi
if [[ ${REV} ]]; then echo "REV=${REV}"; fi
echo "BRANCH=${BRANCH}"
echo "REMOTE=${REMOTE}"
echo "DATE=${DATE}"
repo_info "$@"
Loading

0 comments on commit 25de99b

Please sign in to comment.