xref: /aosp_15_r20/external/cronet/base/version_info/version_info.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_VERSION_INFO_VERSION_INFO_H_
6 #define BASE_VERSION_INFO_VERSION_INFO_H_
7 
8 #include <string>
9 #include <string_view>
10 
11 #include "base/sanitizer_buildflags.h"
12 #include "base/version_info/channel.h"
13 #include "base/version_info/version_info_values.h"
14 #include "build/branding_buildflags.h"
15 #include "build/build_config.h"
16 
17 namespace base {
18 class Version;
19 }
20 
21 namespace version_info {
22 
23 // Returns the product name, e.g. "Chromium" or "Google Chrome".
GetProductName()24 constexpr std::string_view GetProductName() {
25   return PRODUCT_NAME;
26 }
27 
28 // Returns the version number, e.g. "6.0.490.1".
GetVersionNumber()29 constexpr std::string_view GetVersionNumber() {
30   return PRODUCT_VERSION;
31 }
32 
33 // Returns the major component (aka the milestone) of the version as an int,
34 // e.g. 6 when the version is "6.0.490.1".
35 int GetMajorVersionNumberAsInt();
36 
37 // Like GetMajorVersionNumberAsInt(), but returns a string.
38 std::string GetMajorVersionNumber();
39 
40 // Returns the result of GetVersionNumber() as a base::Version.
41 const base::Version& GetVersion();
42 
43 // Returns a version control specific identifier of this release.
GetLastChange()44 constexpr std::string_view GetLastChange() {
45   return LAST_CHANGE;
46 }
47 
48 // Returns whether this is an "official" release of the current version, i.e.
49 // whether knowing GetVersionNumber() is enough to completely determine what
50 // GetLastChange() is.
IsOfficialBuild()51 constexpr bool IsOfficialBuild() {
52   return IS_OFFICIAL_BUILD;
53 }
54 
55 // Returns the OS type, e.g. "Windows", "Linux", "FreeBSD", ...
GetOSType()56 constexpr std::string_view GetOSType() {
57 #if BUILDFLAG(IS_WIN)
58   return "Windows";
59 #elif BUILDFLAG(IS_IOS)
60   return "iOS";
61 #elif BUILDFLAG(IS_MAC)
62   return "Mac OS X";
63 #elif BUILDFLAG(IS_CHROMEOS)
64 #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
65   return "ChromeOS";
66 #else
67   return "ChromiumOS";
68 #endif
69 #elif BUILDFLAG(IS_ANDROID)
70   return "Android";
71 #elif BUILDFLAG(IS_LINUX)
72   return "Linux";
73 #elif BUILDFLAG(IS_FREEBSD)
74   return "FreeBSD";
75 #elif BUILDFLAG(IS_OPENBSD)
76   return "OpenBSD";
77 #elif BUILDFLAG(IS_SOLARIS)
78   return "Solaris";
79 #elif BUILDFLAG(IS_FUCHSIA)
80   return "Fuchsia";
81 #else
82   return "Unknown";
83 #endif
84 }
85 
86 // Returns a list of sanitizers enabled in this build.
GetSanitizerList()87 constexpr std::string_view GetSanitizerList() {
88   return ""
89 #if defined(ADDRESS_SANITIZER)
90          "address "
91 #endif
92 #if BUILDFLAG(IS_HWASAN)
93          "hwaddress "
94 #endif
95 #if defined(LEAK_SANITIZER)
96          "leak "
97 #endif
98 #if defined(MEMORY_SANITIZER)
99          "memory "
100 #endif
101 #if defined(THREAD_SANITIZER)
102          "thread "
103 #endif
104 #if defined(UNDEFINED_SANITIZER)
105          "undefined "
106 #endif
107       ;
108 }
109 
110 }  // namespace version_info
111 
112 #endif  // BASE_VERSION_INFO_VERSION_INFO_H_
113