Skip to content

Conversation

@danbev
Copy link
Contributor

The description for the --link-module configuration option is as
follows:

$ ./configure --help | grep -A 5 'link-module' --link-module=LINKED_MODULE Path to a JS file to be bundled in the binary as a builtin. This module will be referenced by path without extension; e.g. /root/x/y.js will be referenced via require('root/x/y'). Can be used multiple times

This lead me to think that it was possible to specify a file like this:

$ ./configure --link-module=something.js $ NODE_DEBUG=mkcodecache make -j8

This will lead to a compilation error as an entry in the source_ map in
node_javascript.cc will end up having an empty string as its key:

source_.emplace("", UnionBytes{_raw, 105});

This will then be used by CodeCacheBuilder when it iterates over the
module ids, which will lead to the following compilation errors:

/node/out/Release/obj/gen/node_code_cache.cc:12:23: warning:ISO C++17 does not allow a decomposition group to beempty [-Wempty-decomposition]static const uint8_t [] ={ ^/node/out/Release/obj/gen/node_code_cache.cc:12:22: warning:decomposition declarations are a C++17 extension [-Wc++17-extensions]static const uint8_t [] ={ ^~/node/out/Release/obj/gen/node_code_cache.cc:12:1: error:decomposition declaration cannot be declared 'static'static const uint8_t [] ={^~~~~~/node/out/Release/obj/gen/node_code_cache.cc:12:22: error:decomposition declaration cannot be declared with type 'const uint8_t'(aka 'const unsigned char'); declared type must be 'auto' orreference to 'auto'static const uint8_t [] ={ ^/node/out/Release/obj/gen/node_code_cache.cc:12:22: error:excess elements in scalar initializerstatic const uint8_t [] ={ ^/node/out/Release/obj/gen/node_code_cache.cc:660:7: error:expected expression , ^/node/out/Release/obj/gen/node_code_cache.cc:661:24: error:no matching function for call to 'arraysize' static_cast<int>(arraysize()), policy ^~~~~~~~~../src/util.h:667:18: note: candidate function template not viable:requires 1 argument, but 0 were providedconstexpr size_t arraysize(const T (&)[N]){ ^2 warnings and 5 errors generated.

This commit suggests that passing a single file be allowed by modifying
tools/js2c.py, or alternatively raise an Exception with an message that
indicates the cause of this.

With the changes in this PR the usage would look like this:

$ cat something.js'use strict';function logit(){ console.log('something module...');}module.exports ={ logit,} $ ./configure --link-module=something.js && NODE_DEBUG=mkcodecache make -j8...Generated cache for something, size = 840.00B, total = 643.00KB... $ rm something.js $ ./node -p "require('something').logit()"something module...undefined
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-botnodejs-github-bot added the build Issues and PRs related to build files or the CI. label Jun 27, 2019
@nodejs-github-bot
Copy link
Collaborator

@devsnek
Copy link
Member

Before this change, what input to --link-module works?

refack
refack previously requested changes Jun 28, 2019
Copy link
Contributor

@refackrefack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not land without a test.

@refack
Copy link
Contributor

Before this change, what input to --link-module works?

anything with at least 1 / like lib//gaga.js should work.

@danbev
Copy link
ContributorAuthor

Should not land without a test.

I'll take a look at adding a test for this, might not be until next week though. Thanks

@nodejs-github-bot
Copy link
Collaborator

@BridgeARBridgeAR requested a review from refackJuly 4, 2019 17:40
@Trott
Copy link
Member

@refack Test was added. OK to dismiss your request for changes?

@nodejs-github-bot
Copy link
Collaborator

tools/js2c.py Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No as critical, but should be

Suggested change
ifsplit!= []:
iflen(split):

as it's more "pythonic", and doesn't assume split is a list, only that it's enumerable.

@danbev
Copy link
ContributorAuthor

danbev commented Jul 26, 2019 via email

The description for the --link-module configuration option is as follows: $ ./configure --help | grep -A 5 'link-module' --link-module=LINKED_MODULE Path to a JS file to be bundled in the binary as a builtin. This module will be referenced by path without extension; e.g. /root/x/y.js will be referenced via require('root/x/y'). Can be used multiple times This lead me to think that it was possible to specify a file like this: $ ./configure --link-module=something.js $ NODE_DEBUG=mkcodecache make -j8 This will lead to a compilation error as an entry in the source_ map in node_javascript.cc will end up having an empty string as its key: source_.emplace("", UnionBytes{_raw, 105}); This will then be used by CodeCacheBuilder when it iterates over the module ids, which will lead to the following compilation errors: /node/out/Release/obj/gen/node_code_cache.cc:12:23: warning: ISO C++17 does not allow a decomposition group to be empty [-Wempty-decomposition] static const uint8_t [] ={^ /node/out/Release/obj/gen/node_code_cache.cc:12:22: warning: decomposition declarations are a C++17 extension [-Wc++17-extensions] static const uint8_t [] ={^~ /node/out/Release/obj/gen/node_code_cache.cc:12:1: error: decomposition declaration cannot be declared 'static' static const uint8_t [] ={^~~~~~ /node/out/Release/obj/gen/node_code_cache.cc:12:22: error: decomposition declaration cannot be declared with type 'const uint8_t' (aka 'const unsigned char'); declared type must be 'auto' or reference to 'auto' static const uint8_t [] ={^ /node/out/Release/obj/gen/node_code_cache.cc:12:22: error: excess elements in scalar initializer static const uint8_t [] ={^ /node/out/Release/obj/gen/node_code_cache.cc:660:7: error: expected expression , ^ /node/out/Release/obj/gen/node_code_cache.cc:661:24: error: no matching function for call to 'arraysize' static_cast<int>(arraysize()), policy ^~~~~~~~~ ../src/util.h:667:18: note: candidate function template not viable: requires 1 argument, but 0 were provided constexpr size_t arraysize(const T (&)[N]){^ 2 warnings and 5 errors generated. This commit suggests that passing a single file be allowed by modifying tools/js2c.py, or alternatively raise an Exception with an message that indicates the cause of this.
@danbevdanbevforce-pushed the tools_js2c_link-module branch from d31f2e7 to a656ed3CompareAugust 12, 2019 03:49
@nodejs-github-bot
Copy link
Collaborator

@danbevdanbev added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Aug 12, 2019
@danbev
Copy link
ContributorAuthor

Landed in b4f0a18.

@danbevdanbev closed this Aug 12, 2019
@danbevdanbev deleted the tools_js2c_link-module branch August 12, 2019 11:08
pullbot pushed a commit to SimenB/node that referenced this pull request Aug 12, 2019
The description for the --link-module configuration option is as follows: $ ./configure --help | grep -A 5 'link-module' --link-module=LINKED_MODULE Path to a JS file to be bundled in the binary as a builtin. This module will be referenced by path without extension; e.g. /root/x/y.js will be referenced via require('root/x/y'). Can be used multiple times This lead me to think that it was possible to specify a file like this: $ ./configure --link-module=something.js $ NODE_DEBUG=mkcodecache make -j8 This will lead to a compilation error as an entry in the source_ map in node_javascript.cc will end up having an empty string as its key: source_.emplace("", UnionBytes{_raw, 105}); This will then be used by CodeCacheBuilder when it iterates over the module ids, which will lead to the following compilation errors: /node/out/Release/obj/gen/node_code_cache.cc:12:23: warning: ISO C++17 does not allow a decomposition group to be empty [-Wempty-decomposition] static const uint8_t [] ={^ /node/out/Release/obj/gen/node_code_cache.cc:12:22: warning: decomposition declarations are a C++17 extension [-Wc++17-extensions] static const uint8_t [] ={^~ /node/out/Release/obj/gen/node_code_cache.cc:12:1: error: decomposition declaration cannot be declared 'static' static const uint8_t [] ={^~~~~~ /node/out/Release/obj/gen/node_code_cache.cc:12:22: error: decomposition declaration cannot be declared with type 'const uint8_t' (aka 'const unsigned char'); declared type must be 'auto' or reference to 'auto' static const uint8_t [] ={^ /node/out/Release/obj/gen/node_code_cache.cc:12:22: error: excess elements in scalar initializer static const uint8_t [] ={^ /node/out/Release/obj/gen/node_code_cache.cc:660:7: error: expected expression , ^ /node/out/Release/obj/gen/node_code_cache.cc:661:24: error: no matching function for call to 'arraysize' static_cast<int>(arraysize()), policy ^~~~~~~~~ ../src/util.h:667:18: note: candidate function template not viable: requires 1 argument, but 0 were provided constexpr size_t arraysize(const T (&)[N]){^ 2 warnings and 5 errors generated. This commit suggests that passing a single file be allowed by modifying tools/js2c.py. PR-URL: nodejs#28443 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]>
targos pushed a commit that referenced this pull request Aug 19, 2019
The description for the --link-module configuration option is as follows: $ ./configure --help | grep -A 5 'link-module' --link-module=LINKED_MODULE Path to a JS file to be bundled in the binary as a builtin. This module will be referenced by path without extension; e.g. /root/x/y.js will be referenced via require('root/x/y'). Can be used multiple times This lead me to think that it was possible to specify a file like this: $ ./configure --link-module=something.js $ NODE_DEBUG=mkcodecache make -j8 This will lead to a compilation error as an entry in the source_ map in node_javascript.cc will end up having an empty string as its key: source_.emplace("", UnionBytes{_raw, 105}); This will then be used by CodeCacheBuilder when it iterates over the module ids, which will lead to the following compilation errors: /node/out/Release/obj/gen/node_code_cache.cc:12:23: warning: ISO C++17 does not allow a decomposition group to be empty [-Wempty-decomposition] static const uint8_t [] ={^ /node/out/Release/obj/gen/node_code_cache.cc:12:22: warning: decomposition declarations are a C++17 extension [-Wc++17-extensions] static const uint8_t [] ={^~ /node/out/Release/obj/gen/node_code_cache.cc:12:1: error: decomposition declaration cannot be declared 'static' static const uint8_t [] ={^~~~~~ /node/out/Release/obj/gen/node_code_cache.cc:12:22: error: decomposition declaration cannot be declared with type 'const uint8_t' (aka 'const unsigned char'); declared type must be 'auto' or reference to 'auto' static const uint8_t [] ={^ /node/out/Release/obj/gen/node_code_cache.cc:12:22: error: excess elements in scalar initializer static const uint8_t [] ={^ /node/out/Release/obj/gen/node_code_cache.cc:660:7: error: expected expression , ^ /node/out/Release/obj/gen/node_code_cache.cc:661:24: error: no matching function for call to 'arraysize' static_cast<int>(arraysize()), policy ^~~~~~~~~ ../src/util.h:667:18: note: candidate function template not viable: requires 1 argument, but 0 were provided constexpr size_t arraysize(const T (&)[N]){^ 2 warnings and 5 errors generated. This commit suggests that passing a single file be allowed by modifying tools/js2c.py. PR-URL: #28443 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]>
@targostargos mentioned this pull request Aug 19, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.buildIssues and PRs related to build files or the CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@danbev@nodejs-github-bot@devsnek@refack@Trott@lpinca