summaryrefslogtreecommitdiff
path: root/vcstagger.py
diff options
context:
space:
mode:
authorAxel Waggershauser <awagger@gmail.com>2015-02-11 03:27:40 +0100
committerAxel Waggershauser <awagger@gmail.com>2015-02-11 03:27:40 +0100
commit223596d7bf8ab9b839e0031022c132a3ccd4fd1d (patch)
tree8510597bd390076419237f82bd583b0bfefbac4c /vcstagger.py
parentbc4b28b06932cb05270345ecb5e686c6c53dd611 (diff)
downloadmeson-223596d7bf8ab9b839e0031022c132a3ccd4fd1d.tar.gz
added support for optional custom command and replace_string parameter of vcs_tag
Diffstat (limited to 'vcstagger.py')
-rwxr-xr-xvcstagger.py53
1 files changed, 12 insertions, 41 deletions
diff --git a/vcstagger.py b/vcstagger.py
index f754358f5..ccc584e92 100755
--- a/vcstagger.py
+++ b/vcstagger.py
@@ -14,49 +14,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import sys, os, subprocess
+import sys, os, subprocess, re
-def tag(infile, outfile, fallback):
- tagid = get_string(infile, fallback)
- newdata = open(infile).read().replace('@VCS_TAG@', tagid)
+def config_vcs_tag(infile, outfile, fallback, source_dir, replace_string, regex_selector, cmd):
try:
- olddata = open(outfile).read()
- if olddata == newdata:
- return
+ output = subprocess.check_output(cmd, cwd=source_dir)
+ new_string = re.search(regex_selector, output.decode()).group(1).strip()
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
+ new_string = fallback
+
+ new_data = open(infile).read().replace(replace_string, new_string)
+ if (not os.path.exists(outfile)) or (open(outfile).read() != new_data):
+ open(outfile, 'w').write(new_data)
if __name__ == '__main__':
- infile = sys.argv[1]
- outfile = sys.argv[2]
- fallback = sys.argv[3]
- tag(infile, outfile, fallback)
+ infile, outfile, fallback, source_dir, replace_string, regex_selector = sys.argv[1:7]
+ command = sys.argv[7:]
+ config_vcs_tag(infile, outfile, fallback, source_dir, replace_string, regex_selector, command)