Chromium Code Reviews| OLD | NEW |
|---|---|
| (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): | |
| 15 """Builds a parser building function. | |
| 16 | |
| 17 Args: | |
| 18 src_root: Path to the root of the source tree. | |
|
rudominer
2015/12/16 22:47:40
if None then...
azani
2015/12/16 23:11:03
Done.
| |
| 19 go_tool: Path to the go tool. | |
|
rudominer
2015/12/16 22:47:40
if None then...
azani
2015/12/16 23:11:03
Done.
| |
| 20 go_root: Path to the root of the go installation. | |
|
rudominer
2015/12/16 22:47:41
if None then...
azani
2015/12/16 23:11:03
Done.
| |
| 21 | |
| 22 Returns: | |
| 23 A function which accepts a compilation target and builds the parser for it. | |
| 24 """ | |
| 25 if src_root: | |
| 26 src_root = os.path.abspath(src_root) | |
| 27 else: | |
| 28 src_root = os.path.abspath(__file__) | |
| 29 while os.path.basename(src_root) != 'src': | |
| 30 assert src_root != '' and src_root != '/' | |
| 31 src_root = os.path.dirname(src_root) | |
|
rudominer
2015/12/16 22:47:41
It seems more fragile to me to have the hidden dep
azani
2015/12/16 23:11:03
Done.
| |
| 32 | |
| 33 assert os.path.exists(src_root) | |
| 34 | |
| 35 if go_tool: | |
| 36 go_tool = os.path.abspath(go_tool) | |
| 37 else: | |
| 38 go_tool = os.path.join(src_root, | |
| 39 'third_party', 'go', 'tool', 'linux_amd64', 'bin', 'go') | |
| 40 assert os.path.exists(go_tool) | |
| 41 | |
| 42 if go_root: | |
| 43 go_root = os.path.abspath(go_root) | |
| 44 else: | |
| 45 go_root = os.path.dirname(os.path.dirname(go_tool)) | |
| 46 assert os.path.exists(go_root) | |
| 47 | |
| 48 def _build_parser(target_os, target_arch): | |
| 49 """Builds the mojom parser for target_os and target_arch. | |
| 50 | |
| 51 Args: | |
| 52 target_os: Any value valid for GOOS. | |
| 53 target_arch: Any value valid for GOARCH. | |
| 54 | |
| 55 Returns: | |
| 56 The go tool's return value. | |
| 57 """ | |
| 58 output = 'mojom_parser_%s_%s' % (target_os, target_arch) | |
|
rudominer
2015/12/16 22:47:40
How about: the output directory is an argument to
azani
2015/12/16 23:11:03
Done.
| |
| 59 | |
| 60 environ = { | |
| 61 'GOROOT': go_root, | |
| 62 'GOPATH': os.path.dirname(src_root), | |
| 63 'GOOS': target_os, | |
| 64 'GOARCH': target_arch, | |
| 65 } | |
| 66 | |
| 67 save_cwd = os.getcwd() | |
| 68 os.chdir(os.path.join(src_root, 'mojom', 'mojom_parser')) | |
| 69 result = subprocess.call([go_tool, 'build', '-o', output] , env=environ) | |
|
rudominer
2015/12/16 22:47:41
I was under the impression that we had an older ve
azani
2015/12/16 23:11:03
It works and if you call help build on it, it docu
| |
| 70 | |
| 71 os.chdir(save_cwd) | |
| 72 | |
| 73 return result | |
| 74 | |
| 75 return _build_parser | |
| 76 | |
| 77 | |
| 78 def main(): | |
| 79 parser = argparse.ArgumentParser(description="Build the mojom parser.") | |
| 80 parser.add_argument('--src-root', dest='src_root', action='store', | |
| 81 help='Path to the source tree.') | |
|
rudominer
2015/12/16 22:47:41
add to 'optional' help string.
(Do you envision an
azani
2015/12/16 23:11:03
I mostly put it there for completeness' sake.
| |
| 82 parser.add_argument('--go-tool', dest='go_tool', action='store', | |
| 83 help='Path to the go tool.') | |
| 84 parser.add_argument('--go-root', dest='go_root', action='store', | |
| 85 help='Path to the root of the go installation.') | |
| 86 args = parser.parse_args() | |
|
rudominer
2015/12/16 22:47:41
out_dir seems like a natural optional argument.
azani
2015/12/16 23:11:03
Done.
| |
| 87 build_parser = get_parser_builder( | |
| 88 src_root=args.src_root, | |
| 89 go_tool=args.go_tool, | |
| 90 go_root=args.go_root) | |
| 91 | |
| 92 targets = [ | |
| 93 ('darwin', 'amd64'), | |
| 94 ('linux', 'amd64'), | |
| 95 ] | |
| 96 for target_os, target_arch in targets: | |
| 97 result = build_parser(target_os, target_arch) | |
| 98 if result != 0: | |
| 99 return result | |
| 100 | |
| 101 return 0 | |
| 102 | |
| 103 | |
| 104 if __name__ == '__main__': | |
| 105 sys.exit(main()) | |
| OLD | NEW |