From 4455893e0e3483e67b0207ce12fd37505ba74629 Mon Sep 17 00:00:00 2001
From: Andrey Volk <andywolk@gmail.com>
Date: Thu, 29 Jun 2017 03:04:18 +0300
Subject: [PATCH] FS-10436 [mod_v8] Upgrade javascript libv8 from 3.24.14 to
 5.6.326 on windows.

---
 libs/win32/Download V8.2015.vcxproj |  4 +--
 libs/win32/v8/build-v8.bat          | 43 ++++++++++++++++++++++-------
 w32/v8-version.props                |  2 +-
 w32/v8.props                        |  2 +-
 4 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/libs/win32/Download V8.2015.vcxproj b/libs/win32/Download V8.2015.vcxproj
index 55f960d751..64ede7f2f7 100644
--- a/libs/win32/Download V8.2015.vcxproj	
+++ b/libs/win32/Download V8.2015.vcxproj	
@@ -67,12 +67,12 @@
     <CustomBuild Include="cleancount">
       <FileType>Document</FileType>
       <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Downloading V8.</Message>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">if not exist "$(ProjectDir)..\v8-$(V8Version)" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version)-vs2015.tar.bz2 "$(ProjectDir).."
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">if not exist "$(ProjectDir)..\v8-$(V8Version)" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version).tar.bz2 "$(ProjectDir).."
 if not exist "$(ProjectDir)..\v8-$(V8Version)\third_party\cygwin" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version)-win.tar.bz2 "$(ProjectDir).."
 </Command>
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)..\v8-$(V8Version);%(Outputs)</Outputs>
       <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Downloading V8.</Message>
-      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">if not exist "$(ProjectDir)..\v8-$(V8Version)" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version)-vs2015.tar.bz2 "$(ProjectDir).."
+      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">if not exist "$(ProjectDir)..\v8-$(V8Version)" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version).tar.bz2 "$(ProjectDir).."
 if not exist "$(ProjectDir)..\v8-$(V8Version)\third_party\cygwin" cscript /nologo "$(ProjectDir)util.vbs" GetUnzip http://files.freeswitch.org/downloads/libs/v8-$(V8Version)-win.tar.bz2 "$(ProjectDir).."
 </Command>
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)..\v8-$(V8Version);%(Outputs)</Outputs>
diff --git a/libs/win32/v8/build-v8.bat b/libs/win32/v8/build-v8.bat
index 6f0077b2d2..adcc81e02e 100644
--- a/libs/win32/v8/build-v8.bat
+++ b/libs/win32/v8/build-v8.bat
@@ -22,18 +22,28 @@ IF "%1-%2" == "%LAST_BUILD_INFO%" (
 )
 
 SET LIB_DEST_DIR=
+SET DEPOT_TOOLS_WIN_TOOLCHAIN=0
+SET GYP_GENERATORS=msvs
+REM Bake snapshot blobs (natives_blob.bin and snapshot_blob.bin) into the library
+SET GYPFLAGS="-Dv8_use_external_startup_data=0"
+
+CALL .\third_party\python_26\setup_env.bat
 
 IF "%VisualStudioVersion%" == "11.0" (
-	SET VS_VERSION=-Gmsvs_version=2012
+	REM SET VS_VERSION=-Gmsvs_version=2012
+        SET GYP_MSVS_VERSION=2012
 	ECHO Forcing build to use Visual Studio 2012
 ) ELSE IF "%VisualStudioVersion%" == "12.0" (
-	SET VS_VERSION=-Gmsvs_version=2013
+	REM SET VS_VERSION=-Gmsvs_version=2013
+        SET GYP_MSVS_VERSION=2013
 	ECHO Forcing build to use Visual Studio 2013
 ) ELSE IF "%VisualStudioVersion%" == "14.0" (
-	SET VS_VERSION=-Gmsvs_version=2015
+	REM SET VS_VERSION=-Gmsvs_version=2015
+        SET GYP_MSVS_VERSION=2015
 	ECHO Forcing build to use Visual Studio 2015
 ) ELSE IF NOT "%4" == "" (
-	SET VS_VERSION=-Gmsvs_version=%4
+	REM SET VS_VERSION=-Gmsvs_version=%4
+        SET GYP_MSVS_VERSION=%4
 	ECHO Forcing build to use Visual Studio %4
 )
 
