Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
build: refactor engine switch and process.jsEngine
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Jianchun Xu committed May 7, 2015
1 parent d1bf0be commit 3d035d0
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 59 deletions.
25 changes: 25 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down
16 changes: 8 additions & 8 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions deps/chakrashim/chakrashim.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
'include',
],
'defines': [
'USE_CHAKRA=1',
'USE_EDGEMODE_JSRT=1',
'_WIN32_WINNT=0x0601',
'_WIN32_WINNT=0x0A00', # WIN10
],
'libraries': [
'-lchakrart.lib',
Expand Down Expand Up @@ -115,7 +114,7 @@
'action': [
'<(python)',
'./../../tools/js2c.py',
'-chakra',
'--namespace=jsrt',
'<@(_outputs)',
'<@(_inputs)',
],
Expand Down
10 changes: 1 addition & 9 deletions deps/debugger-agent/debugger-agent.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions deps/npm/node_modules/node-gyp/addon.gypi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deps/npm/node_modules/node-gyp/lib/configure.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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' ],
}],
Expand Down
17 changes: 7 additions & 10 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()));
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/res/node.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 9 additions & 6 deletions tools/js2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
27 changes: 14 additions & 13 deletions vcbuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`.

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d035d0

Please sign in to comment.