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

Side by Side Diff: mojom/mojom_parser/tools/build_mojom_parser.py

Issue 1532603002: New script to build the mojom parser. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2015 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 # This script will build the mojom parser for both mac and linux.
7
8 import argparse
9 import subprocess
10 import sys
11 import os
12
13
14 def get_parser_builder(src_root=None, go_tool=None, go_root=None, out_dir=None):
15 """Builds a parser building function.
16
17 Args:
18 src_root: Path to the root of the source tree. (If None, the path of the
19 directory 3 levels above the one containing this script is used.)
20 go_tool: Path to the go tool.
21 (If None, uses {src_root}/third_party/go/tool/linux_amd64/bin/go)
22 go_root: Path to the root of the go installation.
23 (If None, uses the directory containing the go tool.)
24 out_dir: Path to the directory in which the built parser should be placed.
25 (If None, uses the current working directory.)
26
27 Returns:
28 A function which accepts a compilation target and builds the parser for it.
29 """
30 if src_root:
31 src_root = os.path.abspath(src_root)
32 else:
33 src_root = os.path.abspath(
34 os.path.join(os.path.dirname(__file__), *([os.pardir] * 3)))
35 assert os.path.exists(src_root)
36
37 if go_tool:
38 go_tool = os.path.abspath(go_tool)
39 else:
40 go_tool = os.path.join(src_root,
41 'third_party', 'go', 'tool', 'linux_amd64', 'bin', 'go')
42 assert os.path.exists(go_tool)
43
44 if go_root:
45 go_root = os.path.abspath(go_root)
46 else:
47 go_root = os.path.dirname(os.path.dirname(go_tool))
48 assert os.path.exists(go_root)
49
50 if not out_dir:
51 out_dir = os.getcwd()
52 out_dir = os.path.abspath(out_dir)
53
54 def _build_parser(target_os, target_arch):
55 """Builds the mojom parser for target_os and target_arch.
56
57 Args:
58 target_os: Any value valid for GOOS.
59 target_arch: Any value valid for GOARCH.
60
61 Returns:
62 The go tool's return value.
63 """
64 output = os.path.join(out_dir,
65 'mojom_parser_%s_%s' % (target_os, target_arch))
66
67 environ = {
68 'GOROOT': go_root,
69 'GOPATH': os.path.dirname(src_root),
70 'GOOS': target_os,
71 'GOARCH': target_arch,
72 }
73
74 save_cwd = os.getcwd()
75 os.chdir(os.path.join(src_root, 'mojom', 'mojom_parser'))
76 result = subprocess.call([go_tool, 'build', '-o', output] , env=environ)
77
78 os.chdir(save_cwd)
79
80 return result
81
82 return _build_parser
83
84
85 def main():
86 parser = argparse.ArgumentParser(description="Build the mojom parser.")
87 parser.add_argument('--src-root', dest='src_root', action='store',
88 help='Path to the source tree. (optional)')
89 parser.add_argument('--go-tool', dest='go_tool', action='store',
90 help='Path to the go tool. (optional)')
91 parser.add_argument('--go-root', dest='go_root', action='store',
92 help='Path to the root of the go installation.'
93 ' (optional')
94 parser.add_argument('--out-dir', dest='out_dir', action='store',
95 help='Directory in which to place the built parser.'
96 ' (optional)')
97 args = parser.parse_args()
98 build_parser = get_parser_builder(
99 src_root=args.src_root,
100 go_tool=args.go_tool,
101 go_root=args.go_root,
102 out_dir=args.out_dir)
103
104 targets = [
105 ('darwin', 'amd64'),
106 ('linux', 'amd64'),
107 ]
108 for target_os, target_arch in targets:
109 result = build_parser(target_os, target_arch)
110 if result != 0:
111 return result
112
113 return 0
114
115
116 if __name__ == '__main__':
117 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698