| OLD | NEW |
| 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
| 3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
| 4 # | 4 # |
| 5 # This python script creates a version string in a C++ file. | 5 # This python script creates a version string in a C++ file. |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import subprocess | 9 import subprocess |
| 10 import platform | 10 import platform |
| 11 import getpass | 11 import getpass |
| 12 from os.path import join | 12 from os.path import join |
| 13 import time | 13 import time |
| 14 from optparse import OptionParser | 14 from optparse import OptionParser |
| 15 | 15 |
| 16 def getVersionPart(version_file, part): | 16 def getVersionPart(version_file, part): |
| 17 proc = subprocess.Popen(['awk', | 17 proc = subprocess.Popen(['awk', |
| 18 '$1 == "%s" {print $2}' % (part), | 18 '$1 == "%s" {print $2}' % (part), |
| 19 version_file], | 19 version_file], |
| 20 stdout=subprocess.PIPE, | 20 stdout=subprocess.PIPE, |
| 21 stderr=subprocess.STDOUT) | 21 stderr=subprocess.STDOUT) |
| 22 return proc.communicate()[0].split('\n')[0] | 22 return proc.communicate()[0].split('\n')[0] |
| 23 | 23 |
| 24 def getRevision(): | 24 def getRevision(): |
| 25 is_svn = True | 25 is_svn = True |
| 26 if os.path.exists('.svn'): | 26 if os.path.exists('.svn'): |
| 27 cmd = ['svn', 'info'] | 27 cmd = ['svn', 'info'] |
| 28 else: | 28 else: |
| 29 cmd = ['git', 'svn', 'info'] | 29 cmd = ['git', 'svn', 'info'] |
| 30 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 30 try: |
| 31 return proc.communicate()[0].split('\n')[4].split(' ')[1] | 31 proc = subprocess.Popen(cmd, |
| 32 | 32 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 33 return proc.communicate()[0].split('\n')[4].split(' ')[1] |
| 34 except Exception: |
| 35 # If we can't get any revision info (due to lack of tooling) return ''. |
| 36 return '' |
| 37 |
| 38 |
| 33 def makeVersionString(version_file): | 39 def makeVersionString(version_file): |
| 34 id = platform.system() | 40 id = platform.system() |
| 35 if id == 'Windows' or id == 'Microsoft': | 41 if id == 'Windows' or id == 'Microsoft': |
| 36 return '0.0.0.0' | 42 return '0.0.0.0' |
| 37 major = getVersionPart(version_file, 'MAJOR') | 43 major = getVersionPart(version_file, 'MAJOR') |
| 38 minor = getVersionPart(version_file, 'MINOR') | 44 minor = getVersionPart(version_file, 'MINOR') |
| 39 build = getVersionPart(version_file, 'BUILD') | 45 build = getVersionPart(version_file, 'BUILD') |
| 40 patch = getVersionPart(version_file, 'PATCH') | 46 patch = getVersionPart(version_file, 'PATCH') |
| 41 revision = getRevision() | 47 revision = getRevision() |
| 42 user = getpass.getuser() | 48 user = getpass.getuser() |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 91 |
| 86 return 0 | 92 return 0 |
| 87 except Exception, inst: | 93 except Exception, inst: |
| 88 sys.stderr.write('make_version.py exception\n') | 94 sys.stderr.write('make_version.py exception\n') |
| 89 sys.stderr.write(str(inst)) | 95 sys.stderr.write(str(inst)) |
| 90 sys.stderr.write('\n') | 96 sys.stderr.write('\n') |
| 91 return -1 | 97 return -1 |
| 92 | 98 |
| 93 if __name__ == '__main__': | 99 if __name__ == '__main__': |
| 94 sys.exit(main(sys.argv)) | 100 sys.exit(main(sys.argv)) |
| OLD | NEW |