Skip to content

Commit

Permalink
Rework ant version properties
Browse files Browse the repository at this point in the history
Building on @rleigh-dundee's recent changes, this
refactors the work from build.py into a python
script like source-archive. That with the aid of
```
   <var name="x" unset="true"/>
```
elements, it's possible to remove the requirement
to use build.py.
  • Loading branch information
joshmoore committed May 1, 2014
1 parent f1efece commit 579c8f2
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 146 deletions.
68 changes: 2 additions & 66 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,73 +73,9 @@ def calculate_memory_args():

def choose_omero_version():
"""
Returns an array specifying the build parameter for
ant. Returned as an array so that an empty value can
be extended into the build command.
If BUILD_NUMER is set, then "-Domero.version=${omero.version}-b${BUILD_NUMBER}"
otherwise nothing.
No-op. Now handled by components/antlib/resources/version.{py,xml}
"""

omero_build = os.environ.get("BUILD_NUMBER", "")
if omero_build:
omero_build = "-b%s" % omero_build

command = [ find_java(), "omero",BUILD_PY,"-q","version" ]
err = ""
try:
p = popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
omero_version, err = p.communicate()
omero_version = omero_version.split()[1]

# If we're not on hudson, then we don't want to force
# users to deal with rebuilding after each commit.
# Instead, drop everything except for "-DEV"
#
# See gh-67 for the discussion.
if not omero_build:
omero_version = re.sub("([-]DEV)?-\d+-[a-f0-9]+(-dirty)?",\
"-DEV", omero_version)
except:
print "Error getting version for BUILD_NUMBER=%s" % omero_build
if err:
print err
sys.exit(1)

command = [ find_java(), "omero",BUILD_PY,"-q","plainversion" ]
err = ""
try:
p = popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
omero_plain_version, err = p.communicate()
omero_plain_version = omero_plain_version.split()[1]
if not omero_build:
omero_plain_version = re.sub("([-]DEV)?-\d+-[a-f0-9]+(-dirty)?",\
"-DEV", omero_plain_version)
except:
print "Error getting plain version for BUILD_NUMBER=%s" % omero_build
if err:
print err
sys.exit(1)

command = [ find_java(), "omero",BUILD_PY,"-q","shortversion" ]
err = ""
try:
p = popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
omero_short_version, err = p.communicate()
omero_short_version = omero_short_version.split()[1]
if not omero_build:
omero_short_version = re.sub("([-]DEV)?-\d+-[a-f0-9]+(-dirty)?",\
"-DEV", omero_short_version)
except:
print "Error getting short version for BUILD_NUMBER=%s" % omero_build
if err:
print err
sys.exit(1)

return [ "-Domero.version=%s%s" % (omero_version, omero_build),
"-Domero.plainversion=%s" % (omero_plain_version),
"-Domero.shortversion=%s" % (omero_short_version) ]

return []

def handle_tools(args):
_ = os.path.sep.join
Expand Down
63 changes: 3 additions & 60 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ To get started using Eclipse, execute "./build.py build-dev" and import the top-

<property name="gitmatch" value="v.[0-9]*.[0-9]*.[0-9]*"/>
<property name="import.dir" value="${basedir}/components/antlib/resources"/>
<import file="${import.dir}/global.xml"/>
<import file="${import.dir}/gitversion.xml" optional="true"/>
<import file="${import.dir}/global.xml"/>
<import file="${import.dir}/version.xml"/>

<target name="init" depends="check-bioformats,check-ivy,check-scons,check-ice">
<mkdir dir="${blitz.comp}/generated"/>
Expand Down Expand Up @@ -455,6 +456,7 @@ To get started using Eclipse, execute "./build.py build-dev" and import the top-
<exec executable="python" failonerror="true">
<arg value="${omero.home}/components/antlib/scripts/source-archive"/>
<arg value="openmicroscopy"/>
<arg value="${omero.version}"/>
<arg value="${omero.shortversion}"/>
<arg value="${omero.plainversion}"/>
<arg value="components/antlib/resources/gitversion.xml"/>
Expand Down Expand Up @@ -1057,65 +1059,6 @@ omero.version=${omero.version}
</sequential>
</macrodef>

