Have 'mach doc' copy Rust documentation.

This commit is contained in:
Simon Sapin 2014-11-28 18:27:11 +00:00
parent 873ca6cadd
commit d25c66904e
2 changed files with 33 additions and 18 deletions

View file

@ -8,14 +8,9 @@ set -e
cd "$(dirname $0)/../.." cd "$(dirname $0)/../.."
mkdir -p components/servo/target/doc
./mach bootstrap-rust
# Ordered so that:
# * etc/doc.servo.org/index.html overwrites $(mach rust-root)/doc/index.html
# * ./mach doc overwrites $(mach rust-root)/doc/search-index.js
cp -R $(./mach rust-root)/doc/* components/servo/target/doc/
cp etc/doc.servo.org/* components/servo/target/doc/
./mach doc ./mach doc
# etc/doc.servo.org/index.html overwrites $(mach rust-root)/doc/index.html
cp etc/doc.servo.org/* components/servo/target/doc/
ghp-import -n components/servo/target/doc ghp-import -n components/servo/target/doc
git push -qf https://${TOKEN}@github.com/servo/doc.servo.org.git gh-pages git push -qf https://${TOKEN}@github.com/servo/doc.servo.org.git gh-pages

View file

@ -1,13 +1,14 @@
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import argparse import argparse
import os
import os.path as path import os.path as path
from os import chdir from os import chdir
import subprocess import subprocess
import SimpleHTTPServer import SimpleHTTPServer
import SocketServer import SocketServer
import mozdebug import mozdebug
from shutil import copytree, rmtree, ignore_patterns from shutil import copytree, rmtree, ignore_patterns, copy2
from mach.decorators import ( from mach.decorators import (
CommandArgument, CommandArgument,
@ -18,6 +19,13 @@ from mach.decorators import (
from servo.command_base import CommandBase from servo.command_base import CommandBase
def read_file(filename, if_exists=False):
if if_exists and not path.exists(filename):
return None
with open(filename) as f:
return f.read()
@CommandProvider @CommandProvider
class MachCommands(CommandBase): class MachCommands(CommandBase):
@Command('run', @Command('run',
@ -70,6 +78,27 @@ class MachCommands(CommandBase):
help="Command-line arguments to be passed through to cargo doc") help="Command-line arguments to be passed through to cargo doc")
def doc(self, params): def doc(self, params):
self.ensure_bootstrapped() self.ensure_bootstrapped()
rust_docs = path.join(self.config["tools"]["rust-root"], "doc")
docs = path.join("components", "servo", "target", "doc")
if not path.exists(docs):
os.mkdir(docs)
if read_file(path.join(docs, "version_info.html"), if_exists=True) != \
read_file(path.join(rust_docs, "version_info.html")):
print("Copying Rust documentation.")
# copytree doesn't like the destination already existing.
for name in os.listdir(rust_docs):
if not name.startswith('.'):
full_name = path.join(rust_docs, name)
destination = path.join(docs, name)
if path.isdir(full_name):
if path.exists(destination):
rmtree(destination)
copytree(full_name, destination)
else:
copy2(full_name, destination)
return subprocess.call(["cargo", "doc"] + params, return subprocess.call(["cargo", "doc"] + params,
env=self.build_env(), cwd=self.servo_crate()) env=self.build_env(), cwd=self.servo_crate())
@ -81,16 +110,7 @@ class MachCommands(CommandBase):
help="Port to serve documentation at (default is 8888)") help="Port to serve documentation at (default is 8888)")
def serve_docs(self, port): def serve_docs(self, port):
self.doc([]) self.doc([])
servedir = path.join("components", "servo", "target", "serve-docs") chdir(path.join("components", "servo", "target", "doc"))
docdir = path.join("components", "servo", "target", "doc")
rmtree(servedir, True)
copytree(docdir, servedir, ignore=ignore_patterns('.*'))
rustdocs = path.join(self.config["tools"]["rust-root"], "doc")
copytree(rustdocs, path.join(servedir, "rust"), ignore=ignore_patterns('.*'))
chdir(servedir)
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", port), Handler) httpd = SocketServer.TCPServer(("", port), Handler)