-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRubySetupSystem.rb
307 lines (233 loc) · 8.74 KB
/
RubySetupSystem.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# A ruby script for downloading and installing C++ project dependencies
# Made by Henri Hyyryläinen
require_relative 'RubyCommon.rb'
require_relative 'DepGlobber.rb'
require_relative 'ToolChain.rb'
require_relative 'VSVersion.rb'
require_relative 'PrecompiledDB.rb'
require 'optparse'
require 'fileutils'
require 'etc'
require 'os'
require 'open3'
require 'pathname'
require 'zip'
#
# Parse options
#
$options = {}
OptionParser.new do |opts|
# Default banner is fine, scripts calling this can add their options and their banners
# will be correct. See DockerImageCreator.rb for an example
# opts.banner = "Usage: Setup.rb [OPTIONS]"
opts.on('--[no-]sudo', 'Run commands that need sudo. ' \
'This may be needed to run successfuly') do |b|
$options[:sudo] = b
end
opts.on('--only-project', 'Skip all dependencies setup') do |_b|
$options[:onlyProject] = true
end
opts.on('--no-subproject-deps', "Don't setup dependencies in a subproject " \
'(that uses RubySetupSystem)') do |_b|
$options[:noSubProjectDeps] = true
end
opts.on('--only-deps', 'Skip the main project setup') do |_b|
$options[:onlyDeps] = true
end
# TODO: should this be passed to sub setups
opts.on('--only-dep a,b,c', Array, 'Only setup the specified dependencies') do |list|
$options[:only] = list
end
# TODO: should this be passed to sub setups
opts.on('--skip-dep a,b,c', Array, 'Skip setting up the specified dependencies') do |list|
$options[:skip] = list
end
opts.on('--no-packagemanager', 'Skip using the system package manager ' \
'to download libraries') do |_b|
$options[:noPackager] = true
end
opts.on('--pretend-linux OS', 'Pretend that setup is ran on specified Linux OS. ' \
"A good choice is 'fedora' for getting package names if " \
"your OS isn't supported by this setup") do |os|
$pretendLinux = os
end
opts.on('--no-updates', 'Skips downloading dependencies / making sure they ' \
'are up to date') do |_b|
$options[:noUpdates] = true
end
opts.on('-j threads', '--parallel-compiles threads',
'Number of simultaneous compiler instances to run') do |j|
$options[:parallel] = j.to_i
end
opts.on('--fully-parallel-project-compile',
'Even if not all cores are used for compiling dependencies (-j flag) the main ' \
'project is compiled with all cores') do |_b|
$options[:projectFullParallel] = true
end
opts.on('--project-parallel threads',
'Restricts fully parallel project compile to specific number of threads') do |t|
$options[:projectFullParallelLimit] = t.to_i
end
opts.on('--[no-]precompiled', 'Run with or without precompiled dependencies') do |b|
$options[:precompiled] = b
end
opts.on('-h', '--help', 'Show this message') do
puts opts
puts extraHelp if defined? extraHelp
exit
end
# If you want to add flags they need to be in this method instead of parseExtraArgs
getExtraOptions opts if defined? getExtraOptions
end.parse!
unless ARGV.empty?
# Let application specific args to be parsed
parseExtraArgs if defined? parseExtraArgs
unless ARGV.empty?
onError('Unkown arguments. See --help. This was left unparsed: ' + ARGV.join(' '))
end
end
### Setup variables
CMakeBuildType = 'RelWithDebInfo'.freeze
$compileThreads = $options.include?(:parallel) ? $options[:parallel] : Etc.nprocessors
if $compileThreads > Etc.nprocessors
$compileThreads = Etc.nprocessors
puts "Limiting parallel compile to detected number of CPU cores: #{$compileThreads}"
end
# If set to false won't install libs that need sudo
DoSudoInstalls = $options.include?(:sudo) ? $options[:sudo] : true
# If true dependencies won't be updated from remote repositories
SkipPullUpdates = $options[:noUpdates] ? true : false
# If true skips all dependencies
OnlyMainProject = $options[:onlyProject] ? true : false
# If true skips the main project
OnlyDependencies = $options[:onlyDeps] ? true : false
# If specified only deps on this list are ran (case insensitive)
OnlySpecificDeps = $options[:only] || nil
# If specified these dependencies are skipped (case insensitive)
NoSpecificDeps = $options[:skip] || nil
# If true skips running package installs
SkipPackageManager = $options[:noPackager] ? true : false
# If true new version of depot tools and breakpad won't be fetched on install
NoBreakpadUpdateOnWindows = false
# This is either true, false, or "ask" (if not interactive ask turns to false)
# Not constant as this is changed by getSupportedPrecompiledPackage after asking the user
$usePrecompiled = if $options.include?(:precompiled)
if $options[:precompiled]
true
else
false
end
else
if !$stdout.isatty
warning '--[no-]precompiled parameter give and not running in' \
'interactive terminal, disabling precompiled'
false
else
'ask'
end
end
# On windows visual studio will be automatically opened if required
AutoOpenVS = true
# Set tool chain
TC = if OS.windows?
# Leviathan needs by default vs 2017
WindowsMSVC.new(VisualStudio2017.new)
elsif OS.linux?
LinuxNative.new
else
onError 'No toolchain configured for this platform!'
end
# TODO: create a variable for running the package manager on linux if possible
puts "Using toolchain: #{TC.name}"
### Commandline handling
# TODO: add this
if OS.linux?
HasDNF = !which('dnf').nil?
info "Pretending that current Linux OS is: #{$pretendLinux}" if $pretendLinux
else
HasDNF = false
end
# This verifies that CurrentDir is good and assigns it to CurrentDir
CurrentDir = checkRunFolder Dir.pwd
ProjectDir = projectFolder CurrentDir
# This function formats the current options like threads etc. to be
# passed to a dependency that also uses RubySetupSystem
# example of use: system("ruby Setup.rb #{passOptionsToSubRubySetupSystemProject}")
# Note: the unsafe system call needs to be used as the child project might want user input as
# for precompiled selection etc.
def passOptionsToSubRubySetupSystemProject
opts = []
unless $usePrecompiled.nil?
if $usePrecompiled == false
opts.push '--no-precompiled'
elsif $usePrecompiled == true
opts.push '--precompiled'
end
end
opts.push "-j #{$options[:parallel]}" if $options.include?(:parallel)
if $options.include?(:sudo)
if $options[:sudo]
opts.push '--sudo'
else
opts.push '--no-sudo'
end
end
opts.push '--no-packagemanager' if $options.include?(:noPackager)
opts.push '--no-updates' if $options.include?(:noUpdates)
# This option is handled here (translated to the right option)
opts.push '--only-project' if $options.include?(:noSubProjectDeps)
if $pretendLinux
opts.push '--pretend-linux'
opts.push $pretendLinux
end
opts
end
#
# Initial options / status print
#
info "Running in dir '#{CurrentDir}'"
puts "Project dir is '#{ProjectDir}'"
info 'Using dnf package manager' if HasDNF
puts "Using #{$compileThreads} threads to compile, configuration: #{CMakeBuildType}"
if $options.include?(:projectFullParallel)
puts "Main project uses all cores (#{Etc.nprocessors})"
if $options.include?(:projectFullParallelLimit)
if $options[:projectFullParallelLimit] > Etc.nprocessors
puts 'Limiting project parallel to number of detected CPU cores.'
$options[:projectFullParallelLimit] = Etc.nprocessors
end
puts "With extra limit set to #{$options[:projectFullParallelLimit]}"
end
end
puts "With use precompiled set to: #{$usePrecompiled}"
# Set required environment variables with the tool chain
# Most toolchains don't need this
TC.setupEnv
puts ''
puts ''
require_relative 'Installer.rb'
require_relative 'RubyCommon.rb'
require_relative 'WindowsHelpers.rb'
require_relative 'CustomInstaller.rb'
# Returns true if sudo should be enabled
def shouldUseSudo(localOption, warnIfMismatch = true)
if localOption
unless DoSudoInstalls
if warnIfMismatch
warning "Sudo is globally disabled, but a command should be ran as sudo.\n" \
'If something breaks please rerun with sudo allowed.'
end
return false
end
return true
end
false
end
# Returns "sudo" or "" based on options
def getSudoCommand(localOption, warnIfMismatch = true)
return '' unless shouldUseSudo localOption, warnIfMismatch
'sudo '
end
require_relative 'LibraryCopy.rb'
require_relative 'Dependency.rb'
# Library installs are now in separate files in the Libraries sub directory