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

Unified Diff: chrome/build_nacl_irt.py

Issue 7669058: Switching IRT to be built inside the chrome build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « DEPS ('k') | chrome/nacl.gypi » ('j') | chrome/nacl.gypi » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/build_nacl_irt.py
===================================================================
--- chrome/build_nacl_irt.py (revision 0)
+++ chrome/build_nacl_irt.py (revision 0)
@@ -0,0 +1,144 @@
+#!/usr/bin/python
+# Copyright (c) 2011 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.
+
+import optparse
+import os
+import re
+import shutil
+import subprocess
+import sys
+
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+SRC_DIR = os.path.dirname(SCRIPT_DIR)
+NACL_DIR = os.path.join(SRC_DIR, 'native_client')
+
+
+def RelativePath(path, base):
+ """Find the relative path.
+
+ Arguments:
+ path: path we want a relative path to.
+ base: path we want a relative path from.
+ Returns:
+ The relative path from base to path.
+ """
+ path = os.path.abspath(path)
+ base = os.path.abspath(base)
+ path_parts = path.split(os.sep)
+ base_parts = base.split(os.sep)
+ while path_parts and base_parts and path_parts[0] == base_parts[0]:
+ path_parts = path_parts[1:]
+ base_parts = base_parts[1:]
+ rel_parts = ['..'] * len(base_parts) + path_parts
+ return os.sep.join(rel_parts)
+
+
+def PrintInputs(platforms):
+ """Print all the transitive inputs required to build the IRT.
+
+ Arguments:
+ platforms: list of platform names to build for.
+ """
+ if sys.platform in ['win32', 'cygwin']:
+ scons = 'scons.bat'
+ else:
+ scons = './scons'
+
+ inputs = set()
+ for platform in platforms:
+ # Invoke scons to get dependency tree.
+ cmd = [
+ scons, '-n', '--tree=prune',
+ '--mode=nacl', 'platform=' + platform,
+ 'scons-out/nacl_irt-' + platform + '/staging/irt.nexe',
+ ]
+ p = subprocess.Popen(cmd, cwd=NACL_DIR,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ (p_stdout, p_stderr) = p.communicate()
+ if p.returncode != 0:
+ sys.exit(2)
+ # Extract unique inputs.
+ for line in p_stdout.splitlines():
+ m = re.match('^[ -+|]*\+\-(.+)', line)
+ if not m:
+ continue
+ filename = m.group(1)
+ if '[' in filename:
+ continue
+ if filename.startswith('scons-out'):
+ continue
+ if filename.endswith('.nexe'):
+ continue
+ inputs.add(filename)
+ # Print everything.
+ inputs = sorted(list(inputs))
+ for f in inputs:
+ print RelativePath(f, SCRIPT_DIR)
+
+
+def BuildIRT(platforms, out_dir):
+ """Build the IRT for several platforms.
+
+ Arguments:
+ platforms: list of platform names to build for.
+ out_dir: directory to output the IRT to.
+ """
+ # Clean.
+ scons_out = os.path.join(NACL_DIR, 'scons-out')
+ if os.path.exists(scons_out):
+ shutil.rmtree(scons_out)
+ # Build for each platform.
+ for platform in platforms:
+ cmd = [
+ scons, '--verbose', '-j8',
+ '--mode=nacl', 'platform=' + platform,
+ 'scons-out/nacl_irt-' + platform + '/staging/irt.nexe',
+ ]
+ p = subprocess.Popen(cmd, cwd=NACL_DIR)
+ p.wait()
+ if p.returncode != 0:
+ sys.exit(3)
+ # Copy out each platform after stripping.
+ for platform in platforms:
+ nexe = os.path.join(out_dir, 'nacl_irt_' + platform.replace('-', '_') +
+ '.nexe')
+ cmd = [
+ '../native_client/toolchain/linux_x86_newlib/bin/x86_64-nacl-strip',
+ ' --strip-debug',
+ '../native_client/scons-out/nacl_irt-' + platform + '/staging/irt.nexe',
+ '-o', nexe
+ ]
+ p = subprocess.Popen(cmd, cwd=SCRIPT_DIR)
+ p.wait()
+ if p.returncode != 0:
+ sys.exit(4)
+
+
+def Main(argv):
+ parser = optparse.OptionParser()
+ parser.add_option('--inputs', dest='inputs', default=False,
+ action='store_true',
+ help='only emit the transitive inputs to the irt build')
+ parser.add_option('--platform', dest='platforms', action='append',
+ default=[],
+ help='add a platform to build for (x86-32|x86-64)')
+ parser.add_option('--outdir', dest='outdir',
+ help='directory to out irt to')
+ (options, args) = parser.parse_args(argv[1:])
+ if args or not options.platforms or (
+ not options.inputs and not options.outdir):
+ parser.print_help()
+ sys.exit(1)
+
+ if options.inputs:
+ PrintInputs(options.platforms)
+ else:
+ BuildIRT(options.platforms, options.outdir)
+
+
+if __name__ == '__main__':
+ Main(sys.argv)
« no previous file with comments | « DEPS ('k') | chrome/nacl.gypi » ('j') | chrome/nacl.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698