Push version 1.2.2 to trunk.

Fixed bug in array sorting for sparse arrays (issue 326).

Added support for adding a soname when building a shared library on Linux (issue 151).

Fixed bug caused by morphing internal ASCII strings to external two-byte strings.  Slices over ASCII strings have to forward ASCII checks to the underlying buffer string.

Allowed API call-as-function handlers to be called as constructors.

Fixed a crash bug where an external string was disposed but a slice of the external string survived as a symbol.



git-svn-id: http://v8.googlecode.com/svn/trunk@1853 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/SConstruct b/SConstruct
index 05cb625..ac210d5 100644
--- a/SConstruct
+++ b/SConstruct
@@ -35,6 +35,7 @@
 sys.path.append(join(root_dir, 'tools'))
 import js2c, utils
 
+
 # ANDROID_TOP is the top of the Android checkout, fetched from the environment
 # variable 'TOP'.   You will also need to set the CXX, CC, AR and RANLIB
 # environment variables to the cross-compiling tools.
@@ -131,9 +132,30 @@
                        '-Wstrict-aliasing=2'],
       'CPPPATH':      ANDROID_INCLUDES,
     },
+    'wordsize:32': {
+      'arch:x64': {
+        'CCFLAGS':      ['-m64'],
+        'LINKFLAGS':    ['-m64']
+      }
+    },
     'wordsize:64': {
-      'CCFLAGS':      ['-m32'],
-      'LINKFLAGS':    ['-m32']
+      'arch:ia32': {
+        'CCFLAGS':      ['-m32'],
+        'LINKFLAGS':    ['-m32']
+      },
+      'arch:arm': {
+        'CCFLAGS':      ['-m32'],
+        'LINKFLAGS':    ['-m32']
+      }
+    },
+    'arch:ia32': {
+      'CPPDEFINES':   ['V8_ARCH_IA32', 'ILP32']
+    },
+    'arch:arm': {
+      'CPPDEFINES':   ['V8_ARCH_ARM', 'ILP32']
+    },
+    'arch:x64': {
+      'CPPDEFINES':   ['V8_ARCH_X64', 'LP64']
     },
     'prof:oprofile': {
       'CPPDEFINES':   ['ENABLE_OPROFILE_AGENT']
@@ -150,6 +172,9 @@
       'ARFLAGS':      ['/NOLOGO'],
       'CCPDBFLAGS':   ['/Zi']
     },
+    'arch:ia32': {
+      'CPPDEFINES':   ['V8_ARCH_IA32']
+    },
     'mode:debug': {
       'CCFLAGS':      ['/Od', '/Gm'],
       'CPPDEFINES':   ['_DEBUG', 'ENABLE_DISASSEMBLER', 'DEBUG'],
@@ -175,7 +200,7 @@
         'LINKFLAGS':    ['/LTCG'],
         'ARFLAGS':      ['/LTCG'],
       }
-    },
+    }
   }
 }
 
@@ -187,17 +212,16 @@
       'WARNINGFLAGS': ['-Wall', '-Werror', '-W',
           '-Wno-unused-parameter']
     },
-    'arch:arm': {
-      'CPPDEFINES':   ['ARM']
-    },
-    'arch:android': {
-      'CPPDEFINES':   ['ARM']
-    },
     'os:win32': {
       'WARNINGFLAGS': ['-pedantic', '-Wno-long-long']
     },
     'os:linux': {
-      'WARNINGFLAGS': ['-pedantic']
+      'WARNINGFLAGS': ['-pedantic'],
+      'library:shared': {
+        'soname:on': {
+          'LINKFLAGS': ['-Wl,-soname,${SONAME}']
+        }
+      }
     },
     'os:macos': {
       'WARNINGFLAGS': ['-pedantic']
@@ -215,7 +239,7 @@
       'LIBS': ['winmm', 'ws2_32']
     },
     'arch:arm': {
-      'CPPDEFINES':   ['ARM'],
+      'CPPDEFINES':   ['V8_ARCH_ARM'],
       # /wd4996 is to silence the warning about sscanf
       # used by the arm simulator.
       'WARNINGFLAGS': ['/wd4996']
@@ -286,10 +310,34 @@
     'os:win32': {
       'LIBS': ['winmm', 'ws2_32']
     },
-    'wordsize:64': {
-      'CCFLAGS':      ['-m32'],
-      'LINKFLAGS':    ['-m32']
+    'os:android': {
+      'CPPDEFINES':   ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__',
+                       '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'],
+      'CCFLAGS':      ANDROID_FLAGS,
+      'CPPPATH':      ANDROID_INCLUDES,
+      'LIBPATH':     [ANDROID_TOP + '/out/target/product/generic/obj/lib'],
+      'LINKFLAGS':    ANDROID_LINKFLAGS,
+      'LIBS':         ['c', 'stdc++', 'm'],
+      'mode:release': {
+        'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
+      }
     },
+    'wordsize:32': {
+      'arch:x64': {
+        'CCFLAGS':      ['-m64'],
+        'LINKFLAGS':    ['-m64']
+      }
+    },
+    'wordsize:64': {
+      'arch:ia32': {
+        'CCFLAGS':      ['-m32'],
+        'LINKFLAGS':    ['-m32']
+      },
+      'arch:arm': {
+        'CCFLAGS':      ['-m32'],
+        'LINKFLAGS':    ['-m32']
+      }
+    }
   },
   'msvc': {
     'all': {
@@ -298,6 +346,9 @@
     },
     'library:shared': {
       'CPPDEFINES': ['USING_V8_SHARED']
+    },
+    'arch:ia32': {
+      'CPPDEFINES': ['V8_ARCH_IA32']
     }
   }
 }
