| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 | 8 |
| 9 import buildbot_common | 9 import buildbot_common |
| 10 import build_version | 10 import build_version |
| 11 import getos | 11 import getos |
| 12 from buildbot_common import ErrorExit | 12 from buildbot_common import ErrorExit |
| 13 from easy_template import RunTemplateFileIfChanged | 13 from easy_template import RunTemplateFileIfChanged |
| 14 from build_paths import SDK_RESOURCE_DIR | 14 from build_paths import SDK_RESOURCE_DIR |
| 15 | 15 |
| 16 def Trace(msg): | 16 def Trace(msg): |
| 17 if Trace.verbose: | 17 if Trace.verbose: |
| 18 sys.stderr.write(str(msg) + '\n') | 18 sys.stderr.write(str(msg) + '\n') |
| 19 Trace.verbose = False | 19 Trace.verbose = False |
| 20 | 20 |
| 21 | 21 |
| 22 def IsExample(desc): | 22 def IsExample(desc): |
| 23 dest = desc['DEST'] | 23 dest = desc['DEST'] |
| 24 return dest.startswith('examples') or dest.startswith('tests') | 24 return dest.startswith('examples') or dest.startswith('tests') |
| 25 | 25 |
| 26 | 26 |
| 27 def GenerateSourceCopyList(desc): | 27 def GenerateSourceCopyList(desc): |
| 28 sources = [] | 28 sources = [] |
| 29 # Some examples use their own Makefile/sources/etc. |
| 30 if 'TARGETS' not in desc: |
| 31 # Only copy the DATA files. |
| 32 return desc.get('DATA', []) |
| 33 |
| 29 # Add sources for each target | 34 # Add sources for each target |
| 30 for target in desc['TARGETS']: | 35 for target in desc['TARGETS']: |
| 31 sources.extend(target['SOURCES']) | 36 sources.extend(target['SOURCES']) |
| 32 | 37 |
| 33 # And HTML and data files | 38 # And HTML and data files |
| 34 sources.extend(desc.get('DATA', [])) | 39 sources.extend(desc.get('DATA', [])) |
| 35 | 40 |
| 36 if IsExample(desc): | 41 if IsExample(desc): |
| 37 sources.extend(['common.js', 'icon128.png', 'background.js']) | 42 sources.extend(['common.js', 'icon128.png', 'background.js']) |
| 38 | 43 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 FindAndCopyFiles(sources, srcroot, srcdirs, out_dir) | 194 FindAndCopyFiles(sources, srcroot, srcdirs, out_dir) |
| 190 | 195 |
| 191 # Copy public headers to the include directory. | 196 # Copy public headers to the include directory. |
| 192 for headers_set in desc.get('HEADERS', []): | 197 for headers_set in desc.get('HEADERS', []): |
| 193 headers = headers_set['FILES'] | 198 headers = headers_set['FILES'] |
| 194 header_out_dir = os.path.join(dstroot, headers_set['DEST']) | 199 header_out_dir = os.path.join(dstroot, headers_set['DEST']) |
| 195 FindAndCopyFiles(headers, srcroot, srcdirs, header_out_dir) | 200 FindAndCopyFiles(headers, srcroot, srcdirs, header_out_dir) |
| 196 | 201 |
| 197 make_path = os.path.join(out_dir, 'Makefile') | 202 make_path = os.path.join(out_dir, 'Makefile') |
| 198 | 203 |
| 204 outdir = os.path.dirname(os.path.abspath(make_path)) |
| 205 if getos.GetPlatform() == 'win': |
| 206 AddMakeBat(pepperdir, outdir) |
| 207 |
| 208 # If this project has no TARGETS, then we don't need to generate anything. |
| 209 if 'TARGETS' not in desc: |
| 210 return (name, desc['DEST']) |
| 211 |
| 199 if IsNexe(desc): | 212 if IsNexe(desc): |
| 200 template = os.path.join(SDK_RESOURCE_DIR, 'Makefile.example.template') | 213 template = os.path.join(SDK_RESOURCE_DIR, 'Makefile.example.template') |
| 201 else: | 214 else: |
| 202 template = os.path.join(SDK_RESOURCE_DIR, 'Makefile.library.template') | 215 template = os.path.join(SDK_RESOURCE_DIR, 'Makefile.library.template') |
| 203 | 216 |
| 204 # Ensure the order of |tools| is the same as toolchains; that way if | 217 # Ensure the order of |tools| is the same as toolchains; that way if |
| 205 # first_toolchain is set, it will choose based on the order of |toolchains|. | 218 # first_toolchain is set, it will choose based on the order of |toolchains|. |
| 206 tools = [tool for tool in toolchains if tool in desc['TOOLS']] | 219 tools = [tool for tool in toolchains if tool in desc['TOOLS']] |
| 207 if first_toolchain: | 220 if first_toolchain: |
| 208 tools = [tools[0]] | 221 tools = [tools[0]] |
| 209 for target in desc['TARGETS']: | 222 for target in desc['TARGETS']: |
| 210 target.setdefault('CXXFLAGS', []) | 223 target.setdefault('CXXFLAGS', []) |
| 211 target['CXXFLAGS'].insert(0, '-Wall') | 224 target['CXXFLAGS'].insert(0, '-Wall') |
| 212 | 225 |
| 213 template_dict = { | 226 template_dict = { |
| 214 'rel_sdk': '/'.join(['..'] * (len(desc['DEST'].split('/')) + 1)), | 227 'rel_sdk': '/'.join(['..'] * (len(desc['DEST'].split('/')) + 1)), |
| 215 'pre': desc.get('PRE', ''), | 228 'pre': desc.get('PRE', ''), |
| 216 'post': desc.get('POST', ''), | 229 'post': desc.get('POST', ''), |
| 217 'tools': tools, | 230 'tools': tools, |
| 218 'targets': desc['TARGETS'], | 231 'targets': desc['TARGETS'], |
| 219 } | 232 } |
| 220 RunTemplateFileIfChanged(template, make_path, template_dict) | 233 RunTemplateFileIfChanged(template, make_path, template_dict) |
| 221 | 234 |
| 222 outdir = os.path.dirname(os.path.abspath(make_path)) | |
| 223 if getos.GetPlatform() == 'win': | |
| 224 AddMakeBat(pepperdir, outdir) | |
| 225 | |
| 226 if IsExample(desc): | 235 if IsExample(desc): |
| 227 ProcessHTML(srcroot, dstroot, desc, toolchains, configs, | 236 ProcessHTML(srcroot, dstroot, desc, toolchains, configs, |
| 228 first_toolchain) | 237 first_toolchain) |
| 229 GenerateManifest(srcroot, dstroot, desc) | 238 GenerateManifest(srcroot, dstroot, desc) |
| 230 | 239 |
| 231 return (name, desc['DEST']) | 240 return (name, desc['DEST']) |
| 232 | 241 |
| 233 | 242 |
| 234 def GenerateMasterMakefile(pepperdir, out_path, targets): | 243 def GenerateMasterMakefile(pepperdir, out_path, targets): |
| 235 """Generate a Master Makefile that builds all examples. | 244 """Generate a Master Makefile that builds all examples. |
| 236 | 245 |
| 237 Args: | 246 Args: |
| 238 pepperdir: NACL_SDK_ROOT | 247 pepperdir: NACL_SDK_ROOT |
| 239 out_path: Root for output such that out_path+NAME = full path | 248 out_path: Root for output such that out_path+NAME = full path |
| 240 targets: List of targets names | 249 targets: List of targets names |
| 241 """ | 250 """ |
| 242 in_path = os.path.join(SDK_RESOURCE_DIR, 'Makefile.index.template') | 251 in_path = os.path.join(SDK_RESOURCE_DIR, 'Makefile.index.template') |
| 243 out_path = os.path.join(out_path, 'Makefile') | 252 out_path = os.path.join(out_path, 'Makefile') |
| 244 rel_path = os.path.relpath(pepperdir, os.path.dirname(out_path)) | 253 rel_path = os.path.relpath(pepperdir, os.path.dirname(out_path)) |
| 245 template_dict = { | 254 template_dict = { |
| 246 'projects': targets, | 255 'projects': targets, |
| 247 'rel_sdk' : rel_path, | 256 'rel_sdk' : rel_path, |
| 248 } | 257 } |
| 249 RunTemplateFileIfChanged(in_path, out_path, template_dict) | 258 RunTemplateFileIfChanged(in_path, out_path, template_dict) |
| 250 outdir = os.path.dirname(os.path.abspath(out_path)) | 259 outdir = os.path.dirname(os.path.abspath(out_path)) |
| 251 if getos.GetPlatform() == 'win': | 260 if getos.GetPlatform() == 'win': |
| 252 AddMakeBat(pepperdir, outdir) | 261 AddMakeBat(pepperdir, outdir) |
| OLD | NEW |