aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo/post_build_commands.py
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2014-11-28 18:27:11 +0000
committerSimon Sapin <simon.sapin@exyr.org>2014-12-02 21:48:52 -0800
commitd25c66904e32759d1b06e891ff20b021f6aadc76 (patch)
tree233ea4899a9b53f5de50cb7d3c71ce07d4484976 /python/servo/post_build_commands.py
parent873ca6cadddc1a40bead1f5dd0128bb16cfaa11b (diff)
downloadservo-d25c66904e32759d1b06e891ff20b021f6aadc76.tar.gz
servo-d25c66904e32759d1b06e891ff20b021f6aadc76.zip
Have 'mach doc' copy Rust documentation.
Diffstat (limited to 'python/servo/post_build_commands.py')
-rw-r--r--python/servo/post_build_commands.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/python/servo/post_build_commands.py b/python/servo/post_build_commands.py
index 972dea7429b..2f692ce7724 100644
--- a/python/servo/post_build_commands.py
+++ b/python/servo/post_build_commands.py
@@ -1,13 +1,14 @@
from __future__ import print_function, unicode_literals
import argparse
+import os
import os.path as path
from os import chdir
import subprocess
import SimpleHTTPServer
import SocketServer
import mozdebug
-from shutil import copytree, rmtree, ignore_patterns
+from shutil import copytree, rmtree, ignore_patterns, copy2
from mach.decorators import (
CommandArgument,
@@ -18,6 +19,13 @@ from mach.decorators import (
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
class MachCommands(CommandBase):
@Command('run',
@@ -70,6 +78,27 @@ class MachCommands(CommandBase):
help="Command-line arguments to be passed through to cargo doc")
def doc(self, params):
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,
env=self.build_env(), cwd=self.servo_crate())
@@ -81,16 +110,7 @@ class MachCommands(CommandBase):
help="Port to serve documentation at (default is 8888)")
def serve_docs(self, port):
self.doc([])
- servedir = path.join("components", "servo", "target", "serve-docs")
- 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)
+ chdir(path.join("components", "servo", "target", "doc"))
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", port), Handler)