4
4
# For full terms see the included LICENSE file.
5
5
6
6
require 'mkmf'
7
+ require 'timeout'
7
8
8
9
RbConfig ::MAKEFILE_CONFIG [ 'CC' ] = ENV [ 'CC' ] if ENV [ 'CC' ]
9
10
@@ -23,6 +24,26 @@ def sys(cmd)
23
24
ret
24
25
end
25
26
27
+ # Thrown when we detect CMake is taking too long and we killed it
28
+ class CMakeTimeout < StandardError
29
+ end
30
+
31
+ def self . run_cmake ( timeout , args )
32
+ # Set to process group so we can kill it and its children
33
+ pid = Process . spawn ( "cmake #{ args } " , pgroup : true )
34
+
35
+ Timeout . timeout ( timeout ) do
36
+ Process . waitpid ( pid )
37
+ end
38
+
39
+ rescue Timeout ::Error
40
+ # Kill it, #detach is essentially a background wait, since we don't actually
41
+ # care about waiting for it now
42
+ Process . kill ( -9 , pid )
43
+ Process . detach ( pid )
44
+ raise CMakeTimeout . new ( "cmake has exceeded its timeout of #{ timeout } s" )
45
+ end
46
+
26
47
MAKE = if Gem . win_platform?
27
48
# On Windows, Ruby-DevKit only has 'make'.
28
49
find_executable ( 'make' )
@@ -80,7 +101,7 @@ def sys(cmd)
80
101
Dir . chdir ( "build" ) do
81
102
# On Windows, Ruby-DevKit is MSYS-based, so ensure to use MSYS Makefiles.
82
103
generator = "-G \" MSYS Makefiles\" " if Gem . win_platform?
83
- sys ( "cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo #{ cmake_flags . join ( ' ' ) } #{ generator } ")
104
+ run_cmake ( 5 * 60 , " .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo #{ cmake_flags . join ( ' ' ) } #{ generator } ")
84
105
sys ( MAKE )
85
106
86
107
# "normal" libraries (and libgit2 builds) get all these when they build but we're doing it
0 commit comments