| Index: native_client_sdk/src/build_tools/build_app.py
|
| diff --git a/native_client_sdk/src/build_tools/build_app.py b/native_client_sdk/src/build_tools/build_app.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..d90fdffc799ccd31817007c644b299b1016429e0
|
| --- /dev/null
|
| +++ b/native_client_sdk/src/build_tools/build_app.py
|
| @@ -0,0 +1,147 @@
|
| +#!/usr/bin/env python
|
| +# Copyright (c) 2013 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 sys
|
| +
|
| +if sys.version_info < (2, 6, 0):
|
| + sys.stderr.write("python 2.6 or later is required run this script\n")
|
| + sys.exit(1)
|
| +
|
| +import buildbot_common
|
| +import build_sdk
|
| +import build_utils
|
| +import easy_template
|
| +import generate_make
|
| +
|
| +sys.path.append(os.path.join(build_sdk.SDK_SRC_DIR, 'tools'))
|
| +import getos
|
| +import oshelpers
|
| +
|
| +# HACK: A few examples don't work properly as a packaged app right now.
|
| +EXAMPLE_LIST = [
|
| +# 'debugging',
|
| + 'dlopen',
|
| + 'file_histogram',
|
| + 'file_io',
|
| + 'gamepad',
|
| + 'geturl',
|
| + 'hello_nacl_io',
|
| + 'hello_world_stdio',
|
| + 'hello_world',
|
| + 'hello_world_gles',
|
| +# 'hello_world_instance3d',
|
| + 'hello_world_interactive',
|
| + 'input_events',
|
| + 'load_progress',
|
| +# 'mouselock',
|
| + 'pi_generator',
|
| + 'sine_synth',
|
| + 'websocket',
|
| +]
|
| +
|
| +
|
| +def GenerateMake(outdir, toolchains):
|
| + args = ['--dstroot=%s' % outdir, '--master', '--config=Release',
|
| + '--first-valid-toolchain']
|
| + for toolchain in toolchains:
|
| + args.append('--' + toolchain)
|
| +
|
| + for example in EXAMPLE_LIST:
|
| + dsc = os.path.join(build_sdk.SDK_EXAMPLE_DIR, example, 'example.dsc')
|
| + args.append(dsc)
|
| +
|
| + print "Generating Makefiles: %s" % str(args)
|
| + if generate_make.main(args):
|
| + buildbot_common.ErrorExit('Failed to build examples.')
|
| +
|
| +
|
| +def RemoveBuildCruft(outdir):
|
| + for root, _, files in os.walk(outdir):
|
| + for f in files:
|
| + path = os.path.join(root, f)
|
| + ext = os.path.splitext(path)[1]
|
| + if ext in ('.d', '.o'):
|
| + buildbot_common.RemoveFile(path)
|
| + elif f == 'dir.stamp':
|
| + buildbot_common.RemoveFile(path)
|
| +
|
| +
|
| +def StripNexes(outdir, platform, pepperdir):
|
| + for root, _, files in os.walk(outdir):
|
| + for f in files:
|
| + path = os.path.join(root, f)
|
| + m = re.search(r'lib(32|64).*\.so', path)
|
| + arch = None
|
| + if m:
|
| + # System .so file. Must be x86, because ARM doesn't support glibc yet.
|
| + arch = 'x86_' + m.group(1)
|
| + else:
|
| + basename, ext = os.path.splitext(f)
|
| + if ext in ('.nexe', '.so'):
|
| + # We can get the arch from the filename...
|
| + valid_arches = ('x86_64', 'x86_32', 'arm')
|
| + for a in valid_arches:
|
| + if basename.endswith(a):
|
| + arch = a
|
| + break
|
| + if not arch:
|
| + continue
|
| +
|
| + strip = GetStrip(pepperdir, platform, arch, 'newlib')
|
| + buildbot_common.Run([strip, path])
|
| +
|
| +
|
| +def GetStrip(pepperdir, platform, arch, toolchain):
|
| + base_arch = {'x86_32': 'x86', 'x86_64': 'x86', 'arm': 'arm'}[arch]
|
| + bin_dir = os.path.join(pepperdir, 'toolchain',
|
| + '%s_%s_%s' % (platform, base_arch, toolchain), 'bin')
|
| + strip_prefix = {'x86_32': 'i686', 'x86_64': 'x86_64', 'arm': 'arm'}[arch]
|
| + strip_name = '%s-nacl-strip' % strip_prefix
|
| + return os.path.join(bin_dir, strip_name)
|
| +
|
| +
|
| +def main(args):
|
| + parser = optparse.OptionParser()
|
| + _, args = parser.parse_args(args[1:])
|
| +
|
| + toolchains = ['newlib', 'glibc']
|
| +
|
| + pepper_ver = str(int(build_utils.ChromeMajorVersion()))
|
| + pepperdir = os.path.join(build_sdk.OUT_DIR, 'pepper_' + pepper_ver)
|
| + app_dir = os.path.join(build_sdk.OUT_DIR, 'naclsdk_app')
|
| + app_examples_dir = os.path.join(app_dir, 'examples')
|
| + sdk_resources_dir = os.path.join(build_sdk.SDK_EXAMPLE_DIR, 'resources')
|
| + platform = getos.GetPlatform()
|
| +
|
| + buildbot_common.RemoveDir(app_dir)
|
| + buildbot_common.MakeDir(app_dir)
|
| + GenerateMake(app_dir, toolchains)
|
| +
|
| + easy_template.RunTemplateFile(
|
| + os.path.join(sdk_resources_dir, 'manifest.json.template'),
|
| + os.path.join(app_examples_dir, 'manifest.json'),
|
| + {'version': build_utils.ChromeVersionNoTrunk()})
|
| + buildbot_common.CopyFile(os.path.join(sdk_resources_dir, 'background.js'),
|
| + os.path.join(app_examples_dir, 'background.js'))
|
| +
|
| + os.environ['NACL_SDK_ROOT'] = pepperdir
|
| + build_sdk.BuildStepMakeAll(app_dir, platform, 'examples', 'Build Examples',
|
| + False, False, 'Release')
|
| +
|
| + RemoveBuildCruft(app_dir)
|
| + StripNexes(app_dir, platform, pepperdir)
|
| +
|
| + app_zip = os.path.join(app_dir, 'examples.zip')
|
| + os.chdir(app_examples_dir)
|
| + oshelpers.Zip([app_zip, '-r', '*'])
|
| +
|
| + return 0
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + sys.exit(main(sys.argv))
|
|
|