| 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 pwd | 8 import pwd |
| 9 import sys | 9 import sys |
| 10 import subprocess | 10 import subprocess |
| 11 import platform |
| 11 import getpass | 12 import getpass |
| 12 from os.path import join | 13 from os.path import join |
| 13 import time | 14 import time |
| 14 from optparse import OptionParser | 15 from optparse import OptionParser |
| 15 | 16 |
| 16 def getVersionPart(version_file, part): | 17 def getVersionPart(version_file, part): |
| 17 proc = subprocess.Popen(['awk', | 18 proc = subprocess.Popen(['awk', |
| 18 '$1 == "%s" {print $2}' % (part), | 19 '$1 == "%s" {print $2}' % (part), |
| 19 version_file], | 20 version_file], |
| 20 stdout=subprocess.PIPE, | 21 stdout=subprocess.PIPE, |
| 21 stderr=subprocess.STDOUT) | 22 stderr=subprocess.STDOUT) |
| 22 return proc.communicate()[0].split('\n')[0] | 23 return proc.communicate()[0].split('\n')[0] |
| 23 | 24 |
| 24 def getRevision(): | 25 def getRevision(): |
| 25 is_svn = True | 26 is_svn = True |
| 26 if os.path.exists('.svn'): | 27 if os.path.exists('.svn'): |
| 27 cmd = ['svn', 'info'] | 28 cmd = ['svn', 'info'] |
| 28 else: | 29 else: |
| 29 cmd = ['git', 'svn', 'info'] | 30 cmd = ['git', 'svn', 'info'] |
| 30 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 31 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 31 return proc.communicate()[0].split('\n')[4].split(' ')[1] | 32 return proc.communicate()[0].split('\n')[4].split(' ')[1] |
| 32 | 33 |
| 33 def makeVersionString(version_file): | 34 def makeVersionString(version_file): |
| 35 id = platform.system() |
| 36 if id == 'Windows' or id == 'Microsoft': |
| 37 return '0.0.0.0' |
| 34 major = getVersionPart(version_file, 'MAJOR') | 38 major = getVersionPart(version_file, 'MAJOR') |
| 35 minor = getVersionPart(version_file, 'MINOR') | 39 minor = getVersionPart(version_file, 'MINOR') |
| 36 build = getVersionPart(version_file, 'BUILD') | 40 build = getVersionPart(version_file, 'BUILD') |
| 37 patch = getVersionPart(version_file, 'PATCH') | 41 patch = getVersionPart(version_file, 'PATCH') |
| 38 revision = getRevision() | 42 revision = getRevision() |
| 39 user = getpass.getuser() | 43 user = getpass.getuser() |
| 40 return '%s.%s.%s.%s_%s_%s' % (major, minor, build, patch, revision, user) | 44 return '%s.%s.%s.%s_%s_%s' % (major, minor, build, patch, revision, user) |
| 41 | 45 |
| 42 def makeFile(output_file, input_file, version_file): | 46 def makeFile(output_file, input_file, version_file): |
| 43 version_cc_text = open(input_file).read() | 47 version_cc_text = open(input_file).read() |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 86 |
| 83 return 0 | 87 return 0 |
| 84 except Exception, inst: | 88 except Exception, inst: |
| 85 sys.stderr.write('make_version.py exception\n') | 89 sys.stderr.write('make_version.py exception\n') |
| 86 sys.stderr.write(str(inst)) | 90 sys.stderr.write(str(inst)) |
| 87 sys.stderr.write('\n') | 91 sys.stderr.write('\n') |
| 88 return -1 | 92 return -1 |
| 89 | 93 |
| 90 if __name__ == '__main__': | 94 if __name__ == '__main__': |
| 91 sys.exit(main(sys.argv)) | 95 sys.exit(main(sys.argv)) |
| OLD | NEW |