Skip to content

Commit 8dddc7e

Browse files
danbevgibfahn
authored andcommitted
build: fix cctest compilation
Currently the cctest target compiles sources files even though they are compiled for the node target. This is my fault as when I worked on the task of getting the cctest to use the object files from the node target I missed a few sources that were being included from node.gypi. This also effects the build time as these sources are compiled twice. This commit moves the conditions in question into the node target in node.gyp. With this commit there should be no object files in out/Release/obj.target/cctest/src/ (the path will vary depending on the operating system being used). Refs: #16887 PR-URL: #16887 Backport-PR-URL: #17174 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 8fd61e1 commit 8dddc7e

File tree

3 files changed

+233
-170
lines changed

3 files changed

+233
-170
lines changed

doc/guides/writing-tests.md

+5
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ Next add the test to the `sources` in the `cctest` target in node.gyp:
325325
...
326326
],
327327
```
328+
Note that the only sources that should be included in the cctest target are
329+
actual test or helper source files. There might be a need to include specific
330+
object files that are compiled by the `node` target and this can be done by
331+
adding them to the `libraries` section in the cctest target.
332+
328333
The test can be executed by running the `cctest` target:
329334
```console
330335
$ make cctest

node.gyp

+228-29
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,150 @@
292292
# Warn when using deprecated V8 APIs.
293293
'V8_DEPRECATION_WARNINGS=1',
294294
],
295+
'conditions': [
296+
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
297+
'product_extension': '<(shlib_suffix)',
298+
}],
299+
[ 'v8_enable_inspector==1', {
300+
'defines': [
301+
'HAVE_INSPECTOR=1',
302+
],
303+
'sources': [
304+
'src/inspector_agent.cc',
305+
'src/inspector_io.cc',
306+
'src/inspector_js_api.cc',
307+
'src/inspector_socket.cc',
308+
'src/inspector_socket_server.cc',
309+
'src/inspector_agent.h',
310+
'src/inspector_io.h',
311+
'src/inspector_socket.h',
312+
'src/inspector_socket_server.h',
313+
],
314+
'dependencies': [
315+
'v8_inspector_compress_protocol_json#host',
316+
],
317+
'include_dirs': [
318+
'<(SHARED_INTERMEDIATE_DIR)/include', # for inspector
319+
'<(SHARED_INTERMEDIATE_DIR)',
320+
],
321+
}, {
322+
'defines': [ 'HAVE_INSPECTOR=0' ]
323+
}],
324+
[ 'OS=="win"', {
325+
'sources': [
326+
'src/backtrace_win32.cc',
327+
'src/res/node.rc',
328+
],
329+
'defines!': [
330+
'NODE_PLATFORM="win"',
331+
],
332+
'defines': [
333+
'FD_SETSIZE=1024',
334+
# we need to use node's preferred "win32" rather than gyp's preferred "win"
335+
'NODE_PLATFORM="win32"',
336+
'_UNICODE=1',
337+
],
338+
'libraries': [ '-lpsapi.lib' ]
339+
}, { # POSIX
340+
'defines': [ '__POSIX__' ],
341+
'sources': [ 'src/backtrace_posix.cc' ],
342+
}],
343+
[ 'node_use_dtrace=="true"', {
344+
'defines': [ 'HAVE_DTRACE=1' ],
345+
'dependencies': [
346+
'node_dtrace_header',
347+
'specialize_node_d',
348+
],
349+
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
350+
#
351+
# DTrace is supported on linux, solaris, mac, and bsd. There are
352+
# three object files associated with DTrace support, but they're
353+
# not all used all the time:
354+
#
355+
# node_dtrace.o all configurations
356+
# node_dtrace_ustack.o not supported on mac and linux
357+
# node_dtrace_provider.o All except OS X. "dtrace -G" is not
358+
# used on OS X.
359+
#
360+
# Note that node_dtrace_provider.cc and node_dtrace_ustack.cc do not
361+
# actually exist. They're listed here to trick GYP into linking the
362+
# corresponding object files into the final "node" executable. These
363+
# object files are generated by "dtrace -G" using custom actions
364+
# below, and the GYP-generated Makefiles will properly build them when
365+
# needed.
366+
#
367+
'sources': [ 'src/node_dtrace.cc' ],
368+
'conditions': [
369+
[ 'OS=="linux"', {
370+
'sources': [
371+
'<(SHARED_INTERMEDIATE_DIR)/node_dtrace_provider.o'
372+
],
373+
}],
374+
[ 'OS!="mac" and OS!="linux"', {
375+
'sources': [
376+
'src/node_dtrace_ustack.cc',
377+
'src/node_dtrace_provider.cc',
378+
]
379+
}
380+
] ]
381+
} ],
382+
[ 'node_use_openssl=="true"', {
383+
'defines': [ 'HAVE_OPENSSL=1' ],
384+
'sources': [
385+
'src/node_crypto.cc',
386+
'src/node_crypto_bio.cc',
387+
'src/node_crypto_clienthello.cc',
388+
'src/node_crypto.h',
389+
'src/node_crypto_bio.h',
390+
'src/node_crypto_clienthello.h',
391+
'src/tls_wrap.cc',
392+
'src/tls_wrap.h'
393+
],
394+
'conditions': [
395+
['openssl_fips != ""', {
396+
'defines': [ 'NODE_FIPS_MODE' ],
397+
}],
398+
[ 'node_shared_openssl=="false"', {
399+
'dependencies': [
400+
'./deps/openssl/openssl.gyp:openssl',
401+
402+
# For tests
403+
'./deps/openssl/openssl.gyp:openssl-cli',
404+
],
405+
'conditions': [
406+
# -force_load or --whole-archive are not applicable for
407+
# the static library
408+
[ 'node_target_type!="static_library"', {
409+
'xcode_settings': {
410+
'OTHER_LDFLAGS': [
411+
'-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)',
412+
],
413+
},
414+
'conditions': [
415+
['OS in "linux freebsd" and node_shared=="false"', {
416+
'ldflags': [
417+
'-Wl,--whole-archive,'
418+
'<(OBJ_DIR)/deps/openssl/'
419+
'<(OPENSSL_PRODUCT)',
420+
'-Wl,--no-whole-archive',
421+
],
422+
}],
423+
# openssl.def is based on zlib.def, zlib symbols
424+
# are always exported.
425+
['use_openssl_def==1', {
426+
'sources': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'],
427+
}],
428+
['OS=="win" and use_openssl_def==0', {
429+
'sources': ['deps/zlib/win32/zlib.def'],
430+
}],
431+
],
432+
}],
433+
],
434+
}]]
435+
}, {
436+
'defines': [ 'HAVE_OPENSSL=0' ]
437+
}],
438+
],
295439
},
296440
{
297441
'target_name': 'mkssldef',
@@ -647,8 +791,6 @@
647791
'defines': [ 'NODE_WANT_INTERNALS=1' ],
648792

649793
'sources': [
650-
'src/node_platform.cc',
651-
'src/node_platform.h',
652794
'test/cctest/node_test_fixture.cc',
653795
'test/cctest/test_aliased_buffer.cc',
654796
'test/cctest/test_base64.cc',
@@ -664,14 +806,14 @@
664806
'conditions': [
665807
['node_target_type!="static_library"', {
666808
'libraries': [
667-
'<(OBJ_GEN_PATH)<(OBJ_SEPARATOR)node_javascript.<(OBJ_SUFFIX)',
668-
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_debug_options.<(OBJ_SUFFIX)',
669809
'<(OBJ_PATH)<(OBJ_SEPARATOR)async-wrap.<(OBJ_SUFFIX)',
670810
'<(OBJ_PATH)<(OBJ_SEPARATOR)env.<(OBJ_SUFFIX)',
671811
'<(OBJ_PATH)<(OBJ_SEPARATOR)node.<(OBJ_SUFFIX)',
672812
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_buffer.<(OBJ_SUFFIX)',
813+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_debug_options.<(OBJ_SUFFIX)',
673814
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_i18n.<(OBJ_SUFFIX)',
674815
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_perf.<(OBJ_SUFFIX)',
816+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_platform.<(OBJ_SUFFIX)',
675817
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_url.<(OBJ_SUFFIX)',
676818
'<(OBJ_PATH)<(OBJ_SEPARATOR)util.<(OBJ_SUFFIX)',
677819
'<(OBJ_PATH)<(OBJ_SEPARATOR)string_bytes.<(OBJ_SUFFIX)',
@@ -682,40 +824,46 @@
682824
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_buffer.<(OBJ_SUFFIX)',
683825
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_writer.<(OBJ_SUFFIX)',
684826
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)trace_event.<(OBJ_SUFFIX)',
827+
'<(OBJ_GEN_PATH)<(OBJ_SEPARATOR)node_javascript.<(OBJ_SUFFIX)',
828+
],
829+
}],
830+
[ 'node_use_openssl=="true"', {
831+
'libraries': [
832+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_crypto.<(OBJ_SUFFIX)',
833+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_crypto_bio.<(OBJ_SUFFIX)',
834+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_crypto_clienthello.<(OBJ_SUFFIX)',
835+
'<(OBJ_PATH)<(OBJ_SEPARATOR)tls_wrap.<(OBJ_SUFFIX)',
685836
],
686837
}],
687838
['v8_enable_inspector==1', {
688839
'sources': [
689840
'test/cctest/test_inspector_socket.cc',
690841
'test/cctest/test_inspector_socket_server.cc'
691842
],
692-
'conditions': [
693-
[ 'node_shared_zlib=="false"', {
694-
'dependencies': [
695-
'deps/zlib/zlib.gyp:zlib',
696-
]
697-
}],
698-
[ 'node_shared_openssl=="false" and node_shared=="false"', {
699-
'dependencies': [
700-
'deps/openssl/openssl.gyp:openssl'
701-
]
702-
}],
703-
[ 'node_shared_http_parser=="false"', {
704-
'dependencies': [
705-
'deps/http_parser/http_parser.gyp:http_parser'
706-
]
707-
}],
708-
[ 'node_shared_libuv=="false"', {
709-
'dependencies': [
710-
'deps/uv/uv.gyp:libuv'
711-
]
712-
}]
843+
'libraries': [
844+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_agent.<(OBJ_SUFFIX)',
845+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_io.<(OBJ_SUFFIX)',
846+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_js_api.<(OBJ_SUFFIX)',
847+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_socket.<(OBJ_SUFFIX)',
848+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_socket_server.<(OBJ_SUFFIX)',
849+
],
850+
'defines': [
851+
'HAVE_INSPECTOR=1',
852+
],
853+
}],
854+
[ 'node_use_dtrace=="true"', {
855+
'libraries': [
856+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_dtrace.<(OBJ_SUFFIX)',
713857
]
714858
}],
715-
[ 'node_use_v8_platform=="true"', {
716-
'dependencies': [
717-
'deps/v8/src/v8.gyp:v8_libplatform',
718-
],
859+
[ 'OS=="win"', {
860+
'libraries': [
861+
'<(OBJ_PATH)<(OBJ_SEPARATOR)backtrace_win32.<(OBJ_SUFFIX)',
862+
],
863+
}, {
864+
'libraries': [
865+
'<(OBJ_PATH)<(OBJ_SEPARATOR)backtrace_posix.<(OBJ_SUFFIX)',
866+
],
719867
}],
720868
[ 'node_use_dtrace=="true" and OS!="mac" and OS!="linux"', {
721869
'copies': [{
@@ -727,9 +875,60 @@
727875
]},
728876
],
729877
}],
878+
[ 'node_shared_zlib=="false"', {
879+
'dependencies': [
880+
'deps/zlib/zlib.gyp:zlib',
881+
]
882+
}],
883+
[ 'node_shared_openssl=="false" and node_shared=="false"', {
884+
'dependencies': [
885+
'deps/openssl/openssl.gyp:openssl'
886+
]
887+
}],
888+
[ 'node_shared_http_parser=="false"', {
889+
'dependencies': [
890+
'deps/http_parser/http_parser.gyp:http_parser'
891+
]
892+
}],
893+
[ 'node_shared_libuv=="false"', {
894+
'dependencies': [
895+
'deps/uv/uv.gyp:libuv'
896+
]
897+
}],
898+
[ 'node_use_v8_platform=="true"', {
899+
'dependencies': [
900+
'deps/v8/src/v8.gyp:v8_libplatform',
901+
],
902+
}],
730903
['OS=="solaris"', {
731904
'ldflags': [ '-I<(SHARED_INTERMEDIATE_DIR)' ]
732905
}],
906+
[ 'node_use_openssl=="true"', {
907+
'conditions': [
908+
[ 'node_shared_openssl=="false"', {
909+
'conditions': [
910+
# -force_load or --whole-archive are not applicable for
911+
# the static library
912+
[ 'node_target_type!="static_library"', {
913+
'xcode_settings': {
914+
'OTHER_LDFLAGS': [
915+
'-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)',
916+
],
917+
},
918+
'conditions': [
919+
['OS in "linux freebsd" and node_shared=="false"', {
920+
'ldflags': [
921+
'-Wl,--whole-archive,'
922+
'<(OBJ_DIR)/deps/openssl/'
923+
'<(OPENSSL_PRODUCT)',
924+
'-Wl,--no-whole-archive',
925+
],
926+
}],
927+
],
928+
}],
929+
],
930+
}]]
931+
}],
733932
]
734933
}
735934
], # end targets

0 commit comments

Comments
 (0)