From 579c8f20e087330a91024029e7e5deffa02e8a71 Mon Sep 17 00:00:00 2001 From: jmoore Date: Tue, 29 Apr 2014 00:38:38 +0200 Subject: [PATCH] Rework ant version properties 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 ``` ``` elements, it's possible to remove the requirement to use build.py. --- build.py | 68 +-------------- build.xml | 63 +------------- components/antlib/resources/global.xml | 13 --- components/antlib/resources/version.xml | 94 +++++++++++++++++++++ components/antlib/scripts/parse_version | 103 +++++++++++++++++++++++ components/antlib/scripts/source-archive | 20 +++-- 6 files changed, 215 insertions(+), 146 deletions(-) create mode 100644 components/antlib/resources/version.xml create mode 100755 components/antlib/scripts/parse_version diff --git a/build.py b/build.py index 0c1ba9caf43..07be840aa5c 100755 --- a/build.py +++ b/build.py @@ -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 diff --git a/build.xml b/build.xml index ded203b5c0f..90c8b02f8b5 100644 --- a/build.xml +++ b/build.xml @@ -54,8 +54,9 @@ To get started using Eclipse, execute "./build.py build-dev" and import the top- - + + @@ -455,6 +456,7 @@ To get started using Eclipse, execute "./build.py build-dev" and import the top- + @@ -1057,65 +1059,6 @@ omero.version=${omero.version} - - - - - - - - - - - - - - - - - - UNKNOWN - - - - - - - ${omero.plainversion}-ice${versions.ice_lib} - - - - - - ${version.describe}-ice${versions.ice_lib} - - - - - - ${omero.plainversion} - - - - - - ${version.describe} - - - - - - ${omero.shortversion} - - - - - - ${version.describe} - - - - *.maxmem.* settings diff --git a/components/antlib/resources/global.xml b/components/antlib/resources/global.xml index 285974a4c83..62e72efdbc4 100644 --- a/components/antlib/resources/global.xml +++ b/components/antlib/resources/global.xml @@ -247,19 +247,6 @@ - - - - ERROR! - -======================================================== -Please use ./build.py which uses the ant version bundled -with OMERO. -======================================================== - - - - diff --git a/components/antlib/resources/version.xml b/components/antlib/resources/version.xml new file mode 100644 index 00000000000..a016d925ad1 --- /dev/null +++ b/components/antlib/resources/version.xml @@ -0,0 +1,94 @@ + + + + + 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. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Git describe output: ${omero.v.git} + Official: ${omero.version} (${omero.version.source}) + Plain: ${omero.plainversion} (${omero.plainversion.source}) + Short: ${omero.shortversion} (${omero.shortversion.source}) + + + diff --git a/components/antlib/scripts/parse_version b/components/antlib/scripts/parse_version new file mode 100755 index 00000000000..e84ec2b7ce8 --- /dev/null +++ b/components/antlib/scripts/parse_version @@ -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]), diff --git a/components/antlib/scripts/source-archive b/components/antlib/scripts/source-archive index a36a29cd05d..aee89a9e8a1 100755 --- a/components/antlib/scripts/source-archive +++ b/components/antlib/scripts/source-archive @@ -24,14 +24,15 @@ import zipfile # polluting the release with version control files. if __name__ == "__main__": - if len(sys.argv) != 6: - raise Exception('Usage: %s releasename shortversion fullversion versionfile targetdir') + if len(sys.argv) != 7: + raise Exception('Usage: %s releasename version shortversion fullversion versionfile targetdir') release = sys.argv[1] - shortversion = sys.argv[2] - version = sys.argv[3] - versionfile = sys.argv[4] - target = os.path.abspath(sys.argv[5]) + omero_version = sys.argv[2] + shortversion = sys.argv[3] + version = sys.argv[4] + versionfile = sys.argv[5] + target = os.path.abspath(sys.argv[6]) release = "%s-%s" % (release,version) if not os.path.isdir('.git'): @@ -91,7 +92,12 @@ if __name__ == "__main__": basezip.writestr("%s/%s" % (release, versionfile), """ + + + + + -""" % (shortversion, version)) +""" % (omero_version, shortversion, version))