Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1071)

Side by Side Diff: chrome/common/extensions/docs/build/build.py

Issue 159607: Extension docs build script, gyp target and PRESUBMIT.PY check (Closed)
Patch Set: remove build step on mac Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Docbuilder for extension docs."""
7
8 import os
9 import os.path
10 import shutil
11 import sys
12
13 from subprocess import Popen, PIPE
14 from optparse import OptionParser
15
16 _script_path = os.path.realpath(__file__)
17 _build_dir = os.path.dirname(_script_path)
18 _base_dir = os.path.normpath(_build_dir + "/..")
19 _static_dir = _base_dir + "/static"
20 _js_dir = _base_dir + "/js"
21 _template_dir = _base_dir + "/template"
22 _extension_api_dir = os.path.normpath(_base_dir + "/../api")
23
24 _extension_api_json = _extension_api_dir + "/extension_api.json"
25 _api_template_html = _template_dir + "/api_template.html"
26 _page_shell_html = _template_dir + "/page_shell.html"
27 _generator_html = _build_dir + "/generator.html"
28
29 _expected_output_preamble = "<!DOCTYPE html>"
30
31 # HACK! This is required because we can only depend on python 2.4 and
32 # the calling environment may not be setup to set the PYTHONPATH
33 sys.path.append(os.path.normpath(_base_dir +
34 "/../../../../third_party/simplejson"))
35 import simplejson as json
36
37 def RenderPage(name, test_shell):
38 """
39 Calls test_shell --layout-tests .../generator.html?<name> and writes the
40 result to .../docs/<name>.html
41 """
42
43 if not name:
44 raise Exception("RenderPage called with empty name");
45
46 generator_url = _generator_html + "?" + name
47 output_file = _base_dir + "/" + name + ".html"
48
49 # Copy page_shell to destination output;
50 if (os.path.isfile(output_file)):
51 os.remove(output_file)
52
53 shutil.copy(_page_shell_html, output_file)
54
55 # Run test_shell and capture result
56 p = Popen([test_shell, "--layout-tests", generator_url], shell=True,
57 stdout=PIPE)
58
59 # first output line is url that was processed by test_shell
60 p.stdout.readline()
61
62 # second output line is the layoutTestShell.dumpText() value.
63 result = p.stdout.readline()
64 if (not result.startswith(_expected_output_preamble)):
65 raise Exception("test_shell returned unexpected output: " + result);
66
67 # Rewrite result
68 os.remove(output_file)
69 open(output_file, 'w').write(result)
70
71 def FindTestShell(product_dir):
72 search_locations = []
73
74 if (sys.platform in ('cygwin', 'win32')):
75 search_locations.append(product_dir + "/test_shell.exe")
76
77 if (sys.platform in ('linux', 'linux2')):
78 search_locations.append(product_dir + "/test_shell")
79
80 if (sys.platform == 'darwin'):
81 search_locations.append(product_dir +
82 "/TestShell.app/Contents/MacOS/TestShell")
83
84 for loc in search_locations:
85 if os.path.isfile(loc):
86 return loc
87
88 print ("Failed to find test_shell executable in: \n" +
89 "\n".join(search_locations))
90
91 raise Exception('Could not find test_shell executable.')
92
93 def GetRelativePath(path):
94 return os.path.normpath(path)[len(os.getcwd()) + 1:]
95
96 def GetAPIModuleNames():
97 contents = open(_extension_api_json, 'r').read();
98 extension_api = json.loads(contents, encoding="ASCII")
99 return set( module['namespace'].encode() for module in extension_api)
100
101 def GetStaticFileNames():
102 static_files = os.listdir(_static_dir)
103 return set(os.path.splitext(file)[0]
104 for file in static_files
105 if file.endswith(".html"))
106
107 def GetInputFiles():
108 input_files = [];
109
110 input_files.append(GetRelativePath(_api_template_html));
111 input_files.append(GetRelativePath(_page_shell_html));
112 input_files.append(GetRelativePath(_generator_html));
113 input_files.append(GetRelativePath(_script_path));
114 input_files.append(GetRelativePath(_extension_api_json));
115 # static files
116 input_files += [GetRelativePath(_static_dir + "/" + name + ".html")
117 for name in GetStaticFileNames()]
118 # js files
119 input_files += [GetRelativePath(_js_dir + "/" + file)
120 for file in os.listdir(_js_dir)]
121 return input_files
122
123 def GetOutputFiles():
124 page_names = GetAPIModuleNames() | GetStaticFileNames()
125 return [GetRelativePath(_base_dir + "/" + name + ".html")
126 for name in page_names]
127
128 def main():
129 parser = OptionParser()
130 parser.add_option("--list-inputs", action="store_true", dest="list_inputs")
131 parser.add_option("--list-outputs", action="store_true", dest="list_outputs")
132 parser.add_option("--product-dir", dest="product_dir")
133
134 (options, args) = parser.parse_args()
135
136 # Return input list to gyp build target
137 if (options.list_inputs):
138 for f in GetInputFiles():
139 print f
140 return 0;
141 # Return output list to gyp build target
142 if (options.list_outputs):
143 for f in GetOutputFiles():
144 print f
145 return 0;
146
147 test_shell = FindTestShell(options.product_dir)
148
149 # Read static file names
150 static_names = GetStaticFileNames()
151
152 # Read module names
153 module_names = GetAPIModuleNames()
154
155 # All pages to generate
156 page_names = static_names | module_names
157
158 for page in page_names:
159 RenderPage(page, test_shell);
160
161 return 0;
162
163 if __name__ == '__main__':
164 sys.exit(main())
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/bookmarks.html ('k') | chrome/common/extensions/docs/build/generator.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698