@@ -337,9 +388,21 @@
         'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
       }
     },
+    'wordsize:32': {
+      'arch:x64': {
+        'CCFLAGS':      ['-m64'],
+        'LINKFLAGS':    ['-m64']
+      }
+    },
     'wordsize:64': {
-      'CCFLAGS':      ['-m32'],
-      'LINKFLAGS':    ['-m32']
+      'arch:ia32': {
+        'CCFLAGS':      ['-m32'],
+        'LINKFLAGS':    ['-m32']
+      },
+      'arch:arm': {
+        'CCFLAGS':      ['-m32'],
+        'LINKFLAGS':    ['-m32']
+      }
     },
     'mode:release': {
       'CCFLAGS':      ['-O2']
@@ -378,6 +441,9 @@
         'LINKFLAGS':    ['/LTCG'],
       }
     },
+    'arch:ia32': {
+      'CPPDEFINES':     ['V8_ARCH_IA32']
+    },
     'mode:debug': {
       'CCFLAGS':   ['/Od'],
       'LINKFLAGS': ['/DEBUG'],
@@ -454,17 +520,17 @@
   'toolchain': {
     'values': ['gcc', 'msvc'],
     'default': TOOLCHAIN_GUESS,
-    'help': 'the toolchain to use'
+    'help': 'the toolchain to use (' + TOOLCHAIN_GUESS + ')'
   },
   'os': {
     'values': ['freebsd', 'linux', 'macos', 'win32', 'android'],
     'default': OS_GUESS,
-    'help': 'the os to build for'
+    'help': 'the os to build for (' + OS_GUESS + ')'
   },
   'arch': {
-    'values':['arm', 'ia32'],
+    'values':['arm', 'ia32', 'x64'],
     'default': ARCH_GUESS,
-    'help': 'the architecture to build for'
+    'help': 'the architecture to build for (' + ARCH_GUESS + ')'
   },
   'snapshot': {
     'values': ['on', 'off', 'nobuild'],
@@ -481,6 +547,11 @@
     'default': 'static',
     'help': 'the type of library to produce'
   },
+  'soname': {
+    'values': ['on', 'off'],
+    'default': 'off',
+    'help': 'turn on setting soname for Linux shared library'
+  },
   'msvcrt': {
     'values': ['static', 'shared'],
     'default': 'static',
@@ -531,6 +602,49 @@
   return result
 
 
+def GetVersionComponents():
+  MAJOR_VERSION_PATTERN = re.compile(r"#define\s+MAJOR_VERSION\s+(.*)")
+  MINOR_VERSION_PATTERN = re.compile(r"#define\s+MINOR_VERSION\s+(.*)")
+  BUILD_NUMBER_PATTERN = re.compile(r"#define\s+BUILD_NUMBER\s+(.*)")
+  PATCH_LEVEL_PATTERN = re.compile(r"#define\s+PATCH_LEVEL\s+(.*)")
+
+  patterns = [MAJOR_VERSION_PATTERN,
+              MINOR_VERSION_PATTERN,
+              BUILD_NUMBER_PATTERN,
+              PATCH_LEVEL_PATTERN]
+
+  source = open(join(root_dir, 'src', 'version.cc')).read()
+  version_components = []
+  for pattern in patterns:
+    match = pattern.search(source)
+    if match:
+      version_components.append(match.group(1).strip())
+    else:
+      version_components.append('0')
+
+  return version_components
+
+
+def GetVersion():
+  version_components = GetVersionComponents()
+  
+  if version_components[len(version_components) - 1] == '0':
+    version_components.pop()
+  return '.'.join(version_components)
+
+
+def GetSpecificSONAME():
+  SONAME_PATTERN = re.compile(r"#define\s+SONAME\s+\"(.*)\"")
+  
+  source = open(join(root_dir, 'src', 'version.cc')).read()
+  match = SONAME_PATTERN.search(source)
+  
+  if match:
+    return match.group(1).strip()
+  else:
+    return ''
+
+
 def SplitList(str):
   return [ s for s in str.split(",") if len(s) > 0 ]
 
@@ -553,6 +667,12 @@
     Abort("Profiling on windows only supported for static library.")
   if env['prof'] == 'oprofile' and env['os'] != 'linux':
     Abort("OProfile is only supported on Linux.")
+  if env['os'] == 'win32' and env['soname'] == 'on':
+    Abort("Shared Object soname not applicable for Windows.")
+  if env['soname'] == 'on' and env['library'] == 'static':
+    Abort("Shared Object soname not applicable for static library.")
+  if env['arch'] == 'x64' and env['os'] != 'linux':
+    Abort("X64 compilation only allowed on Linux OS.")
   for (name, option) in SIMPLE_OPTIONS.iteritems():
     if (not option.get('default')) and (name not in ARGUMENTS):
       message = ("A value for option %s must be specified (%s)." %
@@ -683,11 +803,23 @@
     'd8': d8_flags
   }
 
+  # Generate library base name.
   target_id = mode
   suffix = SUFFIXES[target_id]
   library_name = 'v8' + suffix
+  version = GetVersion()
+  if context.options['soname'] == 'on':
+    # When building shared object with SONAME version the library name.
+    library_name += '-' + version
   env['LIBRARY'] = library_name
 
+  # Generate library SONAME if required by the build.
+  if context.options['soname'] == 'on':
+    soname = GetSpecificSONAME()
+    if soname == '':
+      soname = 'lib' + library_name + '.so'
+    env['SONAME'] = soname
+
   # Build the object files by invoking SCons recursively.
   (object_files, shell_files, mksnapshot) = env.SConscript(
     join('src', 'SConscript'),