| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import buildbot_common | 6 import buildbot_common |
| 7 import make_rules | |
| 8 import optparse | 7 import optparse |
| 9 import os | 8 import os |
| 10 import sys | 9 import sys |
| 11 | |
| 12 from make_rules import MakeRules, SetVar, GenerateCleanRules, GenerateNMFRules | 10 from make_rules import MakeRules, SetVar, GenerateCleanRules, GenerateNMFRules |
| 13 | 11 |
| 14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 12 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 15 SDK_SRC_DIR = os.path.dirname(SCRIPT_DIR) | 13 SDK_SRC_DIR = os.path.dirname(SCRIPT_DIR) |
| 16 SDK_EXAMPLE_DIR = os.path.join(SDK_SRC_DIR, 'examples') | 14 SDK_EXAMPLE_DIR = os.path.join(SDK_SRC_DIR, 'examples') |
| 17 SDK_DIR = os.path.dirname(SDK_SRC_DIR) | 15 SDK_DIR = os.path.dirname(SDK_SRC_DIR) |
| 18 SRC_DIR = os.path.dirname(SDK_DIR) | 16 SRC_DIR = os.path.dirname(SDK_DIR) |
| 19 OUT_DIR = os.path.join(SRC_DIR, 'out') | 17 OUT_DIR = os.path.join(SRC_DIR, 'out') |
| 20 PPAPI_DIR = os.path.join(SRC_DIR, 'ppapi') | 18 PPAPI_DIR = os.path.join(SRC_DIR, 'ppapi') |
| 21 | 19 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 76 |
| 79 | 77 |
| 80 def GetPlatforms(plat_list, plat_filter): | 78 def GetPlatforms(plat_list, plat_filter): |
| 81 platforms = [] | 79 platforms = [] |
| 82 for plat in plat_list: | 80 for plat in plat_list: |
| 83 if plat in plat_filter: | 81 if plat in plat_filter: |
| 84 platforms.append(plat) | 82 platforms.append(plat) |
| 85 return platforms | 83 return platforms |
| 86 | 84 |
| 87 | 85 |
| 88 def GenerateToolDefaults(desc, tools): | 86 def GenerateToolDefaults(tools): |
| 89 defaults = '' | 87 defaults = '' |
| 90 for tool in tools: | 88 for tool in tools: |
| 91 defaults += MakeRules(tool).BuildDefaults() | 89 defaults += MakeRules(tool).BuildDefaults() |
| 92 return defaults | 90 return defaults |
| 93 | 91 |
| 94 | 92 |
| 95 def GenerateSettings(desc, tools): | 93 def GenerateSettings(desc, tools): |
| 96 settings = SetVar('VALID_TOOLCHAINS', tools) | 94 settings = SetVar('VALID_TOOLCHAINS', tools) |
| 97 settings+= 'TOOLCHAIN?=%s\n\n' % tools[0] | 95 settings += 'TOOLCHAIN?=%s\n\n' % tools[0] |
| 98 for target in desc['TARGETS']: | 96 for target in desc['TARGETS']: |
| 99 project = target['NAME'] | 97 project = target['NAME'] |
| 100 macro = project.upper() | 98 macro = project.upper() |
| 101 srcs = GetSourcesDict(target['SOURCES']) | |
| 102 | 99 |
| 103 c_flags = target.get('CCFLAGS') | 100 c_flags = target.get('CCFLAGS') |
| 104 cc_flags = target.get('CXXFLAGS') | 101 cc_flags = target.get('CXXFLAGS') |
| 105 ld_flags = target.get('LDFLAGS') | 102 ld_flags = target.get('LDFLAGS') |
| 106 | 103 |
| 107 if c_flags: | 104 if c_flags: |
| 108 settings += SetVar(macro + '_CCFLAGS', c_flags) | 105 settings += SetVar(macro + '_CCFLAGS', c_flags) |
| 109 if cc_flags: | 106 if cc_flags: |
| 110 settings += SetVar(macro + '_CXXFLAGS', cc_flags) | 107 settings += SetVar(macro + '_CXXFLAGS', cc_flags) |
| 111 if ld_flags: | 108 if ld_flags: |
| 112 settings += SetVar(macro + '_LDFLAGS', ld_flags) | 109 settings += SetVar(macro + '_LDFLAGS', ld_flags) |
| 113 return settings | 110 return settings |
| 114 | 111 |
| 115 | 112 |
| 116 def GenerateRules(desc, tools): | 113 def GenerateRules(desc, tools): |
| 117 all_targets = [] | |
| 118 clean = [] | |
| 119 rules = '#\n# Per target object lists\n#\n' | 114 rules = '#\n# Per target object lists\n#\n' |
| 120 | 115 |
| 121 #Determine which projects are in the NMF files. | 116 #Determine which projects are in the NMF files. |
| 122 main = None | 117 executable = None |
| 123 dlls = [] | 118 dlls = [] |
| 124 project_list = [] | 119 project_list = [] |
| 125 glibc_rename = [] | 120 glibc_rename = [] |
| 126 | 121 |
| 127 for target in desc['TARGETS']: | 122 for target in desc['TARGETS']: |
| 128 ptype = target['TYPE'].upper() | 123 ptype = target['TYPE'].upper() |
| 129 project = target['NAME'] | 124 project = target['NAME'] |
| 130 project_list.append(project) | 125 project_list.append(project) |
| 131 srcs = GetSourcesDict(target['SOURCES']) | 126 srcs = GetSourcesDict(target['SOURCES']) |
| 132 if ptype == 'MAIN': | 127 if ptype == 'MAIN': |
| 133 main = project | 128 executable = project |
| 134 if ptype == 'SO': | 129 if ptype == 'SO': |
| 135 dlls.append(project) | 130 dlls.append(project) |
| 136 for arch in ['x86_32', 'x86_64']: | 131 for arch in ['x86_32', 'x86_64']: |
| 137 glibc_rename.append('-n %s_%s.so,%s.so' % (project, arch, project)) | 132 glibc_rename.append('-n %s_%s.so,%s.so' % (project, arch, project)) |
| 138 | 133 |
| 139 objects = GetProjectObjects(srcs) | 134 objects = GetProjectObjects(srcs) |
| 140 rules += SetVar('%s_OBJS' % project.upper(), objects) | 135 rules += SetVar('%s_OBJS' % project.upper(), objects) |
| 141 if glibc_rename: | 136 if glibc_rename: |
| 142 rules += SetVar('GLIBC_REMAP', glibc_rename) | 137 rules += SetVar('GLIBC_REMAP', glibc_rename) |
| 143 | 138 |
| 144 configs = desc.get('CONFIGS', ['Debug', 'Release']) | 139 configs = desc.get('CONFIGS', ['Debug', 'Release']) |
| 145 for tc in tools: | 140 for tc in tools: |
| 146 makeobj = MakeRules(tc) | 141 makeobj = MakeRules(tc) |
| 147 arches = makeobj.GetArches() | 142 arches = makeobj.GetArches() |
| 148 rules += makeobj.BuildDirectoryRules(configs) | 143 rules += makeobj.BuildDirectoryRules(configs) |
| 149 for cfg in configs: | 144 for cfg in configs: |
| 150 makeobj.SetConfig(cfg) | 145 makeobj.SetConfig(cfg) |
| 151 for target in desc['TARGETS']: | 146 for target in desc['TARGETS']: |
| 152 project = target['NAME'] | 147 project = target['NAME'] |
| 153 ptype = target['TYPE'] | 148 ptype = target['TYPE'] |
| 154 srcs = GetSourcesDict(target['SOURCES']) | 149 srcs = GetSourcesDict(target['SOURCES']) |
| 155 objs = GetProjectObjects(srcs) | |
| 156 defs = target.get('DEFINES', []) | 150 defs = target.get('DEFINES', []) |
| 157 incs = target.get('INCLUDES', []) | 151 incs = target.get('INCLUDES', []) |
| 158 libs = target.get('LIBS', []) | 152 libs = target.get('LIBS', []) |
| 159 lpaths = target.get('LIBPATHS', []) | |
| 160 ipaths = target.get('INCPATHS', []) | |
| 161 makeobj.SetProject(project, ptype, defs=defs, incs=incs, libs=libs) | 153 makeobj.SetProject(project, ptype, defs=defs, incs=incs, libs=libs) |
| 162 » if ptype == 'main': | 154 if ptype == 'main': |
| 163 » rules += makeobj.GetPepperPlugin() | 155 rules += makeobj.GetPepperPlugin() |
| 164 for arch in arches: | 156 for arch in arches: |
| 165 makeobj.SetArch(arch) | 157 makeobj.SetArch(arch) |
| 166 for src in srcs.get('.c', []): | 158 for src in srcs.get('.c', []): |
| 167 rules += makeobj.BuildCompileRule('CC', src) | 159 rules += makeobj.BuildCompileRule('CC', src) |
| 168 for src in srcs.get('.cc', []): | 160 for src in srcs.get('.cc', []): |
| 169 rules += makeobj.BuildCompileRule('CXX', src) | 161 rules += makeobj.BuildCompileRule('CXX', src) |
| 170 rules += '\n' | 162 rules += '\n' |
| 171 rules += makeobj.BuildObjectList() | 163 rules += makeobj.BuildObjectList() |
| 172 rules += makeobj.BuildLinkRule() | 164 rules += makeobj.BuildLinkRule() |
| 173 if main: | 165 if executable: |
| 174 rules += GenerateNMFRules(tc, main, dlls, cfg, arches) | 166 rules += GenerateNMFRules(tc, executable, dlls, cfg, arches) |
| 175 | 167 |
| 176 rules += GenerateCleanRules(tools, configs) | 168 rules += GenerateCleanRules(tools, configs) |
| 177 rules += '\nall: $(ALL_TARGETS)\n' | 169 rules += '\nall: $(ALL_TARGETS)\n' |
| 178 | 170 |
| 179 return '', rules | 171 return '', rules |
| 180 | 172 |
| 181 | 173 |
| 182 | 174 |
| 183 def GenerateReplacements(desc, tools): | 175 def GenerateReplacements(desc, tools): |
| 184 # Generate target settings | 176 # Generate target settings |
| 185 plats = GetPlatforms(desc['TOOLS'], tools) | |
| 186 | |
| 187 settings = GenerateSettings(desc, tools) | 177 settings = GenerateSettings(desc, tools) |
| 188 tool_def = GenerateToolDefaults(desc, tools) | 178 tool_def = GenerateToolDefaults(tools) |
| 189 all_targets, rules = GenerateRules(desc, tools) | 179 _, rules = GenerateRules(desc, tools) |
| 190 | 180 |
| 191 prelaunch = desc.get('LAUNCH', '') | 181 prelaunch = desc.get('LAUNCH', '') |
| 192 prerun = desc.get('PRE', '') | 182 prerun = desc.get('PRE', '') |
| 193 postlaunch = desc.get('POST', '') | 183 postlaunch = desc.get('POST', '') |
| 194 | 184 |
| 195 target_def = 'all:' | 185 target_def = 'all:' |
| 196 | 186 |
| 197 return { | 187 return { |
| 198 '__PROJECT_SETTINGS__' : settings, | 188 '__PROJECT_SETTINGS__' : settings, |
| 199 '__PROJECT_TARGETS__' : target_def, | 189 '__PROJECT_TARGETS__' : target_def, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 'DESC': (str, '', False), | 224 'DESC': (str, '', False), |
| 235 'INFO': (str, '', False), | 225 'INFO': (str, '', False), |
| 236 'EXPERIMENTAL': (bool, [True, False], False) | 226 'EXPERIMENTAL': (bool, [True, False], False) |
| 237 } | 227 } |
| 238 | 228 |
| 239 | 229 |
| 240 def ErrorMsgFunc(text): | 230 def ErrorMsgFunc(text): |
| 241 sys.stderr.write(text + '\n') | 231 sys.stderr.write(text + '\n') |
| 242 | 232 |
| 243 | 233 |
| 244 def ValidateFormat(src, format, ErrorMsg=ErrorMsgFunc): | 234 def ValidateFormat(src, dsc_format, ErrorMsg=ErrorMsgFunc): |
| 245 failed = False | 235 failed = False |
| 246 | 236 |
| 247 # Verify all required keys are there | 237 # Verify all required keys are there |
| 248 for key in format: | 238 for key in dsc_format: |
| 249 (exp_type, exp_value, required) = format[key] | 239 (exp_type, exp_value, required) = dsc_format[key] |
| 250 if required and key not in src: | 240 if required and key not in src: |
| 251 ErrorMsg('Missing required key %s.' % key) | 241 ErrorMsg('Missing required key %s.' % key) |
| 252 failed = True | 242 failed = True |
| 253 | 243 |
| 254 # For each provided key, verify it's valid | 244 # For each provided key, verify it's valid |
| 255 for key in src: | 245 for key in src: |
| 256 # Verify the key is known | 246 # Verify the key is known |
| 257 if key not in format: | 247 if key not in dsc_format: |
| 258 ErrorMsg('Unexpected key %s.' % key) | 248 ErrorMsg('Unexpected key %s.' % key) |
| 259 failed = True | 249 failed = True |
| 260 continue | 250 continue |
| 261 | 251 |
| 262 exp_type, exp_value, required = format[key] | 252 exp_type, exp_value, required = dsc_format[key] |
| 263 value = src[key] | 253 value = src[key] |
| 264 | 254 |
| 265 # Verify the key is of the expected type | 255 # Verify the key is of the expected type |
| 266 if exp_type != type(value): | 256 if exp_type != type(value): |
| 267 ErrorMsg('Key %s expects %s not %s.' % ( | 257 ErrorMsg('Key %s expects %s not %s.' % ( |
| 268 key, exp_type.__name__.upper(), type(value).__name__.upper())) | 258 key, exp_type.__name__.upper(), type(value).__name__.upper())) |
| 269 failed = True | 259 failed = True |
| 270 continue | 260 continue |
| 271 | 261 |
| 272 # Verify the value is non-empty if required | 262 # Verify the value is non-empty if required |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 sources = GenerateSourceCopyList(desc) | 426 sources = GenerateSourceCopyList(desc) |
| 437 FindAndCopyFiles(sources, srcroot, srcdirs, out_dir) | 427 FindAndCopyFiles(sources, srcroot, srcdirs, out_dir) |
| 438 | 428 |
| 439 # Copy public headers to the include directory. | 429 # Copy public headers to the include directory. |
| 440 for headers_set in desc.get('HEADERS', []): | 430 for headers_set in desc.get('HEADERS', []): |
| 441 headers = headers_set['FILES'] | 431 headers = headers_set['FILES'] |
| 442 header_out_dir = os.path.join(dstroot, headers_set['DEST']) | 432 header_out_dir = os.path.join(dstroot, headers_set['DEST']) |
| 443 FindAndCopyFiles(headers, srcroot, srcdirs, header_out_dir) | 433 FindAndCopyFiles(headers, srcroot, srcdirs, header_out_dir) |
| 444 | 434 |
| 445 if IsNexe(desc): | 435 if IsNexe(desc): |
| 446 template=os.path.join(SCRIPT_DIR, 'template.mk') | 436 template = os.path.join(SCRIPT_DIR, 'template.mk') |
| 447 else: | 437 else: |
| 448 template=os.path.join(SCRIPT_DIR, 'library.mk') | 438 template = os.path.join(SCRIPT_DIR, 'library.mk') |
| 449 | 439 |
| 450 tools = [] | 440 tools = [] |
| 451 for tool in desc['TOOLS']: | 441 for tool in desc['TOOLS']: |
| 452 if tool in toolchains: | 442 if tool in toolchains: |
| 453 tools.append(tool) | 443 tools.append(tool) |
| 454 | 444 |
| 455 # Add Makefile and make.bat | 445 # Add Makefile and make.bat |
| 456 repdict = GenerateReplacements(desc, tools) | 446 repdict = GenerateReplacements(desc, tools) |
| 457 make_path = os.path.join(out_dir, 'Makefile') | 447 make_path = os.path.join(out_dir, 'Makefile') |
| 458 WriteReplaced(template, make_path, repdict) | 448 WriteReplaced(template, make_path, repdict) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 if options.master: | 528 if options.master: |
| 539 master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile') | 529 master_in = os.path.join(SDK_EXAMPLE_DIR, 'Makefile') |
| 540 for dest, projects in master_projects.iteritems(): | 530 for dest, projects in master_projects.iteritems(): |
| 541 master_out = os.path.join(options.dstroot, dest, 'Makefile') | 531 master_out = os.path.join(options.dstroot, dest, 'Makefile') |
| 542 GenerateMasterMakefile(master_in, master_out, projects) | 532 GenerateMasterMakefile(master_in, master_out, projects) |
| 543 return 0 | 533 return 0 |
| 544 | 534 |
| 545 | 535 |
| 546 if __name__ == '__main__': | 536 if __name__ == '__main__': |
| 547 sys.exit(main(sys.argv[1:])) | 537 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |