Skip to content

Commit d4ba6ff

Browse files
committed
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: nodejs#16887 PR-URL:nodejs#16887 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent efdd7c8 commit d4ba6ff

File tree

3 files changed

+233
-170
lines changed

3 files changed

+233
-170
lines changed

doc/guides/writing-tests.md

Lines changed: 5 additions & 0 deletions
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

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

651795
'sources': [
652-
'src/node_platform.cc',
653-
'src/node_platform.h',
654796
'test/cctest/node_test_fixture.cc',
655797
'test/cctest/test_aliased_buffer.cc',
656798
'test/cctest/test_base64.cc',
@@ -666,14 +808,14 @@
666808
'conditions': [
667809
['node_target_type!="static_library"', {
668810
'libraries': [
669-
'<(OBJ_GEN_PATH)<(OBJ_SEPARATOR)node_javascript.<(OBJ_SUFFIX)',
670-
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_debug_options.<(OBJ_SUFFIX)',
671811
'<(OBJ_PATH)<(OBJ_SEPARATOR)async-wrap.<(OBJ_SUFFIX)',
672812
'<(OBJ_PATH)<(OBJ_SEPARATOR)env.<(OBJ_SUFFIX)',
673813
'<(OBJ_PATH)<(OBJ_SEPARATOR)node.<(OBJ_SUFFIX)',
674814
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_buffer.<(OBJ_SUFFIX)',
815+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_debug_options.<(OBJ_SUFFIX)',
675816
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_i18n.<(OBJ_SUFFIX)',
676817
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_perf.<(OBJ_SUFFIX)',
818+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_platform.<(OBJ_SUFFIX)',
677819
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_url.<(OBJ_SUFFIX)',
678820
'<(OBJ_PATH)<(OBJ_SEPARATOR)util.<(OBJ_SUFFIX)',
679821
'<(OBJ_PATH)<(OBJ_SEPARATOR)string_bytes.<(OBJ_SUFFIX)',
@@ -684,40 +826,46 @@
684826
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_buffer.<(OBJ_SUFFIX)',
685827
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_writer.<(OBJ_SUFFIX)',
686828
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)trace_event.<(OBJ_SUFFIX)',
829+
'<(OBJ_GEN_PATH)<(OBJ_SEPARATOR)node_javascript.<(OBJ_SUFFIX)',
830+
],
831+
}],
832+
[ 'node_use_openssl=="true"', {
833+
'libraries': [
834+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_crypto.<(OBJ_SUFFIX)',
835+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_crypto_bio.<(OBJ_SUFFIX)',
836+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_crypto_clienthello.<(OBJ_SUFFIX)',
837+
'<(OBJ_PATH)<(OBJ_SEPARATOR)tls_wrap.<(OBJ_SUFFIX)',
687838
],
688839
}],
689840
['v8_enable_inspector==1', {
690841
'sources': [
691842
'test/cctest/test_inspector_socket.cc',
692843
'test/cctest/test_inspector_socket_server.cc'
693844
],
694-
'conditions': [
695-
[ 'node_shared_zlib=="false"', {
696-
'dependencies': [
697-
'deps/zlib/zlib.gyp:zlib',
698-
]
699-
}],
700-
[ 'node_shared_openssl=="false" and node_shared=="false"', {
701-
'dependencies': [
702-
'deps/openssl/openssl.gyp:openssl'
703-
]
704-
}],
705-
[ 'node_shared_http_parser=="false"', {
706-
'dependencies': [
707-
'deps/http_parser/http_parser.gyp:http_parser'
708-
]
709-
}],
710-
[ 'node_shared_libuv=="false"', {
711-
'dependencies': [
712-
'deps/uv/uv.gyp:libuv'
713-
]
714-
}]
845+
'libraries': [
846+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_agent.<(OBJ_SUFFIX)',
847+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_io.<(OBJ_SUFFIX)',
848+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_js_api.<(OBJ_SUFFIX)',
849+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_socket.<(OBJ_SUFFIX)',
850+
'<(OBJ_PATH)<(OBJ_SEPARATOR)inspector_socket_server.<(OBJ_SUFFIX)',
851+
],
852+
'defines': [
853+
'HAVE_INSPECTOR=1',
854+
],
855+
}],
856+
[ 'node_use_dtrace=="true"', {
857+
'libraries': [
858+
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_dtrace.<(OBJ_SUFFIX)',
715859
]
716860
}],
717-
[ 'node_use_v8_platform=="true"', {
718-
'dependencies': [
719-
'deps/v8/src/v8.gyp:v8_libplatform',
720-
],
861+
[ 'OS=="win"', {
862+
'libraries': [
863+
'<(OBJ_PATH)<(OBJ_SEPARATOR)backtrace_win32.<(OBJ_SUFFIX)',
864+
],
865+
}, {
866+
'libraries': [
867+
'<(OBJ_PATH)<(OBJ_SEPARATOR)backtrace_posix.<(OBJ_SUFFIX)',
868+
],
721869
}],
722870
[ 'node_use_dtrace=="true" and OS!="mac" and OS!="linux"', {
723871
'copies': [{
@@ -729,9 +877,60 @@
729877
]},
730878
],
731879
}],
880+
[ 'node_shared_zlib=="false"', {
881+
'dependencies': [
882+
'deps/zlib/zlib.gyp:zlib',
883+
]
884+
}],
885+
[ 'node_shared_openssl=="false" and node_shared=="false"', {
886+
'dependencies': [
887+
'deps/openssl/openssl.gyp:openssl'
888+
]
889+
}],
890+
[ 'node_shared_http_parser=="false"', {
891+
'dependencies': [
892+
'deps/http_parser/http_parser.gyp:http_parser'
893+
]
894+
}],
895+
[ 'node_shared_libuv=="false"', {
896+
'dependencies': [
897+
'deps/uv/uv.gyp:libuv'
898+
]
899+
}],
900+
[ 'node_use_v8_platform=="true"', {
901+
'dependencies': [
902+
'deps/v8/src/v8.gyp:v8_libplatform',
903+
],
904+
}],
732905
['OS=="solaris"', {
733906
'ldflags': [ '-I<(SHARED_INTERMEDIATE_DIR)' ]
734907
}],
908+
[ 'node_use_openssl=="true"', {
909+
'conditions': [
910+
[ 'node_shared_openssl=="false"', {
911+
'conditions': [
912+
# -force_load or --whole-archive are not applicable for
913+
# the static library
914+
[ 'node_target_type!="static_library"', {
915+
'xcode_settings': {
916+
'OTHER_LDFLAGS': [
917+
'-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)',
918+
],
919+
},
920+
'conditions': [
921+
['OS in "linux freebsd" and node_shared=="false"', {
922+
'ldflags': [
923+
'-Wl,--whole-archive,'
924+
'<(OBJ_DIR)/deps/openssl/'
925+
'<(OPENSSL_PRODUCT)',
926+
'-Wl,--no-whole-archive',
927+
],
928+
}],
929+
],
930+
}],
931+
],
932+
}]]
933+
}],
735934
]
736935
}
737936
], # end targets

0 commit comments

Comments
 (0)