build/buildutils/ver2binver.py
changeset 67 63b81d807542
equal deleted inserted replaced
64:0ea12c182930 67:63b81d807542
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 #
       
    16 # This script changes a JRT version to a binary version usable as 
       
    17 # Symbian mmp-file version or qmake's version.
       
    18 # - each version part is cut to three digits, and then to 8 bits
       
    19 # - qmake's version is taken as is, mmp's version is mangled as by qmake (the
       
    20 #   resulting version is the same in binaries).
       
    21 # - major version is always 10
       
    22 
       
    23 import sys, re 
       
    24 
       
    25 
       
    26 USAGE = "usage: %s [qmake|mmp] 1.2.3\n" % sys.argv[0]
       
    27 
       
    28 def main():
       
    29     try:
       
    30         if len(sys.argv) != 3:
       
    31             raise Exception(USAGE)
       
    32 
       
    33         mode, javaversion = sys.argv[1:]
       
    34 
       
    35         if mode != "qmake" and mode != "mmp":
       
    36             raise Exception(USAGE)
       
    37 
       
    38         # Match version
       
    39         parts = re.match(r"^(\d+)\.(\d+)\.(\d+)$", javaversion)
       
    40         if not parts:
       
    41             raise Exception(USAGE)
       
    42 
       
    43         # Change to integer
       
    44         parts = [int(p) for p in parts.groups()]
       
    45 
       
    46         # Modulo 1000, 256
       
    47         parts = [(p % 1000) % 256 for p in parts]
       
    48 
       
    49         # Print according to type
       
    50         if mode == "qmake":
       
    51             print "%d.%d.%d" % (10, parts[1], parts[2])
       
    52         else:
       
    53             print "%d.%d" % (10, (parts[1] << 8) + parts[2])
       
    54 
       
    55     
       
    56     except Exception, e:
       
    57         sys.stderr.write(e.__str__())
       
    58         sys.exit(1)
       
    59 
       
    60 
       
    61 if __name__ == "__main__":
       
    62     main()
       
    63 
       
    64