2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-10-31 04:31:19 -04:00
using System ;
2015-09-24 12:37:21 -04:00
using System.IO ;
2014-10-31 04:31:19 -04:00
using System.Text ;
using UnrealBuildTool ;
using System.Diagnostics ;
using System.Collections.Generic ;
using System.Text.RegularExpressions ;
namespace UnrealBuildTool
{
2015-07-04 18:45:54 -04:00
public class HTML5SDKInfo
{
2015-09-24 12:37:21 -04:00
static string SDKBase { get { return Path . GetFullPath ( Path . Combine ( new string [ ] { BuildConfiguration . RelativeEnginePath , "Source" , "ThirdParty" , "HTML5" , "emsdk" } ) ) ; } }
2015-09-16 05:35:30 -04:00
// A GUID as a string. Allows updates to flush the emscripten install without bumping the SDK version number. Useful if a programming-error causes a bogus install.
static string SDKInfoGUID = "49CA9678-2667-48BC-A6A9-25D6FB341F08" ;
2015-07-04 18:45:54 -04:00
static string SDKVersion = "1.30.0" ;
static string EMSCRIPTEN_ROOT { get { return Path . Combine ( SDKBase , "emscripten" , SDKVersion ) ; } }
2014-10-31 04:31:19 -04:00
2015-09-24 12:37:21 -04:00
static string PYTHON_WIN { get { return Path . Combine ( SDKBase , "Win64" , "python" , "2.7.5.3_64bit" , "python.exe" ) ; } }
2015-07-04 18:45:54 -04:00
// python is default installed on mac.
2015-09-24 12:37:21 -04:00
static string PYTHON_MAC { get { return Path . Combine ( "/usr/bin/python" ) ; } }
2014-10-31 04:31:19 -04:00
2015-07-04 18:45:54 -04:00
static string PYTHON
2014-12-10 09:07:36 -05:00
{
2015-07-04 18:45:54 -04:00
get
2014-12-10 09:07:36 -05:00
{
2015-07-04 18:45:54 -04:00
switch ( BuildHostPlatform . Current . Platform )
2014-12-10 09:07:36 -05:00
{
2015-07-04 18:45:54 -04:00
case UnrealTargetPlatform . Win64 :
return PYTHON_WIN ;
case UnrealTargetPlatform . Mac :
return PYTHON_MAC ;
default :
return "" ;
2014-12-10 09:07:36 -05:00
}
}
2015-02-20 04:41:01 -05:00
}
2015-07-04 18:45:54 -04:00
static string LLVM_ROOT_WIN { get { return Path . Combine ( SDKBase , "Win64" , "clang" , "e" + SDKVersion + "_64bit" ) ; } }
static string LLVM_ROOT_MAC { get { return Path . Combine ( SDKBase , "Mac" , "clang" , "e" + SDKVersion + "_64bit" ) ; } }
2015-02-20 04:41:01 -05:00
2015-07-04 18:45:54 -04:00
static string LLVM_ROOT
{
get
2015-02-20 04:41:01 -05:00
{
2015-07-04 18:45:54 -04:00
switch ( BuildHostPlatform . Current . Platform )
2015-02-20 04:41:01 -05:00
{
2015-07-04 18:45:54 -04:00
case UnrealTargetPlatform . Win64 :
return LLVM_ROOT_WIN ;
case UnrealTargetPlatform . Mac :
return LLVM_ROOT_MAC ;
default :
return "" ;
2015-02-20 04:41:01 -05:00
}
}
2014-12-10 09:07:36 -05:00
}
2015-07-04 18:45:54 -04:00
static string NODE_JS_WIN { get { return Path . Combine ( SDKBase , "Win64" , "node" , "0.12.2_64bit" , "node.exe" ) ; } }
static string NODE_JS_MAC { get { return Path . Combine ( SDKBase , "Mac" , "node" , "0.12.2_64bit" , "bin" , "node" ) ; } }
2015-02-20 04:41:01 -05:00
2015-07-04 18:45:54 -04:00
static string NODE_JS
2014-12-10 09:07:36 -05:00
{
2015-07-04 18:45:54 -04:00
get
{
switch ( BuildHostPlatform . Current . Platform )
{
case UnrealTargetPlatform . Win64 :
return NODE_JS_WIN ;
case UnrealTargetPlatform . Mac :
return NODE_JS_MAC ;
default :
return "" ;
}
}
2014-12-10 09:07:36 -05:00
}
2015-08-07 07:10:38 -04:00
static string OPTIMIZER_NAME
{
get
{
switch ( BuildHostPlatform . Current . Platform )
{
case UnrealTargetPlatform . Win64 :
return "optimizer.exe" ;
case UnrealTargetPlatform . Mac :
return "optimizer" ;
default :
return "" ;
}
}
}
2015-07-09 09:12:36 -04:00
static public string DOT_EMSCRIPTEN
{
2015-09-24 12:37:21 -04:00
get
2015-07-09 09:12:36 -04:00
{
2015-07-09 15:31:44 -04:00
var TempPath = Path . GetFullPath ( Path . Combine ( BuildConfiguration . RelativeEnginePath , BuildConfiguration . BaseIntermediateFolder , "HTML5" ) ) ;
2015-07-09 09:12:36 -04:00
if ( ! Directory . Exists ( TempPath ) )
{
Directory . CreateDirectory ( TempPath ) ;
}
return Path . Combine ( TempPath , ".emscripten" ) ;
}
}
2015-07-09 15:31:44 -04:00
static public string EMSCRIPTEN_CACHE
{
get
{
var TempPath = Path . GetFullPath ( Path . Combine ( BuildConfiguration . RelativeEnginePath , BuildConfiguration . BaseIntermediateFolder , "HTML5" ) ) ;
if ( ! Directory . Exists ( TempPath ) )
{
Directory . CreateDirectory ( TempPath ) ;
}
2015-09-24 12:37:21 -04:00
return Path . Combine ( TempPath , "EmscriptenCache" ) ; ;
2015-07-09 15:31:44 -04:00
}
}
2015-09-24 12:37:21 -04:00
public static string SetupEmscriptenTemp ( )
2014-12-10 09:07:36 -05:00
{
2015-07-15 16:37:24 -04:00
string HTML5Intermediatory = Path . GetFullPath ( Path . Combine ( BuildConfiguration . RelativeEnginePath , BuildConfiguration . BaseIntermediateFolder , "HTML5" ) ) ;
2015-09-24 12:37:21 -04:00
string TempPath = Path . Combine ( HTML5Intermediatory , "EmscriptenTemp" ) ;
2015-07-14 13:06:21 -04:00
try
2015-07-04 18:45:54 -04:00
{
2015-07-14 13:06:21 -04:00
if ( Directory . Exists ( TempPath ) )
{
Directory . Delete ( TempPath , true ) ;
}
2015-07-04 18:45:54 -04:00
Directory . CreateDirectory ( TempPath ) ;
}
2015-09-24 12:37:21 -04:00
catch ( Exception Ex )
2015-07-14 13:06:21 -04:00
{
Log . TraceErrorOnce ( " Recreation of Emscripten Temp folder failed because of " + Ex . ToString ( ) ) ;
}
2015-09-24 12:37:21 -04:00
2015-07-04 18:45:54 -04:00
return TempPath ;
2014-12-10 09:07:36 -05:00
}
2015-07-04 18:45:54 -04:00
public static string SetUpEmscriptenConfigFile ( )
2015-02-20 04:41:01 -05:00
{
2015-07-09 09:12:36 -04:00
string ConfigFile = DOT_EMSCRIPTEN ;
2015-07-04 18:45:54 -04:00
2015-09-16 05:35:30 -04:00
if ( ! File . Exists ( ConfigFile ) | | ! File . ReadAllText ( ConfigFile ) . Contains ( "GENERATEDBYUE4='" + SDKVersion + "+" + SDKInfoGUID + "'" ) )
2015-07-04 18:45:54 -04:00
{
var ConfigString = String . Join (
Environment . NewLine ,
"import os" ,
"SPIDERMONKEY_ENGINE = ''" ,
2015-09-24 12:37:21 -04:00
"LLVM_ROOT='" + LLVM_ROOT + "'" ,
"NODE_JS= '" + NODE_JS + "'" ,
"PYTHON= '" + PYTHON + "'" ,
2015-08-07 07:10:38 -04:00
"EMSCRIPTEN_NATIVE_OPTIMIZER='" + Path . Combine ( LLVM_ROOT , OPTIMIZER_NAME ) + "'" ,
2015-07-04 18:45:54 -04:00
"EMSCRIPTEN_ROOT= '" + EMSCRIPTEN_ROOT + "'" ,
"TEMP_DIR= '" + SetupEmscriptenTemp ( ) + "'" ,
"COMPILER_ENGINE = NODE_JS" ,
"JS_ENGINES = [NODE_JS]" ,
"V8_ENGINE = ''" ,
2015-09-24 12:37:21 -04:00
"GENERATEDBYUE4='" + SDKVersion + "+" + SDKInfoGUID + "'"
2015-07-04 18:45:54 -04:00
) ;
2015-09-24 12:37:21 -04:00
File . WriteAllText ( ConfigFile , ConfigString . Replace ( "\\" , "/" ) ) ;
2015-07-04 18:45:54 -04:00
}
return ConfigFile ;
2015-02-20 04:41:01 -05:00
}
2015-07-04 18:45:54 -04:00
public static string EmscriptenBase ( )
{
2015-09-24 12:37:21 -04:00
return EMSCRIPTEN_ROOT ;
2015-07-04 18:45:54 -04:00
}
2015-09-24 12:37:21 -04:00
public static string EmscriptenVersion ( )
2015-07-04 18:45:54 -04:00
{
2015-09-24 12:37:21 -04:00
return SDKVersion ;
}
public static string Python ( )
{
return PYTHON ;
2015-07-04 18:45:54 -04:00
}
public static string EmscriptenPackager ( )
{
2015-09-24 12:37:21 -04:00
return Path . Combine ( EmscriptenBase ( ) , "tools" , "file_packager.py" ) ;
2015-07-04 18:45:54 -04:00
}
public static string EmscriptenCompiler ( )
{
2015-09-24 12:37:21 -04:00
return "\"" + Path . Combine ( EmscriptenBase ( ) , "emcc" ) + "\"" ;
2015-07-04 18:45:54 -04:00
}
public static bool IsSDKInstalled ( )
{
bool SDK = File . Exists ( GetVersionInfoPath ( ) ) ;
switch ( BuildHostPlatform . Current . Platform )
{
2015-09-24 12:37:21 -04:00
case UnrealTargetPlatform . Win64 :
return SDK & & Directory . Exists ( Path . Combine ( SDKBase , "Win64" ) ) ;
case UnrealTargetPlatform . Mac :
return SDK & & Directory . Exists ( Path . Combine ( SDKBase , "Mac" ) ) & & File . Exists ( PYTHON ) ;
2015-07-04 18:45:54 -04:00
default :
2015-09-24 12:37:21 -04:00
return false ;
2015-07-04 18:45:54 -04:00
}
}
2014-11-03 10:50:47 -05:00
static string GetVersionInfoPath ( )
{
2015-09-24 12:37:21 -04:00
return Path . Combine ( EmscriptenBase ( ) , "emscripten-version.txt" ) ;
2014-11-03 10:50:47 -05:00
}
2015-07-04 18:45:54 -04:00
}
2014-10-31 04:31:19 -04:00
}