OLD | NEW |
1 #! -*- python -*- | 1 #! -*- python -*- |
2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2012 The Native Client 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 json | 6 import json |
7 import os | 7 import os |
8 import shutil | 8 import shutil |
9 import sys | 9 import sys |
10 | 10 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 def CopyLibsForExtensionCommand(target, source, env): | 166 def CopyLibsForExtensionCommand(target, source, env): |
167 source_manifest = str(source[0]) | 167 source_manifest = str(source[0]) |
168 target_manifest = str(target[0]) | 168 target_manifest = str(target[0]) |
169 shutil.copyfile(source_manifest, target_manifest) | 169 shutil.copyfile(source_manifest, target_manifest) |
170 target_dir = os.path.dirname(target_manifest) | 170 target_dir = os.path.dirname(target_manifest) |
171 libs_file = open(str(source[1]), 'r') | 171 libs_file = open(str(source[1]), 'r') |
172 for line in libs_file.readlines(): | 172 for line in libs_file.readlines(): |
173 lib_info = ParseLibInfoInRunnableLdLog(line) | 173 lib_info = ParseLibInfoInRunnableLdLog(line) |
174 if lib_info: | 174 if lib_info: |
175 lib_name, lib_path = lib_info | 175 lib_name, lib_path = lib_info |
176 # Note: This probably does NOT work with pnacl _pexes_ right now, because | |
177 # the NEEDED metadata in the bitcode doesn't have the original file paths. | |
178 # This should probably be done without such knowledge. | |
179 if lib_path == 'NaClMain': | 176 if lib_path == 'NaClMain': |
180 # This is a fake file name, which we cannot copy. | 177 # This is a fake file name, which we cannot copy. |
181 continue | 178 continue |
182 shutil.copyfile(lib_path, os.path.join(target_dir, lib_name)) | 179 shutil.copyfile(lib_path, os.path.join(target_dir, lib_name)) |
183 shutil.copyfile(env.subst('${NACL_SDK_LIB}/runnable-ld.so'), | 180 shutil.copyfile(env.subst('${NACL_SDK_LIB}/runnable-ld.so'), |
184 os.path.join(target_dir, 'runnable-ld.so')) | 181 os.path.join(target_dir, 'runnable-ld.so')) |
185 libs_file.close() | 182 libs_file.close() |
186 | 183 |
187 | 184 |
188 # Extensions are loaded from directory on disk and so all dynamic libraries | 185 # Extensions are loaded from directory on disk and so all dynamic libraries |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 obj['files']['main.nexe'] = {} | 282 obj['files']['main.nexe'] = {} |
286 for k, v in obj['program'].items(): | 283 for k, v in obj['program'].items(): |
287 obj['files']['main.nexe'][k] = v.copy() | 284 obj['files']['main.nexe'][k] = v.copy() |
288 v['url'] = 'runnable-ld.so' | 285 v['url'] = 'runnable-ld.so' |
289 # Write the new manifest! | 286 # Write the new manifest! |
290 target_file = open(str(target[0]), 'w') | 287 target_file = open(str(target[0]), 'w') |
291 json.dump(obj, target_file, sort_keys=True, indent=2) | 288 json.dump(obj, target_file, sort_keys=True, indent=2) |
292 target_file.close() | 289 target_file.close() |
293 return 0 | 290 return 0 |
294 | 291 |
295 def GenerateManifestPnacl(env, dest_file, manifest, exe_file): | |
296 return env.Command( | |
297 dest_file, | |
298 ['${GENNMF}', exe_file, manifest], | |
299 # Generate a flat url scheme to simplify file-staging. | |
300 ('${SOURCES[0]} ${SOURCES[1]} -L${NACL_SDK_LIB} -L${LIB_DIR} ' | |
301 ' --flat-url-scheme --base-nmf ${SOURCES[2]} -o ${TARGET}')) | |
302 | 292 |
303 def GenerateManifestDynamicLink(env, dest_file, lib_list_file, | 293 def GenerateManifestDynamicLink(env, dest_file, lib_list_file, |
304 manifest, exe_file): | 294 manifest, exe_file): |
305 # Run sel_ldr on the nexe to trace the NEEDED libraries. | 295 # Run sel_ldr on the nexe to trace the NEEDED libraries. |
306 lib_list_node = env.Command( | 296 lib_list_node = env.Command( |
307 lib_list_file, | 297 lib_list_file, |
308 [env.GetSelLdr(), | 298 [env.GetSelLdr(), |
309 '${NACL_SDK_LIB}/runnable-ld.so', | 299 '${NACL_SDK_LIB}/runnable-ld.so', |
310 exe_file, | 300 exe_file, |
311 '${SCONSTRUCT_DIR}/DEPS'], | 301 '${SCONSTRUCT_DIR}/DEPS'], |
(...skipping 17 matching lines...) Expand all Loading... |
329 fh.close() | 319 fh.close() |
330 node = env.Command(dest_file, [], Func)[0] | 320 node = env.Command(dest_file, [], Func)[0] |
331 # Scons does not track the dependency of dest_file on exe_name or on | 321 # Scons does not track the dependency of dest_file on exe_name or on |
332 # the Python code above, so we should always recreate dest_file when | 322 # the Python code above, so we should always recreate dest_file when |
333 # it is used. | 323 # it is used. |
334 env.AlwaysBuild(node) | 324 env.AlwaysBuild(node) |
335 return node | 325 return node |
336 | 326 |
337 | 327 |
338 def GenerateSimpleManifest(env, dest_file, exe_name): | 328 def GenerateSimpleManifest(env, dest_file, exe_name): |
339 if env.Bit('pnacl_generate_pexe'): | 329 if env.Bit('nacl_static_link'): |
340 static_manifest = GenerateSimpleManifestStaticLink( | |
341 env, '%s.static' % dest_file, exe_name) | |
342 return GenerateManifestPnacl(env, dest_file, static_manifest, | |
343 '${STAGING_DIR}/%s.pexe' % | |
344 env.ProgramNameForNmf(exe_name)) | |
345 elif env.Bit('nacl_static_link'): | |
346 return GenerateSimpleManifestStaticLink(env, dest_file, exe_name) | 330 return GenerateSimpleManifestStaticLink(env, dest_file, exe_name) |
347 else: | 331 else: |
348 static_manifest = GenerateSimpleManifestStaticLink( | 332 static_manifest = GenerateSimpleManifestStaticLink( |
349 env, '%s.static' % dest_file, exe_name) | 333 env, '%s.static' % dest_file, exe_name) |
350 return GenerateManifestDynamicLink( | 334 return GenerateManifestDynamicLink( |
351 env, dest_file, '%s.tmp_lib_list' % dest_file, static_manifest, | 335 env, dest_file, '%s.tmp_lib_list' % dest_file, static_manifest, |
352 '${STAGING_DIR}/%s.nexe' % env.ProgramNameForNmf(exe_name)) | 336 '${STAGING_DIR}/%s.nexe' % env.ProgramNameForNmf(exe_name)) |
353 | 337 |
354 pre_base_env.AddMethod(GenerateSimpleManifest) | 338 pre_base_env.AddMethod(GenerateSimpleManifest) |
355 | 339 |
356 | 340 |
357 # Returns a pair (main program, is_portable), based on the program | 341 # Returns a pair (main program, is_portable), based on the program |
358 # specified in manifest file. | 342 # specified in manifest file. |
359 def GetMainProgramFromManifest(env, manifest): | 343 def GetMainProgramFromManifest(env, manifest): |
360 obj = json.loads(env.File(manifest).get_contents()) | 344 obj = json.loads(env.File(manifest).get_contents()) |
361 program_dict = obj['program'] | 345 program_dict = obj['program'] |
362 if env.Bit('pnacl_generate_pexe') and 'portable' in program_dict: | 346 return program_dict[env.subst('${TARGET_FULLARCH}')]['url'] |
363 return program_dict['portable']['pnacl-translate']['url'] | |
364 else: | |
365 return program_dict[env.subst('${TARGET_FULLARCH}')]['url'] | |
366 | 347 |
367 | 348 |
368 # Returns scons node for generated manifest. | 349 # Returns scons node for generated manifest. |
369 def GeneratedManifestNode(env, manifest): | 350 def GeneratedManifestNode(env, manifest): |
370 manifest = env.subst(manifest) | 351 manifest = env.subst(manifest) |
371 manifest_base_name = os.path.basename(manifest) | 352 manifest_base_name = os.path.basename(manifest) |
372 main_program = GetMainProgramFromManifest(env, manifest) | 353 main_program = GetMainProgramFromManifest(env, manifest) |
373 result = env.File('${STAGING_DIR}/' + manifest_base_name) | 354 result = env.File('${STAGING_DIR}/' + manifest_base_name) |
374 # Always generate the manifest for nacl_glibc and pnacl pexes. | 355 # Always generate the manifest for nacl_glibc. |
375 # For nacl_glibc, generating the mapping of shared libraries is non-trivial. | 356 # For nacl_glibc, generating the mapping of shared libraries is non-trivial. |
376 # For pnacl, the manifest currently hosts a sha for the pexe. | 357 if not env.Bit('nacl_glibc'): |
377 if not env.Bit('nacl_glibc') and not env.Bit('pnacl_generate_pexe'): | |
378 env.Install('${STAGING_DIR}', manifest) | 358 env.Install('${STAGING_DIR}', manifest) |
379 return result | 359 return result |
380 if env.Bit('pnacl_generate_pexe'): | 360 return GenerateManifestDynamicLink( |
381 return GenerateManifestPnacl( | 361 env, '${STAGING_DIR}/' + manifest_base_name, |
382 env, | 362 # Note that CopyLibsForExtension() and WhitelistLibsForExtension() |
383 '${STAGING_DIR}/' + manifest_base_name, | 363 # assume that it can find the library list file under this filename. |
384 manifest, | 364 GlibcManifestLibsListFilename(manifest_base_name), |
385 env.File('${STAGING_DIR}/' + os.path.basename(main_program))) | 365 manifest, |
386 else: | 366 env.File('${STAGING_DIR}/' + os.path.basename(main_program))) |
387 return GenerateManifestDynamicLink( | |
388 env, '${STAGING_DIR}/' + manifest_base_name, | |
389 # Note that CopyLibsForExtension() and WhitelistLibsForExtension() | |
390 # assume that it can find the library list file under this filename. | |
391 GlibcManifestLibsListFilename(manifest_base_name), | |
392 manifest, | |
393 env.File('${STAGING_DIR}/' + os.path.basename(main_program))) | |
394 return result | 367 return result |
395 | 368 |
396 | 369 |
397 # Compares output_file and golden_file. | 370 # Compares output_file and golden_file. |
398 # If they are different, prints the difference and returns 1. | 371 # If they are different, prints the difference and returns 1. |
399 # Otherwise, returns 0. | 372 # Otherwise, returns 0. |
400 def CheckGoldenFile(golden_file, output_file, | 373 def CheckGoldenFile(golden_file, output_file, |
401 filter_regex, filter_inverse, filter_group_only): | 374 filter_regex, filter_inverse, filter_group_only): |
402 golden = open(golden_file).read() | 375 golden = open(golden_file).read() |
403 actual = open(output_file).read() | 376 actual = open(output_file).read() |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 427 |
455 # No browser tests run on arm-thumb2 | 428 # No browser tests run on arm-thumb2 |
456 # Bug http://code.google.com/p/nativeclient/issues/detail?id=2224 | 429 # Bug http://code.google.com/p/nativeclient/issues/detail?id=2224 |
457 if env.Bit('target_arm_thumb2'): | 430 if env.Bit('target_arm_thumb2'): |
458 return [] | 431 return [] |
459 | 432 |
460 # Handle issues with mutating any python default arg lists. | 433 # Handle issues with mutating any python default arg lists. |
461 if browser_flags is None: | 434 if browser_flags is None: |
462 browser_flags = [] | 435 browser_flags = [] |
463 | 436 |
464 if env.Bit('pnacl_generate_pexe'): | |
465 # We likely prefer to choose the 'portable' field in nmfs in this mode. | |
466 args = args + ['--prefer_portable_in_manifest'] | |
467 | |
468 # Lint the extra arguments that are being passed to the tester. | 437 # Lint the extra arguments that are being passed to the tester. |
469 special_args = ['--ppapi_plugin', '--sel_ldr', '--irt_library', '--file', | 438 special_args = ['--ppapi_plugin', '--sel_ldr', '--irt_library', '--file', |
470 '--map_file', '--extension', '--mime_type', '--tool', | 439 '--map_file', '--extension', '--mime_type', '--tool', |
471 '--browser_flag', '--test_arg'] | 440 '--browser_flag', '--test_arg'] |
472 for arg_name in special_args: | 441 for arg_name in special_args: |
473 if arg_name in args: | 442 if arg_name in args: |
474 raise Exception('%s: %r is a test argument provided by the SCons test' | 443 raise Exception('%s: %r is a test argument provided by the SCons test' |
475 ' wrapper, do not specify it as an additional argument' % | 444 ' wrapper, do not specify it as an additional argument' % |
476 (target, arg_name)) | 445 (target, arg_name)) |
477 | 446 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 | 568 |
600 pre_base_env.AddMethod(PPAPIGraphics3DIsBroken) | 569 pre_base_env.AddMethod(PPAPIGraphics3DIsBroken) |
601 | 570 |
602 | 571 |
603 def AddChromeFilesFromGroup(env, file_group): | 572 def AddChromeFilesFromGroup(env, file_group): |
604 env['BUILD_SCONSCRIPTS'] = ExtendFileList( | 573 env['BUILD_SCONSCRIPTS'] = ExtendFileList( |
605 env.get('BUILD_SCONSCRIPTS', []), | 574 env.get('BUILD_SCONSCRIPTS', []), |
606 ppapi_scons_files[file_group]) | 575 ppapi_scons_files[file_group]) |
607 | 576 |
608 pre_base_env.AddMethod(AddChromeFilesFromGroup) | 577 pre_base_env.AddMethod(AddChromeFilesFromGroup) |
OLD | NEW |