Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / native_client / SConstruct
index f443d59..f17c3ff 100755 (executable)
@@ -26,8 +26,7 @@ sys.path.append("tools")
 import command_tester
 import test_lib
 
-sys.path.append("build")
-import platform_tools
+import pynacl.platform
 
 # NOTE: Underlay for  src/third_party_mod/gtest
 # TODO: try to eliminate this hack
@@ -449,7 +448,7 @@ def GetTargetPlatform():
   return ARGUMENTS.get('platform', 'x86-32')
 
 def GetBuildPlatform():
-  arch_dict = platform_tools.ArchDict()
+  arch_dict = pynacl.platform.ArchDict()
   machine = platform.machine().lower()
   if machine not in arch_dict:
     raise UserError('Unrecognized host architecture: %s', platform.machine())
@@ -757,12 +756,7 @@ tests_to_disable_qemu = set([
     # Note, for now these tests disable both the irt and non-irt variants
     'run_atomic_ops_test',    # still broken with qemu 2012/06/12
     'run_atomic_ops_nexe_test',
-    # The debug stub test is not set up to insert QEMU at the right
-    # point, and service_runtime's thread suspension does not work
-    # under QEMU.
-    'run_debug_stub_test',
     'run_egyptian_cotton_test',  # still broken with qemu 2012/06/12
-    'run_faulted_thread_queue_test',
     'run_many_threads_sequential_test',
     'run_mmap_atomicity_test',   # still broken with qemu 2012/06/12
     # http://code.google.com/p/nativeclient/issues/detail?id=2142
@@ -941,7 +935,6 @@ AVAILABLE_PLATFORMS = {
     'x86-64'      : { 'arch' : 'x86' , 'subarch' : '64' },
     'mips32'      : { 'arch' : 'mips', 'subarch' : '32' },
     'arm'         : { 'arch' : 'arm' , 'subarch' : '32' },
-    'arm-thumb2'  : { 'arch' : 'arm' , 'subarch' : '32' }
     }
 
 # Decode platform into list [ ARCHITECTURE , EXEC_MODE ].
@@ -959,9 +952,6 @@ DeclareBit('build_mips32', 'Building binaries for the MIPS architecture',
            exclusive_groups='build_arch')
 DeclareBit('build_arm_arm', 'Building binaries for the ARM architecture',
            exclusive_groups='build_arch')
-DeclareBit('build_arm_thumb2',
-           'Building binaries for the ARM architecture (thumb2 ISA)',
-           exclusive_groups='build_arch')
 DeclareBit('target_x86_32', 'Tools being built will process x86-32 binaries',
            exclusive_groups='target_arch')
 DeclareBit('target_x86_64', 'Tools being built will process x86-36 binaries',
@@ -970,15 +960,11 @@ DeclareBit('target_mips32', 'Tools being built will process MIPS binaries',
            exclusive_groups='target_arch')
 DeclareBit('target_arm_arm', 'Tools being built will process ARM binaries',
            exclusive_groups='target_arch')
-DeclareBit('target_arm_thumb2',
-           'Tools being built will process ARM binaries (thumb2 ISA)',
-           exclusive_groups='target_arch')
 
 # Shorthand for either the 32 or 64 bit version of x86.
 DeclareBit('build_x86', 'Building binaries for the x86 architecture')
 DeclareBit('target_x86', 'Tools being built will process x86 binaries')
 
-# Shorthand for either arm or thumb2 versions of ARM
 DeclareBit('build_arm', 'Building binaries for the arm architecture')
 DeclareBit('target_arm', 'Tools being built will process arm binaries')
 
@@ -1005,12 +991,12 @@ def MakeArchSpecificEnv(platform=None):
 
   if env.Bit('build_x86_32') or env.Bit('build_x86_64'):
     env.SetBits('build_x86')
-  if env.Bit('build_arm_arm') or env.Bit('build_arm_thumb2'):
+  if env.Bit('build_arm_arm'):
     env.SetBits('build_arm')
 
   if env.Bit('target_x86_32') or env.Bit('target_x86_64'):
     env.SetBits('target_x86')
-  if env.Bit('target_arm_arm') or env.Bit('target_arm_thumb2'):
+  if env.Bit('target_arm_arm'):
     env.SetBits('target_arm')
 
   env.Replace(BUILD_ISA_NAME=platform)
@@ -1256,6 +1242,19 @@ def GetIrtNexe(env, chrome_irt=False):
 
 pre_base_env.AddMethod(GetIrtNexe)
 
+def ApplyTLSEdit(env, nexe_name, raw_nexe):
+  # If the environment was built elsewhere, we do not need to apply tls_edit
+  # since it only needs to be done during building.
+  if env.Bit('built_elsewhere'):
+    return env.File(nexe_name)
+
+  tls_edit_exe = env['BUILD_ENV'].File('${STAGING_DIR}/tls_edit${PROGSUFFIX}')
+  return env.Command(
+      nexe_name,
+      [tls_edit_exe, raw_nexe],
+      '${SOURCES[0]} --verbose ${SOURCES[1:]} ${TARGET}')
+
+pre_base_env.AddMethod(ApplyTLSEdit)
 
 def CommandValidatorTestNacl(env, name, image,
                              validator_flags=None,
@@ -1704,8 +1703,8 @@ def ApplyTestWrapperCommand(command_args, extra_deps):
 
 def CommandTest(env, name, command, size='small', direct_emulation=True,
                 extra_deps=[], posix_path=False, capture_output=True,
-                wrapper_program_prefix=None, scale_timeout=None,
-                **extra):
+                capture_stderr=True, wrapper_program_prefix=None,
+                scale_timeout=None, **extra):
   if not name.endswith('.out') or name.startswith('$'):
     raise Exception('ERROR: bad test filename for test output %r' % name)
 
@@ -1811,6 +1810,8 @@ def CommandTest(env, name, command, size='small', direct_emulation=True,
   # Other extra flags
   if not capture_output:
     script_flags.extend(['--capture_output', '0'])
+  if not capture_stderr:
+    script_flags.extend(['--capture_stderr', '0'])
 
   # Set command_tester.py's output filename.  We skip this when using
   # test_wrapper because the run_test_via_ssh.py wrapper does not have
@@ -1841,7 +1842,7 @@ def FileSizeTest(env, name, envFile, max_size=None):
     command_tester.LogPerfResult(name,
                                  env.GetPerfEnvDescription(),
                                  '%.3f' % (actual_size / 1024.0),
-                                 'kilobytes')
+                                 'KB')
     # Also get zipped size.
     nexe_file = open(filepath, 'rb')
     zipped_size = len(zlib.compress(nexe_file.read()))
@@ -1849,7 +1850,7 @@ def FileSizeTest(env, name, envFile, max_size=None):
     command_tester.LogPerfResult(name,
                                  'ZIPPED_' + env.GetPerfEnvDescription(),
                                  '%.3f' % (zipped_size / 1024.0),
-                                 'kilobytes')
+                                 'KB')
     # Finally, do the size check.
     if max_size is not None and actual_size > max_size:
       # NOTE: this exception only triggers a failure for this particular test,
@@ -2056,8 +2057,6 @@ def MakeBaseTrustedEnv(platform=None):
   )
   if base_env.Bit('ncval_testing'):
     base_env.Append(CPPDEFINES = ['NCVAL_TESTING'])
-  if base_env.Bit('target_arm_thumb2'):
-    base_env.Append(CPPDEFINES = ['NACL_TARGET_ARM_THUMB2_MODE=1'])
 
   base_env.Append(BUILD_SCONSCRIPTS = [
       # KEEP THIS SORTED PLEASE
@@ -2075,6 +2074,7 @@ def MakeBaseTrustedEnv(platform=None):
       'src/trusted/cpu_features/build.scons',
       'src/trusted/debug_stub/build.scons',
       'src/trusted/desc/build.scons',
+      'src/trusted/desc_cacheability/build.scons',
       'src/trusted/fault_injection/build.scons',
       'src/trusted/generic_container/build.scons',
       'src/trusted/gio/build.scons',
@@ -3281,16 +3281,17 @@ if nacl_irt_env.Bit('bitcode'):
 nacl_irt_env.Replace(LINK=(nacl_irt_env['LINK'].
                            replace('pnacl-clang++', 'pnacl-clang')))
 
+if nacl_irt_env.Bit('bitcode'):
+  nacl_irt_env.Append(LINKFLAGS=['--pnacl-allow-native'])
+
 # All IRT code must avoid direct use of the TLS ABI register, which
 # is reserved for user TLS.  Instead, ensure all TLS accesses use a
 # call to __nacl_read_tp, which the IRT code overrides to segregate
-# IRT-private TLS from user TLS.
-if nacl_irt_env.Bit('bitcode'):
-  nacl_irt_env.Append(LINKFLAGS=['--pnacl-allow-native', '-Wt,-mtls-use-call'])
-elif nacl_irt_env.Bit('target_arm'):
-  nacl_irt_env.Append(CCFLAGS=['-mtp=soft'])
-else:
-  nacl_irt_env.Append(CCFLAGS=['-mtls-use-call'])
+# IRT-private TLS from user TLS. This only applies to mips now, on
+# other platforms we modify the TLS register through tls_edit as a
+# post process.
+if nacl_irt_env.Bit('target_mips32'):
+  nacl_irt_env.Append(LINKFLAGS=['-Wt,-mtls-use-call'])
 
 # TODO(mcgrathr): Clean up uses of these methods.
 def AddLibraryDummy(env, nodes):
@@ -3409,6 +3410,7 @@ nacl_irt_env.Append(
         'src/shared/gio/nacl.scons',
         'src/shared/platform/nacl.scons',
         'src/shared/srpc/nacl.scons',
+        'src/tools/tls_edit/build.scons',
         'src/untrusted/irt/nacl.scons',
         'src/untrusted/nacl/nacl.scons',
         'src/untrusted/stubs/nacl.scons',
@@ -3611,7 +3613,14 @@ def MakeBuildEnv():
 
   build_env = make_env_func(build_platform)
   build_env['IS_BUILD_ENV'] = True
-  build_env['BUILD_SCONSCRIPTS'] = []
+
+  # Building tls_edit depends on gio, platform, and validator_ragel.
+  build_env['BUILD_SCONSCRIPTS'] = [
+    # KEEP THIS SORTED PLEASE
+    'src/shared/gio/build.scons',
+    'src/shared/platform/build.scons',
+    'src/trusted/validator_ragel/build.scons',
+    ]
 
   # The build environment is only used for intermediate steps and should
   # not be creating any targets. Aliases are used as means to add targets
@@ -3620,17 +3629,35 @@ def MakeBuildEnv():
   # override the alias function and essentially stub it out.
   build_env.Alias = lambda env, target, source=[], actions=None, **kw : []
 
-  dbg_build_env, opt_build_env = GenerateOptimizationLevels(build_env)
+  return build_env
 
-  return opt_build_env
+def LinkBuildEnv(selected_envs):
+  build_env_map = {
+    'opt': opt_build_env,
+    'dbg': dbg_build_env,
+    }
+
+  # We need to find the optimization level in order to know which
+  # build environment we want to use
+  opt_level = None
+  for env in selected_envs:
+    if env.get('OPTIMIZATION_LEVEL', None):
+      opt_level = env['OPTIMIZATION_LEVEL']
+      break
 
-def LinkBuildEnv(selected_envs, build_env):
+  build_env = build_env_map.get(opt_level, opt_build_env)
   for env in selected_envs:
     env['BUILD_ENV'] = build_env
 
-  # If platform is not the same as the host environment, add the targets
-  #  of the host environment so scons can find them
-  if GetBuildPlatform() != GetTargetPlatform():
+  # If the build environment is different from all the selected environments,
+  # we will need to also append it to the selected environments so the targets
+  # can be built.
+  build_env_root = build_env.subst('${TARGET_ROOT}')
+  for env in selected_envs:
+    if build_env_root == env.subst('${TARGET_ROOT}'):
+      break
+  else:
+    # Did not find a matching environment, append the build environment now.
     selected_envs.append(build_env)
 
 def DumpEnvironmentInfo(selected_envs):
@@ -3685,7 +3712,7 @@ CheckArguments()
 SanityCheckEnvironments(environment_list)
 selected_envs = FilterEnvironments(environment_list)
 
-# If we are building nacl, build nacl_irt too.  This works around it being
+# If we are building NaCl, build nacl_irt too.  This works around it being
 # a separate mode due to the vagaries of scons when we'd really rather it
 # not be, while not requiring that every bot command line using --mode be
 # changed to list '...,nacl,nacl_irt' explicitly.
@@ -3696,10 +3723,16 @@ if nacl_env in selected_envs:
 if nacl_irt_test_env in selected_envs and nacl_env not in selected_envs:
   selected_envs.append(nacl_env)
 
-
 DumpEnvironmentInfo(selected_envs)
 LinkTrustedEnv(selected_envs)
-LinkBuildEnv(selected_envs, MakeBuildEnv())
+
+# When building NaCl, any intermediate build tool that is used during the
+# build process must be built using the current build environment, not the
+# target. Create a build environment for this purpose and link it into
+# the selected environments
+dbg_build_env, opt_build_env = GenerateOptimizationLevels(MakeBuildEnv())
+LinkBuildEnv(selected_envs)
+
 # This must happen after LinkTrustedEnv, since that is where TRUSTED_ENV
 # is finally set, and env.UsingEmulator() checks TRUSTED_ENV for the emulator.
 # This must also happen before BuildEnvironments.