<macrodef name="gitdescribe">
<attribute name="regexp" default="^(v.)?(.*?)(-[0-9]+)?((-)g(.*?))?$"/>
<attribute name="select" default="\2"/>
<attribute name="match" default="${gitmatch}"/>
<sequential>
<trycatch>
<try>
<git command="describe" output="fullversion" failonerror="true">
<args>
<arg value="--match"/>
<arg value="@{match}"/>
<arg line="--dirty"/>
</args>
</git>
<propertyregex property="version.describe" input="${fullversion}" regexp="@{regexp}" select="@{select}"/>
</try>
<catch>
<echo>UNKNOWN</echo>
</catch>
</trycatch>
</sequential>
</macrodef>

<target name="version-embed" if="omero.plainversion">
<echo>${omero.plainversion}-ice${versions.ice_lib}</echo>
</target>

<target name="version-git" unless="omero.plainversion">
<gitdescribe select="\2\3\5\6">
</gitdescribe>
<echo>${version.describe}-ice${versions.ice_lib}</echo>
</target>

<target name="version" depends="version-embed,version-git"/>

<target name="plainversion-embed" if="omero.plainversion">
<echo>${omero.plainversion}</echo>
</target>

<target name="plainversion-git" unless="omero.plainversion">
<gitdescribe select="\2\3\5\6">
</gitdescribe>
<echo>${version.describe}</echo>
</target>

<target name="plainversion" depends="plainversion-embed,plainversion-git"/>

<target name="shortversion-embed" if="omero.shortversion">
<echo>${omero.shortversion}</echo>
</target>

<target name="shortversion-git" unless="omero.shortversion">
<gitdescribe select="\2">
</gitdescribe>
<echo>${version.describe}</echo>
</target>

<target name="shortversion" depends="shortversion-embed,shortversion-git"/>

<target name="print-mem">
<echo>
*.maxmem.* settings
Expand Down
13 changes: 0 additions & 13 deletions components/antlib/resources/global.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,6 @@
</else>
</if>

<!-- prevent direct use of ant -->
<if><not><isset property="build.py"/></not>
<then>
<fail> ERROR!

========================================================
Please use ./build.py which uses the ant version bundled
with OMERO.
========================================================
</fail>
</then>
</if>

<!-- Now, if the memory settings have not been changed
check the defaults passed in on the command line -->
<if><and><not><isset property="javac.maxmem"/></not>
Expand Down
94 changes: 94 additions & 0 deletions components/antlib/resources/version.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="version" default="version" basedir=".">
<!--
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright 2014 Glencoe Software, Inc. All rights reserved.
# Use is subject to license terms supplied in LICENSE.txt
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Written by: Josh Moore, josh at glencoesoftware.com
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-->
<description>
Provides git-based version strings. These can be overwritten on the
command-line by setting the following properties:

omero.version 5.0.0-ice35-b10, etc.
omero.plainversion e.g. 5.0.0-SNAPSHOT
omero.shortversion e.g. 5.0.0

The omero.v namespace is for properties internal to this build file
and should not be modified.
</description>

<property name="omero.v.regexp" value="^(v.)?(.*?)(-[0-9]+)?((-)g(.*?))?$"/>

<!-- Unset from etc/local.properties -->
<if>
<equals arg1="${omero.version}" arg2="UNKNOWN"/>
<then>
<var name="omero.version" unset="true"/>
</then>
</if>

<macrodef name="omero_v_was_preset">
<attribute name="property"/>
<sequential>
<if>
<isset property="@{property}"/>
<then>
<property name="@{property}.source" value="preset"/>
</then>
</if>
</sequential>
</macrodef>

<trycatch>
<try>
<!-- *EITHER* these values are preset -->
<omero_v_was_preset property="omero.version"/>
<omero_v_was_preset property="omero.plainversion"/>
<omero_v_was_preset property="omero.shortversion"/>

