1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
from __future__ import print_function, unicode_literals
import os.path as path
from os import chdir
import subprocess
import SimpleHTTPServer
import SocketServer
from shutil import copytree, rmtree, ignore_patterns
from mach.decorators import (
CommandArgument,
CommandProvider,
Command,
)
from servo.command_base import CommandBase
@CommandProvider
class MachCommands(CommandBase):
@Command('run',
description='Run Servo',
category='post-build',
allow_all_args=True)
@CommandArgument(
'params', default=None, nargs='...',
help="Command-line arguments to be passed through to Servo")
def run(self, params):
subprocess.check_call([path.join("target", "servo")] + params,
env=self.build_env())
@Command('doc',
description='Generate documentation',
category='post-build',
allow_all_args=True)
@CommandArgument(
'params', default=None, nargs='...',
help="Command-line arguments to be passed through to cargo doc")
def doc(self, params):
self.ensure_bootstrapped()
return subprocess.call(["cargo", "doc"] + params,
env=self.build_env())
@Command('serve-docs',
description='Locally serve Servo and Rust documentation',
category='post-build',
allow_all_args=True)
@CommandArgument(
'port', default=8888, nargs='?', type=int, metavar='PORT',
help="Port to serve documentation at (default is 8888)")
def serve_docs(self, port):
self.doc([])
servedir = path.join("target", "serve-docs")
docdir = path.join("target", "doc")
rmtree(servedir, True)
copytree(docdir, servedir, ignore=ignore_patterns('.*'))
rustdocs = path.join("rust", self.rust_snapshot_path(), "doc")
copytree(rustdocs, path.join(servedir, "rust"), ignore=ignore_patterns('.*'))
chdir(servedir)
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", port), Handler)
print("serving at port", port)
httpd.serve_forever()
|