Home | History | Annotate | Download | only in build_tools
      1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """Small utility library of python functions used during SDK building.
      6 """
      7 
      8 import os
      9 import sys
     10 
     11 # pylint: disable=E0602
     12 
     13 # Reuse last change utility code.
     14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
     15 SRC_DIR = os.path.dirname(os.path.dirname(os.path.dirname(SCRIPT_DIR)))
     16 sys.path.append(os.path.join(SRC_DIR, 'build/util'))
     17 import lastchange
     18 
     19 
     20 # Location of chrome's version file.
     21 VERSION_PATH = os.path.join(SRC_DIR, 'chrome', 'VERSION')
     22 
     23 
     24 def ChromeVersion():
     25   '''Extract chrome version from src/chrome/VERSION + svn.
     26 
     27   Returns:
     28     Chrome version string or trunk + svn rev.
     29   '''
     30   info = lastchange.FetchVersionInfo(None)
     31   if info.url.startswith('/trunk/'):
     32     return 'trunk.%s' % info.revision
     33   else:
     34     return ChromeVersionNoTrunk()
     35 
     36 
     37 def ChromeVersionNoTrunk():
     38   '''Extract the chrome version from src/chrome/VERSION.
     39   Ignore whether this is a trunk build.
     40 
     41   Returns:
     42     Chrome version string.
     43   '''
     44   exec(open(VERSION_PATH).read())
     45   return '%s.%s.%s.%s' % (MAJOR, MINOR, BUILD, PATCH)
     46 
     47 
     48 def ChromeMajorVersion():
     49   '''Extract chrome major version from src/chrome/VERSION.
     50 
     51   Returns:
     52     Chrome major version.
     53   '''
     54   exec(open(VERSION_PATH, 'r').read())
     55   return str(MAJOR)
     56 
     57 
     58 def ChromeRevision():
     59   '''Extract chrome revision from svn.
     60 
     61   Returns:
     62     The Chrome revision as a string. e.g. "12345"
     63   '''
     64   return lastchange.FetchVersionInfo(None).revision
     65 
     66 def NaClRevision():
     67   '''Extract NaCl revision from svn.
     68 
     69   Returns:
     70     The NaCl revision as a string. e.g. "12345"
     71   '''
     72   nacl_dir = os.path.join(SRC_DIR, 'native_client')
     73   return lastchange.FetchVersionInfo(None, nacl_dir).revision
     74