@@ -46,13 +56,15 @@ IF "%1" == "x64" (
 
 IF "%1" == "x64" (
 	IF NOT "%SKIP_V8_SNAPSHOT%" == "" ECHO Targeting x64 platform on a x86 system, disabling V8 snapshout feature to make this work [%SKIP_V8_SNAPSHOT%]
-	IF NOT "%COPY_FILES_ONLY%" == "1" .\third_party\python_26\python.exe build\gyp_v8 -Dtarget_arch=x64 -Dcomponent=shared_library %SKIP_V8_SNAPSHOT% %VS_VERSION%
+	REM IF NOT "%COPY_FILES_ONLY%" == "1" .\third_party\python_26\python.exe build\gyp_v8 -Dtarget_arch=x64 -Dcomponent=shared_library %SKIP_V8_SNAPSHOT% %VS_VERSION%
+	IF NOT "%COPY_FILES_ONLY%" == "1" .\third_party\python_26\python.exe gypfiles\gyp_v8 -Dtarget_arch=x64 -Dcomponent=shared_library %GYPFLAGS%
 	IF ERRORLEVEL 1 GOTO Fail
 	SET LIB_DEST_DIR=..\..\x64\%2\
 )
 
 IF "%1" == "x86" (
-	IF NOT "%COPY_FILES_ONLY%" == "1" .\third_party\python_26\python.exe build\gyp_v8 -Dcomponent=shared_library %VS_VERSION%
+	REM IF NOT "%COPY_FILES_ONLY%" == "1" .\third_party\python_26\python.exe build\gyp_v8 -Dcomponent=shared_library %VS_VERSION%
+	IF NOT "%COPY_FILES_ONLY%" == "1" .\third_party\python_26\python.exe gypfiles\gyp_v8 -Dcomponent=shared_library %GYPFLAGS%
 	IF ERRORLEVEL 1 GOTO Fail
 	SET LIB_DEST_DIR=..\..\Win32\%2\
 )
@@ -63,10 +75,12 @@ IF "%COPY_FILES_ONLY%" == "1" GOTO CopyFiles
 
 REM Clean build before we continue
 REM First try to clean using the solution path (works for most VS versions)
-msbuild "tools\gyp\v8.sln" /t:"_tools_\_gyp_\v8:Clean" /p:Configuration=%2 /clp:WarningsOnly
+REM msbuild "tools\gyp\v8.sln" /t:"_tools_\_gyp_\v8:Clean" /p:Configuration=%2 /clp:WarningsOnly
+msbuild "src\v8.sln" /t:"_src_\v8:Clean" /p:Configuration=%2 /clp:WarningsOnly
 IF NOT ERRORLEVEL 1 GOTO CleanDone
 REM If clean using solution path didn't work, try to build without the path (works for some VS versions...)
-msbuild "tools\gyp\v8.sln" /t:v8:Clean /p:Configuration=%2
+REM msbuild "tools\gyp\v8.sln" /t:v8:Clean /p:Configuration=%2
+msbuild "src\v8.sln" /t:v8:Clean /p:Configuration=%2
 IF ERRORLEVEL 1 GOTO Fail
 :CleanDone
 
@@ -75,10 +89,13 @@ rmdir /S /Q .\build\%2
 
 REM Build the V8 library
 REM First try to build using the solution path (works for most VS versions)
-msbuild "tools\gyp\v8.sln" /t:"_tools_\_gyp_\v8:Rebuild" /p:Configuration=%2 /clp:WarningsOnly
+REM msbuild "tools\gyp\v8.sln" /t:"_tools_\_gyp_\v8:Rebuild" /p:Configuration=%2 /clp:WarningsOnly
+REM msbuild "src\v8.sln" /t:"_src_\v8_libpaltfrom:Rebuild" /p:Configuration=%2 /clp:WarningsOnly
+msbuild "src\v8.sln" /t:"_src_\v8:Rebuild" /p:Configuration=%2 /clp:WarningsOnly
 IF NOT ERRORLEVEL 1 GOTO CopyFiles
 REM If build using solution path didn't work, try to build without the path (works for some VS versions...)
-msbuild "tools\gyp\v8.sln" /t:v8:Rebuild /p:Configuration=%2
+REM msbuild "tools\gyp\v8.sln" /t:v8:Rebuild /p:Configuration=%2
+msbuild "src\v8.sln" /t:v8:Rebuild /p:Configuration=%2
 IF ERRORLEVEL 1 GOTO Fail
 
 :CopyFiles
@@ -92,6 +109,12 @@ IF ERRORLEVEL 1 GOTO Fail
 xcopy /C /F /R /Y .\build\%2\v8.dll %LIB_DEST_DIR%
 IF ERRORLEVEL 1 GOTO Fail
 
+xcopy /C /F /R /Y .\build\%2\v8_libplatform.dll %LIB_DEST_DIR%
+IF ERRORLEVEL 1 GOTO Fail
+
+xcopy /C /F /R /Y .\build\%2\v8_libbase.dll %LIB_DEST_DIR%
+IF ERRORLEVEL 1 GOTO Fail
+
 ECHO %1-%2> last_build
 
 exit /b 0
diff --git a/w32/v8-version.props b/w32/v8-version.props
index 800ab9a7e6..be5059ff9d 100644
--- a/w32/v8-version.props
+++ b/w32/v8-version.props
@@ -2,7 +2,7 @@
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ImportGroup Label="PropertySheets" />
   <PropertyGroup Label="UserMacros">
-    <V8Version>3.24.14</V8Version>
+    <V8Version>5.6.326</V8Version>
   </PropertyGroup>
   <PropertyGroup>
     <V8VersionImported>true</V8VersionImported>
diff --git a/w32/v8.props b/w32/v8.props
index 5476106df3..1368c703cd 100644
--- a/w32/v8.props
+++ b/w32/v8.props
@@ -13,7 +13,7 @@
     </ClCompile>
     <Link>
       <AdditionalLibraryDirectories>$(SolutionDir)libs\v8-$(V8Version)\build\$(Configuration)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
-      <AdditionalDependencies>icui18n.lib;icuuc.lib;v8.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>icui18n.lib;icuuc.lib;v8.lib;v8_libplatform.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
 </Project>