2016-05-08 15:03:01 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2016-06-01 14:45:54 +00:00
|
|
|
import os, re, shutil, sys
|
2016-05-08 15:03:01 +00:00
|
|
|
from subprocess import check_call
|
|
|
|
|
|
|
|
class Git:
|
|
|
|
def __init__(self, dir):
|
|
|
|
self.dir = dir
|
|
|
|
|
|
|
|
def call(self, method, args, **kwargs):
|
|
|
|
return check_call(['git', method] + list(args), **kwargs)
|
|
|
|
|
|
|
|
def clone(self, *args):
|
|
|
|
return self.call('clone', list(args) + [self.dir])
|
|
|
|
|
|
|
|
def checkout(self, *args):
|
|
|
|
return self.call('checkout', args, cwd=self.dir)
|
|
|
|
|
2016-05-26 13:44:20 +00:00
|
|
|
def clean(self, *args):
|
|
|
|
return self.call('clean', args, cwd=self.dir)
|
|
|
|
|
|
|
|
def reset(self, *args):
|
|
|
|
return self.call('reset', args, cwd=self.dir)
|
|
|
|
|
2016-06-01 14:45:54 +00:00
|
|
|
def pull(self, *args):
|
|
|
|
return self.call('pull', args, cwd=self.dir)
|
|
|
|
|
|
|
|
def update(self, *args):
|
|
|
|
if not os.path.exists(self.dir):
|
|
|
|
self.clone(*args)
|
|
|
|
|
|
|
|
# Import the documentation build module.
|
2016-05-08 15:03:01 +00:00
|
|
|
fmt_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
sys.path.insert(0, os.path.join(fmt_dir, 'doc'))
|
2016-06-01 14:45:54 +00:00
|
|
|
import build
|
|
|
|
|
2016-06-02 13:52:07 +00:00
|
|
|
build_dir = 'build'
|
2016-06-01 14:45:54 +00:00
|
|
|
|
|
|
|
# Virtualenv and repos are cached to speed up builds.
|
2016-06-02 13:52:07 +00:00
|
|
|
build.create_build_env(os.path.join(build_dir, 'virtualenv'))
|
2016-05-08 15:03:01 +00:00
|
|
|
|
2016-06-02 13:52:07 +00:00
|
|
|
fmt_repo = Git(os.path.join(build_dir, 'fmt'))
|
2016-06-01 14:45:54 +00:00
|
|
|
fmt_repo.update('git@github.com:fmtlib/fmt')
|
2016-05-26 13:44:20 +00:00
|
|
|
|
2016-06-02 13:52:07 +00:00
|
|
|
doc_repo = Git(os.path.join(build_dir, 'fmtlib.github.io'))
|
2016-06-01 14:45:54 +00:00
|
|
|
doc_repo.update('git@github.com:fmtlib/fmtlib.github.io')
|
2016-05-09 15:36:16 +00:00
|
|
|
|
2016-06-02 15:47:33 +00:00
|
|
|
for version in ['1.0.0', '1.1.0', '2.0.0', '3.0.0']:
|
2016-06-01 14:45:54 +00:00
|
|
|
fmt_repo.clean('-f', '-d')
|
|
|
|
fmt_repo.reset('--hard')
|
|
|
|
fmt_repo.checkout(version)
|
|
|
|
target_doc_dir = os.path.join(fmt_repo.dir, 'doc')
|
|
|
|
# Remove the old theme.
|
|
|
|
for entry in os.listdir(target_doc_dir):
|
|
|
|
path = os.path.join(target_doc_dir, entry)
|
|
|
|
if os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
|
|
|
# Copy the new theme.
|
|
|
|
for entry in ['_static', '_templates', 'basic-bootstrap', 'bootstrap',
|
2016-06-02 13:52:07 +00:00
|
|
|
'conf.py', 'fmt.less']:
|
2016-06-01 14:45:54 +00:00
|
|
|
src = os.path.join(fmt_dir, 'doc', entry)
|
|
|
|
dst = os.path.join(target_doc_dir, entry)
|
|
|
|
copy = shutil.copytree if os.path.isdir(src) else shutil.copyfile
|
|
|
|
copy(src, dst)
|
|
|
|
# TODO: update links in navbar
|
|
|
|
# Rename index to contents.
|
|
|
|
contents = os.path.join(target_doc_dir, 'contents.rst')
|
|
|
|
if not os.path.exists(contents):
|
|
|
|
os.rename(os.path.join(target_doc_dir, 'index.rst'), contents)
|
|
|
|
# Fix issues in reference.rst.
|
|
|
|
reference = os.path.join(target_doc_dir, 'reference.rst')
|
|
|
|
if os.path.exists(reference):
|
|
|
|
with open(reference) as f:
|
|
|
|
data = f.read()
|
|
|
|
data = data.replace('std::ostream &', 'std::ostream&')
|
|
|
|
data = re.sub(r'doxygenfunction.. (bin|oct|hexu|hex)',
|
2016-06-02 13:52:07 +00:00
|
|
|
r'doxygenfunction:: \1(int)', data)
|
2016-06-01 14:45:54 +00:00
|
|
|
with open(reference, 'w') as f:
|
|
|
|
f.write(data)
|
|
|
|
# Build the docs.
|
2016-06-02 15:47:33 +00:00
|
|
|
html_dir = os.path.join(build_dir, 'html')
|
|
|
|
if os.path.exists(html_dir):
|
|
|
|
shutil.rmtree(html_dir)
|
|
|
|
build.build_docs(version, doc_dir=target_doc_dir,
|
|
|
|
include_dir=fmt_repo.dir, work_dir=build_dir)
|
2016-06-01 14:45:54 +00:00
|
|
|
# Create symlinks for older versions.
|
|
|
|
for link, target in {'index': 'contents', 'api': 'reference'}.items():
|
2016-06-02 15:47:33 +00:00
|
|
|
link = os.path.join(html_dir, link) + '.html'
|
|
|
|
target += '.html'
|
|
|
|
if os.path.exists(os.path.join(html_dir, target)) and \
|
|
|
|
not os.path.exists(link):
|
|
|
|
os.symlink(target, link)
|
2016-06-01 14:45:54 +00:00
|
|
|
# Copy docs to the website.
|
|
|
|
version_doc_dir = os.path.join(doc_repo.dir, version)
|
|
|
|
shutil.rmtree(version_doc_dir)
|
|
|
|
shutil.move(html_dir, version_doc_dir)
|