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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/mojom_parser/tools/build_mojom_parser.py
diff --git a/mojom/mojom_parser/tools/build_mojom_parser.py b/mojom/mojom_parser/tools/build_mojom_parser.py
new file mode 100755
index 0000000000000000000000000000000000000000..bfc75f3b0abd69bda9d95ebf59a53a4f46c930aa
--- /dev/null
+++ b/mojom/mojom_parser/tools/build_mojom_parser.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This script will build the mojom parser for both mac and linux.
+
+import argparse
+import subprocess
+import sys
+import os
+
+
+def get_parser_builder(src_root=None, go_tool=None, go_root=None):
+ """Builds a parser building function.
+
+ Args:
+ 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.
+ 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.
+ 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.
+
+ Returns:
+ A function which accepts a compilation target and builds the parser for it.
+ """
+ if src_root:
+ src_root = os.path.abspath(src_root)
+ else:
+ src_root = os.path.abspath(__file__)
+ while os.path.basename(src_root) != 'src':
+ assert src_root != '' and src_root != '/'
+ 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.
+
+ assert os.path.exists(src_root)
+
+ if go_tool:
+ go_tool = os.path.abspath(go_tool)
+ else:
+ go_tool = os.path.join(src_root,
+ 'third_party', 'go', 'tool', 'linux_amd64', 'bin', 'go')
+ assert os.path.exists(go_tool)
+
+ if go_root:
+ go_root = os.path.abspath(go_root)
+ else:
+ go_root = os.path.dirname(os.path.dirname(go_tool))
+ assert os.path.exists(go_root)
+
+ def _build_parser(target_os, target_arch):
+ """Builds the mojom parser for target_os and target_arch.
+
+ Args:
+ target_os: Any value valid for GOOS.
+ target_arch: Any value valid for GOARCH.
+
+ Returns:
+ The go tool's return value.
+ """
+ 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.
+
+ environ = {
+ 'GOROOT': go_root,
+ 'GOPATH': os.path.dirname(src_root),
+ 'GOOS': target_os,
+ 'GOARCH': target_arch,
+ }
+
+ save_cwd = os.getcwd()
+ os.chdir(os.path.join(src_root, 'mojom', 'mojom_parser'))
+ 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
+
+ os.chdir(save_cwd)
+
+ return result
+
+ return _build_parser
+
+
+def main():
+ parser = argparse.ArgumentParser(description="Build the mojom parser.")
+ parser.add_argument('--src-root', dest='src_root', action='store',
+ 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.
+ parser.add_argument('--go-tool', dest='go_tool', action='store',
+ help='Path to the go tool.')
+ parser.add_argument('--go-root', dest='go_root', action='store',
+ help='Path to the root of the go installation.')
+ 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.
+ build_parser = get_parser_builder(
+ src_root=args.src_root,
+ go_tool=args.go_tool,
+ go_root=args.go_root)
+
+ targets = [
+ ('darwin', 'amd64'),
+ ('linux', 'amd64'),
+ ]
+ for target_os, target_arch in targets:
+ result = build_parser(target_os, target_arch)
+ if result != 0:
+ return result
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« 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