Distro.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- Distro.h - Linux distribution detection support --------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_DRIVER_DISTRO_H
  14. #define LLVM_CLANG_DRIVER_DISTRO_H
  15. #include "llvm/ADT/Triple.h"
  16. #include "llvm/Support/VirtualFileSystem.h"
  17. namespace clang {
  18. namespace driver {
  19. /// Distro - Helper class for detecting and classifying Linux distributions.
  20. ///
  21. /// This class encapsulates the clang Linux distribution detection mechanism
  22. /// as well as helper functions that match the specific (versioned) results
  23. /// into wider distribution classes.
  24. class Distro {
  25. public:
  26. enum DistroType {
  27. // Special value means that no detection was performed yet.
  28. UninitializedDistro,
  29. // NB: Releases of a particular Linux distro should be kept together
  30. // in this enum, because some tests are done by integer comparison against
  31. // the first and last known member in the family, e.g. IsRedHat().
  32. AlpineLinux,
  33. ArchLinux,
  34. DebianLenny,
  35. DebianSqueeze,
  36. DebianWheezy,
  37. DebianJessie,
  38. DebianStretch,
  39. DebianBuster,
  40. DebianBullseye,
  41. DebianBookworm,
  42. DebianTrixie,
  43. Exherbo,
  44. RHEL5,
  45. RHEL6,
  46. RHEL7,
  47. Fedora,
  48. Gentoo,
  49. OpenSUSE,
  50. UbuntuHardy,
  51. UbuntuIntrepid,
  52. UbuntuJaunty,
  53. UbuntuKarmic,
  54. UbuntuLucid,
  55. UbuntuMaverick,
  56. UbuntuNatty,
  57. UbuntuOneiric,
  58. UbuntuPrecise,
  59. UbuntuQuantal,
  60. UbuntuRaring,
  61. UbuntuSaucy,
  62. UbuntuTrusty,
  63. UbuntuUtopic,
  64. UbuntuVivid,
  65. UbuntuWily,
  66. UbuntuXenial,
  67. UbuntuYakkety,
  68. UbuntuZesty,
  69. UbuntuArtful,
  70. UbuntuBionic,
  71. UbuntuCosmic,
  72. UbuntuDisco,
  73. UbuntuEoan,
  74. UbuntuFocal,
  75. UbuntuGroovy,
  76. UbuntuHirsute,
  77. UbuntuImpish,
  78. UbuntuJammy,
  79. UbuntuKinetic,
  80. UbuntuLunar,
  81. UnknownDistro
  82. };
  83. private:
  84. /// The distribution, possibly with specific version.
  85. DistroType DistroVal;
  86. public:
  87. /// @name Constructors
  88. /// @{
  89. /// Default constructor leaves the distribution unknown.
  90. Distro() : DistroVal() {}
  91. /// Constructs a Distro type for specific distribution.
  92. Distro(DistroType D) : DistroVal(D) {}
  93. /// Detects the distribution using specified VFS.
  94. explicit Distro(llvm::vfs::FileSystem &VFS, const llvm::Triple &TargetOrHost);
  95. bool operator==(const Distro &Other) const {
  96. return DistroVal == Other.DistroVal;
  97. }
  98. bool operator!=(const Distro &Other) const {
  99. return DistroVal != Other.DistroVal;
  100. }
  101. bool operator>=(const Distro &Other) const {
  102. return DistroVal >= Other.DistroVal;
  103. }
  104. bool operator<=(const Distro &Other) const {
  105. return DistroVal <= Other.DistroVal;
  106. }
  107. /// @}
  108. /// @name Convenience Predicates
  109. /// @{
  110. bool IsRedhat() const {
  111. return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
  112. }
  113. bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
  114. bool IsDebian() const {
  115. return DistroVal >= DebianLenny && DistroVal <= DebianTrixie;
  116. }
  117. bool IsUbuntu() const {
  118. return DistroVal >= UbuntuHardy && DistroVal <= UbuntuLunar;
  119. }
  120. bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }
  121. bool IsGentoo() const { return DistroVal == Gentoo; }
  122. /// @}
  123. };
  124. } // end namespace driver
  125. } // end namespace clang
  126. #endif
  127. #ifdef __GNUC__
  128. #pragma GCC diagnostic pop
  129. #endif