| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 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 import optparse |
| 7 import os |
| 8 import re |
| 9 import sys |
| 10 |
| 11 if sys.version_info < (2, 6, 0): |
| 12 sys.stderr.write("python 2.6 or later is required run this script\n") |
| 13 sys.exit(1) |
| 14 |
| 15 import buildbot_common |
| 16 import build_sdk |
| 17 import build_utils |
| 18 import easy_template |
| 19 import generate_make |
| 20 |
| 21 sys.path.append(os.path.join(build_sdk.SDK_SRC_DIR, 'tools')) |
| 22 import getos |
| 23 import oshelpers |
| 24 |
| 25 # HACK: A few examples don't work properly as a packaged app right now. |
| 26 EXAMPLE_LIST = [ |
| 27 # 'debugging', |
| 28 'dlopen', |
| 29 'file_histogram', |
| 30 'file_io', |
| 31 'gamepad', |
| 32 'geturl', |
| 33 'hello_nacl_io', |
| 34 'hello_world_stdio', |
| 35 'hello_world', |
| 36 'hello_world_gles', |
| 37 # 'hello_world_instance3d', |
| 38 'hello_world_interactive', |
| 39 'input_events', |
| 40 'load_progress', |
| 41 # 'mouselock', |
| 42 'pi_generator', |
| 43 'sine_synth', |
| 44 'websocket', |
| 45 ] |
| 46 |
| 47 |
| 48 def GenerateMake(outdir, toolchains): |
| 49 args = ['--dstroot=%s' % outdir, '--master', '--config=Release', |
| 50 '--first-valid-toolchain'] |
| 51 for toolchain in toolchains: |
| 52 args.append('--' + toolchain) |
| 53 |
| 54 for example in EXAMPLE_LIST: |
| 55 dsc = os.path.join(build_sdk.SDK_EXAMPLE_DIR, example, 'example.dsc') |
| 56 args.append(dsc) |
| 57 |
| 58 print "Generating Makefiles: %s" % str(args) |
| 59 if generate_make.main(args): |
| 60 buildbot_common.ErrorExit('Failed to build examples.') |
| 61 |
| 62 |
| 63 def RemoveBuildCruft(outdir): |
| 64 for root, _, files in os.walk(outdir): |
| 65 for f in files: |
| 66 path = os.path.join(root, f) |
| 67 ext = os.path.splitext(path)[1] |
| 68 if ext in ('.d', '.o'): |
| 69 buildbot_common.RemoveFile(path) |
| 70 elif f == 'dir.stamp': |
| 71 buildbot_common.RemoveFile(path) |
| 72 |
| 73 |
| 74 def StripNexes(outdir, platform, pepperdir): |
| 75 for root, _, files in os.walk(outdir): |
| 76 for f in files: |
| 77 path = os.path.join(root, f) |
| 78 m = re.search(r'lib(32|64).*\.so', path) |
| 79 arch = None |
| 80 if m: |
| 81 # System .so file. Must be x86, because ARM doesn't support glibc yet. |
| 82 arch = 'x86_' + m.group(1) |
| 83 else: |
| 84 basename, ext = os.path.splitext(f) |
| 85 if ext in ('.nexe', '.so'): |
| 86 # We can get the arch from the filename... |
| 87 valid_arches = ('x86_64', 'x86_32', 'arm') |
| 88 for a in valid_arches: |
| 89 if basename.endswith(a): |
| 90 arch = a |
| 91 break |
| 92 if not arch: |
| 93 continue |
| 94 |
| 95 strip = GetStrip(pepperdir, platform, arch, 'newlib') |
| 96 buildbot_common.Run([strip, path]) |
| 97 |
| 98 |
| 99 def GetStrip(pepperdir, platform, arch, toolchain): |
| 100 base_arch = {'x86_32': 'x86', 'x86_64': 'x86', 'arm': 'arm'}[arch] |
| 101 bin_dir = os.path.join(pepperdir, 'toolchain', |
| 102 '%s_%s_%s' % (platform, base_arch, toolchain), 'bin') |
| 103 strip_prefix = {'x86_32': 'i686', 'x86_64': 'x86_64', 'arm': 'arm'}[arch] |
| 104 strip_name = '%s-nacl-strip' % strip_prefix |
| 105 return os.path.join(bin_dir, strip_name) |
| 106 |
| 107 |
| 108 def main(args): |
| 109 parser = optparse.OptionParser() |
| 110 _, args = parser.parse_args(args[1:]) |
| 111 |
| 112 toolchains = ['newlib', 'glibc'] |
| 113 |
| 114 pepper_ver = str(int(build_utils.ChromeMajorVersion())) |
| 115 pepperdir = os.path.join(build_sdk.OUT_DIR, 'pepper_' + pepper_ver) |
| 116 app_dir = os.path.join(build_sdk.OUT_DIR, 'naclsdk_app') |
| 117 app_examples_dir = os.path.join(app_dir, 'examples') |
| 118 sdk_resources_dir = os.path.join(build_sdk.SDK_EXAMPLE_DIR, 'resources') |
| 119 platform = getos.GetPlatform() |
| 120 |
| 121 buildbot_common.RemoveDir(app_dir) |
| 122 buildbot_common.MakeDir(app_dir) |
| 123 GenerateMake(app_dir, toolchains) |
| 124 |
| 125 easy_template.RunTemplateFile( |
| 126 os.path.join(sdk_resources_dir, 'manifest.json.template'), |
| 127 os.path.join(app_examples_dir, 'manifest.json'), |
| 128 {'version': build_utils.ChromeVersionNoTrunk()}) |
| 129 buildbot_common.CopyFile(os.path.join(sdk_resources_dir, 'background.js'), |
| 130 os.path.join(app_examples_dir, 'background.js')) |
| 131 |
| 132 os.environ['NACL_SDK_ROOT'] = pepperdir |
| 133 build_sdk.BuildStepMakeAll(app_dir, platform, 'examples', 'Build Examples', |
| 134 False, False, 'Release') |
| 135 |
| 136 RemoveBuildCruft(app_dir) |
| 137 StripNexes(app_dir, platform, pepperdir) |
| 138 |
| 139 app_zip = os.path.join(app_dir, 'examples.zip') |
| 140 os.chdir(app_examples_dir) |
| 141 oshelpers.Zip([app_zip, '-r', '*']) |
| 142 |
| 143 return 0 |
| 144 |
| 145 |
| 146 if __name__ == '__main__': |
| 147 sys.exit(main(sys.argv)) |
| OLD | NEW |