Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1011a17

Browse filesBrowse files
danbevtargos
authored andcommitted
tools: allow single JS file for --link-module
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 <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent cb16229 commit 1011a17
Copy full SHA for 1011a17

File tree

Expand file treeCollapse file tree

3 files changed

+22
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-1
lines changed
Open diff view settings
Collapse file

‎Makefile‎

Copy file name to clipboardExpand all lines: Makefile
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ jstest: build-addons build-js-native-api-tests build-node-api-tests ## Runs addo
294294
$(CI_JS_SUITES) \
295295
$(CI_NATIVE_SUITES)
296296

297+
.PHONY: tooltest
298+
tooltest:
299+
@$(PYTHON) test/tools/test-js2c.py
300+
297301
.PHONY: coverage-run-js
298302
coverage-run-js:
299303
$(RM) -r out/$(BUILDTYPE)/.coverage
@@ -311,6 +315,7 @@ test: all ## Runs default tests, linters, and builds docs.
311315
$(MAKE) -s build-node-api-tests
312316
$(MAKE) -s cctest
313317
$(MAKE) -s jstest
318+
$(MAKE) -s tooltest
314319

315320
.PHONY: test-only
316321
test-only: all ## For a quick test, does not run linter or build docs.
@@ -319,6 +324,7 @@ test-only: all ## For a quick test, does not run linter or build docs.
319324
$(MAKE) build-node-api-tests
320325
$(MAKE) cctest
321326
$(MAKE) jstest
327+
$(MAKE) tooltest
322328

323329
# Used by `make coverage-test`
324330
test-cov: all
Collapse file

‎test/tools/test-js2c.py‎

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import unittest
2+
import sys, os
3+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),
4+
'..', '..', 'tools')))
5+
from js2c import NormalizeFileName
6+
7+
class Js2ctest(unittest.TestCase):
8+
def testNormalizeFileName(self):
9+
self.assertEqual(NormalizeFileName('dir/mod.js'), 'mod')
10+
self.assertEqual(NormalizeFileName('deps/mod.js'), 'internal/deps/mod')
11+
self.assertEqual(NormalizeFileName('mod.js'), 'mod')
12+
13+
if __name__ == '__main__':
14+
unittest.main()
Collapse file

‎tools/js2c.py‎

Copy file name to clipboardExpand all lines: tools/js2c.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ def NormalizeFileName(filename):
261261
split = ['internal'] + split
262262
else: # `lib/**/*.js` so drop the 'lib' part
263263
split = split[1:]
264-
filename = '/'.join(split)
264+
if len(split):
265+
filename = '/'.join(split)
265266
return os.path.splitext(filename)[0]
266267

267268

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.