-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
build_info.cpp
470 lines (365 loc) · 10.7 KB
/
build_info.cpp
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
/*
Copyright (C) 2015 - 2018 by Iris Morelle <shadowm2006@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "build_info.hpp"
#include "desktop/version.hpp"
#include "game_config.hpp"
#include "filesystem.hpp"
#include "formatter.hpp"
#include "gettext.hpp"
#include "serialization/unicode.hpp"
#include "game_version.hpp"
#include <algorithm>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_ttf.h>
#include <boost/version.hpp>
#ifndef __APPLE__
#include <openssl/crypto.h>
#include <openssl/opensslv.h>
#endif
#include <pango/pangocairo.h>
#ifdef __APPLE__
// apple_notification.mm uses Foundation.h, which is an Objective-C header;
// but CoreFoundation.h is a C header which also defines these.
#include <CoreFoundation/CoreFoundation.h>
#endif
namespace game_config
{
namespace {
struct version_table_manager
{
std::vector<std::string> compiled, linked, names;
std::vector<optional_feature> features;
version_table_manager();
};
const version_table_manager versions;
#if 0
std::string format_version(unsigned a, unsigned b, unsigned c)
{
return formatter() << a << '.' << b << '.' << c;
}
#endif
std::string format_version(const SDL_version& v)
{
return formatter() << static_cast<unsigned>(v.major) << '.'
<< static_cast<unsigned>(v.minor) << '.'
<< static_cast<unsigned>(v.patch);
}
#ifndef __APPLE__
std::string format_openssl_patch_level(uint8_t p)
{
return p <= 26
? std::string(1, 'a' + static_cast<char>(p) - 1)
: "patch" + std::to_string(p);
}
std::string format_openssl_version(long v)
{
int major, minor, fix, patch, status;
std::ostringstream fmt;
//
// The people who maintain OpenSSL are not from this world. I suppose it's
// only fair that I'm the one who gets to try to make sense of their version
// encoding scheme. -- shadowm
//
if(v < 0x0930L) {
// Pre-0.9.3 seems simpler times overall.
minor = v & 0x0F00L >> 8;
fix = v & 0x00F0L >> 4;
patch = v & 0x000FL;
fmt << "0." << minor << '.' << fix;
if(patch) {
fmt << format_openssl_patch_level(patch);
}
} else {
//
// Note that they either assume the major version will never be greater than
// 9, they plan to use hexadecimal digits for versions 10.x.x through
// 15.x.x, or they expect long to be always > 32-bits by then. Who the hell
// knows, really.
//
major = (v & 0xF0000000L) >> 28;
minor = (v & 0x0FF00000L) >> 20;
fix = (v & 0x000FF000L) >> 12;
patch = (v & 0x00000FF0L) >> 4;
status = (v & 0x0000000FL);
if(v < 0x00905100L) {
//
// From wiki.openssl.org (also mentioned in opensslv.h, in the most oblique
// fashion possible):
//
// "Versions between 0.9.3 and 0.9.5 had a version identifier with this interpretation:
// MMNNFFRBB major minor fix final beta/patch"
//
// Both the wiki and opensslv.h fail to accurately list actual version
// numbers that ended up used in the wild -- e.g. 0.9.3a is supposedly
// 0x0090301f when it really was 0x00903101.
//
const uint8_t is_final = (v & 0xF00L) >> 8;
status = is_final ? 0xF : 0;
patch = v & 0xFFL;
} else if(v < 0x00906000L) {
//
// Quoth opensslv.h:
//
// "For continuity reasons (because 0.9.5 is already out, and is coded
// 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level
// part is slightly different, by setting the highest bit. This means
// that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start
// with 0x0090600S..."
//
patch ^= 1 << 7;
}
fmt << major << '.' << minor << '.' << fix;
if(patch) {
fmt << format_openssl_patch_level(patch);
}
if(status == 0x0) {
fmt << "-dev";
} else if(status < 0xF) {
fmt << "-beta" << status;
}
}
return fmt.str();
}
#endif
version_table_manager::version_table_manager()
: compiled(LIB_COUNT, "")
, linked(LIB_COUNT, "")
, names(LIB_COUNT, "")
, features()
{
SDL_version sdl_version;
//
// SDL
//
SDL_VERSION(&sdl_version);
compiled[LIB_SDL] = format_version(sdl_version);
SDL_GetVersion(&sdl_version);
linked[LIB_SDL] = format_version(sdl_version);
names[LIB_SDL] = "SDL";
//
// SDL_image
//
SDL_IMAGE_VERSION(&sdl_version);
compiled[LIB_SDL_IMAGE] = format_version(sdl_version);
const SDL_version* sdl_rt_version = IMG_Linked_Version();
if(sdl_rt_version) {
linked[LIB_SDL_IMAGE] = format_version(*sdl_rt_version);
}
names[LIB_SDL_IMAGE] = "SDL_image";
//
// SDL_mixer
//
SDL_MIXER_VERSION(&sdl_version);
compiled[LIB_SDL_MIXER] = format_version(sdl_version);
sdl_rt_version = Mix_Linked_Version();
if(sdl_rt_version) {
linked[LIB_SDL_MIXER] = format_version(*sdl_rt_version);
}
names[LIB_SDL_MIXER] = "SDL_mixer";
//
// SDL_ttf
//
SDL_TTF_VERSION(&sdl_version);
compiled[LIB_SDL_TTF] = format_version(sdl_version);
sdl_rt_version = TTF_Linked_Version();
if(sdl_rt_version) {
linked[LIB_SDL_TTF] = format_version(*sdl_rt_version);
}
names[LIB_SDL_TTF] = "SDL_ttf";
//
// Boost
//
compiled[LIB_BOOST] = BOOST_LIB_VERSION;
std::replace(compiled[LIB_BOOST].begin(), compiled[LIB_BOOST].end(), '_', '.');
names[LIB_BOOST] = "Boost";
//
// OpenSSL/libcrypto
//
#ifndef __APPLE__
compiled[LIB_CRYPTO] = format_openssl_version(OPENSSL_VERSION_NUMBER);
linked[LIB_CRYPTO] = format_openssl_version(SSLeay());
names[LIB_CRYPTO] = "OpenSSL/libcrypto";
#endif
//
// Cairo
//
compiled[LIB_CAIRO] = CAIRO_VERSION_STRING;
linked[LIB_CAIRO] = cairo_version_string();
names[LIB_CAIRO] = "Cairo";
//
// Pango
//
compiled[LIB_PANGO] = PANGO_VERSION_STRING;
linked[LIB_PANGO] = pango_version_string();
names[LIB_PANGO] = "Pango";
//
// Features table.
//
features.emplace_back(N_("feature^JPG screenshots"));
#ifdef SDL_IMAGE_VERSION_ATLEAST
#if SDL_IMAGE_VERSION_ATLEAST(2, 0, 2)
features.back().enabled = true;
#endif
#endif
features.emplace_back(N_("feature^Lua console completion"));
#ifdef HAVE_HISTORY
features.back().enabled = true;
#endif
features.emplace_back(N_("feature^Legacy bidirectional rendering"));
#ifdef HAVE_FRIBIDI
features.back().enabled = true;
#endif
#ifdef _X11
features.emplace_back(N_("feature^D-Bus notifications back end"));
#ifdef HAVE_LIBDBUS
features.back().enabled = true;
#endif
#endif /* _X11 */
#ifdef _WIN32
// Always compiled in.
features.emplace_back(N_("feature^Win32 notifications back end"));
features.back().enabled = true;
#endif
#ifdef __APPLE__
// Always compiled in.
features.emplace_back(N_("feature^Cocoa notifications back end"));
features.back().enabled = true;
#endif /* __APPLE__ */
}
const std::string empty_version = "";
} // end anonymous namespace 1
std::vector<optional_feature> optional_features_table()
{
std::vector<optional_feature> res = versions.features;
for(std::size_t k = 0; k < res.size(); ++k) {
res[k].name = _(res[k].name.c_str());
}
return res;
}
const std::string& library_build_version(LIBRARY_ID lib)
{
if(lib >= LIB_COUNT) {
return empty_version;
}
return versions.compiled[lib];
}
const std::string& library_runtime_version(LIBRARY_ID lib)
{
if(lib >= LIB_COUNT) {
return empty_version;
}
return versions.linked[lib];
}
const std::string& library_name(LIBRARY_ID lib)
{
if(lib >= LIB_COUNT) {
return empty_version;
}
return versions.names[lib];
}
namespace {
bool strlen_comparator(const std::string& a, const std::string& b)
{
return a.length() < b.length();
}
std::size_t max_strlen(const std::vector<std::string>& strs)
{
const std::vector<std::string>::const_iterator it =
std::max_element(strs.begin(), strs.end(), strlen_comparator);
return it != strs.end() ? it->length() : 0;
}
std::string report_heading(const std::string& heading_text)
{
return heading_text + '\n' + std::string(utf8::size(heading_text), '=') + '\n';
}
} // end anonymous namespace 2
std::string library_versions_report()
{
std::ostringstream o;
const std::size_t col2_start = max_strlen(versions.names) + 2;
const std::size_t col3_start = max_strlen(versions.compiled) + 1;
for(unsigned n = 0; n < LIB_COUNT; ++n)
{
const std::string& name = versions.names[n];
const std::string& compiled = versions.compiled[n];
const std::string& linked = versions.linked[n];
if(name.empty()) {
continue;
}
o << name << ": ";
const std::size_t pos2 = name.length() + 2;
if(pos2 < col2_start) {
o << std::string(col2_start - pos2, ' ');
}
o << compiled;
if(!linked.empty()) {
const std::size_t pos3 = compiled.length() + 1;
if(pos3 < col3_start) {
o << std::string(col3_start - pos3, ' ');
}
o << " (runtime " << linked << ")";
}
o << '\n';
}
return o.str();
}
std::string optional_features_report()
{
// Yes, it's for stdout/stderr but we still want the localized version so
// that the context prefixes are stripped.
const std::vector<optional_feature>& features = optional_features_table();
std::size_t col2_start = 0;
for(std::size_t k = 0; k < features.size(); ++k)
{
col2_start = std::max(col2_start, features[k].name.length() + 2);
}
std::ostringstream o;
for(std::size_t k = 0; k < features.size(); ++k)
{
const optional_feature& f = features[k];
o << f.name << ": ";
const std::size_t pos2 = f.name.length() + 2;
if(pos2 < col2_start) {
o << std::string(col2_start - pos2, ' ');
}
o << (f.enabled ? "yes" : "no") << '\n';
}
return o.str();
}
std::string full_build_report()
{
std::ostringstream o;
o << "The Battle for Wesnoth version " << game_config::revision << '\n'
<< "Running on " << desktop::os_version() << '\n'
<< '\n'
<< report_heading("Game paths")
<< '\n'
<< "Data dir: " << filesystem::sanitize_path(game_config::path) << '\n'
<< "User config dir: " << filesystem::sanitize_path(filesystem::get_user_config_dir()) << '\n'
<< "User data dir: " << filesystem::sanitize_path(filesystem::get_user_data_dir()) << '\n'
<< "Saves dir: " << filesystem::sanitize_path(filesystem::get_saves_dir()) << '\n'
<< "Add-ons dir: " << filesystem::sanitize_path(filesystem::get_addons_dir()) << '\n'
<< "Cache dir: " << filesystem::sanitize_path(filesystem::get_cache_dir()) << '\n'
<< '\n'
<< report_heading("Libraries")
<< '\n'
<< game_config::library_versions_report()
<< '\n'
<< report_heading("Features")
<< '\n'
<< game_config::optional_features_report();
return o.str();
}
} // end namespace game_config