diff options
| author | Axel Waggershauser <awagger@gmail.com> | 2015-02-11 00:17:30 +0100 |
|---|---|---|
| committer | Axel Waggershauser <awagger@gmail.com> | 2015-02-11 00:17:30 +0100 |
| commit | bc4b28b06932cb05270345ecb5e686c6c53dd611 (patch) | |
| tree | 310ea92700de4062498617376f54de34d4406fd8 /vcstagger.py | |
| parent | 129bb902bc94547c3a2a8e4ff29ee91c8d5fc427 (diff) | |
| parent | 57e74de3aea47a361cfb358bfbb78dbda5866109 (diff) | |
| download | meson-bc4b28b06932cb05270345ecb5e686c6c53dd611.tar.gz | |
tracked upstream (mostly new vcs_tag)
Diffstat (limited to 'vcstagger.py')
| -rwxr-xr-x | vcstagger.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vcstagger.py b/vcstagger.py new file mode 100755 index 000000000..f754358f5 --- /dev/null +++ b/vcstagger.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +# Copyright 2015 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys, os, subprocess + +def tag(infile, outfile, fallback): + tagid = get_string(infile, fallback) + newdata = open(infile).read().replace('@VCS_TAG@', tagid) + try: + olddata = open(outfile).read() + if olddata == newdata: + return + except Exception: + pass + open(outfile, 'w').write(newdata) + +def get_string(infile, fallback): + absfile = os.path.join(os.getcwd(), infile) + directory = os.path.split(absfile)[0] + segs = directory.replace('\\', '/').split('/') + for i in range(len(segs), -1, -1): + curdir = '/'.join(segs[:i]) + if os.path.isdir(os.path.join(curdir, '.git')): + output = subprocess.check_output(['git', 'describe'], + cwd = directory) + return output.decode().strip() + elif os.path.isdir(os.path.join(curdir, '.hg')): + output = subprocess.check_output(['hg', 'identify'], + cwd=directory) + return output.decode().strip() + elif os.path.isdir(os.path.join(curdir, '.bzr')): + output = subprocess.check_output(['bzr', 'revno'], + cwd=directory) + return output.decode().strip() + elif os.path.isdir(os.path.join(curdir, '.svn')): + output = subprocess.check_output(['svn', 'info'], + cwd=directory) + for line in output.decode().split('\n'): + (k, v) = line.split(':', 1) + if k.strip() == 'Revision': + return v.strip() + raise RuntimeError('Svn output malformed.') + return fallback + +if __name__ == '__main__': + infile = sys.argv[1] + outfile = sys.argv[2] + fallback = sys.argv[3] + tag(infile, outfile, fallback) |
