From dd428129687899fd2d37f139064852ef4b16d077 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Mon, 30 Jul 2018 00:16:56 -0400 Subject: [PATCH 1/3] build: prevent C++ linker from overwriting executable Running `make run-ci` with multiple jobs, it is possible for the C++ linker to be invoked while build-addons is running, this can result in intermittent ENOENT failures when spawning `nodeGyp`. To prevent this, originally provide a different name for the executable, and rename it to the correct name only after the link completes successfully. Fixes 22006. Kinda. Sorta. --- node.gyp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/node.gyp b/node.gyp index 8c42474bbed90a..922052e341b8c7 100644 --- a/node.gyp +++ b/node.gyp @@ -301,6 +301,12 @@ # the executable and rename it back to node.exe later 'product_name': '<(node_core_target_name)-win', }], + [ 'OS=="mac" or OS=="linux"', { + # On Unix builds, the build may replace the executable while it is + # running. To avoid this, we provide a different PRODUCT_NAME for + # the executable and rename it back to node later + 'product_name': '<(node_core_target_name)-unix', + }], ], }, { @@ -899,6 +905,34 @@ } ], ] }, + { + # When building executable in Mac OS/X, in order to avoid overwriting + # the executable while it it running, build it with a different name + # and then rename it back to node. + 'target_name': 'rename_node_bin_mac', + 'type': 'none', + 'dependencies': [ + '<(node_core_target_name)', + ], + 'conditions': [ + [ 'OS=="mac"', { + 'actions': [ + { + 'action_name': 'rename_node_bin_mac', + 'inputs': [ + '<(PRODUCT_DIR)/<(node_core_target_name)-unix' + ], + 'outputs': [ + '<(PRODUCT_DIR)/<(node_core_target_name)', + ], + 'action': [ + 'mv', '<@(_inputs)', '<@(_outputs)', + ], + }, + ], + } ], + ] + }, { # When using shared lib to build executable in Windows, in order to avoid # filename collision, the executable name is node-win.exe. Need to rename From eb76e9fb0b9468e8cd2f7790bded527ac08ef1b8 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Sat, 18 Aug 2018 13:13:09 -0400 Subject: [PATCH 2/3] make it work on linux --- node.gyp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/node.gyp b/node.gyp index 922052e341b8c7..b2fba466caf7dc 100644 --- a/node.gyp +++ b/node.gyp @@ -909,16 +909,16 @@ # When building executable in Mac OS/X, in order to avoid overwriting # the executable while it it running, build it with a different name # and then rename it back to node. - 'target_name': 'rename_node_bin_mac', + 'target_name': 'rename_node_bin_unix', 'type': 'none', 'dependencies': [ '<(node_core_target_name)', ], 'conditions': [ - [ 'OS=="mac"', { + [ 'OS=="mac" or OS=="linux"', { 'actions': [ { - 'action_name': 'rename_node_bin_mac', + 'action_name': 'rename_node_bin_unix', 'inputs': [ '<(PRODUCT_DIR)/<(node_core_target_name)-unix' ], @@ -968,6 +968,7 @@ 'dependencies': [ '<(node_lib_target_name)', 'rename_node_bin_win', + 'rename_node_bin_unix', 'deps/gtest/gtest.gyp:gtest', 'node_js2c#host', 'node_dtrace_header', From 0437cef1695a137b55c9f5594bdcbc7f77af76ac Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Sat, 18 Aug 2018 14:00:40 -0400 Subject: [PATCH 3/3] refactor; and handle all non-windows platforms as 'unix' --- node.gyp | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/node.gyp b/node.gyp index b2fba466caf7dc..a74508d22457ee 100644 --- a/node.gyp +++ b/node.gyp @@ -301,7 +301,7 @@ # the executable and rename it back to node.exe later 'product_name': '<(node_core_target_name)-win', }], - [ 'OS=="mac" or OS=="linux"', { + [ 'OS!="win"', { # On Unix builds, the build may replace the executable while it is # running. To avoid this, we provide a different PRODUCT_NAME for # the executable and rename it back to node later @@ -906,24 +906,24 @@ ] }, { - # When building executable in Mac OS/X, in order to avoid overwriting - # the executable while it it running, build it with a different name - # and then rename it back to node. - 'target_name': 'rename_node_bin_unix', + 'target_name': 'rename_node_bin', 'type': 'none', 'dependencies': [ '<(node_core_target_name)', ], 'conditions': [ - [ 'OS=="mac" or OS=="linux"', { + # When using shared lib to build executable in Windows, in order to + # avoid filename collision, the executable name is node-win.exe. Need + # to rename it back to node.exe + [ 'OS=="win" and node_intermediate_lib_type=="shared_library"', { 'actions': [ { - 'action_name': 'rename_node_bin_unix', + 'action_name': 'rename_node_bin_win', 'inputs': [ - '<(PRODUCT_DIR)/<(node_core_target_name)-unix' + '<(PRODUCT_DIR)/<(node_core_target_name)-win.exe' ], 'outputs': [ - '<(PRODUCT_DIR)/<(node_core_target_name)', + '<(PRODUCT_DIR)/<(node_core_target_name).exe', ], 'action': [ 'mv', '<@(_inputs)', '<@(_outputs)', @@ -931,27 +931,18 @@ }, ], } ], - ] - }, - { - # When using shared lib to build executable in Windows, in order to avoid - # filename collision, the executable name is node-win.exe. Need to rename - # it back to node.exe - 'target_name': 'rename_node_bin_win', - 'type': 'none', - 'dependencies': [ - '<(node_core_target_name)', - ], - 'conditions': [ - [ 'OS=="win" and node_intermediate_lib_type=="shared_library"', { + # When building executable on Unix operating systems, in order to + # avoid overwriting the executable while it it running, build it with + # a different name and then rename it back to node. + [ 'OS!="win"', { 'actions': [ { - 'action_name': 'rename_node_bin_win', + 'action_name': 'rename_node_bin_unix', 'inputs': [ - '<(PRODUCT_DIR)/<(node_core_target_name)-win.exe' + '<(PRODUCT_DIR)/<(node_core_target_name)-unix' ], 'outputs': [ - '<(PRODUCT_DIR)/<(node_core_target_name).exe', + '<(PRODUCT_DIR)/<(node_core_target_name)', ], 'action': [ 'mv', '<@(_inputs)', '<@(_outputs)', @@ -967,8 +958,7 @@ 'dependencies': [ '<(node_lib_target_name)', - 'rename_node_bin_win', - 'rename_node_bin_unix', + 'rename_node_bin', 'deps/gtest/gtest.gyp:gtest', 'node_js2c#host', 'node_dtrace_header',