<!-- *OR* they'll be set by git -->
<git command="describe" output="omero.v.git" failonerror="true">
<args>
<arg value="--match"/>
<arg value="${gitmatch}"/>
<arg line="--dirty"/>
</args>
</git>
<propertyregex property="omero.shortversion"
input="${omero.v.git}" regexp="${omero.v.regexp}" select="\2"/>
<propertyregex property="omero.plainversion"
input="${omero.v.git}" regexp="${omero.v.regexp}" select="\2\3\5\6"/>
<exec executable = "python" dir = "${basedir}/components/antlib/scripts"
outputproperty = "omero.version"
failonerror = "true">
<arg value = "parse_version" />
<arg value = "${omero.plainversion}-ice${versions.ice_lib}"/>
</exec>
<property name="omero.version.source" value="git"/>
<property name="omero.plainversion.source" value="git"/>
<property name="omero.shortversion.source" value="git"/>
</try>
<catch>
<!-- *OR* we'll finally fall back to UNKNOWN -->
<property name="omero.version" value="UNKNOWN"/>
<property name="omero.plainversion" value="UNKNOWN"/>
<property name="omero.shortversion" value="UNKNOWN"/>
</catch>
</trycatch>

<target name="version-info">
<echo>Git describe output: ${omero.v.git}</echo>
<echo>Official: ${omero.version} (${omero.version.source})</echo>
<echo>Plain: ${omero.plainversion} (${omero.plainversion.source})</echo>
<echo>Short: ${omero.shortversion} (${omero.shortversion.source})</echo>
</target>

</project>
103 changes: 103 additions & 0 deletions components/antlib/scripts/parse_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
# Copyright (C) 2014 Glencoe Software, Inc. All Rights Reserved.
# Use is subject to license terms supplied in LICENSE.txt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

"""
Helper script to simpliy version.xml
"""

import os
import re
import sys

def choose_omero_version(omero_version):
"""
Returns an array specifying the build parameter for
ant. Returned as an array so that an empty value can
be extended into the build command.
If BUILD_NUMER is set, then "-Domero.version=${omero.version}-b${BUILD_NUMBER}"
otherwise nothing.
"""

omero_build = os.environ.get("BUILD_NUMBER", "")
if omero_build:
omero_build = "-b%s" % omero_build

err = ""
try:
if not omero_build:
try:
omero_version = snapshot_logic(omero_version)
except:
pass
return "%s%s" % (omero_version, omero_build)
except:
print "Error getting version for BUILD_NUMBER=%s" % omero_build
if err:
print err
sys.exit(1)

def snapshot_logic(omero_version):
"""
If we're not on hudson, then we don't want to force
users to deal with rebuilding after each commit.
Instead, drop everything except for "-DEV"
See gh-67 for the discussion.
"""

omero_version = re.sub("([-]DEV)?-\d+-[a-f0-9]+(-dirty)?-ice[0-9]+$",
"-SNAPSHOT", omero_version)

# For maven-compatibility, we take "SNAPSHOT" of the _next_ version
try:
# First we try to use distutils
from distutils.version import LooseVersion
version = LooseVersion(omero_version).version
# Find the last index which is an int
for idx in range(len(version)-1, 0, -1):
val = version[idx]
if isinstance(val, int):
version[idx] += 1
break

last_int = False
new_vers = ""
for val in version:
if isinstance(val, int):
if last_int:
new_vers += "."
else:
last_int = True
else:
last_int = False
new_vers += str(val)
omero_version = new_vers
except:
# But if that doesn't work, we brute force with regex
m = re.match("^([^\d]*\d+[.]\d+[.])(\d+)-SNAPSHOT$", omero_version)
if m:
next = int(m.group(2)) + 1
omero_version = "%s%s-SNAPSHOT" % (m.group(1), next)
return omero_version

if __name__ == "__main__":
print choose_omero_version(sys.argv[1]),
Loading

0 comments on commit 579c8f2

Please sign in to comment.