From 4b0e858529c3522dc2c622b335729d82fde3e859 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 19 Feb 2015 16:32:45 +0000 Subject: [PATCH] Add $GIT_VERSION to the spec which is replaced by the gendoc script. --- scripts/gendoc.py | 62 ++++++++++++++++++++++++++++++++++++++ specification/00_basis.rst | 3 +- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/scripts/gendoc.py b/scripts/gendoc.py index c5a7aae0..7af17259 100755 --- a/scripts/gendoc.py +++ b/scripts/gendoc.py @@ -1,20 +1,81 @@ #! /usr/bin/env python from docutils.core import publish_file +import fileinput import glob import os import shutil +import subprocess import sys stylesheets = { "stylesheet_path": ["basic.css", "nature.css"] } + +def get_git_ver_string(): + null = open(os.devnull, 'w') + cwd = os.path.dirname(os.path.abspath(__file__)) + try: + git_branch = subprocess.check_output( + ['git', 'rev-parse', '--abbrev-ref', 'HEAD'], + stderr=null, + cwd=cwd, + ).strip() + except subprocess.CalledProcessError: + git_branch = "" + try: + git_tag = subprocess.check_output( + ['git', 'describe', '--exact-match'], + stderr=null, + cwd=cwd, + ).strip() + git_tag = "tag=" + git_tag + except subprocess.CalledProcessError: + git_tag = "" + try: + git_commit = subprocess.check_output( + ['git', 'rev-parse', '--short', 'HEAD'], + stderr=null, + cwd=cwd, + ).strip() + except subprocess.CalledProcessError: + git_commit = "" + try: + dirty_string = "-this_is_a_dirty_checkout" + is_dirty = subprocess.check_output( + ['git', 'describe', '--dirty=' + dirty_string, "--all"], + stderr=null, + cwd=cwd, + ).strip().endswith(dirty_string) + git_dirty = "dirty" if is_dirty else "" + except subprocess.CalledProcessError: + git_dirty = "" + + if git_branch or git_tag or git_commit or git_dirty: + git_version = ",".join( + s for s in + (git_branch, git_tag, git_commit, git_dirty,) + if s + ) + return git_version.encode("ascii") + return "Unknown rev" + + def glob_spec(out_file_name): with open(out_file_name, "wb") as outfile: for f in sorted(glob.glob("../specification/*.rst")): with open(f, "rb") as infile: outfile.write(infile.read()) + +def set_git_version(filename): + git_ver = get_git_ver_string() + # inplace search and replace, stdout is redirected to the output + # file, hence the "print" lines here. + for line in fileinput.input(filename, inplace=True): + if "$GIT_VERSION" in line: + line = line.replace("$GIT_VERSION", git_ver) + print line.rstrip("\n") def rst2html(i, o): @@ -45,6 +106,7 @@ def cleanup_env(): def main(): prepare_env() glob_spec("tmp/full_spec.rst") + set_git_version("tmp/full_spec.rst") rst2html("tmp/full_spec.rst", "gen/specification.html") rst2html("../howtos/client-server.rst", "gen/howtos.html") cleanup_env() diff --git a/specification/00_basis.rst b/specification/00_basis.rst index 77aec367..22a78a2c 100644 --- a/specification/00_basis.rst +++ b/specification/00_basis.rst @@ -1,5 +1,6 @@ Matrix Specification ==================== +$GIT_VERSION Table of Contents ================= @@ -85,7 +86,7 @@ Version ======= The Matrix spec is currently rapidly evolving, and there have been no versioned -releases as yet. Versions should be identified by git revision, or failing that +releases as yet. Versions should be identified by git revision, or failing that timestamp. Overview