From 3d035d0e3d564ec2a6c2398a873c0f458d36dff6 Mon Sep 17 00:00:00 2001 From: Jianchun Xu Date: Thu, 7 May 2015 16:59:50 -0700 Subject: [PATCH] build: refactor engine switch and process.jsEngine These changes are mostly proposed by Alexis Campailla (orangemocha). build: Change the specific node_use_chakra flag to more general node_engine variable. common.gypi: Add node_engine_include_dir variable for clients that need v8 headers (debugger-agent.gyp and node-gyp addon.gypi). Define NODE_ENGINE symbol and NODE_ENGINE_V8/NODE_ENGINE_CHAKRA flags respectively, used in node.cc. node.cc: Add runtime property process.jsEngine and use everywhere js engine check is needed. chakrashim.gyp: add WIN10 requirement. js2c.py: replace "-chakra" flag to more general "--namespace=..." switch. node-gyp: add --node_engine switch, default to process.jsEngine and fall back to "v8". Reviewed-By: orangemocha PR-URL: [#15](https://github.com/Microsoft/node-msft/pull/15) --- common.gypi | 25 +++++++++++++++++ configure | 16 +++++------ deps/chakrashim/chakrashim.gyp | 5 ++-- deps/debugger-agent/debugger-agent.gyp | 10 +------ deps/npm/node_modules/node-gyp/addon.gypi | 4 +-- .../node_modules/node-gyp/lib/configure.js | 2 +- lib/repl.js | 6 ++--- node.gyp | 7 ++--- src/node.cc | 17 +++++------- src/res/node.rc | 2 +- tools/js2c.py | 15 ++++++----- vcbuild.bat | 27 ++++++++++--------- 12 files changed, 77 insertions(+), 59 deletions(-) diff --git a/common.gypi b/common.gypi index df46fd3b880..3f0aff5ef29 100644 --- a/common.gypi +++ b/common.gypi @@ -11,6 +11,7 @@ 'gcc_version%': 'unknown', 'clang%': 0, 'python%': 'python', + 'node_engine%': 'v8', # Enable disassembler for `--print-code` v8 options 'v8_enable_disassembler': 1, @@ -33,6 +34,30 @@ }], ], }, + 'conditions': [ + ['node_engine=="v8"', { + 'target_defaults': { + 'defines': [ + 'NODE_ENGINE="v8"', + 'NODE_ENGINE_V8=1', + ], + }, + 'variables': { + 'node_engine_include_dir%': 'deps/v8/include' + }, + }], + ['node_engine=="chakra"', { + 'target_defaults': { + 'defines': [ + 'NODE_ENGINE="chakra"', + 'NODE_ENGINE_CHAKRA=1' + ], + }, + 'variables': { + 'node_engine_include_dir%': 'deps/chakrashim/include' + }, + }], + ], 'target_defaults': { 'default_configuration': 'Release', diff --git a/configure b/configure index fab76f619d9..65070bd55ce 100755 --- a/configure +++ b/configure @@ -318,10 +318,10 @@ parser.add_option('--xcode', dest='use_xcode', help='generate build files for use with xcode') -parser.add_option("--use-chakra", - action="store_true", - dest="use_chakra", - help="Use the Chakra JavaScript engine instead of V8") +parser.add_option('--engine', + action='store', + dest='engine', + help='Use specified JS engine (default is V8)') (options, args) = parser.parse_args() @@ -984,9 +984,9 @@ def configure_intl(o): pprint.pformat(icu_config, indent=2) + '\n') return # end of configure_intl -def configure_chakra(o): - o['variables']['node_use_chakra'] = b(options.use_chakra) - +def configure_engine(o): + engine = options.engine or 'v8' + o['variables']['node_engine'] = engine.lower() # determine the "flavor" (operating system) we're building for, # leveraging gyp's GetFlavor function @@ -1013,7 +1013,7 @@ configure_openssl(output) configure_winsdk(output) configure_intl(output) configure_fullystatic(output) -configure_chakra(output) +configure_engine(output) # variables should be a root level element, # move everything else to target_defaults diff --git a/deps/chakrashim/chakrashim.gyp b/deps/chakrashim/chakrashim.gyp index 875a6238225..0d601f35563 100644 --- a/deps/chakrashim/chakrashim.gyp +++ b/deps/chakrashim/chakrashim.gyp @@ -30,9 +30,8 @@ 'include', ], 'defines': [ - 'USE_CHAKRA=1', 'USE_EDGEMODE_JSRT=1', - '_WIN32_WINNT=0x0601', + '_WIN32_WINNT=0x0A00', # WIN10 ], 'libraries': [ '-lchakrart.lib', @@ -115,7 +114,7 @@ 'action': [ '<(python)', './../../tools/js2c.py', - '-chakra', + '--namespace=jsrt', '<@(_outputs)', '<@(_inputs)', ], diff --git a/deps/debugger-agent/debugger-agent.gyp b/deps/debugger-agent/debugger-agent.gyp index 7471f09113a..2220be1d912 100644 --- a/deps/debugger-agent/debugger-agent.gyp +++ b/deps/debugger-agent/debugger-agent.gyp @@ -5,6 +5,7 @@ "include_dirs": [ "src", "include", + "../../<(node_engine_include_dir)", "../uv/include", # Private node.js folder and stuff needed to include from it @@ -17,15 +18,6 @@ ], }, 'conditions': [ - ['node_use_chakra=="false"', { - "include_dirs": [ - "../v8/include", - ], - }, { - "include_dirs": [ - "../chakrashim/include", - ], - }], [ 'gcc_version<=44', { # GCC versions <= 4.4 do not handle the aliasing in the queue # implementation, so disable aliasing on these platforms diff --git a/deps/npm/node_modules/node-gyp/addon.gypi b/deps/npm/node_modules/node-gyp/addon.gypi index d7956ff1516..f03a96eeae0 100644 --- a/deps/npm/node_modules/node-gyp/addon.gypi +++ b/deps/npm/node_modules/node-gyp/addon.gypi @@ -5,7 +5,7 @@ 'include_dirs': [ '<(node_root_dir)/src', '<(node_root_dir)/deps/uv/include', - '<(node_root_dir)/deps/<(depv8)/include' + '<(node_root_dir)/<(node_engine_include_dir)' ], 'target_conditions': [ @@ -18,7 +18,7 @@ # older linkers don't support this flag. 'standalone_static_library': '<(standalone_static_library)' }], - ['"<(depv8)"=="chakrashim"', { + ['node_engine=="chakra"', { 'defines': [ 'USE_EDGEMODE_JSRT=1' ], 'libraries': [ '-lchakrart.lib' ], }], diff --git a/deps/npm/node_modules/node-gyp/lib/configure.js b/deps/npm/node_modules/node-gyp/lib/configure.js index 0ae6ef5f2ce..77c340aea8f 100644 --- a/deps/npm/node_modules/node-gyp/lib/configure.js +++ b/deps/npm/node_modules/node-gyp/lib/configure.js @@ -312,7 +312,7 @@ function configure (gyp, argv, callback) { argv.push('-Dvisibility=default') argv.push('-Dnode_root_dir=' + nodeDir) argv.push('-Dmodule_root_dir=' + process.cwd()) - argv.push('-Ddepv8=' + (process.versions.chakra ? 'chakrashim' : 'v8')); + argv.push('-Dnode_engine=' + (gyp.opts.node_engine || process.jsEngine || 'v8')) argv.push('--depth=.') argv.push('--no-parallel') diff --git a/lib/repl.js b/lib/repl.js index 9cb19f969e3..f329c34a73a 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -950,9 +950,9 @@ function isRecoverableError(e) { return e && e.name === 'SyntaxError' && (/^(Unexpected end of input|Unexpected token :)/.test(e.message) || - (process.versions.chakra && - /^Expected /.test(e.message) && - !/ in regular expression$/.test(e.message))); + (process.jsEngine === 'chakra' && + /^Expected /.test(e.message) && + !/ in regular expression$/.test(e.message))); } function Recoverable(err) { diff --git a/node.gyp b/node.gyp index f074fecedc4..5ea05de2355 100644 --- a/node.gyp +++ b/node.gyp @@ -14,7 +14,7 @@ 'node_shared_openssl%': 'false', 'node_use_mdb%': 'false', 'node_v8_options%': '', - 'node_use_chakra%': 'false', + 'node_engine%': 'v8', 'library_files': [ 'src/node.js', 'lib/_debugger.js', @@ -301,16 +301,17 @@ ], }, }], - [ 'node_use_chakra=="false" and node_shared_v8=="false"', { + [ 'node_engine=="v8" and node_shared_v8=="false"', { 'sources': [ 'deps/v8/include/v8.h', 'deps/v8/include/v8-debug.h', ], 'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:v8' ], }], - ['node_use_chakra=="true"', { + ['node_engine=="chakra"', { 'dependencies': [ 'deps/chakrashim/chakrashim.gyp:chakrashim' ], }], + [ 'node_shared_zlib=="false"', { 'dependencies': [ 'deps/zlib/zlib.gyp:zlib' ], }], diff --git a/src/node.cc b/src/node.cc index 29eeabf791e..ff2f78fd5d1 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2569,6 +2569,11 @@ void SetupProcessObject(Environment* env, ProcessTitleGetter, ProcessTitleSetter); + // process.jsEngine + READONLY_PROPERTY(process, + "jsEngine", + FIXED_ONE_BYTE_STRING(env->isolate(), NODE_ENGINE)); + // process.version READONLY_PROPERTY(process, "version", @@ -2594,17 +2599,9 @@ void SetupProcessObject(Environment* env, READONLY_PROPERTY(versions, "node", OneByteString(env->isolate(), NODE_VERSION + 1)); - -#ifdef USE_CHAKRA -#define NODE_JS_ENGINE "chakra" -#else -#define NODE_JS_ENGINE "v8" -#endif READONLY_PROPERTY(versions, - NODE_JS_ENGINE, + NODE_ENGINE, OneByteString(env->isolate(), V8::GetVersion())); -#undef NODE_JS_ENGINE - READONLY_PROPERTY(versions, "uv", OneByteString(env->isolate(), uv_version_string())); @@ -3102,7 +3099,7 @@ static void StartDebug(Environment* env, bool wait) { env->debugger_agent()->set_dispatch_handler( DispatchMessagesDebugAgentCallback); -#ifdef USE_CHAKRA +#ifdef NODE_ENGINE_CHAKRA // ChakraShim does not support debugger_agent debugger_running = v8::Debug::EnableAgent(); #else diff --git a/src/res/node.rc b/src/res/node.rc index 0ae35b7b44d..73bd364bf39 100644 --- a/src/res/node.rc +++ b/src/res/node.rc @@ -52,7 +52,7 @@ BEGIN BEGIN VALUE "CompanyName", "Joyent, Inc" VALUE "ProductName", "Node.js" -#ifdef USE_CHAKRA +#ifdef NODE_ENGINE_CHAKRA VALUE "FileDescription", "Evented I/O for JavaScript (Chakra)" #else VALUE "FileDescription", "Evented I/O for V8 JavaScript" diff --git a/tools/js2c.py b/tools/js2c.py index 5cec62633bc..2e545b15e1c 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -366,16 +366,19 @@ def JS2C(source, target, namespace): }) output.close() + +NAMESPACE_SWITCH = "--namespace=" + def main(): - if sys.argv[1] == "-chakra": - namespace = 'jsrt' - natives = sys.argv[2] - source_files = sys.argv[3:] + i = 1 + if sys.argv[i].startswith(NAMESPACE_SWITCH): + namespace = sys.argv[i][len(NAMESPACE_SWITCH):] + i += 1 else: namespace = 'node' - natives = sys.argv[1] - source_files = sys.argv[2:] + natives = sys.argv[i] + source_files = sys.argv[(i + 1):] JS2C(source_files, [natives], namespace) if __name__ == "__main__": diff --git a/vcbuild.bat b/vcbuild.bat index a43708c4b94..34f6b4cdedd 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -38,7 +38,8 @@ set noperfctr_msi_arg= set i18n_arg= set download_arg= set build_release= -set engine=v8 +set engine= +set engine_arg= set openssl_no_asm= :next-arg @@ -66,17 +67,17 @@ if /i "%1"=="test-gc" set test=test-gc&set buildnodeweak=1&goto arg-ok if /i "%1"=="test-all" set test=test-all&set buildnodeweak=1&goto arg-ok if /i "%1"=="test" set test=test&goto arg-ok @rem Include small-icu support with MSI installer -if /i "%1"=="msi" set msi=1&set licensertf=1&set download_arg="--download=all"&set i18n_arg=small-icu&goto arg-ok -if /i "%1"=="upload" set upload=1&goto arg-ok -if /i "%1"=="jslint" set jslint=1&goto arg-ok -if /i "%1"=="small-icu" set i18n_arg=%1&goto arg-ok -if /i "%1"=="full-icu" set i18n_arg=%1&goto arg-ok -if /i "%1"=="intl-none" set i18n_arg=%1&goto arg-ok -if /i "%1"=="download-all" set download_arg="--download=all"&goto arg-ok -if /i "%1"=="build-release" set build_release=1&goto arg-ok -if /i "%1"=="v8" set engine=v8&goto arg-ok -if /i "%1"=="chakra" set engine=chakra&goto arg-ok -if /i "%1"=="openssl-no-asm" set openssl_no_asm=--openssl-no-asm&goto arg-ok +if /i "%1"=="msi" set msi=1&set licensertf=1&set download_arg="--download=all"&set i18n_arg=small-icu&goto arg-ok +if /i "%1"=="upload" set upload=1&goto arg-ok +if /i "%1"=="jslint" set jslint=1&goto arg-ok +if /i "%1"=="small-icu" set i18n_arg=%1&goto arg-ok +if /i "%1"=="full-icu" set i18n_arg=%1&goto arg-ok +if /i "%1"=="intl-none" set i18n_arg=%1&goto arg-ok +if /i "%1"=="download-all" set download_arg="--download=all"&goto arg-ok +if /i "%1"=="build-release" set build_release=1&goto arg-ok +if /i "%1"=="v8" set engine=v8&goto arg-ok +if /i "%1"=="chakra" set engine=chakra&goto arg-ok +if /i "%1"=="openssl-no-asm" set openssl_no_asm=--openssl-no-asm&goto arg-ok echo Warning: ignoring invalid command line option `%1`. @@ -106,7 +107,7 @@ if "%target_arch%"=="x64" set msiplatform=x64 if defined nosnapshot set nosnapshot_arg=--without-snapshot if defined noetw set noetw_arg=--without-etw& set noetw_msi_arg=/p:NoETW=1 if defined noperfctr set noperfctr_arg=--without-perfctr& set noperfctr_msi_arg=/p:NoPerfCtr=1 -if "%engine%"=="chakra" set engine_arg=--use-chakra +if not "%engine%"=="" set engine_arg=--engine="%engine%" if "%i18n_arg%"=="full-icu" set i18n_arg=--with-intl=full-icu if "%i18n_arg%"=="small-icu" set i18n_arg=--with-intl=small-icu